Fix ExportFormatSpecification copy-c'tor
[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 not r:to_track ():isnil () then
22                         tracks:push_back (r)
23                 end
24         end
25
26         if tracks:size () > 0 then
27                 local bus = Session:new_audio_route (chn, chn, nil, 1, "", ARDOUR.PresentationInfo.Flag.AudioBus, ARDOUR.PresentationInfo.max_order)
28                 if bus:size () > 0 then
29                         Session:add_internal_sends (bus:front (), ARDOUR.Placement.PostFader, tracks);
30                 end
31         end
32 end end
33
34 function icon (params) return function (ctx, width, height, fg)
35         local txt = Cairo.PangoLayout (ctx, "ArdourMono ".. math.ceil (math.min (width, height) * .5) .. "px")
36         txt:set_text ("\u{2192}B") -- "->B"
37         local tw, th = txt:get_pixel_size ()
38         ctx:move_to (.5 * (width - tw), .5 * (height - th))
39         ctx:set_source_rgba (ARDOUR.LuaAPI.color_to_rgba (fg))
40         txt:show_in_cairo_context (ctx)
41 end end