Permalink
Browse files

Support transpose for broken rhythms, grace notes, and tuplets, too.

  • Loading branch information...
1 parent 3c1943f commit 8841e3bf6626177afc36801bbeac14941394f34f @colomon committed Jun 3, 2012
Showing with 27 additions and 3 deletions.
  1. +10 −1 lib/ABC/BrokenRhythm.pm
  2. +7 −1 lib/ABC/GraceNotes.pm
  3. +6 −1 lib/ABC/Tuplet.pm
  4. +4 −0 t/08-transpose.t
View
@@ -1,10 +1,11 @@
use v6;
use ABC::Duration;
+use ABC::Pitched;
use ABC::Note;
use ABC::Stem;
-class ABC::BrokenRhythm does ABC::Duration {
+class ABC::BrokenRhythm does ABC::Duration does ABC::Pitched {
has $.stem1;
has $.gracing1;
has $.broken-rhythm;
@@ -51,4 +52,12 @@ class ABC::BrokenRhythm does ABC::Duration {
# Handle gracings here, too
$.stem1 ~ $.broken-rhythm ~ $.stem2;
}
+
+ method transpose($pitch-changer) {
+ ABC::BrokenRhythm.new($.stem1.transpose($pitch-changer),
+ $.gracing1,
+ $.broken-rhythm,
+ $.gracing2,
+ $.stem2.transpose($pitch-changer));
+ }
}
View
@@ -1,6 +1,8 @@
use v6;
-class ABC::GraceNotes {
+use ABC::Pitched;
+
+class ABC::GraceNotes does ABC::Pitched {
has $.acciaccatura;
has @.notes;
@@ -12,4 +14,8 @@ class ABC::GraceNotes {
method Str() {
'{' ~ ($.acciaccatura ?? '/' !! '') ~ @.notes.join('') ~ '}';
}
+
+ method transpose($pitch-changer) {
+ ABC::GraceNotes.new($.acciaccatura, @.notes>>.transpose($pitch-changer));
+ }
}
View
@@ -1,8 +1,9 @@
use v6;
use ABC::Duration;
+use ABC::Pitched;
-class ABC::Tuplet does ABC::Duration {
+class ABC::Tuplet does ABC::Duration does ABC::Pitched {
has $.tuple;
has @.notes;
@@ -14,4 +15,8 @@ class ABC::Tuplet does ABC::Duration {
method Str() {
"(" ~ $.tuple ~ @.notes.join("");
}
+
+ method transpose($pitch-changer) {
+ ABC::Tuplet.new($.tuple, @.notes>>.transpose($pitch-changer));
+ }
}
View
@@ -39,6 +39,10 @@ is transpose("a''2", &up-octave), "a'''2", "Octave bump to a'' yields a'''";
is transpose("A,-", &up-octave), "A-", "Octave bump to A, yields A";
is transpose("A,,", &up-octave), "A,", "Octave bump to A,, yields A,";
is transpose("[C,Eg]", &up-octave), "[Ceg']", "Octave bump to [C,Eg] yields [Ceg']";
+is transpose("[C,Eg]", &up-octave), "[Ceg']", "Octave bump to [C,Eg] yields [Ceg']";
+is transpose("(3C,Eg", &up-octave), "(3Ceg'", "Octave bump to (3C,Eg yields (3Ceg'";
+is transpose("A<a", &up-octave), "a<a'", "Octave bump to A<a yields a<a'";
+is transpose('{Bc}', &up-octave), '{bc\'}', "Octave bump to Bc yields bc'";
done;

0 comments on commit 8841e3b

Please sign in to comment.