Accessing track order with Lua

I wonder, if there’s a way to access the vertical “index” of a track with Lua.
To be more precise, I want to make a Lua script that hides a selected track and generates a new track, which than takes over the position of the hidden track in the track order.
So, how can i get the position of a track in this vertical order, and how can I set it for a new track?
For example, I know, there’s a new_audio_track() method, but it takes 9 parameters and most of them are obscure to me.

First be sure that you don’t just want to use a new playlist in the existing track.

Maybe I should make things a bit clearer:
I’m trying to find a way to make a kind of midi track freeze (there are a a couple of synonyms for that, i hope you know what I mean…), to save cpu ressources in larger projects.
I planned to build the script to function as follows after execution:

  1. Stop transport play.
  2. Check if a single track is selected and if it’s a midi track.
  3. Bounce the full track to “Sources” with a specific name.
  4. Get the vertical “index” of the midi track, deactivate it and make it invisible.
  5. Load the bounced audio to a new audio track, that takes over the place of the hidden midi track.

I’m planning to make a scond script for an “unfreeze” action, that removes the audio track and unhides/activates the midi track again.

At the moment I have just these few lines, I’d be thankful for feedback and suggestions:

ardour {
	  ["type"]    = "EditorAction",
	  name        = "Midi Track Freeze",
	}

	function factory (unused_params)
	  return function ()
		function dialog (text)
		LuaDialog.Message ("Information", text, LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run ()
		end 

		local selCount = Editor:get_selection().tracks:routelist():size()
		local r = Session:route_by_selected_count(0)
		local track = r:to_track()

		if Session:transport_stopped() == false then Session:request_stop(false, false, 0)
		end

		if selCount < 1 then dialog("No track selected. Please select a MIDI track.")
			elseif selCount > 1 then dialog("Please select a single MIDI track.")
			elseif selCount == 1 and r:presentation_info_ptr():flags() ~= 17410 then dialog("No MIDI track selected.")
                -- alternative: elseif selCount == 1 and r:data_type():to_string() ~= "midi" then dialog("No MIDI track selected.")
			elseif selCount == 1 and r:presentation_info_ptr():flags() == 17410 then
                -- alternative: elseif selCount == 1 and r:data_type():to_string() == "midi" then 
				local trackname = r : name()
				dialog("You have selected MIDI track ’" .. trackname.."’ to freeze.")
				-- Bounce MIDI regions in selected track
				track:bounce(ARDOUR.InterThreadInfo (),"*** "..trackname)
				-- Deactivate the MIDI Track
				r:set_active (false, nil)
		end
	  end
	end

You likely want Route:presentation_info_ptr:order()

I may have the syntax wrong since I don’t do Lua, but that’s where the ordering is held.

However, creating a new track with the same order number is far from trivial. The way this is normally done is the responsibility of the UI creating the track, and you can’t just assign the same order as the existing track.

1 Like

Maybe I’m missing something here but Session:new_audio_route() creates a route and its last parameter is where to position it. So for that value you’d use whatever presentation_info_ptr():order() gave you for the route you’re replacing.

--where r = the route to be replaced
local pos = r:presentation_info_ptr():order()

local newTrack = Session:new_audio_route (
  2, -- in channel count
  2, -- out channel count
  nil, -- group (type = RouteGroup)
  1,   -- number of them to create
  "xxx", -- track name
  ARDOUR.PresentationInfo.Flag.AudioTrack,  -- route type
  pos  -- track position (0 = first, ARDOUR.PresentationInfo.max_order = last)
):front()

Session:new_audio_track() is similar but has different parameters and I’m not sure what they are.

1 Like

Yeah, correct, thats what I already found out too, and for my purposes it seems to work fine! Thank you for your reply! :slight_smile:

EDIT: By the way, in new_audio_track() it seems to be the 6th parameter, which is setting the order.

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