Monday, March 23, 2009

Finale Duplicated Chords Bug Fix

Finale has come a long way since it was first introduced. For me, it used to be only a typographical software -- I used to compose in a sequencer and then import the MIDI file into Finale to do the output. I had to do that because Finale didn't have good editing capability, nor did it sound good. However, its recent versions have improved to a point where I can do most of my work in it. (I still use my sequencer to produce the demo track since MIDI editing and virtual instrument tweaking is not Finale's strength (yet?).) There are a few things that I think would make Finale better.

One of them I encountered recently when I was trying to meet a dead line was the bug in Chord copying. When I was writing block chords for a whole reed section, I kept using Exploding and Imploding back and forth, which makes Finale slower and slower and eventually unusable. It turns out that when Finale copies a chord onto an existing one, it does not erase the original one. Therefore, if there is a chord symbol on an imploded staff, exploding would make, say, 5 copies of that chord onto 5 different staffs. When I implode them back to the top staff, the top staff chord, though looking like one copy, is actually 5 identical copies. If I try to delete it, I have to do it 5 times. Now, if I explode again, each of the 5 staffs will have 5 identical chords. Another implode will yield to 25 copies in the top staff. And then 125 copies, 625 copies, etc.

Obviously what Finale needs to do is overwrite the original copy rather than create another identical copy.

I was meeting a dead line, so I had to solve it myself. What I did was to export everything into a Music XML file, fix that file, and then import it back.

Here's the Perl code to fix that Music XML file. Since Finale's XML output is predictable, I didn't bother parsing the XML. This script removes duplicated chord symbols by simple string manipulation.


#!/usr/bin/perl
#
# Filename: Finale_MusicXML_Chord_CleanUp.pl
# This Perl code removes duplicated Chord items in Finale's Music XML file.
#
# Usage:
# % perl Finale_MusicXML_Chord_CleanUp.pl < original.xml > fixed.xml
#

my $buffer = "";
my $last_buffer = "";
my $in_harmony = 0;
while (<stdin>)
{
chop $_;
if ($in_harmony && /^\s*<\/harmony/)
{
$buffer .= $_ . "\n";
if ($buffer ne $last_buffer)
{
print $buffer;
$last_buffer = $buffer;
}
$buffer = "";
$in_harmony = 0;
}
elsif (/^\s+<harmony .*/ || $in_harmony)
{
$buffer .= $_ . "\n";
$in_harmony = 1;
}
elsif (! $in_harmony)
{
print $_ . "\n";
}
}

No comments:

Post a Comment