Skip to content
Browse files

Allow clefs other than treble.

Still primitive.  Unfortunately it is also broken on Niecza right now.
  • Loading branch information...
1 parent 4d73dc3 commit e6cc1fac81c0c22e69ca7996dac5e2f7816b8d75 @colomon committed Mar 3, 2013
Showing with 17 additions and 4 deletions.
  1. +16 −4 bin/abc2ly
  2. +1 −0 lib/ABC/KeyInfo.pm
View
20 bin/abc2ly
@@ -33,15 +33,15 @@ class Context {
has $.meter;
has $.length;
- method new($key-name, $meter, $length) {
+ method new($key-name, $meter, $length, :$current-key-info) {
self.bless(*, :$key-name,
- :key-info(KeyInfo.new($key-name)),
+ :key-info(ABC::KeyInfo.new($key-name, :$current-key-info)),
:$meter,
:$length);
}
method get-Lilypond-pitch(ABC::Note $abc-pitch) {
- my $real-accidental = $abc-pitch.accidental || ($.key{$abc-pitch.basenote.uc} // "");
+ my $real-accidental = $abc-pitch.accidental || ($.key-info.key{$abc-pitch.basenote.uc} // "");
my $octave = +($abc-pitch.basenote ~~ 'a'..'z');
given $abc-pitch.octave {
@@ -116,6 +116,15 @@ class Context {
}
"\\key $major-key-name \\major\n";
}
+
+ method clef-to-string() {
+ my $lilypond-clef = "treble";
+ given $.key-info.clef {
+ when not .defined { }
+ when "treble" | "alto" | "tenor" | "bass" { $lilypond-clef = ~$.key-info.clef; }
+ }
+ "\\clef $lilypond-clef";
+ }
}
sub HeaderToLilypond(ABC::Header $header, $out) {
@@ -254,8 +263,10 @@ class TuneConvertor {
when "K" {
$!context = Context.new($element.value.value,
$!context.meter,
- $!context.length);
+ $!context.length,
+ :current-key-info($!context.key-info));
$lilypond ~= $!context.key-to-string;
+ $lilypond ~= $!context.clef-to-string;
}
when "M" {
$!context = Context.new($!context.key-name,
@@ -327,6 +338,7 @@ class TuneConvertor {
method BodyToLilypond(@elements, $out) {
$out.say: "\{";
$out.print: $.context.key-to-string;
+ $out.print: $.context.clef-to-string;
$out.print: $.context.meter-to-string;
my $start-of-section = 0;
View
1 lib/ABC/KeyInfo.pm
@@ -6,6 +6,7 @@ class ABC::KeyInfo {
has $.clef;
method new($key-field, :$current-key-info) {
+ # say "K: $key-field";
my $match = ABC::Grammar.parse($key-field, :rule<key>);
# say :$match.perl;
die "Illegal key signature\n" unless $match;

0 comments on commit e6cc1fa

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