I made a LUA action to add a track and do some basic config.
Question: How can I make this newly created track the selected track in the UI ? I found the Editor:set_selection method but can’t figure out how to build a “SelectionList” to pass as a parameter where what I have available is a Route/Track (or RouteList)
However, I have a hacky workaround script for this. It deselects all routes and then goes into a “select next route” action loop (starting from the first route) until it sees that the currently selected route is the one in question.
It can only be used to select a single route, not multiple at once, due to the deselect-all and select-next steps. I.e. If you use this to select route A and then use it to select route B then B will now be selected, not A.
There is also the option to scroll the route into view. It doesn’t always work the way I expect it to but better than nothing.
-- Selects this route.
-- NOTE: It deselects all other routes, therefore cannot be used multiple times for selecting multiple routes at once.
-- r: the route in question.
-- scrollIntoView: if true (or nil) then also scrolls the route into view.
-- unhide: if the route is hidden then this function does nothing unless this parameter is true (or nil) in which case it unhides the route.
function routeSelect(r, scrollIntoView, unhide)
if r:is_hidden() then
if unhide ~= nil and unhide ~= true then return end
Editor:show_track_in_display(routeToTav(r), true)
end
Editor:access_action("Mixer", "select-none")
repeat
Editor:access_action("Editor", "select-next-route")
until r:is_selected()
if scrollIntoView == nil or scrollIntoView == true then
routeScrollIntoView(r)
end
end
-- Scrolls the mixer's route pane such that this route is visible. Typically this will make it the left-most visible
-- route but only if the available scrolling range allows it.
-- r: the route in question.
-- unhide: if the route is hidden then this function does nothing unless this parameter is true (or nil) in which case it unhides the route.
function routeScrollIntoView(r, unhide)
if r:is_hidden() then
if unhide ~= nil and unhide ~= true then return end
Editor:show_track_in_display(routeToTav(r), true)
end
for i = 1, Session:get_stripables():size() do
Editor:access_action("Mixer", "scroll-left")
end
local pos = routePosition(r)
local numVisibleBeforeThis = 0
for r2 in Session:get_routes():iter() do
if routePosition(r2) < pos and not r2:is_hidden() then
numVisibleBeforeThis = numVisibleBeforeThis + 1
end
end
for i = 1, numVisibleBeforeThis do
Editor:access_action("Mixer", "scroll-right")
end
end
-- Returns the TimeAxisView for this route.
-- r: the route in question.
function routeToTav(r)
return Editor:rtav_from_route(r):to_timeaxisview()
end
-- Returns strip position (presentation order), first strip = 0.
-- r: the route in question.
function routePosition(r)
return r:presentation_info_ptr():order()
end
Example usage:
local r = # the route in question, e.g. a newly created one #
routeSelect(r)
If you don’t want it to scroll into view:
local r = # the route in question, e.g. a newly created one #
routeSelect(r, false)