From c92d5580670452a48a36184a2cebdec4c60464f4 Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Tue, 18 May 2021 05:04:27 +0200 Subject: [PATCH] added some API examples to the README --- README.md | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/README.md b/README.md index bca9efb..7c91398 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,72 @@ Here a short list of features: * Extensible framework for quickly developing new nodes at compile time * A comprehensive automated test suite +## API Examples + +### Raw `NodeConfigurator` API + +This API is the most low level API provided by HexoDSP. +It shows how to create nodes and connect them. +The execution of the nodes in the audio thread is +controlled by a `NodeProg`, which defines the order +the nodes are executed in. + +This only showcases the non-realtime generation of audio +samples. For a real time application of this library please +refer to the examples that come with this library. + + use hexosynth::*; + + let (mut node_conf, mut node_exec) = new_node_engine(); + + node_conf.create_node(NodeId::Sin(0)); + node_conf.create_node(NodeId::Amp(0)); + + let mut prog = node_conf.rebuild_node_ports(); + + node_conf.add_prog_node(&mut prog, &NodeId::Sin(0)); + node_conf.add_prog_node(&mut prog, &NodeId::Amp(0)); + + node_conf.set_prog_node_exec_connection( + &mut prog, + (NodeId::Amp(0), NodeId::Amp(0).inp("inp").unwrap()), + (NodeId::Sin(0), NodeId::Sin(0).out("sig").unwrap())); + + node_conf.upload_prog(prog, true); + + let (out_l, out_r) = node_exec.test_run(0.1, false); + +### Hexagonal Matrix API + +This is a short overview of the API provided by the +hexagonal Matrix API, which is the primary API used +inside [HexoSynth](https://github.com/WeirdConstructor/HexoSynth). + +This only showcases the non-realtime generation of audio +samples. For a real time application of this library please +refer to the examples that come with this library. + + use hexodsp::*; + + let (node_conf, mut node_exec) = new_node_engine(); + let mut matrix = Matrix::new(node_conf, 3, 3); + + + let sin = NodeId::Sin(0); + let amp = NodeId::Amp(0); + matrix.place(0, 0, Cell::empty(sin) + .out(None, None, sin.out("sig"))); + matrix.place(0, 1, Cell::empty(amp) + .input(amp.inp("inp"), None, None)); + matrix.sync().unwrap(); + + let gain_p = amp.inp_param("gain").unwrap(); + matrix.set_param(gain_p, SAtom::param(0.25)); + + let (out_l, out_r) = node_exec.test_run(0.11, true); + // out_l and out_r contain two channels of audio + // samples now. + ## State of Development As of 2021-05-18: The architecture and it's functionality have been mostly