Remove dsp_has_midi_*() in favor of dsp_ioconfig()
[ardour.git] / scripts / midigenerator.lua
1 ardour {
2         ["type"]    = "dsp",
3         name        = "Midi Generator",
4         category    = "Example", -- "Utility"
5         license     = "MIT",
6         author      = "Ardour Lua Task Force",
7         description = [[An Example Midi Generator for prototyping.]]
8 }
9
10 function dsp_ioconfig ()
11         return { { midi_out = 1, audio_in = 0, audio_out = 0}, }
12 end
13
14 local tme = 0 -- sample-counter
15 local seq = 1 -- sequence-step
16 local spb = 0 -- samples per beat
17
18 local midi_sequence = {
19         { 0x90, 64, 127 },
20         { 0x80, 64,   0 },
21 }
22
23 function dsp_init (rate)
24         local bpm = 120
25         spb = rate * 60 / bpm
26         if spb < 2 then spb = 2 end
27 end
28
29 function dsp_run (_, _, n_samples)
30         assert (type(midiout) == "table")
31         assert (spb > 1)
32         local m = 1
33
34         for time = 1,n_samples do -- not very efficient
35                 -- TODO, timestamp the sequence in beats, calc/skip to next event
36                 tme = tme + 1
37
38                 if tme >= spb then
39                         midiout[m] = {}
40                         midiout[m]["time"] = time
41                         midiout[m]["data"] = midi_sequence[seq]
42
43                         tme = 0
44                         m = m + 1
45                         if seq == #midi_sequence then seq = 1 else seq = seq + 1 end
46                 end
47         end
48 end