fix drawing of zero-length notes
[ardour.git] / scripts / _sort_tracks_by_name.lua
1 ardour {
2         ["type"] = "EditorAction",
3         name = "Track Sort",
4         author = "Ardour Lua Taskforce",
5         description = [[Sort tracks alphabetically by name]]
6 }
7
8 function factory () return function ()
9
10         -- sort compare function
11         -- a,b here are http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Route
12         -- return true if route "a" should be ordered before route "b"
13         function tsort (a, b)
14                 return a:name() < b:name()
15         end
16
17         -- create a sortable list of tracks
18         local tracklist = {}
19         for t in Session:get_tracks():iter() do
20                 table.insert(tracklist, t)
21         end
22
23         -- sort the list using the compare function
24         table.sort(tracklist, tsort)
25
26         -- traverse the sorted list and assign "presentation-order" to each track
27         local pos = 1;
28         for _, t in ipairs(tracklist) do
29                 t:set_presentation_order(pos)
30                 pos = pos + 1
31         end
32
33         -- drop all track references
34         tracklist = nil
35         collectgarbage ()
36 end end