04-23-2022, 10:32 AM
Hi
i need some help with a LUA Script.
The overall goal is to Control Mixbus during a Live-Session via foot-pedal Midi Controller:
But i'm Stuck with the "Jump to a specific Marker".
The Basic idea is to check the Midi-Events from the Midi-Control Device and if it is a ProgramChange Command, jump to the specific Marker with the corresponding Number.
I started to play around with a Session Lua Script to achieve this, but there are some questions.
Below is my draft Script. (basically copy'n'paste'n'modify from two example scripts provided in the Ardour source.)
First of all: How do i 'translate' a Evoral:Event to a Midi-Command. (retrieve the Channel, the Command Type and the Number)?
2nd: Is the Session Script also executed, when nothing is playing? (i wonder because of the n_samples)
3rd: How can i debug such a Lua Session Script?
OR: Is there a better, totally different way to achieve this?
I posted this question already in the Ardour-Forum in the past. Without success :/
many thanks in advance
F4lkH3
P.S.: Sadly i'm not allowed to post Links to My GitHub Source nor the related Ardour-Post
i need some help with a LUA Script.
The overall goal is to Control Mixbus during a Live-Session via foot-pedal Midi Controller:
- Start/Stop Playing
- Jump to Next/Previous Section or Marker
- Jump to a specific Marker
But i'm Stuck with the "Jump to a specific Marker".
The Basic idea is to check the Midi-Events from the Midi-Control Device and if it is a ProgramChange Command, jump to the specific Marker with the corresponding Number.
I started to play around with a Session Lua Script to achieve this, but there are some questions.
Below is my draft Script. (basically copy'n'paste'n'modify from two example scripts provided in the Ardour source.)
First of all: How do i 'translate' a Evoral:Event to a Midi-Command. (retrieve the Channel, the Command Type and the Number)?
2nd: Is the Session Script also executed, when nothing is playing? (i wonder because of the n_samples)
3rd: How can i debug such a Lua Session Script?
OR: Is there a better, totally different way to achieve this?
I posted this question already in the Ardour-Forum in the past. Without success :/
many thanks in advance
F4lkH3
P.S.: Sadly i'm not allowed to post Links to My GitHub Source nor the related Ardour-Post
Code:
-- based on _midi_rec_start.lua
-- and _midi_rewrite.lua
ardour {
["type"] = "Session",
name = "MIDI Program Change Jump To Marker",
category = "MIDI Controls",
license = "MIT",
author = "FalkHe",
description = [[An script to map Midi PC Commands to Track Markers ]]
}
function string.starts(String,Start)
return string.sub(String,1,string.len(Start))==Start
end
function jumpToMarker(nr)
Session:request_stop();
for loc in Session:locations():list():iter() do
if loc:is_mark() then
if string.starts(loc:name(), "PC-"..nr.." |") then -- aka "Marker Number XY"
-- jump to marker starting with "PC-1 |"
Session:request_locate(loc:start())
return
end
end
end
end
function factory ()
return function (n_samples)
if Session:actively_recording() then return end -- when recording already, do nothing
-- iterate over all MIDI ports
_, PortList = Session:engine():get_ports(ARDOUR.DataType.midi(), ARDOUR.PortList())
for port in PortList[2]:iter () do
-- skip output ports
if not port:receives_input() then goto next end
local midiport = port:to_midiport()
-- and skip async event ports
if midiport:isnil() then goto next end
-- only use the port "MIDI control in"
if port:name() ~= "MIDI control in" then goto next end
-- can i rely on "port:name() === "MIDI control in" to watch only the configured Midi Control?
-- Is there a better way to directly get the configured Control MIDI Device?
local midiBuffer = midiport:get_midi_buffer(n_samples) -- get the midi-data buffers
local events = midiBuffer:table() -- copy event list into lua table
for k, event in pairs(events) do -- iterate over all events in the midi-buffer
-- event is-a manual.ardour.org/lua-scripting/class_reference/#Evoral:Event
------------------------------------------------------------------------------------------------
-- HERE I'm stuck. How to translate event into midi signal values Channel, Type, ProgramNumber
------------------------------------------------------------------------------------------------
-- Goal:
-- "if event is a ProgrammChange, jumpToMarker(ProgramNumber)"
end
::next::
end
::fine::
end
end