Fun with Awk, XML and Ardour
First rule of XML club is "Never use text munging tools with XML".
Here's a case where I successfully used text munging tools with XML. I had Ardour with a video clip inserted, against which I was preparing to compose a soundtrack. Part of my workflow for that is to run through the video and add markers to the timeline for events in the clip (camera angle changes, focus shifts, actions points etc) in order to later line up musical elements to the video action. I had just done this and then discovered that for some reason Ardour's session had the wrong frame rate with respect to the clip (it usually adjusts it automagically when you import a clip, so not sure what happened - probably PEBKAC). Anyway, after fixing the frame rate in session properties (from 30fps to 23.97fps), my markers no longer lined up at the right frames.
Rather than drag them into place manually, I decided to "just" break out awk and modify the ardour session file to move the markers. This was both very clever and very stupid. It probably took longer to solve than it would have to just re-do the markers. But now I have slightly better awk skills. Fair trade.
First, I saved the session, then moved my "last frame" marker to the right spot and saved it again to a different file. Comparing the xml in the two files showed me the two values for the end marker:
$ diff -u musi364-dungbeetle.ardour-prefpsfix musi364-dungbeetle.ardour | grep Location.*session
- <Location id="215" name="session" start="0" end="5935630" flags="IsSessionRange" locked="0" position-lock-style="AudioTime"/>
+ <Location id="215" name="session" start="0" end="7427419" flags="IsSessionRange" locked="0" position-lock-style="AudioTime"/>
The difference between the end values gave me a factor I could multiply all other start/end values in order to slid my markers to the new positions - I just had to multiply each start and end marker location by 1.25132782872 (ie, 7427419 / 5935630). Awk to the rescue!
cat sessionfile.ardour | awk -vFS='"' -vOFS='"'
'{
if ($1 == " <Location id=" && $5 == " start="){
$6=int($6 * 1.25132782872); $8=int($8 * 1.25132782872)
};
print
}' > sessionfile.ardour-fixed
(linebreaks added for readability).
The evil here is assuming that the xml is consistently formed from ardour (it is) and assuming that no other lines contained the >Location id= string that I was matching against (they don't).
Hey, presto! All my markers now lined up with the footage (within a frame or so for rounding and floating point suckage) and life is good again...
Now to battle with sync of tempo maps between musescore and ardour...
Add new comment