summaryrefslogtreecommitdiff
path: root/scripts/midigenerator.lua
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2016-05-29 20:36:16 +0200
committerRobin Gareus <robin@gareus.org>2016-05-29 20:36:32 +0200
commit39e818a03afdf76a123bb802f020008276646708 (patch)
tree79e73fd6399cd415cc11c1540b5a53e10c864d46 /scripts/midigenerator.lua
parent60200bf92300388d2b0d002559a3db1b544d9705 (diff)
prototype lua midi generators & filters and port event-rewrite
Diffstat (limited to 'scripts/midigenerator.lua')
-rw-r--r--scripts/midigenerator.lua52
1 files changed, 52 insertions, 0 deletions
diff --git a/scripts/midigenerator.lua b/scripts/midigenerator.lua
new file mode 100644
index 0000000000..e9aa55d280
--- /dev/null
+++ b/scripts/midigenerator.lua
@@ -0,0 +1,52 @@
+ardour {
+ ["type"] = "dsp",
+ name = "Midi Generator",
+ category = "Utility",
+ license = "MIT",
+ author = "Robin Gareus",
+ email = "robin@gareus.org",
+ site = "http://gareus.org",
+ description = [[An Example Midi Generator for prototyping.]]
+}
+
+function dsp_ioconfig ()
+ return { { audio_in = 0, audio_out = 0}, }
+end
+
+function dsp_has_midi_output () return true end
+
+local tme = 0 -- sample-counter
+local seq = 1 -- sequence-step
+local spb = 0 -- samples per beat
+
+local midi_sequence = {
+ { 0x90, 64, 127 },
+ { 0x80, 64, 0 },
+}
+
+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)
+ local m = 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
+ midiout[m] = {}
+ midiout[m]["time"] = time
+ midiout[m]["data"] = midi_sequence[seq]
+
+ tme = 0
+ m = m + 1
+ if seq == #midi_sequence then seq = 1 else seq = seq + 1 end
+ end
+ end
+end