lua-scope handle unconnected in-place buffers
[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 p = params or {}
24                 local uniq = p["unique"] or "yes"
25                 local pos = p["position"] or 0
26
27                 -- loop over all tracks
28                 for t in Session:get_tracks():iter() do
29                         local insert = true;
30
31                         -- check if a scope is already present
32                         if uniq ~= "no" then
33                                 local proc;
34                                 local i = 0;
35                                 repeat
36                                         -- get Nth Ardour::Processor
37                                         proc = t:nth_plugin (i)
38                                         -- check if it's a scope
39                                         if (not proc:isnil() and proc:display_name () == "Inline Scope") then
40                                                 insert = false;
41                                         end
42                                         i = i + 1
43                                 until proc:isnil() or insert == false
44                         end
45
46                         -- create a new processor and insert it
47                         if insert then
48                                 local a = ARDOUR.LuaAPI.new_luaproc(Session, "Inline Scope");
49                                 if (not a:isnil()) then
50                                         t:add_processor_by_index(a, pos, nil, true)
51                                         ARDOUR.LuaAPI.set_processor_param (a, 0, 5) -- timescale 5sec
52                                         -- ARDOUR.LuaAPI.set_processor_param (a, 1, 1) -- logscale on
53                                         -- ARDOUR.LuaAPI.set_processor_param (a, 2, 3) -- "Max" height
54                                         a = nil -- explicitly drop shared-ptr reference
55                                 end
56                         end
57                 end
58         end
59 end