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