007b1363563e1260aff010e1753c9cc033a7e02f
[ardour.git] / scripts / track_organizer.lua
1 ardour {
2     ["type"] = "EditorAction",
3     name = "Track Organizer",
4     author = "Mixbus Lua Taskforce",
5     description = [[Easily modifiable session overview and track property editor]]
6 }
7
8 function factory () return function ()
9
10     local rbow = { ["----"] = "", ["Red"] = 0xD10000FF, ["Orange"] = 0xFF6622FF, ["Yellow"] = 0xFFDA21FF,
11     ["Green"] = 0x33DD00FF, ["Blue"] = 0x1133CCFF, ["Indigo"] = 0x220066FF, ["Violet"] = 0x330044FF
12 }
13
14    --now  starting to build our dialog
15    local dialog_options = {
16       { type = "label", colspan="4", title = "Change your Track settings here:" },
17       { type = "heading", title = "Track",   col = 0, colspan = 1 },
18       { type = "heading", title = "Group",   col = 1, colspan = 1 },
19       { type = "heading", title = "Comment", col = 2, colspan = 1 },
20       { type = "heading", title = "Color",   col = 3, colspan = 1 },
21    }
22
23    --group option payload
24    --@ToDo: Add 'fake' groups for people to select, create them if they want it
25    local pl = {["----"]   = "", ["Drums"] = "Drums", ["Bass"] = "Bass", ["Guitars"] = "Guitars",
26    ["Keys"] = "Keys", ["Strings"] = "Strings", ["Vox"] = "Vox"
27 }
28
29    for g in Session:route_groups():iter() do
30        pl[g:name()] = g
31    end
32
33    --helper function to find default group option
34    function interrogate(t)
35        local v = "----"
36        for g in Session:route_groups():iter() do
37            for r in g:route_list():iter() do
38                if r:name() == t:name() then v = g:name() end
39            end
40        end return v
41    end
42
43    function find_color(t)
44        local c = "----"
45        for k, v in pairs(rbow) do
46            if(t:presentation_info_ptr():color() == v) then c = k end
47        end return c
48    end
49
50    --insert an entry into our dialog_options table for each track with appropriate info
51    for t in Session:get_tracks():iter() do
52        table.insert(dialog_options, {
53            type = "entry",    key = t:name() .. ' n',  col = 0, colspan = 1, default = t:name(), title = "" --@ToDo: Shorten Names so they can still see what track they're changing?
54        }) --name
55        table.insert(dialog_options, {
56            type = "dropdown", key = t:name() .. ' g',  col = 1, colspan = 1, title = "", values = pl, default = interrogate(t)
57        }) --group
58        table.insert(dialog_options, {
59            type = "entry",    key = t:name() .. ' cm', col = 2, colspan = 1, default = t:comment(), title = ""
60        }) --comment
61        table.insert(dialog_options, {
62            type = "dropdown", key = t:name() .. ' c',  col = 3, colspan = 1, title = "", values = rbow, default = find_color(t)
63        }) --color
64    end
65
66    table.insert(dialog_options, {
67       { type = "label", colspan="3", title = "" },
68       { type = "label", colspan="3", title = "Note that this is a script which can be user-edited to match your needs." },
69       { type = "label", colspan="3", title = "" },
70    })
71
72    --run dialog_options
73    local rv = LuaDialog.Dialog("Track Organizer", dialog_options):run()
74    if not(rv) then goto script_end end
75    assert(rv, 'Dialog box was cancelled or is ' .. type(rv))
76
77    --begin track operation
78    for t in Session:get_tracks():iter() do
79        local cgrp = interrogate(t)
80        local name = rv[t:name() .. ' n' ]
81        local ngrp = rv[t:name() .. ' g' ]
82        local cmnt = rv[t:name() .. ' cm']
83        local colr = rv[t:name() .. ' c' ]
84
85        if t:name() ~= name    then t:set_name(name)         end
86
87        if t:comment() ~= cmnt then t:set_comment(cmnt, nil) end
88
89        if not(colr == "") then t:presentation_info_ptr():set_color(colr) end
90
91        if type(ngrp) == "userdata" then
92            if cgrp ~= ngrp:name() then
93                ngrp:add(t)
94            end
95        end
96
97        if type(ngrp) == "string" and not(ngrp == "") then
98            ngrp = Session:new_route_group(ngrp)
99            if cgrp ~= ngrp:name() then
100                ngrp:add(t)
101            end
102        end
103    end
104
105         ::script_end::
106 end end