diff options
author | Robin Gareus <robin@gareus.org> | 2017-01-02 00:52:25 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2017-01-02 00:52:25 +0100 |
commit | 83c964cfd44756197ff0f3eeb8f584718f313439 (patch) | |
tree | e4d65ddfe80324d0835a1516ccb53dcc69badddc /scripts | |
parent | ead84f75a5b6495cf74c2ddbdb2961c58ba5a407 (diff) |
Add an example script to start recording on a MIDI event
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/_midi_rec_start.lua | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/scripts/_midi_rec_start.lua b/scripts/_midi_rec_start.lua new file mode 100644 index 0000000000..edd67eb7af --- /dev/null +++ b/scripts/_midi_rec_start.lua @@ -0,0 +1,37 @@ +ardour { + ["type"] = "session", + name = "MIDI Record Enable", + category = "Example", -- "Utility" + license = "MIT", + author = "Ardour Lua Task Force", + description = [[An example script to start recording on note-on.]] +} + +function factory () + return function (n_samples) + if Session:actively_recording() then return end -- when recording already, do nothing + -- iterate over all MIDI ports + _, t = Session:engine ():get_ports (ARDOUR.DataType.midi (), ARDOUR.PortList ()) + for p in t[2]:iter () do + -- skip output ports + if not p:receives_input () then goto next end + local midiport = p:to_midiport () + -- and skip async event ports + if midiport:isnil () then goto next end + local mb = midiport:get_midi_buffer (n_samples) -- get the midi-data buffers + local events = mb:table () -- copy event list into lua table + for _,e in pairs (events) do -- iterate over all events in the midi-buffer + if bit32.band (e:buffer():array()[1], 0xf0) == 0x90 then -- note on + Session:maybe_enable_record (true) -- global record-enable from rt-context + -- maybe-enable may fail if there are no tracks or step-entry is active + -- roll transport if record-enable suceeded: + if ARDOUR.Session.RecordState.Enabled == Session:record_status() then + Session:request_transport_speed (1.0, true) -- ...and go. + end + return + end + end + ::next:: + end + end +end |