Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support sixteenth note as a note length, and better (though note yet …

…fully correct) support for quartuplets and quintuplets.
  • Loading branch information...
commit ea8c7862c0065d6e343209186f56c76caaf7a895 1 parent 86f9b66
@colomon authored
View
25 bin/abc2ly.pl
@@ -31,6 +31,17 @@
method new($key-name, $meter, $length) {
my %cheat-length-map;
given $length {
+ when "1/16" { %cheat-length-map = ( '/' => "32",
+ "" => "16",
+ "1" => "16",
+ "3/2" => "16.",
+ "2" => "8",
+ "3" => "8.",
+ "7/2" => "8..",
+ "4" => "4",
+ "6" => "4.",
+ "8" => "2");
+ }
when "1/8" { %cheat-length-map = ( '/' => "16",
"" => "8",
"1" => "8",
@@ -207,16 +218,12 @@ (ABC::Header $header, $out)
$suffix = "";
}
when "tuplet" {
- $lilypond ~= " \\times 2/3 \{";
- if +$element.value.notes == 3 && $element.value.ticks == 2 {
- $lilypond ~= self.StemToLilypond($element.value.notes[0], "[");
- $lilypond ~= self.StemToLilypond($element.value.notes[1]);
- $lilypond ~= self.StemToLilypond($element.value.notes[2], "]");
- } else {
- for $element.value.notes -> $stem {
- $lilypond ~= self.StemToLilypond($stem);
- }
+ $lilypond ~= " \\times 2/{ $element.value.tuple } \{";
+ $lilypond ~= self.StemToLilypond($element.value.notes[0], "[");
+ for 1..($element.value.notes - 2) -> $i {
+ $lilypond ~= self.StemToLilypond($element.value.notes[$i]);
}
+ $lilypond ~= self.StemToLilypond($element.value.notes[*-1], "]");
$lilypond ~= " } ";
$suffix = "";
}
View
2  lib/ABC/Actions.pm
@@ -59,7 +59,7 @@ class ABC::Actions {
}
method tuplet($/) {
- make ABC::Tuplet.new(3, @( $<stem> )>>.ast);
+ make ABC::Tuplet.new(+@( $<stem> ), @( $<stem> )>>.ast);
}
method broken_rhythm($/) {
View
10 lib/ABC/Grammar.pm
@@ -43,10 +43,12 @@ grammar ABC::Grammar
regex broken_rhythm { <stem> <g1=b_elem>* <broken_rhythm_bracket> <g2=b_elem>* <stem> }
regex t_elem { <gracing> | <grace_notes> | <broken_rhythm> | <slur_begin> | <slur_end> }
- # next line should work, but is NYI in Rakudo
- # regex tuple { '('(<digit>+) [<t_elem>* <stem>] ** { $0 } }
- # next block makes the most common case work
- regex tuplet { '(3' [<t_elem>* <stem>] ** 3 }
+ # next line should work, but is NYI in Rakudo/Niecza
+ # regex tuplet { '('(<digit>+) [<t_elem>* <stem>] ** { +$0 } }
+ # next block makes the most common cases work
+ regex tuplet { ['(3' [<t_elem>* <stem>] ** 3 <slur_end>? ]
+ | ['(4' [<t_elem>* <stem>] ** 4 <slur_end>? ]
+ | ['(5' [<t_elem>* <stem>] ** 5 <slur_end>? ] }
regex nth_repeat_num { <digit>+ [[',' | '-'] <digit>+]* }
regex nth_repeat_text { '"' .*? '"' }
View
3  lib/ABC/Tuplet.pm
@@ -8,7 +8,6 @@ class ABC::Tuplet does ABC::Duration {
method new($tuple, @notes) {
die "Tuplet must have at least one note" if +@notes == 0;
- die "Only handle triplets so far" if $tuple != 3;
- self.bless(*, :$tuple, :@notes, :ticks(2/3 * [+] @notes>>.ticks));
+ self.bless(*, :$tuple, :@notes, :ticks(2/$tuple * [+] @notes>>.ticks));
}
}
View
13 t/01-regexes.t
@@ -201,6 +201,19 @@ use ABC::Grammar;
}
{
+ my $match = ABC::Grammar.parse("(5abcde", :rule<tuplet>);
+ isa_ok $match, Match, 'Got a match';
+ ok $match, '"(5abcde" is a tuplet';
+ is ~$match, "(5abcde", '"(5abcde" was the portion matched';
+ is +@( $match<stem> ), 5, 'Three notes matched';
+ is $match<stem>[0], "a", 'first note is a';
+ is $match<stem>[1], "b", 'second note is b';
+ is $match<stem>[2], "c", 'third note is c';
+ is $match<stem>[3], "d", 'fourth note is d';
+ is $match<stem>[4], "e", 'fifth note is e';
+}
+
+{
my $match = ABC::Grammar.parse("[a2bc]3", :rule<stem>);
isa_ok $match, Match, 'Got a match';
ok $match, '"[a2bc]3" is a stem';
Please sign in to comment.
Something went wrong with that request. Please try again.