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 sub convert_0_1_9_to_0_1_10
170 s/Grandstaff/Grand_staff/;
173 sub convert_0_1_10_to_0_1_14
175 while ( /([ \n\t\]\[<>()])\'+[a-zA-Z]/ )
177 s/([ \n\t\[<>()\]])\'(\'*[a-zA-Z]+)/$1$2,/g;
180 sub convert_0_1_14_to_0_1_15
182 # junked \duration last and \duration 4, 8, 16 etc.
183 # junked \octave relative
184 print STDERR
"Not smart enough to convert \\duration\n" if (/\\duration/) ;
185 print STDERR
"Not smart enough to convert \\octave relative\n" if (/\\octave relative/) ;
188 ###############################################################
198 print STDERR
"This is convert-mudela " . $convert_mudela_version .
199 " (up to mudela version ", last_conversion
, ")\n";
205 print STDERR
"Usage: convert-mudela [options] [mudela-file]...\n"
206 . "Convert old mudela source from mudela-file or stdin\n\n"
208 . " -e, --edit perform in-place conversion\n"
209 . " -f, --from=PATHLEVEL use source version 0.0.PATCHLEVEL\n"
210 . " -h, --help print this help\n"
211 . " -o, --output=FILE name output file\n"
212 . " -s, --show-rules print all known conversion rules\n"
213 . " -t, --to=VERSION convert to version VERSION\n"
217 my %minor_conversions = ("0.0.50" => \
&no_conv
,
218 "0.0.52" => \
&convert_0_0_50_to_0_0_52
,
219 "0.0.53" => \
&convert_0_0_52_to_0_0_53
,
220 "0.0.54" => \
&convert_0_0_53_to_0_0_54
,
221 "0.0.55" => \
&convert_0_0_54_to_0_0_55
,
222 "0.0.56" => \
&convert_0_0_55_to_0_0_56
,
223 "0.0.57" => \
&convert_0_0_56_to_0_0_57
,
224 "0.0.58" => \
&convert_0_0_57_to_0_0_58
,
225 "0.0.59" => \
&convert_0_0_58_to_0_0_59
,
226 "0.0.60" => \
&convert_0_0_59_to_0_0_60
,
227 "0.0.61" => \
&convert_0_0_60_to_0_0_61
,
228 "0.1.1" => \
&convert_0_1_0_to_0_1_1
,
229 "0.1.2" => \
&no_conv
,
230 "0.1.3" => \
&convert_0_1_2_to_0_1_3
,
231 "0.1.4" => \
&no_conv
,
232 "0.1.5" => \
&convert_0_1_4_to_0_1_5
,
233 "0.1.6" => \
&convert_0_1_5_to_0_1_6
234 ,"0.1.7" => \
&convert_0_1_6_to_0_1_7
235 ,"0.1.8" => \
&convert_0_1_7_to_0_1_8
236 ,"0.1.9" => \
&convert_0_1_8_to_0_1_9
237 ,"0.1.10" => \
&convert_0_1_9_to_0_1_10
238 , "0.1.14" => \
&convert_0_1_10_to_0_1_14
239 , "0.1.15" => \
&convert_0_1_14_to_0_1_15
246 return (sort { cmpver
; } (keys %minor_conversions));
254 print "Rules: ", join(", ", @v), "\n";
262 my @applicable_conversion;
267 if (version_compare
($ver, $from) > 0 && version_compare
($ver,$to) <= 0 ){
268 push @applicable_conversion, $minor_conversions{$ver};
269 push @mudela_levels, $ver;
273 print STDERR
"Applying following rules: ", join(", ", @mudela_levels) , "\n";
276 generic_conversion_scan
;
277 foreach $subroutine (@applicable_conversion) {
282 version_string_conv
$from, $to;
291 open INLY
, $fn || die "Can't open";
294 s/^.*\\version \"([^\"]*)\".*$//;
296 print STDERR
"Guessing version: ", $1, ".. ";
302 print STDERR
"can't determine mudela version in $fn.\n";
314 $outfile = $opt_output if (defined($opt_output));
319 if (!(-f
$infile) && !($infile =~ /\.ly$/s)) {
322 if ($opt_edit && $infile ne "-") {
324 $outfile = "$infile.NEW";
327 print STDERR
"Input ", (($infile eq "-") ?
"STDIN" : $infile), " .. ";
335 local ($from_version, $to_version);
336 $from_version = $opt_from;
337 $to_version = $opt_to;
339 ($from_version = get_auto_from
$infile) unless defined($opt_from);
340 return if (!defined($from_version));
342 ($to_version = last_conversion
) unless (defined($opt_to));
344 die "can't open \`$infile\'" unless open INLY
,$infile ;
345 die "can't open \`$outfile\'" unless open OUTLY
, ">$outfile";
347 do_conversion
$from_version, $to_version;
352 rename $infile, "$infile~";
353 rename $outfile, "$infile";
362 GetOptions
("help", "output=s", "from=s", "to=s", "minor=i", "edit", "show-rules");
366 $opt_help = 0; # to extinguish typo check.
370 if ($opt_show_rules) {
372 $opt_show_rules = 0; # to extinguish typo check.
376 local ( $infile,$outfile);
379 while (defined($ARGV[0])) {
384 do_one_arg
unless ($processed_one);