diff --git a/pae2xml.pl b/pae2xml.pl index 9158eae1feadd78aea4a025f9f111898e49027b3..61990e055c1186b35ece6a446a4185f1a638beef 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 0000000000000000000000000000000000000000..b28d27be87c79ee2acf01e4209a55e7146380aab --- /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 0000000000000000000000000000000000000000..897dba24e77fa063831a56d4e382422a6e27a61a --- /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