1 ardour { ["type"] = "EditorAction", name = "Stereo to Mono",
3 author = "Ardour Team",
4 description = [[Convert a Stereo Track into two Mono Tracks]]
8 function factory (params) return function ()
9 -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:Selection
10 -- the Ardour Selection can include multiple items
11 -- (regions, tracks, ranges, markers, automation, midi-notes etc)
12 local sel = Editor:get_selection ()
15 for t in sel.tracks:routelist ():iter () do
16 local track = t:to_track ()
17 if track:isnil() then goto next end
20 local playlist = track:playlist ()
21 if playlist:data_type ():to_string () ~= "audio" then goto next end
23 -- skip tracks without any regions
24 if playlist:region_list ():size() == 0 then goto next end
26 -- we can't access diskstream n_channels()
27 local channels = track:n_inputs(): n_audio()
30 if channels ~= 2 then goto next end
32 -- create 2 new tracks (using the name of the original track)(
33 local newtracks = Session:new_audio_track (2, 2, nil, 2, t:name(), ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
34 assert (newtracks:size() == 2)
36 for r in playlist:region_list ():iter () do
37 local region = r:to_audioregion ()
38 local rl = ARDOUR.RegionVector ()
39 local _, rv = region:separate_by_channel (rl)
40 assert (rv[1]:size () == 2)
41 -- 1:1 mapping of regions to new tacks
43 for nr in rv[1]:iter () do
44 local pl = newtracks:table()[plc]:playlist()
45 pl:add_region (nr, r:position(), 1, false, 0, 0, false)
50 -- TODO remove the old track
52 -- drop references for good.