Saturday, 15 February 2020 00:00

Ardour LUA script to add drum tracks, group them, assign inputs and create busses.

ardour {
["type"] = "EditorAction",
name = "Add a new set of drum tracks and busses and assign inputs",
license = "MIT",
author = "Matthew Smith (kinggeek.co.uk)",
description = [[Add Drum Tracks, assign inputs and create busses for kick/snare reverb and master. Invoke more than once for multiple takes.]]
}

function factory () return function ()

local names = { "Kick Front","Kick Rear","Snare Top","Snare Bottom","Tom 1","Tom 2","OH L","OH R" }
local inputs = {"system:capture_11","system:capture_12","system:capture_13","system:capture_14","system:capture_15","system:capture_16","system:capture_17","system:capture_18", }




drum_bus_name="Drum Bus"

drumbus = Session:new_audio_route (2, 2, nil, 1, drum_bus_name, ARDOUR.PresentationInfo.Flag.AudioBus, ARDOUR.PresentationInfo.max_order)
for g in drumbus:iter () do
take_number=string.sub(g:name(),string.len(drum_bus_name)+2)
end

if (take_number~="") then take_number=" "..take_number end

print ("This will be take (and group) number: "..take_number)

drummaster = Session:new_audio_route (2, 2, nil, 1, "Drum Master"..take_number, ARDOUR.PresentationInfo.Flag.AudioBus, ARDOUR.PresentationInfo.max_order)
drumverb = Session:new_audio_route (2, 2, nil, 1, "Drum Verb"..take_number, ARDOUR.PresentationInfo.Flag.AudioBus, ARDOUR.PresentationInfo.max_order)
kickbus = Session:new_audio_route (2, 2, nil, 1, "Kick Bus"..take_number, ARDOUR.PresentationInfo.Flag.AudioBus, ARDOUR.PresentationInfo.max_order)
snarebus = Session:new_audio_route (2, 2, nil, 1, "Snare Bus"..take_number, ARDOUR.PresentationInfo.Flag.AudioBus, ARDOUR.PresentationInfo.max_order)


local drum_group = Session:new_route_group("Drums "..take_number)
assert(drum_group);
drum_group:set_active (true, nil)
--drum_group:set_color(color)
drum_group:set_gain(false)
drum_group:set_monitoring(false)
drum_group:set_mute(false)
drum_group:set_recenable(true)
drum_group:set_route_active(false)
drum_group:set_select(false)
drum_group:set_solo(false)

for g in drumbus:iter () do
drum_group:add(g);
end

verbtracks = ARDOUR.RouteListPtr ()
for g in drumverb:iter () do
drum_group:add(g);
verbtracks:push_back(g);
end
for g in drummaster:iter () do
drum_group:add(g);
end
for g in kickbus:iter () do
drum_group:add(g);
end
for g in snarebus:iter () do
drum_group:add(g);
end



local e=Session:engine()
local a = Session:engine()
print ("Ports from Backend");
_, t = a:get_ports (ARDOUR.DataType("audio"), ARDOUR.PortList())
-- table 't' holds argument references. t[2] is the PortList
for p in t[2]:iter() do
print (p:name())
end

local _,bi = e:get_backend_ports ("", ARDOUR.DataType("audio"), ARDOUR.PortFlags.IsOutput | ARDOUR.PortFlags.IsPhysical, C.StringVector())
for pi in bi[4]:iter() do
print (pi);
end


local i = 1
while names[i] do
local tl = Session:new_audio_track (1, 2, nil, 1, names[i],
ARDOUR.PresentationInfo.max_order,
ARDOUR.TrackMode.Normal)

for track in tl:iter () do
--track:presentation_info_ptr():set_color(ARDOUR.LuaAPI.color_to_rgba (200))
drum_group:add(track)
_, t = a:get_ports (ARDOUR.DataType("audio"), ARDOUR.PortList())
for p in t[2]:iter() do
if (p:name ():find (track:name ())) then
if (p:receives_input ()) then
a:disconnect_port(p)
p:connect(inputs[i])
print ("INPUT TRACK - "..track:name ()..". Connect: ",p:name()," ",track:name ()," to ",inputs[i])
end
if (p:sends_output()) then
a:disconnect_port(p);
chan=string.sub(p:name(),string.len(p:name()));
output=drum_bus_name..take_number.."/audio_in "..chan
if (track:name():find("Kick") ) then output="Kick Bus"..take_number.."/audio_in "..chan end
if (track:name():find("Snare") ) then output="Snare Bus"..take_number.."/audio_in "..chan end
p:connect(output)
print ("OUPUT TRACK - "..track:name ()..". Connect: ",p:name()," to ",output)
end
end
if i==1 then
if (p:name ():find ("Kick Bus"..take_number)) or (p:name ():find ("Snare Bus"..take_number)) then
if (p:sends_output()) then
a:disconnect_port(p)
chan=string.sub(p:name(),string.len(p:name()))
output="Drum Bus"..take_number.."/audio_in "..chan
p:connect(output)
print ("OUTPUT BUS - "..p:name ()..". connect: ",p:name()," to ",output)
end
end
if (p:name ():find (drum_bus_name..take_number)) or (p:name ():find ("Drum Verb"..take_number)) then
if (p:sends_output()) then
a:disconnect_port(p)
chan=string.sub(p:name(),string.len(p:name()))
output="Drum Master"..take_number.."/audio_in "..chan
p:connect(output)
print ("OUTPUT BUS - "..p:name ()..". connect: ",p:name()," to ",output)
end
end
end
end
end



i = i +1
end
for g in drummaster:iter () do
g:set_presentation_order(ARDOUR.PresentationInfo.max_order)
end
for g in drumbus:iter () do
g:set_presentation_order(ARDOUR.PresentationInfo.max_order)
end
for g in snarebus:iter () do
g:set_presentation_order(ARDOUR.PresentationInfo.max_order)
end
for g in kickbus:iter () do
g:set_presentation_order(ARDOUR.PresentationInfo.max_order)
end






Session:add_internal_sends (drumbus:front (), ARDOUR.Placement.PostFader, verbtracks);

end end

Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.