diff options
author | R <@gmail.com> | 2020-02-26 20:30:58 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2020-02-26 20:39:21 +0100 |
commit | b10d9cf09bf6150f0ba0eae5dc34fd8db8b2fa91 (patch) | |
tree | dc1d372d236b370254f22d8b7966e6658de8099b /share | |
parent | 8702ff2189665b473918ed60f34b6be4010a06f7 (diff) |
Add example Lua DSP script with multiple MIDI outputs
Diffstat (limited to 'share')
-rw-r--r-- | share/scripts/_midigenerator_multi_ports.lua | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/share/scripts/_midigenerator_multi_ports.lua b/share/scripts/_midigenerator_multi_ports.lua new file mode 100644 index 0000000000..a61db04e5a --- /dev/null +++ b/share/scripts/_midigenerator_multi_ports.lua @@ -0,0 +1,48 @@ +ardour { + ["type"] = "dsp", + name = "MIDI generator with multiple ports", + category = "Example", + license = "MIT", + author = "R8000", + description = [[An Example Midi Generator for prototyping.]] +} + +function dsp_ioconfig () return { { midi_out = 5} } end + +local tme = 0 -- sample-counter +local seq = 0 -- sequence-step +local spb = 0 -- samples per beat + +local midi_sequence_one = { + { 0x90, 64, 127 }, + { 0x80, 64, 0 }, +} +local midi_sequence_two = { + { 0x90, 60, 70 }, + { 0x80, 60, 0 }, +} + +local midi_sequences = { midi_sequence_one, midi_sequence_two } + +function dsp_init (rate) + local bpm = 120 + spb = rate * 60 / bpm + if spb < 2 then spb = 2 end +end + +function dsp_run (_, _, n_samples) + assert (type(midiout) == "table") + assert (spb > 1) + + for time = 1,n_samples do -- not very efficient + -- TODO, timestamp the sequence in beats, calc/skip to next event + tme = tme + 1 + if tme >= spb then + for m = 1, 5 do + midiout[m] = {time = time, data = midi_sequences[m % 2 + 1][seq + 1]} + end + tme = 0 + seq = (seq + 1) % 2 + end + end +end |