Permalink
Browse files

Add default-length-from-meter sub and use it in abc2ly.

  • Loading branch information...
1 parent 817476f commit 8e34d563726782a7817910f956b05ccae009cdad @colomon committed Jan 18, 2014
Showing with 24 additions and 1 deletion.
  1. +1 −1 bin/abc2ly
  2. +8 −0 lib/ABC/Utils.pm
  3. +15 −0 t/10-utils.t
View
@@ -421,7 +421,7 @@ sub TuneStreamToLilypondStream($in, $out, $filter = True) {
my $key = $tune.header.get-first-value("K");
my $meter = $tune.header.get-first-value("M");
- my $length = $tune.header.get-first-value("L") // "1/8";
+ my $length = $tune.header.get-first-value("L") // default-length-from-meter($meter);
my $convertor = TuneConvertor.new($key, $meter, $length);
$convertor.BodyToLilypond($tune.music, $out);
View
@@ -211,6 +211,14 @@ package ABC::Utils {
$i++;
}
}
+
+ sub default-length-from-meter($meter) is export {
+ if $meter ~~ m{(\d+ '/' \d+)} {
+ $0.Rat < 3/4 ?? "1/16" !! "1/8";
+ } else {
+ "1/8";
+ }
+ }
}
View
@@ -0,0 +1,15 @@
+use v6;
+use Test;
+use ABC::Utils;
+
+is default-length-from-meter("4/4"), "1/8", "4/4 defaults to eighth note";
+is default-length-from-meter("2/2"), "1/8", "2/2 defaults to eighth note";
+is default-length-from-meter("3/4"), "1/8", "3/4 defaults to eighth note";
+is default-length-from-meter("6/8"), "1/8", "6/8 defaults to eighth note";
+is default-length-from-meter("2/4"), "1/16", "2/4 defaults to sixteenth note";
+is default-length-from-meter("C"), "1/8", "Common time defaults to eighth note";
+is default-length-from-meter("C|"), "1/8", "Cut time defaults to eighth note";
+is default-length-from-meter(""), "1/8", "No meter defaults to eighth note";
+is default-length-from-meter("none"), "1/8", "No meter defaults to eighth note";
+
+done;

0 comments on commit 8e34d56

Please sign in to comment.