This is my first lua script and it saves a lot of clicks for those who use groups with the boxes unticked.
I cut and pasted from other scripts until I got lucky. I do not know how to make it automatically give the new group a unique name/number and please amend if you do.
ardour {
["type"] = "EditorAction",
name = "FreshGroup",
license = "MIT",
author = "Assistant",
description = [[MakeFreshGroup]]
}
function factory()
return function()
-- get the current session
local session = Session
-- get the list of tracks
local tracks = session:get_tracks()
local sel = Editor:get_selection ()
local rl = sel.tracks:routelist ()
-- create a new group
local new_group = Session:new_route_group ("New Group")
-- add selected track to the new group
for r in rl:iter () do
new_group:add (r)
end
-- set key-value pairs for the group
new_group:set_color (color)
new_group:set_gain (false)
new_group:set_monitoring (false)
new_group:set_mute (false)
new_group:set_recenable (false)
new_group:set_route_active (false)
new_group:set_select (false)
new_group:set_solo (false)
end
end
Thanks for sharing your script! It would be easier for us to read if you edited your message and wrapped the whole thing in triple backticks, top and bottom, with lua after the top one (to get the best syntax highlighting). E.g.:
ardour {
[“type”] = “EditorAction”,
name = “FreshGroup”,
license = “MIT”,
author = “Assistant”,
description = [[MakeFreshGroup]]
function factory () return function ()
-- function body here
end end
Nice idea. As requested, the below script variation will give the group a unique name (number). It also does nothing if no tracks are selected, rather than create an empty group. And it comments out the set_color() line because that is not doing anything (color is not defined in your script).
ardour {
["type"] = "EditorAction",
name = "FreshGroup",
license = "MIT",
author = "Assistant",
description = [[MakeFreshGroup]]
}
function factory()
return function()
-- get the selected tracks
local rl = Editor:get_selection ().tracks:routelist ()
if rl:size () == 0 or (rl:size() == 1 and rl:front ():is_master ()) then
-- nothing selected, or only the Master is selected
print "no tracks selected"
else
-- create a name for the group: the first number from 1
-- onwards that no group is already named
local groupName
for i = 1,50 do
local exists = false
for g in Session:route_groups ():iter () do
if g:name() == tostring(i) then
exists = true
break
end
end
if not exists then
groupName = tostring(i)
break
end
end
-- create a new group
local new_group = Session:new_route_group (groupName)
-- add selected track(s) to the new group
for r in rl:iter () do
new_group:add (r)
end
-- set key-value pairs for the group
--new_group:set_color (color)
new_group:set_gain (false)
new_group:set_monitoring (false)
new_group:set_mute (false)
new_group:set_recenable (false)
new_group:set_route_active (false)
new_group:set_select (false)
new_group:set_solo (false)
end
end
end