Add a Lua Action Script to add scopes to all tracks
[ardour.git] / scripts / addscopes.lua
1 ardour {
2         ["type"]    = "EditorAction",
3         name        = "Add Scopes",
4         license     = "MIT",
5         author      = "Robin Gareus",
6         email       = "robin@gareus.org",
7         site        = "http://gareus.org",
8         description = [[Add 'Inline Scope' Lua Processor to all Tracks]]
9 }
10
11 function action_params ()
12         return
13         {
14                 ["unique"]   = { title = "Only add Scope if non is present already (yes/no)", default = "yes"},
15                 ["position"] = { title = "Insert Position from top (0,..)",                   default = "0"},
16         }
17 end
18
19
20 function factory (params)
21         return function ()
22                 -- get configuration
23                 local uniq = params["unique"] or "yes"
24                 local pos = params["position"] or 0
25
26                 -- loop over all tracks
27                 for t in Session:get_tracks():iter() do
28                         local insert = true;
29
30                         -- check if a scope is already present
31                         if uniq ~= "no" then
32                                 local proc;
33                                 local i = 0;
34                                 repeat
35                                         -- get Nth Ardour::Processor
36                                         proc = t:nth_plugin (i)
37                                         -- check if it's a scope
38                                         if (not proc:isnil() and proc:display_name () == "Inline Scope") then
39                                                 insert = false;
40                                         end
41                                         i = i + 1
42                                 until proc:isnil() or insert == false
43                         end
44
45                         -- create a new processor and insert it
46                         if insert then
47                                 local a = ARDOUR.LuaAPI.new_luaproc(Session, "Inline Scope");
48                                 if (not a:isnil()) then
49                                         t:add_processor_by_index(a, pos, nil, true)
50                                         a = nil
51                                 end
52                         end
53                 end
54         end
55 end