Permalink
Browse files

Add simple stringification for stems, tuplets, and broken rhythms.

  • Loading branch information...
1 parent 2ad3502 commit c32d681af6d5f2dede659e2aeb2854129de47ef5 @colomon committed May 26, 2012
Showing with 19 additions and 3 deletions.
  1. +5 −1 lib/ABC/BrokenRhythm.pm
  2. +4 −0 lib/ABC/Stem.pm
  3. +4 −0 lib/ABC/Tuplet.pm
  4. +6 −2 t/07-stringify.t
@@ -46,5 +46,9 @@ class ABC::BrokenRhythm does ABC::Duration {
new-rhythm($.stem2, self.broken-direction-forward ?? $.stem2.ticks * self.broken-factor
!! $.stem2.ticks * (2 - self.broken-factor));
}
-
+
+ method Str() {
+ # Handle gracings here, too
+ $.stem1 ~ $.broken-rhythm ~ $.stem2;
+ }
}
View
@@ -10,4 +10,8 @@ class ABC::Stem does ABC::Duration {
die "Stem must have at least one note" if +@notes == 0;
self.bless(*, :@notes, :ticks(@notes>>.ticks.max * $duration.ticks), :$is-tie);
}
+
+ method Str() {
+ "[" ~ @.notes.join("") ~ "]" ~ ($.is-tie ?? "-" !! "");
+ }
}
View
@@ -10,4 +10,8 @@ class ABC::Tuplet does ABC::Duration {
die "Tuplet must have at least one note" if +@notes == 0;
self.bless(*, :$tuple, :@notes, :ticks(2/$tuple * [+] @notes>>.ticks));
}
+
+ method Str() {
+ "(" ~ $.tuple ~ @.notes.join("");
+ }
}
View
@@ -14,13 +14,17 @@ use ABC::LongRest;
use ABC::GraceNotes;
use ABC::Actions;
-my @simple-cases = ("a", "B,", "c'''", "^D2", "_E,,/", "^^f/4", "=G3");
+my @simple-cases = ("a", "B,", "c'''", "^D2-", "_E,,/", "^^f/4", "=G3",
+ "[ceg]", "[D3/2d3/2]", "[A,2F2]",
+ "(3abc", "(5A/B/C/D/E/",
+ "a>b", "^c/4<B,,/4",
+ "(", ")");
for @simple-cases -> $test-case {
my $match = ABC::Grammar.parse($test-case, :rule<element>, :actions(ABC::Actions.new));
ok $match, "$test-case parsed";
my $object = $match.ast.value;
- say $object.perl;
+ # say $object.perl;
is ~$object, $test-case, "Stringified version matches";
}

0 comments on commit c32d681

Please sign in to comment.