At the moment I’m trying to dig into Lua, but since I have only little experience in scripting, this is more of trial and error.
I have the following code, which checks for a selected track and prints out the trackname to the console:
["type"] = "EditorAction",
name = "",
function factory (unused_params)
return function ()
-- Selected track
local sel = Session:route_by_selected_count(0)
local track = sel : to_track();
-- Print Name of selectetd track
local trackname = sel : name()
I’m trying to change some attribute of the selected track, such as deactivate it or change it’s visibility.
Can someone give me a hint, how to do that?
Also i’d like to check, if there’s only one track selected and if that track is a Midi Track.
At the moment I’m a bit lost, it’s hard for me, to understand how to apply the methods from the Lua Reference.
I’d be thankful for tipps and hints!
--get the count of selected routes (.tracks here = tracks, busses & Master)
local selCount = Editor:get_selection().tracks:routelist():size()
if selCount == 1 then
--only one route selected: get it
local r = Session:route_by_selected_count(0)
if r:presentation_info_ptr():flags() & ARDOUR.PresentationInfo.Flag.MidiTrack == ARDOUR.PresentationInfo.Flag.MidiTrack then
-- it is a MIDI Track
When I enter your code into the scripting window, I get an error message Error: [string "--get the count of selected routes (.tracks h..."]:2: attempt to call a nil value (method 'size')
although I had selected a track.
EDIT: I also couldn’t find the method size() in the API. I just forgot to put a space before the brackets!
However, I still get the error message attempt to call a nil value (method 'size')…
Oops. :routelist():size() not :size()
Fixed in the earlier post.
Spaces before brackets are not required. It’s the accepted convention/style for readability purposes, for some languages at least (?). I’m not sure when it became a thing but I missed the memo, so I’m often stuck in the old no-space ways.
Great, thank you mate!
I actually just seem to have problems, to understand what is happening there.
First I thought, routelist()returns a kind of array containing the selected tracks and the size()method returns the size of that array, but I’m beginning to think, that this assumption is wrong…
Thank you anyway, it’s a great help to me!