Browse files

Fix broken bits of last refactor, add two MAIN subs, one of which tak…

…es a filename.
  • Loading branch information...
1 parent 1f9e3a6 commit b90e9e270ca279db69beb16ccc911f30678ac69e @colomon committed May 3, 2012
Showing with 23 additions and 5 deletions.
  1. +23 −5 bin/abc2ly.pl
View
28 bin/abc2ly.pl
@@ -315,8 +315,8 @@ (ABC::Header $header, $out)
method BodyToLilypond(@elements, $out) {
$out.say: "\{";
- print $.context.key-to-string;
- printf $.context.meter-to-string;
+ $out.print: $.context.key-to-string;
+ $out.print: $.context.meter-to-string;
my $start-of-section = 0;
loop (my $i = 0; $i < +@elements; $i++) {
@@ -327,7 +327,7 @@ (ABC::Header $header, $out)
&& @elements[$i].value ne "|") {
if @elements[$i].key eq "nth_repeat"
|| @elements[$i].value eq ':|:' | ':|' | '::' {
- print "\\repeat volta 2 "; # 2 is abitrarily chosen here!
+ $out.print: "\\repeat volta 2 "; # 2 is abitrarily chosen here!
}
self.SectionToLilypond(@elements[$start-of-section ..^ $i], $out);
$start-of-section = $i + 1;
@@ -369,7 +369,7 @@ (ABC::Header $header, $out)
if $start-of-section + 1 < @elements.elems {
if @elements[*-1].value eq ':|:' | ':|' | '::' {
- print "\\repeat volta 2 "; # 2 is abitrarily chosen here!
+ $out.print: "\\repeat volta 2 "; # 2 is abitrarily chosen here!
}
self.SectionToLilypond(@elements[$start-of-section ..^ +@elements]);
if @elements[*-1].value eq '|]' {
@@ -406,4 +406,22 @@ ($in, $out)
}
}
-TuneStreamToLilypondStream($*IN, $*OUT);
+multi sub MAIN() {
+ TuneStreamToLilypondStream($*IN, $*OUT);
+}
+
+multi sub MAIN($abc-file) {
+ my $ly-file = $abc-file ~ ".ly";
+ if $abc-file ~~ /^(.*) ".abc"/ {
+ $ly-file = $0 ~ ".ly";
+ }
+ $*ERR.say: "Reading $abc-file, writing $ly-file";
+
+ my $in = open $abc-file, :r or die "Unable to open $abc-file";
+ my $out = open $ly-file, :w or die "Unable to open $ly-file";
+
+ TuneStreamToLilypondStream($in, $out);
+
+ $out.close;
+ $in.close;
+}

0 comments on commit b90e9e2

Please sign in to comment.