Fix Mixbus action fc83d044f8 & 65bda27d4 rebase ordering
[ardour.git] / scripts / addscopes.lua
1 ardour {
2         ["type"]    = "EditorAction",
3         name        = "Add Scopes",
4         license     = "MIT",
5         author      = "Ardour Team",
6         description = [[Add 'Inline Scope' Lua Processor to all Tracks]]
7 }
8
9 function action_params ()
10         return
11         {
12                 ["unique"]   = { title = "Only add Scope if non is present already (yes/no)", default = "yes"},
13                 ["position"] = { title = "Insert Position from top (0,..)",                   default = "0"},
14         }
15 end
16
17
18 function factory (params)
19         return function ()
20                 -- get configuration
21                 local p = params or {}
22                 local uniq = p["unique"] or "yes"
23                 local pos = p["position"] or 0
24
25                 -- loop over all tracks
26                 for t in Session:get_tracks():iter() do
27                         local insert = true;
28
29                         -- check if a scope is already present
30                         if uniq ~= "no" then
31                                 local proc;
32                                 local i = 0;
33                                 repeat
34                                         -- get Nth Ardour::Processor
35                                         proc = t:nth_plugin (i)
36                                         -- check if it's a scope
37                                         if (not proc:isnil() and proc:display_name () == "a-Inline Scope") then
38                                                 insert = false;
39                                         end
40                                         i = i + 1
41                                 until proc:isnil() or insert == false
42                         end
43
44                         -- create a new processor and insert it
45                         if insert then
46                                 local a = ARDOUR.LuaAPI.new_luaproc(Session, "a-Inline Scope");
47                                 if (not a:isnil()) then
48                                         t:add_processor_by_index(a, pos, nil, true)
49                                         ARDOUR.LuaAPI.set_processor_param (a, 0, 5) -- timescale 5sec
50                                         -- ARDOUR.LuaAPI.set_processor_param (a, 1, 1) -- logscale on
51                                         -- ARDOUR.LuaAPI.set_processor_param (a, 2, 3) -- "Max" height
52                                         a = nil -- explicitly drop shared-ptr reference
53                                 end
54                         end
55                 end
56         end
57 end
58
59
60 function icon (params) return function (ctx, width, height)
61         local wh = math.min (width, height) * .5
62         local x0 = math.ceil (wh * .4)
63         local x1 = math.floor (wh * 1.6)
64         ctx:rectangle (wh * .4, wh * .4, wh * 1.2, wh * 1.2)
65         ctx:set_source_rgba (.7, .7, .7, 1)
66         ctx:fill ()
67         ctx:set_line_width (1)
68         ctx:set_source_rgba (.0, .0, .0, 1)
69         ctx:move_to (x0, wh)
70         for x = x0, x1 do
71                 ctx:line_to (x, wh - math.sin (2 * math.pi * (x-x0) / (x1-x0)) * wh * .5)
72         end
73         ctx:stroke ()
74 end end