I had need of a script that would recombine poly files which had been split into mono files by evil, nasty, picture editing software. I had two major requirements: First the audio in the files had to retain their relationship to the Reaper timeline (unlike 3rd party poly-channel combiners - what better place to accomplish this than inside Reaper). And second, the channel combiner had to retain the handles (audio information outside the slip edits).
One can almost accomplish this with Reaper's glue, except that glue loses everything beyond the slip edits.
I imagine this script being most useful to my fellow audio-for-picture engineers, but I hope others may find it useful as well.
The script is here:
https://stash.reaper.fm/21978/mono2poly.py
The script's documentation header is below as it will give you a pretty good sense of what the script does (so you can decide whether you want to bother with it or not):
"""
mono2poly.py - (C) 2014 Doug Gallob
v1.0
Consolidate selected items with mono audio source files into items with
poly-channel source files.
NOTE: Presently uses a 3rd party executable approach with sox. You will
need to have the audio utility sox installed on your machine in order
to use this script.
As of this writing, you could find sox here:
http://sox.sourceforge.net/
TODO: Someday look into using more integrated audio manipulation libraries.
__________________________________________________ ____________________________
APPLICATION:
My primary need for this script was to re-join stereo files split into
separate mono files by video editing software (OMF/AAF exports - sometimes
hundreds of split stereo clips) - WITHOUT losing the audio in the handles
(i.e. audio in the source files, but outside the slip edits) and WITHOUT
losing the audio's location on the timeline.
There are plenty of 3rd party tools to rejoin split stereo files, but because
they are outside of Reaper, they are not suitable for retaining the Reaper
timeline location.
There are also tools within Reaper for recombining stereo files, like "glue",
but glue does not retain the audio in the handles, an absolute necessity for
sound-for-picture work.
This script should allow you to re-assemble stereo files so that they can be
popped open in an external editor like Izotope RX and cleaned up as stereo
files.
Given that application, I generalized this script for the broader problem of
re-combining mono items into poly files of any number of channels.
Although the most common case will be to combine audio that starts and ends
at the same point in time, this script attempts to avoid that restriction
and allows combination of sources that may begin and end at different times
(provided they overlap somewhere in time).
__________________________________________________ ____________________________
BASIC USAGE:
Install sox and modify this script to point to your sox executable. search for
"sox = " in the code to find the right line to modify (or just scroll down -
I tried to keep that statement near the top few lines of code.)
Select several items that overlap in time and run this script.
You can select items across several areas of overlap. For example, selecting
all 4 of the following items,
tr1: |mono item 1| |mono item 3|
tr2: |mono item 2| |mono item 4|
would create two new items, each containing a 2-channel source file. One would
contain audio from mono 1 and mono 2. The second, audio from mono 3 and mono 4.
On the other hand, if all 4 of those items overlap in time, like this:
tr1: |mono item 1| |mono item 3|
tr2: --- |mono item 2| |mono item 4|
then this script would consolidate all 4 items into a single 4-channel poly
file (padding appropriately with silence where necessary so that each element
of audio retains its original relationship to the timeline).
__________________________________________________ ____________________________
ADDITIONAL DETAILS ON BEHAVIOR:
There is much this script will NOT do. I tried to document as many of its
limitations as I could foresee. If not here in this header, then throughout
the code. Search for "TODO"s and "NOTE"s and "WARNING"s below.
- The new poly items will be created on a new track above the first selected
original item.
- Original items will not be deleted.
- Restores earliest leading slip edit and latest trailing slip edit of
originally selected mono items to new poly item.
- Ignores fades, envelopes, and pans. This is not glue!! I could not identify
the most intuitive behavior for item level volume information while still
respecting my primary objective for the typical case of simply re-combining
underlying sources originally split elsewhere. I am open to suggestions for
preferred behavior.
- BWF metadata preservation is not guaranteed in the new poly files. I did
not test what sox does to input BWF chunks when combining BWF files.
TODO - Theoretically, BWF metadata can be exported (preserved) and imported
(restored) by the command line version of BWF Metaedit. Look into this
sometime.
- Works on Windows. Untested on Mac! sox uses an odd piped/quoted command
line syntax for padding and combining input files. By the time I got the
proper quote escaping that worked for python and for sox and for the OS, my
brain was bleeding. If it doesn't work for you on the Mac, you may need to
play with the command line quoting a bit yourself.
__________________________________________________ ____________________________
LICENSE:
The script is free to use personally or commercially. However, if you find it
useful, I would appreciate a note in this forum letting me know.
This script may not be modified for commercial purposes without my permission.
You may modify this script to improve its behavior (or to make it more
"Pythonic", or more "Reaperish") for your own use or to share with the Reaper
community, BUT if you do, you must:
1. Give me just a bit of credit for the original script.
2. Share a copy of the improved script with me.
If you have a better approach to anything I'm doing here, I would be extremely
grateful if you would share it.
"""