Skip to content
Browse files

Closer to having working key signature code.

  • Loading branch information...
1 parent 0aaec06 commit 9b8264b2fa85710912c59094362f3157045e2f79 @LastOfTheCarelessMen committed Dec 29, 2009
Showing with 42 additions and 1 deletion.
  1. +42 −1 playing.pl
View
43 playing.pl
@@ -30,4 +30,45 @@
}
}
-@notes.map({.say});
+sub key_signature($key_signature_name)
+{
+ my %keys = (
+ 'C' => 0,
+ 'G' => 1,
+ 'D' => 2,
+ 'A' => 3,
+ 'E' => 4,
+ 'B' => 5,
+ 'F#' => 6,
+ 'C#' => 7,
+ 'F' => -1,
+ 'Bb' => -2,
+ 'Eb' => -3,
+ 'Ab' => -4,
+ 'Db' => -5,
+ 'Gb' => -6,
+ 'Cb' => -7
+ );
+
+ $match = $key_signature_name ~~ m/ <ABC::basenote> ('#' | 'b')? (\w*) /;
+ die "Illegal key signature\n" unless $match ~~ Match;
+ say "$key_signature_name:";
+ my $lookup = [~] $match<ABC::basenote>.uc, $match[0];
+
+ my @sharps = <F C G D A E B>;
+ my %hash = @sharps Z @sharps;
+
+ given %keys{$lookup} {
+ when 1..7 { for ^%keys{$lookup} -> $i { %hash{@sharps[$i]} = "^" ~ @sharps[$i]; } }
+ when -7..-1 { for ^(-%keys{$lookup}) -> $i { %hash{@sharps[6-$i]} = "_" ~ @sharps[6-$i]; } }
+ }
+
+ say %hash.perl;
+
+}
+
+# @notes.map({.<pitch>.say});
+
+key_signature("Abmix");
+key_signature("Ab");
+key_signature("Amix");

0 comments on commit 9b8264b

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