Calling menu commands in Lua (newbie)

Hey there,

i run into some repeating click tasks lately and wondered if/how i can automate that process.

task 1

snap selected regions to grid, then close gaps

so getting the selected regions should do with

    local sel = Editor:get_selection ()
    local sel_regions = sel.regions:regionlist()

and for processing each region i’d do

    for r in sel_regions:iter() do

but then for the actual task, i’m a little overwhelmed from the Lua Bindings Class Reference.
Is there a method that executes commands from the menu?

I guess the snap part could be done with

    r.set_snap_to_grid() = true

but for the close gaps part i’m lost.

task 1 +

As you may guess i intend to speed up my editing here. The process ist

  • rhythm ferret
  • snap to grid
  • close gaps
    I wondered if i could do a dialog-box with a button for each part and to enter the parameter settings. The Menu itself should be less of a problem, but again i must know how to start the functions out of Lua and to forward the setting parameters.

task 2

create X numbers of audio-tracks with same i/o settings

There i suppose i have to use the AudioTrack object but my research focused more on task 1 for now to be honest.

Sidenote

Coming from a non OOP background AND being a Lua noob, my question is very basic and tends to sound like “write that script so i don’t have to.” That’s not my intention. I’m happy to be just pointed into some general direction, if possible.

For the first task, you effectively want to perform two menu actions (Menu > Region > Position > Snap to grid; Region > Edit > Close Gaps (see The Ardour Manual for a list of actions):

Editor:access_action ("Region", "snap-regions-to-grid")
Editor:access_action ("Region", "close-region-gaps")

However the latter is a problem since it is interactive. To automate this, you cannot use Ardour’s built-in editor function, but instead implement the functionality in Lua directly: _close_region_gaps.lua · GitHub

Yes, have a look at ardour/_dialog_test.lua at master · Ardour/ardour · GitHub or various example scripts in the share/scripts folder.

Adding removing tracks is a session operation:

local n_inputs  = 1
local n_outputs = 2
local how_many  = 16
local name_template = ""

Session:new_audio_track (n_inputs,
                         n_outputs,
                         nil,
                         how_many,
                         name_template,
                         ARDOUR.PresentationInfo.max_order,
                         ARDOUR.TrackMode.Normal)

hope that helps

1 Like

Awesome, that’s exactly what i need!

Big thanks!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.