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

Implement proper beaming

parent 900e8313
No related branches found
No related tags found
No related merge requests found
......@@ -62,6 +62,7 @@ $divisions = 960;
$old_duration = $divisions;
$old_type = "";
$old_octave = 4;
$BEAM = 0;
# Store all alterations already used in the current measure, so that e.g.
# xCC also detects the second note as a Cis! Needs to be reset at the
......@@ -244,7 +245,6 @@ sub parse_notes {
}
$notes =~ s/!([^!]*)!(f*)/repeat($1, length($2)+1)/gse; # write out repetitions
$notes =~ s/\{([^\}]*)\}/$1/gs; # ignore beamings
while ( $notes =~ s/(:?\/+:?|^)([^\/:]*)(:?\/+:?)i(:?\/+:?)/$1$2$3$2$4/gs) {}; # replace whole-measure repeats (i notation)
$notes =~ s/(\d+)\(([^;]+\))/\($1$2/gs; # pull note lengths into fermatas or triplets
......@@ -265,6 +265,12 @@ sub parse_notes {
} elsif ($notes =~ /^r(.*)$/) { # End grace
$notes = $1;
$qq = 0;
} elsif ($notes =~ /^{(.*)$/) { # Begin beam
$notes = $1;
$BEAM = 1;
# Beam endings are handled by the last note of the beam, since
# we need to know for the last note that the <beam>end</beam> tag
# should be used!
} elsif ($notes =~ /^\=(\d*)(\/.*)$/) { # multi-measure rests
$measrest = $1;
$notes = $2;
......@@ -300,16 +306,16 @@ sub parse_notes {
}
}
}
} elsif ($notes =~ /^((\^)?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?)(.*)$/) { # a note
} elsif ($notes =~ /^((\^)?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?}?)(.*)$/) { # a note
($note, $notes) = ($1,$7);
parse_note($note, $keysig, "", "", $qq);
} elsif ($notes =~ /^(\((g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)[t\+]*\)[t\+]*)(.*)$/) { # one note with a fermata
} elsif ($notes =~ /^(\((g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)[t\+]*\)[t\+}]*)(.*)$/) { # one note with a fermata
($note, $notes) = ($1,$6);
parse_note($note, $keysig, "", "", $qq);
} elsif ($notes =~ /^(\(((\^)?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?){3}\))(.*)$/) { # a triplet
} elsif ($notes =~ /^(\(((\^)?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?}?){3}\))(.*)$/) { # a triplet
($triplet, $notes) = ($1,$8);
# print "TRIPLET: ".$triplet." -> ";
$triplet =~ /^\(((\^)?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?)(.*)\)$/gs;
$triplet =~ /^\(((\^)?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?}?)(.*)\)$/gs;
($note, $triplet) = ($1,$7);
#print "$note $triplet\n";
parse_note($note, $keysig, '<tuplet type="start"/>', ' <time-modification>
......@@ -327,10 +333,10 @@ sub parse_notes {
<actual-notes>3</actual-notes>
<normal-notes>2</normal-notes>
</time-modification>', $qq);
} elsif ($notes =~ /^((\d+)\(((\^)?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?)+\;(\d+)\))(.*)$/) { # an n-tuplet
} elsif ($notes =~ /^((\d+)\(((\^)?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?}?)+\;(\d+)\))(.*)$/) { # an n-tuplet
($tuplet, $notes) = ($1,$10);
# print "N-TUPLET: ".$tuplet." -> ";
$tuplet =~ /^(\d+)\(((\,|\')*(x|xx|b|bb|n)?\d*\.*(g|q)?(\-|A|B|C|D|E|F|G)t?\+?)(.*);(\d)\)$/gs;
$tuplet =~ /^(\d+)\(((\,|\')*(x|xx|b|bb|n)?\d*\.*(g|q)?(\-|A|B|C|D|E|F|G)t?\+?}?)(.*);(\d)\)$/gs;
($combdur, $note, $tuplet, $numval) = ($1,$2,$7,$8);
#print "i=$combdur, n=$numval; $note / $tuplet\n";
my $ind_dur = duration($combdur)/$numval;
......@@ -340,7 +346,7 @@ sub parse_notes {
<actual-notes>'.$act_notes.'</actual-notes>
<normal-notes>1</normal-notes>
</time-modification>', $qq);
while ($tuplet =~ /^((g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?)(.+)$/gs) {
while ($tuplet =~ /^((g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?}?)(.+)$/gs) {
($note, $tuplet) = ($1,$6);
#print "$note / $tuplet\n";
parse_note($note, $keysig, '', ' <time-modification>
......@@ -440,7 +446,7 @@ sub parse_notes {
</note>
';
}
elsif ($notes =~ s/(\d+\.*)\(((g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?)\)/\($1$2\)/gs) { # pull duration into fermata parentheses
elsif ($notes =~ s/(\d+\.*)\(((g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?}?)\)/\($1$2\)/gs) { # pull duration into fermata parentheses
# print "after replacement: $notes\n"; exit;
}
elsif ($notes =~ /^ +(.*)$/) {
......@@ -474,8 +480,8 @@ sub parse_note {
$fermata = 1;
}
$note =~ /^(\^)?(g|q)?((\,|\')*)(x|xx|b|bb|n)?(\d*)(\.*)(\-|A|B|C|D|E|F|G)(t?)(\+?)$/;
my ($chord, $gracecue, $oct, $acc, $dur, $dot, $pitch, $trill, $tie) = ($1, $2, $3, $5, $6, $7, $8, $9, $10);
$note =~ /^(\^)?(g|q)?((\,|\')*)(x|xx|b|bb|n)?(\d*)(\.*)(\-|A|B|C|D|E|F|G)(t?)(\+?)(}?)$/;
my ($chord, $gracecue, $oct, $acc, $dur, $dot, $pitch, $trill, $tie, $beamend) = ($1, $2, $3, $5, $6, $7, $8, $9, $10, $11);
print OUT ' <note>
';
......@@ -534,8 +540,20 @@ sub parse_note {
# If we have an explicit accidental on the note, print the <accidental> tag
print OUT accidental_explicit ($acc);
# addition is typically empty or a time-modification tag
print OUT $addition;
# print out beaming information if needed:
if ($BEAM == 1) {
print OUT " <beam>begin</beam>\n";
$BEAM = 2;
} elsif (($BEAM > 0) && ($beamend eq "}")) {
print OUT " <beam>end</beam>\n";
$BEAM = 0;
} elsif ($BEAM > 0) {
print OUT " <beam>continue</beam>\n";
}
my $notationbracket = $fermata || $tienotation || ($trill eq "t") || ($notation ne "");
if ($notationbracket) {
print OUT " <notations>\n";
......
Test Composer
Test case for beams
1.1.1: S beams
plain&easy: %G-2@4/4$bBEA {''6E'B8G}{GA}-''C{'3B8..G}//
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