summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2017-08-23 19:39:23 +0200
committerRobin Gareus <robin@gareus.org>2017-08-23 21:33:29 +0200
commita96d64e4f372daab23cf0d4e532c50548b271ee5 (patch)
treecab18d408f244f305a8e228c56ce9395e0942735 /scripts
parentea5d75a05b76c8e61e2261521339e385d81094d0 (diff)
Example Stereo to 2 x Mono track Lua script
Diffstat (limited to 'scripts')
-rw-r--r--scripts/_stereo_to_mono.lua57
1 files changed, 57 insertions, 0 deletions
diff --git a/scripts/_stereo_to_mono.lua b/scripts/_stereo_to_mono.lua
new file mode 100644
index 0000000000..81fa0316a7
--- /dev/null
+++ b/scripts/_stereo_to_mono.lua
@@ -0,0 +1,57 @@
+ardour { ["type"] = "EditorAction", name = "Stereo to Mono",
+ license = "MIT",
+ author = "Ardour Team",
+ description = [[Convert a Stereo Track into two Mono Tracks]]
+}
+
+
+function factory (params) return function ()
+ -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:Selection
+ -- the Ardour Selection can include multiple items
+ -- (regions, tracks, ranges, markers, automation, midi-notes etc)
+ local sel = Editor:get_selection ()
+
+ -- for each track..
+ for t in sel.tracks:routelist ():iter () do
+ local track = t:to_track ()
+ if track:isnil() then goto next end
+
+ -- only audio tracks
+ local playlist = track:playlist ()
+ if playlist:data_type ():to_string () ~= "audio" then goto next end
+
+ -- skip tracks without any regions
+ if playlist:region_list ():size() == 0 then goto next end
+
+ -- we can't access diskstream n_channels()
+ local channels = track:n_inputs(): n_audio()
+
+ -- stereo only
+ if channels ~= 2 then goto next end
+
+ -- create 2 new tracks (using the name of the original track)(
+ local newtracks = Session:new_audio_track (2, 2, nil, 2, t:name(), ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
+ assert (newtracks:size() == 2)
+
+ for r in playlist:region_list ():iter () do
+ local region = r:to_audioregion ()
+ local rl = ARDOUR.RegionVector ()
+ local _, rv = region:separate_by_channel (rl)
+ assert (rv[1]:size () == 2)
+ -- 1:1 mapping of regions to new tacks
+ local plc = 1
+ for nr in rv[1]:iter () do
+ local pl = newtracks:table()[plc]:playlist()
+ pl:add_region (nr, r:position(), 1, false, 0, 0, false)
+ plc = plc + 1
+ end
+ end
+
+ -- TODO remove the old track
+
+ -- drop references for good.
+ collectgarbage ()
+ ::next::
+ end
+
+end end