Found the issue: Session:new_audio_track returns a RouteList, not a Route (due to the fact that you can create many identical routes in one function call), so you should put :front() after your function call to get the first (and in your case only) route from the list. Needed for both the bus and the route.
Not sure about your system, but the script runs for me only in Ardour 8.12. 9.2 crashes when I try to create a bus (midi or audio).
ardour {
["type"] = "EditorAction",
name = "Add Bus and Tracks",
license = "MIT",
author = "author",
description = [[Add Bus and Tracks]]
}
function factory()
return function()
local function connectAudioRoutes(source, destination)
assert(source)
assert(destination)
if source:name() ~= destination:name()
then
for i = 1, source:n_outputs():n_audio() do
local source_port = source:output():audio(i - 1)
local destination_port = destination:input():audio(i - 1)
source_port:disconnect_all() -- FIXME: Check if output port is connected to the port already and disconnect all other ports
source_port:connect(destination_port:name())
end
end
end
soundbus = Session:new_audio_route(2, 2, nil, 1, "SoundBus", ARDOUR.PresentationInfo.Flag.AudioBus,
ARDOUR.PresentationInfo.max_order):front()
tr = Session:new_audio_track(2, 2, nil, 1, "Sound", -1, ARDOUR.TrackMode.Normal, true):front()
connectAudioRoutes(tr, soundbus)
tr = Session:new_audio_track(2, 2, nil, 1, "Sound", -2, ARDOUR.TrackMode.Normal, true):front()
connectAudioRoutes(tr, soundbus)
tr = Session:new_audio_track(2, 2, nil, 1, "Sound", -3, ARDOUR.TrackMode.Normal, true):front()
connectAudioRoutes(tr, soundbus)
Editor:access_action("Editor", "select-none")
end
end
Works in Ardour 8.12 as you intended.