6 detect \lyrics and \melodic, and do substitution accordingly.
9 Ugh . Perl sux. Anybody for Python?
16 # version of "supporting" engine, not mudela conversions.
22 $convert_mudela_version = "0.1.2";
36 my(@a)= split /\./,$a;
37 my(@b)= split /\./,$b;
40 return $a[$i] <=> $b[$i] if ($a[$i] != $b[$i]);
45 sub version_string_conv
47 my ($from_version, $to_version) = @_;
48 s/\version \"$from_version\"/\version \"$to_version\"/g;
51 ################################################################
57 sub convert_0_0_52_to_0_0_53
60 s/include \"/$1\\include \"/g;
64 sub convert_0_0_54_to_0_0_55
70 sub convert_0_0_53_to_0_0_54
72 print STDERR "Not smart enough to convert \\transpose\n" if (/\\transpose/) ;
75 # we-re not at 58 yet, but this is at least one of the rules
76 sub convert_0_0_55_to_0_0_56
81 sub convert_0_0_56_to_0_0_57
83 s/\(([ \]\[|\t-\.>]|\\[<!>a-z]+)*\)/\~ $1/g;
86 sub convert_0_0_57_to_0_0_58
88 s/\[ *([^\[\]]*)\] *([1-9]*) *\/ *([1-9]*)/[$2\/$3 $1]1\/1/g;
91 sub convert_0_0_58_to_0_0_59
93 die "Not smart enough to convert 0.0.58 to 0.0.59\n";
96 sub convert_0_0_59_to_0_0_60
98 s/(\\unitspace [0-9.mcptin\\ ]+|\\geometric [0-9.]+|\\width [0-9.mcp\\tin]+)/$1;/g;
99 s/(\\output \"[^\"]+\")/$1;/;
100 s/(\\tempo [0-9: ]+)/$1;/;
103 sub convert_0_0_60_to_0_0_61
105 s/(\\unitspace|\\geometric|\\width)/$1=/g;
109 sub convert_0_1_0_to_0_1_1
111 s/\\tempo (.*):(.*);/\\tempo $1 = $2;/g
114 sub convert_0_1_2_to_0_1_3
116 s/\\stem *(\\up|1) *;/\\stemup/g;
117 s/\\stem *(\\down|-1) *;/\\stemdown/g;
118 s/\\stem *0 *;/\\stemboth/g;
119 s/\\hshift ([^;]+) *;/\\property Voice.hshift = $1/g;
124 sub generic_conversion_scan
130 if ($header_b && /^ *\}/)
135 sub convert_0_1_4_to_0_1_5
137 s/([<{]) *\\id "Piano" (.+);/\\type Grandstaff = $3 $1/;
138 s/([<{]) *\\id (.+) (.+);/\\type $2 = $3 $1/;
142 sub convert_0_1_5_to_0_1_6
144 s/< *\\multi (.*);/\\multi $1 </;
147 sub convert_0_1_6_to_0_1_7
151 s/^([a-zA-z]+)[ \t]+(.*)$/$1 =\t \"$2\";/;
152 s/^([ \t])+(.*)$/$1 \"$2\";/;
156 sub convert_0_1_7_to_0_1_8
158 s/\\plet *1 *\/ *1 *;/\\]/;
159 s/\\plet *([1-9][0-9]*) *\/ *([2-9][0-9]*) *;/\\[$1\/$2/;
162 sub convert_0_1_8_to_0_1_9
164 # sticky plet shorthand...
165 # print "introduced plet and finger shorthands...\n";
168 ###############################################################
178 print STDERR "This is convert-mudela " . $convert_mudela_version .
179 " (up to mudela version ", last_conversion, ")\n";
185 print STDERR "Usage: convert-mudela [options] [mudela-file]...\n"
186 . "Convert old mudela source from mudela-file or stdin\n\n"
188 . " -e, --edit perform in-place conversion\n"
189 . " -f, --from=PATHLEVEL use source version 0.0.PATCHLEVEL\n"
190 . " -h, --help print this help\n"
191 . " -o, --output=FILE name output file\n"
192 . " -s, --show-rules print all known conversion rules\n"
193 . " -t, --to=VERSION convert to version VERSION\n"
197 my %minor_conversions = ("0.0.50" => \&no_conv,
198 "0.0.52" => \&convert_0_0_50_to_0_0_52,
199 "0.0.53" => \&convert_0_0_52_to_0_0_53,
200 "0.0.54" => \&convert_0_0_53_to_0_0_54,
201 "0.0.55" => \&convert_0_0_54_to_0_0_55,
202 "0.0.56" => \&convert_0_0_55_to_0_0_56,
203 "0.0.57" => \&convert_0_0_56_to_0_0_57,
204 "0.0.58" => \&convert_0_0_57_to_0_0_58,
205 "0.0.59" => \&convert_0_0_58_to_0_0_59,
206 "0.0.60" => \&convert_0_0_59_to_0_0_60,
207 "0.0.61" => \&convert_0_0_60_to_0_0_61,
208 "0.1.1" => \&convert_0_1_0_to_0_1_1,
209 "0.1.2" => \&no_conv,
210 "0.1.3" => \&convert_0_1_2_to_0_1_3,
211 "0.1.4" => \&no_conv,
212 "0.1.5" => \&convert_0_1_4_to_0_1_5,
213 "0.1.6" => \&convert_0_1_5_to_0_1_6
214 ,"0.1.7" => \&convert_0_1_6_to_0_1_7
215 ,"0.1.8" => \&convert_0_1_7_to_0_1_8
216 ,"0.1.9" => \&convert_0_1_8_to_0_1_9
223 return (sort { cmpver; } (keys %minor_conversions));
231 print "Rules: ", join(", ", @v), "\n";
239 my @applicable_conversion;
244 if (version_compare($ver, $from) > 0 && version_compare($ver,$to) <= 0 ){
245 push @applicable_conversion, $minor_conversions{$ver};
246 push @mudela_levels, $ver;
250 print STDERR "Applying following rules: ", join(", ", @mudela_levels) , "\n";
253 generic_conversion_scan;
254 foreach $subroutine (@applicable_conversion) {
259 version_string_conv $from, $to;
268 open INLY, $fn || die "Can't open";
271 s/^.*\\version \"([^\"]*)\".*$//;
273 print STDERR "Guessing version: ", $1, ".. ";
279 print STDERR "can't determine mudela version in $fn.\n";
291 $outfile = $opt_output if (defined($opt_output));
296 if (!(-f $infile) && !($infile =~ /\.ly$/s)) {
299 if ($opt_edit && $infile ne "-") {
301 $outfile = "$infile.NEW";
304 print STDERR "Input ", (($infile eq "-") ?"STDIN" : $infile), " .. ";
312 local ($from_version, $to_version);
313 $from_version = $opt_from;
314 $to_version = $opt_to;
316 ($from_version = get_auto_from $infile) unless defined($opt_from);
317 return if (!defined($from_version));
319 ($to_version = last_conversion) unless (defined($opt_to));
321 die "can't open \`$infile\'" unless open INLY,$infile ;
322 die "can't open \`$outfile\'" unless open OUTLY, ">$outfile";
324 do_conversion $from_version, $to_version;
329 rename $infile, "$infile~";
330 rename $outfile, "$infile";
339 GetOptions ("help", "output=s", "from=s", "to=s", "minor=i", "edit", "show-rules");
343 $opt_help = 0; # to extinguish typo check.
347 if ($opt_show_rules) {
349 $opt_show_rules = 0; # to extinguish typo check.
353 local ( $infile,$outfile);
356 while (defined($ARGV[0])) {
361 do_one_arg unless ($processed_one);