Add a Lua script to send multiple tracks to an aux-bus.
[ardour.git] / scripts / send_to_bus.lua
1 ardour { ["type"] = "EditorAction", name = "Send Tracks to Bus",
2         license     = "MIT",
3         author      = "Ardour Team",
4         description = [[Create a Bus and add aux-sends from all selected tracks]]
5 }
6
7 function factory () return function ()
8         -- find number of channels to use for the new bus, follow master-bus' inputs
9         local chn = 2
10         local mst = Session:master_out();
11         if not mst:isnil() then
12                 chn = mst:n_inputs():n_audio()
13         end
14         mst = nil -- explicitly drop reference
15
16         local sel = Editor:get_selection () -- get selection
17         local tracks = ARDOUR.RouteListPtr() -- create a new list
18
19         -- find selected *tracks*, add to tracks list
20         for r in sel.tracks:routelist ():iter () do
21                 if r:to_track():isnil() then
22                         goto next
23                 end
24                 tracks:push_back (r)
25                 ::next::
26         end
27
28         if tracks:size() > 0 then
29                 local bus = Session:new_audio_route (chn, chn, nil, 1, "", ARDOUR.PresentationInfo.Flag.AudioBus, ARDOUR.PresentationInfo.max_order)
30                 if bus:size () > 0 then
31                         Session:add_internal_sends (bus:front(), ARDOUR.Placement.PostFader, tracks);
32                 end
33         end
34 end end
35
36 function icon (params) return function (ctx, width, height, fg)
37         local txt = Cairo.PangoLayout (ctx, "ArdourMono ".. math.ceil(math.min (width, height) * .5) .. "px")
38         txt:set_text ("\u{2192}B") -- "->B"
39         local tw, th = txt:get_pixel_size ()
40         ctx:move_to (.5 * (width - tw), .5 * (height - th))
41         ctx:set_source_rgba (ARDOUR.LuaAPI.color_to_rgba (fg))
42         txt:show_in_cairo_context (ctx)
43 end end