Stupid User Tricks - AutoMixing multiple projects with a shell script
I have an oddball little thing I'm doing with ardour that may or may not be an idea anyone else is interested in, so I'll share it.
But I'm also having a small problem with it, and am looking for a hand figuring it out. This could go under either "how do I" or here, I suppose... I'll just post it here. :)
First, the scenario in which it would be useful... mine. Or maybe any other instance where one has a large number of ardour projects that consist of live recordings (multiple tracks) of the same sources.
For example, I started recording band rehearsals and writing/jam session. Each "take" is a separate named ardour project, but they all are identical sources. The same instruments, the same mics, the same levels on all of the amps/mixers/etc.
At the end of a session I would do a rough mix (setting basic levels for the tracks, etc), exporting to wav/mp3, then distribute to the other participants before heading home.
I found myself making the same kinds of changes for each file, which was sort of time consuming. I started thinking there had to be a way to automatically make the same changes to a bunch of ardour files at once.
(Perhaps making those changes to my template beforehand would get me the same end-result... but I still thought "mass identical changes" might be nice. Namely the ability to apply mass changes AFTER recording, which would be outside the scope of templates. I could also maybe record everything in a single long session... But thought it might be time consuming to break it back into pieces. Tips along those lines are welcome.)
Anyway, here's what I'm doing... After testing last night there is a bit of a hicccup, but it is mostly working:
Using a shell script, some variable assignment (to handle track names and changes to make) and a bunch of string replacements (with sed), I'm making changes directly to the projectname.ardour file.
The first thing the script does is look for a configuration file. Which is nothing but another bash script that assigns a bunch of variables. First it looks in the current working directory, then in the home directory. If found in neither, it goes with some defaults.
Then it takes the name of the file to be processed (passed via command line of course) and goes to work making a bunch of string replacements based on the settings made in the config file. Pretty simple, really.
Here are some small snippets from it... Enough to get the basic idea:
# Track Names:
# Mute Setting:
# Invert Phase Setting:
# Gain Changes:
sed -e "s/\(name=.$track_00.*\)gain.*iolimits/\1gain=\"$gain_00\" iolimits/" $filename |
sed -e "s/\(name=.$track_01.*\)gain.*iolimits/\1gain=\"$gain_01\" iolimits/" |
sed -e "s/\(name=.$track_02.*\)gain.*iolimits/\1gain=\"$gain_02\" iolimits/" |
# Doing a match over 3 lines is a pain, and it was easier to
# Combine two of the lines first, then break them back up again when done.
# So that's what I did.
sed "N;s/\(Route.active.*\)\n\(.*MIDI.*\)/\1XXX\2/g;P;D;" |
sed "N;s/\(Route.active.*\)muted=.*soloed\(.*\)phase-invert=.*mute\(.*\n.*IO.name=.$track_00\)/\1muted=\"$mute_00\" soloed\2phase-invert=\"$phase_00\" mute\3/g;P;D;" |
sed "N;s/\(Route.active.*\)muted=.*soloed\(.*\)phase-invert=.*mute\(.*\n.*IO.name=.$track_01\)/\1muted=\"$mute_01\" soloed\2phase-invert=\"$phase_01\" mute\3/g;P;D;" |
sed "N;s/\(Route.active.*\)muted=.*soloed\(.*\)phase-invert=.*mute\(.*\n.*IO.name=.$track_02\)/\1muted=\"$mute_02\" soloed\2phase-invert=\"$phase_02\" mute\3/g;P;D;" |
sed "N;s/\(Route.active.*\)XXX\(.*MIDI.*\)/\1\n\2/g;P;D;" > $filename.automix
If anyone actually wants a copy of this thing, I'm happy to post it. The guts that make it actually work are right there, though.
FWIW, I'm sure an actual programmer (which I am not) could do a much better/cleaner job of it with better design (even I know it's pretty ugly/hackish), or even by using proper XML processing tools instead of bash and sed. But hey... It's a start and it is mostly working.
That said, here is the problem I'm having:
For some reason, ardour doesn't seem to like opening a file that doesn't end in the name ".ardour". Even just copying/renaming a known good file to anything else seems to make it barf. (It says it can understand it, and won't open it.)
It doesn't like it if .ardour appears more than once, either. ("project1.ardour.new.ardour") Oddly enough, if I have it just overwrite the original file ("project.ardour"), it works beautifully. It does exactly what I expect it to do. Mutes the track I want muted for all but one or two of the projects, flips the phase on the kickdrum track, sets the levels to match what I want. (I got the numbers by reading the file from a project with good basic levels.)
Another thing it doesn't like... I have another small script whose sole purpose is to call this one against a whole batch of files. In my filesystem, all projects recorded on a given day are in unique directory, named by the date. My goal is to drop into this particular directory (which may or may not contain a unique config file to be used), and... well, just read it:
for file in */*.ardour
echo " "
echo "Press ENTER to continue. "
It works, but... ardour won't read the resulting file. It's weird... for the same file I can run the main script and it works fine. But call it with this little snippet, and it can't read the file it makes. I haven't done a diff on a copy of each yet (ran out of time) but... it seems silly that there would be a difference.
Am I missing something totally obvious? Is there some magic involved with ardour reading an XML file that makes it not like copy of a working file that just doesn't match the usual name it uses? Is there some magic in an XML file to make some inexplicable difference between the result of running my main script manually (which works) and calling it with another one (which doesn't)?
Any help with those last annoying bits is much appreciated!
Now, my ultimate goal will have to wait until ardour to gains some "offline" scripting ability. Namely, to export an entire project to wav (the main L/R channels, same as one can do in the GUI) via the command line.
That would be the slickest thing ever. If I could do that... imagine what could happen with a single script! The entire nights work could be rough-mixed, exported to wav, burned to CD, and encoded into mp3... all while I go have a beer. That would ROCK!!!!! :)