Skip to content
Browse files

Working early key signature framework.

  • Loading branch information...
1 parent 325c475 commit a326b88fc99ffe3d0491413257977cffcde2b00a @LastOfTheCarelessMen LastOfTheCarelessMen committed Dec 30, 2009
Showing with 29 additions and 5 deletions.
  1. +8 −0 lib/ABC.pm
  2. +21 −5 playing.pl
View
8 lib/ABC.pm
@@ -39,6 +39,14 @@ grammar ABC
regex tune { <header> <music> }
}
+sub header_hash($header_match)
+{
+ gather for $header_match<header_field>
+ {
+ take $_.<header_field_name>.Str => $_.<header_field_data>.Str;
+ }
+}
+
sub key_signature($key_signature_name)
{
my %keys = (
View
26 playing.pl
@@ -11,7 +11,7 @@
K:D
A/B/c/A/ +trill+c>d e>deg | GG +trill+B>c d/B/A/G/ B/c/d/B/ |
A/B/c/A/ c>d e>deg | dB/A/ gB +trill+A2 +trill+e2 ::
-g>ecg ec e/f/g/e/ | d/c/B/A/ Gd BG B/c/d/B/ |
+g>ecg ec e/=f/g/e/ | d/c/B/A/ Gd BG B/c/d/B/ |
g/f/e/d/ c/d/e/f/ gc e/f/g/e/ | dB/A/ gB +trill+A2 +trill+e2 :|»;
my $match = $abc ~~ m/ <ABC::tune> /;
@@ -30,8 +30,24 @@
}
}
-# @notes.map({.<pitch>.say});
+sub apply_key_signature(%key_signature, $pitch)
+{
+ my $resulting_note = "";
+ if $pitch<accidental>
+ {
+ $resulting_note ~= $pitch<accidental>.Str;
+ }
+ else
+ {
+ $resulting_note ~= %key_signature{$pitch<basenote>.uc}
+ if (%key_signature.exists($pitch<basenote>.uc));
+ }
+ $resulting_note ~= $pitch<basenote>;
+ $resulting_note ~= $pitch<octave> if $pitch<octave>;
+ return $resulting_note;
+}
+
+my %header = header_hash($match<ABC::tune><header>);
+my %key_signature = key_signature(%header<K>);
-say key_signature("Ab mix").perl;
-say key_signature("Ab").perl;
-say key_signature("Amix").perl;
+@notes.map({say .<pitch> ~ " => " ~ apply_key_signature(%key_signature, .<pitch>)});

0 comments on commit a326b88

Please sign in to comment.
Something went wrong with that request. Please try again.