Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Jump To Marker via Midi Control Pedal
#1
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:
  • Start/Stop Playing
  • Jump to Next/Previous Section or Marker
  • Jump to a specific Marker
I solved Play/Stop/Prev/Next easily with a Custom Midi Map.

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 Sad

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
Reply
#2
Hi F4lkH3 welcome to the Mixbus Forum

https://forum.harrisonconsoles.com/threa...l#pid26468

Editor/goto-mark-1 thru mark-9..... Not sure if this will help...
Macmini 8,1 | OS X 13.6.3 | 3 GHz i5 32G | Scarlett 18i20 | Mixbus 32C  9.2.172 | PT_2024.3.1 .....  Macmini 9,1 | OS X 14.4.1 | M1 2020 | Mixbus 32C  9.2.172 | Resolve 18.6.5
Reply
#3
https://manual.ardour.org/lua-scripting/...oral:Event
...from the comments of your script, shows that it has a channel() method, also type() and presumably buffer() is the value but I don't know what any of those methods are actually returning.

It feels like a Session script might not be the best approach due to it running on every process cycle: hundreds/thousands of times per second every second just to see if a particular program change event has happened in this cycle which 99.9999% of the time it wouldn't have.

An alternative might be using a MIDI map instead, as this way things only happen in response to you doing something (firing the program change). For example, you could write a Lua ActionScript that jumps to the first marker, assign that script to a script action slot, then have the MIDI map configured such that program change of value 1 on channel whatever executes the script.

E.g. You might put that script in Action slot 13, so the MIDI map would be like this (except that this example is for MIDI notes - you'd need to find out how to do it for program changes):
Code:
<Binding channel="1" note="90" action="LuaAction/script-13" />

Then you could repeat all of the above for however many markers you need, a new script for each one, in its own Action slot, with its own MIDI map entry. There are only 32 Action script slots so there is a limit here. Plus obviously this is going to chew up those slots which personally I'd be loathe to do - they are precious! But maybe you do have lots of slots left and are unlikely to need them for other scripts.

It would be nice if parameters could be passed to Action scripts somehow, so just the one script would be needed.

OSC can also trigger Action scripts. 

Link to your Ardour site thread:
https://discourse.ardour.org/t/use-midi-...lua/102439
Reply
#4
You are absolutely right

but still no Solution. :/

Using Action-Scripts would be better indeed. But one script per "Marker to jump to ..." No, that's too limiting and such a non-generic solution makes my developer-heart bleed. Sad If one could pass the PC parameter to the script, that would be perfect ... but without any hint from the Mixbus developers or documentation on this, it's impossible to realize it that way.

... trying to reach out the devs, now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)