Permalink
Browse files

Add transpose to Stem.

  • Loading branch information...
1 parent d13c7ad commit 3c1943ffe872896cf97e38f53fda02662c91de93 @colomon committed Jun 3, 2012
Showing with 11 additions and 4 deletions.
  1. +2 −1 lib/ABC/Note.pm
  2. +6 −1 lib/ABC/Stem.pm
  3. +3 −2 t/08-transpose.t
View
3 lib/ABC/Note.pm
@@ -1,8 +1,9 @@
use v6;
use ABC::Duration;
+use ABC::Pitched;
-class ABC::Note does ABC::Duration {
+class ABC::Note does ABC::Duration does ABC::Pitched {
has $.accidental;
has $.basenote;
has $.octave;
View
7 lib/ABC/Stem.pm
@@ -1,8 +1,9 @@
use v6;
use ABC::Duration;
+use ABC::Pitched;
-class ABC::Stem does ABC::Duration {
+class ABC::Stem does ABC::Duration does ABC::Pitched {
has @.notes;
has $.is-tie;
@@ -14,4 +15,8 @@ class ABC::Stem does ABC::Duration {
method Str() {
"[" ~ @.notes.join("") ~ "]" ~ ($.is-tie ?? "-" !! "");
}
+
+ method transpose($pitch-changer) {
+ ABC::Stem.new(@.notes>>.transpose($pitch-changer), self, $.is-tie);
+ }
}
View
5 t/08-transpose.t
@@ -35,9 +35,10 @@ sub up-octave($accidental, $basenote, $octave) {
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("a''", &up-octave), "a'''", "Octave bump to a'' yields a'''";
-is transpose("A,", &up-octave), "A", "Octave bump to A, yields A";
+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']";
done;

0 comments on commit 3c1943f

Please sign in to comment.