Lua script works on 8.12 but breaks 9.2

The following Lua script lets Ardour 9.0 and 9.2 crash but works on 8.12.

Yes the script is rough and even has some “IDK why” comments but as stated it did what i needed in 8.12. Do i have to adjust something for 9 or is this a bug in Ardour?

ardour { ["type"] = "EditorAction",
	name = "Add Tracks To Selected Buses",
	license     = "MIT",
	author      = "d-night-audio",
	description = [[Adds a Track for every selected Bus and routes the output of that Bus to the Track input]]
}

function factory () return function ()

	-- prepare undo operation
	Session:begin_reversible_command ("Add Tracks To Selected Buses")
	local add_undo = false -- keep track if something has changed

    local rlp = ARDOUR.RouteListPtr ()
    local selbus = Editor:get_selection ()
    local a = Session:engine()



	-- loop over all tracks in the session
	for selectedBusses in selbus.tracks:routelist ():iter() do
        -- get track name and add "sw_"
        get_name = selectedBusses:name ()
        get_name = "sw_" .. get_name


        -- add tracks
        --local sel = Editor:get_selection ()
        local ctrls = ARDOUR.ControlListPtr () -- create a list of controls to change
    
        if not Editor:get_selection ():empty () and not Editor:get_selection ().tracks:routelist ():empty ()  then
            tr = Session:new_audio_track (1, 2, nil, 1, get_name, Editor:get_selection ().tracks:routelist ():front():presentation_info_ptr ():order () + 1, ARDOUR.TrackMode.Normal, true)
        else
            tr = Session:new_audio_track (1, 2, nil, 1, get_name, -1, ARDOUR.TrackMode.Normal, true)
        end
    
        -- mute and rec enable the tracks
        for track in tr:iter() do
            track:mute_control ():set_value  (1, PBD.GroupControlDisposition.NoGroup)
            track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)

            -- reroute
            _, t = a:get_ports (ARDOUR.DataType("audio"), ARDOUR.PortList())
            for p in t[2]:iter() do
                if  (p:name ():find (track:name ())) then
                    print (p:name())

                    -- real rerouting starts here
                    a:disconnect_port(p)
                    busport = selectedBusses:name() .. "/audio_out 1"
                    p:connect(busport)

                end
            end  
    
        end

        --don't know why this is necessery
        rlp:push_back (selectedBusses) 
	end


    
	-- all done. now commit the combined undo operation
	if add_undo then
		-- the 'nil' command here means to use all collected diffs
		Session:commit_reversible_command (nil)
	else
		Session:abort_reversible_command ()
	end
end end



Various API calls have been changed for Arodur 9.0. Since Lua directly uses libardour, all scripts have to be updated as well.

Here specifically the RouteGroup [1,2] and hence calls to Session:new_audio_track.

In your your script change the third argument of Session:new_audio_track from nil to ARDOUR.RouteGroup() like


[1] Use shared_ptr to manage RouteGroups everywhere (libs edition) · Ardour/ardour@371bb41 · GitHub
[2] Update Lua script to use new RouteGroup API · Ardour/ardour@6eeed82 · GitHub

2 Likes

That’s what broke my scripts I guess! Good to know, thanks

2 Likes

Thx for the quick solution, Robin! Seems i didn’t catch the LUA changes to version 9.