Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Expanded tuplet processing code a bit. Definitely still needs work!

  • Loading branch information...
commit 982963c1f9aaae507f75b833ed566b20edbe2e14 1 parent ce43d74
@colomon authored
Showing with 21 additions and 5 deletions.
  1. +2 −1  lib/ABC/Grammar.pm
  2. +19 −4 lib/ABC/Tuplet.pm
View
3  lib/ABC/Grammar.pm
@@ -50,7 +50,8 @@ grammar ABC::Grammar
# If the previous line fails, you can use the next rule to get the most common cases
# next block makes the most common cases work
# token tuplet { '(' (<digit>+) {} (<t_elem>* <stem>)*? <?{ say $1.perl; say $0.perl; $1.elems == $0 }> <slur_end>? }
- token tuplet { ['(3' [<t_elem>* <stem>] ** 3 <slur_end>? ]
+ token tuplet { ['(2' [<t_elem>* <stem>] ** 2 <slur_end>? ]
+ | ['(3' [<t_elem>* <stem>] ** 3 <slur_end>? ]
| ['(4' [<t_elem>* <stem>] ** 4 <slur_end>? ]
| ['(5' [<t_elem>* <stem>] ** 5 <slur_end>? ] }
View
23 lib/ABC/Tuplet.pm
@@ -4,19 +4,34 @@ use ABC::Duration;
use ABC::Pitched;
class ABC::Tuplet does ABC::Duration does ABC::Pitched {
- has $.tuple;
+ has $.p;
+ has $.q;
has @.notes;
- method new($tuple, @notes) {
+ multi method new($p, @notes) {
+ my $q;
+ given $p {
+ when 3 | 6 { $q = 2; }
+ when 2 | 4 | 8 { $q = 3; }
+ default { $q = 2; } # really need to know the time signature for this!
+ }
+ self.new($p, $q, @notes);
+ }
+
+ multi method new($p, $q, @notes) {
die "Tuplet must have at least one note" if +@notes == 0;
- self.bless(:$tuple, :@notes, :ticks(2/$tuple * [+] @notes>>.ticks));
+ self.bless(:$p, :$q, :@notes, :ticks($q/$p * [+] @notes>>.ticks));
}
method Str() {
- "(" ~ $.tuple ~ @.notes.join("");
+ # MUST: factor in $q when that has non-default values
+ @.notes == $.p ?? "(" ~ $.p ~ @.notes.join("")
+ !! "(" ~ $.p ~ "::" ~ +@.notes ~ @.notes.join("");
}
method transpose($pitch-changer) {
ABC::Tuplet.new($.tuple, @.notes>>.transpose($pitch-changer));
}
+
+ method tuple() { $.p; } # for backwards compatibility, probably needs to go in the long run
}
Please sign in to comment.
Something went wrong with that request. Please try again.