Each "instrument"/module is an object filled with already-connected and setup audioNodes.
A very simple instrument might look like this:
{
oscillator: OscillatorNode,
filter: BiquadFilterNode,
gain: GainNode
}
But of course the keys to the nodes are arbitrary, you might have 12 filter nodes in this instrument, use whatever pattern you like for naming these things. In this example, the nodes might be connected like so:
oscillator.connect(filter)
filter.connect(gain)
The instrument should respond to the following methods:
keys()=> returns list of keys to audioNodes.connect(destination)=> connect the output nodes to a destination or other nodes. In the example this would bethis.gain.connect(destination).start()=> calls start() on all the source nodes. In the example, this would bethis.oscillator.start().export()=> returns JSON respresentation of the instrument state.import(data)=> loads a JSON of the instrument state.
An example of an implemented instrument
Multiple modules could be chained together into complex instruments, without having to pay attention to the low level details of connecting nodes or setting values to good defaults.
TODO:
- needs some way of identifying what type of node something is (maybe check what it responds to?)
- related to that, some way of programmatically generating UI for each node. That way given an instrument you could create a basic html unstyled component and then go from there.
- set values on import through A-Param methods