From 2a1282a9be32326ec3d560ca3679ecd2e702169d Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer <reinhold@kainhofer.com> Date: Sun, 18 Jul 2010 17:51:03 +0200 Subject: [PATCH] Implement all time signatures with appropriate fallbacks and warning if feature not supported by MusicXML --- pae2xml.pl | 76 ++++++++++------------ sample_files/TimeSignature-alternating.pae | 7 ++ sample_files/TimeSignature.pae | 7 ++ 3 files changed, 50 insertions(+), 40 deletions(-) create mode 100644 sample_files/TimeSignature-alternating.pae create mode 100644 sample_files/TimeSignature.pae diff --git a/pae2xml.pl b/pae2xml.pl index 9158eae..61990e0 100755 --- a/pae2xml.pl +++ b/pae2xml.pl @@ -167,7 +167,7 @@ sub parse_pe { $pe =~ s/@�/@0�/gs; # make missing time signature explicit while ($pe =~ s/([^\-])(\d+)(\'|\,)(A|B|C|D|E|F|G)/$1$3$2$4/gs) {}; # octave first, then duration. Truly global. - if ($pe =~ /^\s*(%([\w\-\+\d]+))?(@([\d\w\/]+))?\s*&?\s*(\$([^�]*))?�(.*)$/gs) { + if ($pe =~ /^\s*(%([\w\-\+\d]+))?(@([\d\w\/ ]+))?\s*&?\s*(\$([^�]*))?�(.*)$/gs) { my ($clef, $timesig, $keysig, $rest) = ($2, $4, $6, $7); print "Writing $filename...\n"; @@ -363,8 +363,8 @@ sub parse_notes { print OUT " <attributes>\n"; print OUT clef ($clef); print OUT " </attributes>\n"; - } elsif ($notes =~ /^@(\d\/\d|c\/?)\s*(.*)$/) { # time signatue change - ($timesig,$notes) = ($1,$2); + } elsif ($notes =~ /^@(c?\d+(\/\d+)?( \d+\/\d+)*|c\/?|o\.?)\s*(.*)$/) { # time signatue change + ($timesig,$notes) = ($1,$4); print OUT " <attributes>\n"; print OUT timesignature($timesig); print OUT " </attributes>\n"; @@ -730,54 +730,50 @@ sub keysignature { sub timesignature { my ($timesig) = @_; + my $symbol = ""; - if ($timesig eq "c3") { - $timesig = "3/2"; # it would be better to display it as "C". Example: 451.023.814 + if ($timesig =~ /^(o(\.)?)$/) { + if ($2 eq ".") { + $timesig = "9/8"; + } else { + $timesig = "3/4"; + } + print "Mensural time signature \"$1\" not supported, using $timesig.\n"; + } + if ($timesig =~ /^(\d+\/\d+)( \d+\/\d+)+$/ ) { + print "Alternating time signature \"$timesig\" not supported by MusicXML, falling back to $1.\n"; + $timesig = $1; } - if ($timesig =~ /^c(\d+)\/(\d+)$/gs) { - $timesig = "$1/$2"; # it would be better to show the "C" + # TODO: + if ($timesig =~ /^c((\d+)(\/(\d+))?)$/gs) { + print "Time signature \"$timesig\" not supported by MusicXML, falling back to $1.\n"; + $timesig = "$1"; # it would be better to show the "C". Example: 451.023.814 } - if ($timesig eq "0" || $timesig eq "") { # unclear how to handle absence of time signature. - $timesig =' <time symbol="common"> - <beats>4</beats> - <beat-type>4</beat-type> - </time> -'; # using 4/4 for now. + # For missing timesignature, fall back to "c" + if ($timesig eq "0" || $timesig eq "" || $timesig eq "c" ) { + $symbol = "common"; ($beats, $beattype) = (4,4); - } elsif ($timesig =~ /^c(\/?)$/gi) { - if ($1 eq "/") { - $timesig = ' <time symbol="cut"> - <beats>2</beats> - <beat-type>2</beat-type> - </time> -'; - ($beats, $beattype) = (2,2); - } else { - $timesig = ' <time symbol="common"> - <beats>4</beats> - <beat-type>4</beat-type> - </time> -'; - ($beats, $beattype) = (4,4); - } + } elsif ($timesig =~ /^c\/$/gi) { + $symbol = "cut"; + ($beats, $beattype) = (2,2); } elsif ($timesig =~ /^(\d+)\/(\d+)$/gs) { ($beats, $beattype) = ($1, $2); - $timesig = ' <time> - <beats>'.$beats.'</beats> - <beat-type>'.$beattype.'</beat-type> - </time> -'; + } elsif ($timesig =~/^(\d+)$/gs) { + $symbol = "single-number"; + ($beats, $beattype) = ($1,2); } else { print_error("Time signature '$timesig' looks strange.\n"); - # $timesig = ""; we assume 4/4 just to get something legible: ($beats, $beattype) = (4,4); - $timesig = ' <time> - <beats>'.$beats.'</beats> - <beat-type>'.$beattype.'</beat-type> - </time> -'; } + if ($symbol) { + $symbol = " symbol=\"$symbol\""; + } + $timesig = " <time$symbol> + <beats>$beats</beats> + <beat-type>$beattype</beat-type> + </time> +"; return $timesig; } diff --git a/sample_files/TimeSignature-alternating.pae b/sample_files/TimeSignature-alternating.pae new file mode 100644 index 0000000..b28d27b --- /dev/null +++ b/sample_files/TimeSignature-alternating.pae @@ -0,0 +1,7 @@ +Test Composer +Test case for alternating time signature +1.1.1: S alternating time signature +plain&easy: %G-2@4/4 3/4$� '1C/2.C/1C/2.C// + +Test Library +00000000 \ No newline at end of file diff --git a/sample_files/TimeSignature.pae b/sample_files/TimeSignature.pae new file mode 100644 index 0000000..897dba2 --- /dev/null +++ b/sample_files/TimeSignature.pae @@ -0,0 +1,7 @@ +Test Composer +Test case for time signatures +1.1.1: S time signatures +plain&easy: %G-2@c$� '1C/@2/4 2C/@12/16 2.C/@3 2C/@c 1C/@c3 C/@c3/2 1.C/@c/ 1C/@o 2.C/@o. 2.C/@4/4 3/4 1C/2.C/1C/@c 1C/@4 9C// + +Test Library +00000000 \ No newline at end of file -- GitLab