Lua script that selects all the regions of a selected track

Hi,

I want to write a Lua script that selects all the regions of a selected track. I’m new to Ardour and Lua scripts, but fortunately the manual and this forum are helping me to get accustomed to scripting.

So far, I found a script that finds info of a selected route. See the link to the forum post where I found the script:

I need some help with te following steps:
-Select all the regions in the current track (track context menu/Select/Select All in Track)
-Plays the duration of the session from the start of the earliest selected region to the end of the latest selected region (track context menu/Play/Play Region

Is it possible to acces the track context menu of a selected track via Lua scripts?

In Context.
I want to use Ardour for triggering backingtracks/clicktracks. I want to create a project where I can launch backingtracks, play soft synths and monitor microphone inputs.
I don’t want to use location/range markers, because if I use markers, I have to edit the markers every time I edit the track order or add/delete a track.

For a similar option using Logic Pro x, see the following video. It’s in the chapter How to Start Each Song with “Play From Selected Region”.

If someone has a better idea than creating the script I suggested, feel free to leave a reply. Although, I’m still curious if Lua scripts have acces to the track context menu of a selected track. Thanks in advance for your help.

I have a lua script that sort of does the inverse of that. It is my script for opening up a region in musescore. One of the things it does is connects musescore to the synth that is on the current track(script requires a midi region be selected). I’d have to play around and see if there is a way to do what you are asking.

That’s cool! Good to know that it is possible to do things with a selected track or region. I hope it is also possible to acces the track context menu in a script. Thank you for the effort in advance.

I found a challenge though. ‘Select All in Track’ is part of the track context menu. I expect the ‘is selected’ porperty belongs to the route. The route context menu has no option to ‘Select All in Track’.

This is the route context menu.
IMG-20250204-WA0000

This is the track context menu.

I was looking through the keyboard shortcut bindings to see if I could assign shortcuts to get the job done. I still want a script, but this way I could have a temporary fix.
I found a way to assign the ‘Play selected region’ command to the spacebar key. This way, playback starts at the beginning of the region and stops at the end of the region. If there isn’t a selected region, the spacebar works as it usually does.
I didn’t find a way to acces the track context menu via keyboard shortcuts. I’m not able to ‘Select all in Track’ via keyboard shortcuts unfortunately.

I’m double checking the manual and the preferences menu to see if there is a setting that does what I want to do in a script. I will take a look next time I load up Ardour.

I was digging through the manual and I think I found the solution. I have not yet been able to test this though. I will report back.
I think the right way to do this, is creating a editor hook that triggers a function when a selection changes.
When the selection changes, set the region boundaries to the selected tracks boundaries.

function signals ()
  return LuaSignal.Set():add ({[LuaSignal.SelectionChanged] = true})
end

function factory ()
  return function (signal)
    RCConfiguration:set_region_boundaries_from_selected_tracks()
  end

I can then use the keyboard shortcut from the previous post that I bound to the spacebar to trigger playing the selected region and automatically stop the playback after reaching the region end.

1 Like

My previous scripts didn’t work, but I found a solution to my problem. I basically took the “Region Select/2” script and modified it. My version selects all the regions on all selected tracks and plays the selection back.

ardour {
	["type"]    = "EditorAction",
	name        = "Select And Play All Regions",
	author      = "Luminyx Willem",
	description = "Selects and plays all regions of the selected tracks",
}

function factory () return function ()

	local sl = ArdourUI.SelectionList () -- empty selection list

	local sel = Editor:get_selection () -- get current selection
	-- for each selected track/bus..
	for route in sel.tracks:routelist ():iter () do
		-- consider only tracks
		local track = route:to_track ()
		if track:isnil() then
			goto continue
		end

		-- iterate over all regions of the given track
		for region in track:playlist():region_list():iter() do
				-- get RegionView (GUI object to be selected)
				local rv = Editor:regionview_from_region (region)
				-- add it to the list of Objects to be selected
				sl:push_back (rv);
		end
		::continue::
	end

	-- set/replace current selection in the editor
	Editor:set_selection (sl, ArdourUI.SelectionOp.Set);
	-- play current selection
	Editor:play_selection ();
end end

You can still stop and pause playback and you can still start playback from where you placed the playhead. This is exactly what I wanted to do. I can now start creating my project!

SelectAndPlayAllRegions

1 Like

And this is why I love Ardour and it’s lua scripting API, it allows us to add some of the functionality found in other DAWs to Ardour.

1 Like