Skip to content
Snippets Groups Projects
Commit 2a1282a9 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Implement all time signatures with appropriate fallbacks and warning if...

Implement all time signatures with appropriate fallbacks and warning if feature not supported by MusicXML
parent cc2b7951
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
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
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment