Permalink
Browse files

Rename Duration.Str to Duration.duration-to-str (so it can be easily …

…used by classes which do the role). Update abs2ly.pl to work with Duration.
  • Loading branch information...
1 parent 7edf476 commit 0d17ae0cfc2e83e7b2ee30d89222c3ace2868bf7 @colomon committed Oct 1, 2010
Showing with 17 additions and 21 deletions.
  1. +6 −19 bin/abc2ly.pl
  2. +2 −2 lib/ABC/Duration.pm
  3. +9 −0 t/05-actions.t
View
@@ -3,6 +3,8 @@
use ABC::Tune;
use ABC::Grammar;
use ABC::Actions;
+use ABC::Duration;
+use ABC::Note;
class Context {
@@ -34,20 +36,7 @@ (ABC::Header $header)
);
sub Duration(Context $context, $element) {
- given $element.key {
- when "stem" {
- my $match = ABC::Grammar.parse($element.value, :rule<mnote>); # bad in at least two ways....
- given ~$match<note_length> {
- when "/" { return 1/2; }
- when "" { return 1; }
- return +$_;
- }
- }
-
- # should do broken_rhythms and rests as well!
- }
-
- 0;
+ $element.value ~~ ABC::Duration ?? $element.value.ticks !! 0;
}
my %cheat-length-map = ( '/' => "16",
@@ -58,11 +47,9 @@ (Context $context, $element)
);
sub StemToLilypond(Context $context, $stem) {
- my $match = ABC::Grammar.parse($stem, :rule<mnote>); # bad in at least two ways....
- my $pitch = ~$match<pitch>;
- my $length = ~$match<note_length>;
-
- print " { %note-map{$pitch} }{ %cheat-length-map{$length} } ";
+ if $stem ~~ ABC::Note {
+ print " { %note-map{$stem.pitch} }{ %cheat-length-map{$stem.duration-to-str} } ";
+ }
}
sub SectionToLilypond(Context $context, @elements) {
View
@@ -15,9 +15,9 @@ role ABC::Duration {
}
}
- our method Str() {
+ our method duration-to-str() {
given $.ticks {
- when 1 { "---"; } # for debugging, should be ""
+ when 1 { ""; }
when 1/2 { "/"; }
when Int { .Str; }
when Rat { .perl; }
View
@@ -26,6 +26,15 @@ plan *;
}
{
+ my $match = ABC::Grammar.parse("^e,/", :rule<mnote>, :actions(ABC::Actions.new));
+ isa_ok $match, Match, 'element recognized';
+ isa_ok $match.ast, ABC::Note, '$match.ast is an ABC::Note';
+ is $match.ast.pitch, "^e,", "Pitch ^e,";
+ is $match.ast.ticks, 1/2, "Duration 1/2 ticks";
+}
+
+
+{
my $music = q«X:64
T:Cuckold Come Out o' the Amrey
S:Northumbrian Minstrelsy

0 comments on commit 0d17ae0

Please sign in to comment.