In this example we will show how to create a plugin instruments and effects and connect them using MIDI and audio connections.
The signal path for this example:
[System MIDI Input] -> [Instrument Plugin] -> [Effect Plugin] -> [System Audio Output]
First we will create the MIDI input:
local midiInput = Midi.Input("myinput")
The Midi.Input object represents a system MIDI input to the script, at creation time we specify the name of the connection as it will appear to the system. If this line executes we should be able to see the input, in e.g. QJackCtl.
Now we can connect this input to a MIDI hardware device or other software application.
The next step is to create the instrument plugin. When we create an LV2 plugin we have to specify the URI that identifies which plugin we want, in this case we have chosen the Monosynth LV2 instrument from Calf Studio Gear.
local synth = Lv2.Plugin("http://calf.sourceforge.net/plugins/Monosynth")
Now we use the plugin's connectMidi method to connect the MIDI input to our plugin.
Now we want to enhance the sound of our instrument plugin by adding an effect plugin to our signal chain, in this case we have chosen the Reverb plugin, also from the CALF plugin suite. We create the plugin in the exact same way we created the instrument plugin, by specifying its URI:
local effect = Lv2.Plugin("http://calf.sourceforge.net/plugins/Reverb")
Now we use the effect plugin's connect method to make the audio connections between the output of the instrument and the input of the effect. Note there will be two audio connections in this case because both plugins are stereo, the connect method will create both connections:
At this point we can play MIDI notes on the instrument and audio would flow into the reverb effect but we would still not hear anything - the effect plugin's audio outputs are not connected to anything.
To fix this we create a StereoOutput object that connects to the main system outputs:
local mainOutput = Audio.StereoOutput("main", "system:playback_1", "system:playback_2")
[output connection image]
Finally we use the output's connect method in order to make the audio connections from the effect plugin to the system outputs.
At this point if we ran the script it would create our desired signal path and then immediately terminate. There are no scheduled events of any kind in this script so the script process does not know to stay alive.
To solve this we issue the System.stayAlive() command which keeps the script process active until:
Now the script is complete, any MIDI notes we send to the input will play on the synthesizer plugin thru the effect output to the system outputs.
local midiInput = Midi.Input("myinput") local synth = Lv2.Plugin("http://calf.sourceforge.net/plugins/Monosynth") synth.connectMidi(midiInput) local effect = Lv2.Plugin("http://calf.sourceforge.net/plugins/Reverb") effect.connect(synth) local mainOutput = Audio.StereoOutput("main", "system:playback_1", "system:playback_2") mainOutput.connect(effect) System.stayAlive()