ardour/share/scripts/_sort_tracks_by_name.lua

33 lines
812 B
Lua
Raw Normal View History

2019-06-20 18:43:29 -04:00
ardour {
2019-06-20 18:46:23 -04:00
["type"] = "EditorAction",
name = "Track Sort",
2020-09-30 16:06:35 -04:00
author = "Ardour Team",
2019-06-20 18:46:23 -04:00
description = [[Sort tracks alphabetically by name]]
2019-06-20 18:43:29 -04:00
}
function factory () return function ()
2019-06-24 09:09:34 -04:00
-- sort compare function
-- a,b here are http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Route
-- return true if route "a" should be ordered before route "b"
2019-06-20 18:43:29 -04:00
function tsort (a, b)
return a:name() < b:name()
end
2019-06-24 09:09:34 -04:00
-- create a sortable list of tracks
2019-06-20 18:43:29 -04:00
local tracklist = {}
2019-06-20 18:46:23 -04:00
for t in Session:get_tracks():iter() do
table.insert(tracklist, t)
end
2019-06-20 18:43:29 -04:00
2019-06-24 09:09:34 -04:00
-- sort the list using the compare function
2019-06-20 18:46:23 -04:00
table.sort(tracklist, tsort)
2019-06-20 18:43:29 -04:00
2019-06-24 09:09:34 -04:00
-- traverse the sorted list and assign "presentation-order" to each track
2019-06-20 18:46:23 -04:00
local pos = 1;
for _, t in ipairs(tracklist) do
t:set_presentation_order(pos)
pos = pos + 1
end
end end