4 # Copyright (C) 2003 Rainer Typke
5 # Copyright (C) 2010 Reinhold Kainhofer <reinhold@kainhofer.com>
6 #pae2xml is licensed under the terms of the GNU General Public License Version
7 #2 as published by the <a href="http://www.fsf.org/" target="_top">Free Software Foundation</a>.
8 #This gives you legal permission to copy, distribute and/or modify <em>pae2xml</em> under
9 #certain conditions. Read
10 #the <a href="http://www.gnu.org/copyleft/gpl.html" target="_top">online version of the license</a>
11 #for more details. pae2xml is provided AS IS with NO WARRANTY OF ANY KIND,
12 #INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
14 our $script = "pae2xml.pl";
17 ### Handle command-line options
26 print 'pae2xml.pl [OPTIONS...] FILE
28 Converts the Plaine & Easie file FILE to MusicXML. If FILE is -, STDIN is used.
31 -h, --help Prints out this help message
32 --format=FORMAT, -f FORMAT
33 Interprets input file as FORMAT. Possible values are
34 rism, pae (default: rism)
35 -v, -- version Prints out version information
39 print "$script $version
40 Copyright (C) 2003 Rainer Typke
41 Copyright (C) 2010 Reinhold Kainhofer <reinhold\@kainhofer.com>
46 my $print_version = 0;
47 my $result = GetOptions
("f|format=s" => \
$format, "help|h" => \
$print_help, "version|v" => \
$print_version);
52 if ($print_help || (@ARGV == 0)) {
62 $old_duration = $divisions;
67 $rhythmic_model_index = 0;
69 # Store all alterations already used in the current measure, so that e.g.
70 # xCC also detects the second note as a Cis! Needs to be reset at the
71 # beginning of a new bar.
72 %active_alterations = {};
74 ($mday, $mon, $year) = (localtime()) [3..5];
75 $encoding_date = sprintf("%4d-%02d-%02d", $year + 1900, $mon+1, $mday);
82 if ($format eq "rism") {
83 $p =~ s/\s*\=\=+\s*(.*?)\s*\=\=+\s*/$1/sg;
84 $p =~ s/\s*included.*?-------------*\s*(.*?)\s*/$1/s;
87 if ($q !~ /^.*1\.1\.1.*$/gsx && $r =~ /^.*plain.*$/gsx) {
88 print_error
("$a contains 'plain', but not 1.1.1!\n");
90 if ($p =~ /^\s*([^\n]+)\n(.*?)\n((\d+\.\d+\.\d.*?plain.*?\n)+)(.*?)\n?([^\n]+)\n([^\n]+)\s*$/gs) {
91 my ($comp, $title, $incipits, $sonst, $libsig, $rismsig) = ($1, $2, $3, $5, $6, $7);
99 RISM SIGN.: $rismsig\n\n";
100 parse_rism_incipits
($incipits, $comp, $title, $sonst, $libsig, $rismsig);
103 if (index($p,"plain&easy") > -1) {
104 print_error
("Ignoring the following text:\n\n\n$p\n\n\n");
109 # Just a plaine & easie snippet, without any further RISM fields
111 $filename = "out.xml";
113 $filename = basename
($a, ".pae") . ".xml";
115 parse_pe
($filename, $p, "", "", "", "", "", "", "");
120 ##############################################################################
121 ### RISM file parsing
122 ##############################################################################
124 sub parse_rism_incipits
{
125 my ($incipits, $comp, $title, $sonst, $libsig, $rismsig) = @_;
127 $toprint .= "parsing: $incipits\n";
129 while ($incipits =~ /^(\d+\.\d+\..+?)(\d+\.\d+\..*)$/gs) {
132 parse_rism_incipit
($inc1, $comp, $title, $sonst, $libsig, $rismsig);
134 parse_rism_incipit
($incipits, $comp, $title, $sonst, $libsig, $rismsig);
137 sub parse_rism_incipit
{
138 my ($pe, $comp, $title, $sonst, $libsig, $rismsig) = @_;
140 if ($pe =~ /^\s*(\d+\.\d+\.\d)(\.|:)\s*(.*?)\nplain&easy:\s*(.*)$/gs) {
141 my ($inr, $instr, $pecode) = ($1, $3, $4);
143 my $filename="$rismsig-$inr.xml";
144 $filename =~ s/RISM\s*A\/II\s*:?\s*//gs
;
146 foreach $_ ($rismsig,$title,$inr,$instr,$comp,$libsig,$sonst)
154 parse_pe
($filename, $pecode, $inr, $instr, $comp, $title, $sonst, $libsig, $rismsig);
157 print_error
("could not parse $pe\n");
162 ##############################################################################
163 ### pure Plaine & Easie data parsing
164 ##############################################################################
167 my ($filename, $pe, $inr, $instr, $comp, $title, $sonst, $libsig, $rismsig) = @_;
169 $pe =~ s/@ü/@0ü/gs; # make missing time signature explicit
170 while ($pe =~ s/([^\-])(\d+)(\'|\,)(A|B|C|D|E|F|G)/$1$3$2$4/gs) {}; # octave first, then duration. Truly global.
172 if ($pe =~ /^\s*(%([\w\-\+\d]+))?(@([\d\w\/ ]+))?\s
*&?\s
*(\
$([^ü
]*))?ü
(.*)$/gs
) {
173 my ($clef, $timesig, $keysig, $rest) = ($2, $4, $6, $7);
175 print "Writing $filename...\n";
176 open(OUT
, ">$filename");
179 print OUT
'<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
180 <!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 2.0 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
183 print OUT
" <work>\n" if ($rismsig || $title);
184 print OUT
" <work-number>$rismsig</work-number>\n" if ($rismsig);
185 print OUT
" <work-title>$title</work-title>\n" if ($title);
186 print OUT
" </work>\n" if ($rismsig || $title);
187 print OUT
" <movement-number>$inr</movement-number>\n" if ($inr);
188 print OUT
" <movement-title>$instr</movement-title>\n" if ($instr);
189 print OUT
" <identification>\n";
190 print OUT
" <creator type=\"composer\">$comp</creator>\n" if ($comp);
191 print OUT
' <encoding>
192 <software>pae2xml by R. Typke</software>
193 <encoding-date>'.$encoding_date.'</encoding-date>
196 print OUT
" <source>$libsig</source>\n" if ($libsig);
197 print OUT
' </identification>
200 <part-name>'.$sonst.'</part-name>
206 <divisions>'.$divisions.'</divisions>
207 '.keysignature
($keysig)
208 .timesignature
($timesig)
219 parse_notes
($rest, $keysig);
221 else { print_error
("could not parse $pe\n"); }
223 </score-partwise>\n";
227 # Repeat $1 by a count of $2
229 (my $e, my $count) = @_;
231 for (my $i=1; $i <= $count; ++$i)
239 my ($notes, $keysig) = @_;
240 my $qq = 0; # in group of cue notes
242 my $meas = 2; # measure number
243 my $mopen = 1; # measure tag still open
245 if ($notes =~ /^\s*(.*?)\s*$/) {
249 $notes =~ s/!([^!]*)!(f*)/repeat($1, length($2)+1)/gse; # write out repetitions
250 while ( $notes =~ s/(:?\/+:?|^)([^\/:]*)(:?\
/+:?)i(:?\/+:?
)/$1$2$3$2$4/gs) {}; # replace whole-measure repeats (i notation)
252 $notes =~ s/(\d+)\(([^;]+\))/\($1$2/gs; # pull note lengths into fermatas or triplets
253 $notes =~ s/(xx|x|bb|b|n)\(/\($1/gs; # pull accidentals into tuplets or fermatas:
254 $notes =~ s/(\d+)(xx|x|bb|b|n)(A|B|C|D|E|F|G)/$2$1$3/gs; # accidentals first, then duration
256 $notes =~ s/(\.|\d|\,|\')qq/qq$1/gs; # pull beginning mark of group of grace notes in front of corresponding notes
257 $notes =~ s/(xx|x|bb|b|n)qq/qq$1/gs; # qq first, then parts of notes
258 $notes =~ s/([\.\d,'xbn])+(q|g)/$2$1/gs; # q and g first, then parts of notes
260 # Beam starts/endings are handled by the first/last note of the beam, since
261 # we need to know for the first note the <beam>begin</beam> and for the
262 # last note that the <beam>end</beam> tag should be used!
263 # Thus, the RegExp for a note contains the beam start/end tags { and }
264 while ($notes ne "") {
265 if ($notes =~ /^(\'+|\,+)(.*)$/) { # Octave marks
266 ($oct, $notes) = ($1, $2);
268 } elsif ($notes =~ /^qq(.*)$/) { # Begin grace
271 } elsif ($notes =~ /^r(.*)$/) { # End grace
274 } elsif ($notes =~ /^([0-9]\.?(?:\s?[0-9]+\.?)+)\s*(.*)$/) { # Rhythmic model
275 ($model, $notes) = ($1, $2);
276 @rhythmic_model = parse_rhythmic_model
($1);
277 $rhythmic_model_index = -1;
278 } elsif ($notes =~ /^\=(\d*)(\/.*)$/) { # multi-measure rests
281 if ($measrest eq '') {
284 $toprint .= "$measrest measures of rest.\n";
286 # Create a real multi-bar rest
287 print OUT
' <attributes>
289 <multiple-rest>'.$measrest.'</multiple-rest>
294 # Now create the measures
295 for $n (1..$measrest) {
298 <duration>'.($beats*$divisions*4/$beattype).'</duration
>
301 if ($n < $measrest) {
302 print OUT " </measure>\n";
303 reset_measure_attributes ();
305 print OUT ' <measure number
="'.$meas.'">
313 } elsif ($notes =~ /^({?(\^)?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?}?)(.*)$/) { # a note
314 ($note, $notes) = ($1,$7);
315 parse_note($note, $keysig, "", "", $qq);
316 } elsif ($notes =~ /^({?\((g|q)?{?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)[t\+]*\)[t\+}]*)(.*)$/) { # one note with a fermata
317 ($note, $notes) = ($1,$6);
318 parse_note($note, $keysig, "", "", $qq);
319 } elsif ($notes =~ /^(\(({?(\^)?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?}?){3}\))(.*)$/) { # a triplet
320 ($triplet, $notes) = ($1,$8);
321 $triplet =~ /^\(({?(\^)?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?}?)(.*)\)$/gs;
322 ($note, $triplet) = ($1,$7);
323 my $time_mod = " <time-modification>
324 <actual-notes>3</actual-notes>
325 <normal-notes>2</normal-notes>
326 </time-modification>\n";
327 parse_note($note, $keysig, '<tuplet type
="start"/>', $time_mod, $qq);
328 $triplet =~ /^({?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?}?)(.*)$/gs;
329 ($note, $triplet) = ($1,$6);
330 parse_note($note, $keysig, '', $time_mod, $qq);
331 parse_note($triplet, $keysig, '<tuplet type
="stop"/>', $time_mod, $qq);
332 } elsif ($notes =~ /^((\d+)\(({?(\^)?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?}?)+\;(\d+)\))(.*)$/) { # an n-tuplet
333 ($tuplet, $notes) = ($1,$10);
334 $tuplet =~ /^(\d+)\(({?(\,|\')*(x|xx|b|bb|n)?(\d*\.*)(g|q)?(\-|A|B|C|D|E|F|G)t?\+?}?)(.*);(\d)\)$/gs;
335 ($combdur, $note, $notedur, $tuplet, $numval) = ($1,$2,$5, $8,$9);
336 my $act_notes = $numval;
337 my $norm_notes = duration($combdur)/duration($notedur);
338 my $time_mod = " <time-modification>
339 <actual-notes>$act_notes</actual-notes>
340 <normal-notes>$norm_notes</normal-notes>
341 </time-modification>\n";
342 parse_note($note, $keysig, '<tuplet type
="start"/>', $time_mod, $qq);
343 while ($tuplet =~ /^({?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?\}?)([^}]+}?)$/gs) {
344 ($note, $tuplet) = ($1,$6);
345 parse_note($note, $keysig, '', $time_mod, $qq);
347 parse_note($tuplet, $keysig, '<tuplet type
="stop"/>', $time_mod, $qq);
348 } elsif ($notes =~ /^(%(\w(-|\+)\d))(.*)$/) { # Clef change
349 ($clef,$notes) = ($2,$4);
350 print OUT " <attributes>\n";
351 print OUT clef ($clef);
352 print OUT " </attributes>\n";
353 } elsif ($notes =~ /^@(c?\d+(\/\d+)?( \d+\/\d+)*|c\/?|o\.?)\s*(.*)$/) { # time signatue change
354 ($timesig,$notes) = ($1,$4);
355 print OUT " <attributes>\n";
356 print OUT timesignature($timesig);
357 print OUT " </attributes>\n";
358 } elsif ($notes =~ /^\$((b|x)[ABCDEFG]*)\s*(.*)$/) { # key signature change
359 ($keysig, $notes) = ($1, $3);
360 print OUT " <attributes>\n";
361 print OUT keysignature ($keysig);
362 print OUT " </attributes>\n";
363 } elsif ($notes =~ /^(:?\/+:?)(.*)$/) { # Barline (and repeats)
366 if ($barline =~ /^:\/\/:/) {
367 print OUT ' <barline location
="right">
368 <bar
-style
>light
-light
</bar
-style
>
369 <repeat direction
="backward"/>
372 } elsif ($barline =~ /^:\/\/$/ ) {
373 print OUT ' <barline location
="right">
374 <bar
-style
>light
-heavy
</bar
-style
>
375 <repeat direction
="backward"/>
378 } elsif ($barline =~ /^\/\/$/) {
379 $type = "light-light";
380 # At the end of a piece use a light-heavy barline
382 $type = "light-heavy";
384 print OUT " <barline location=\"right\">
385 <bar-style>$type</bar-style>
389 print OUT " </measure>\n";
390 reset_measure_attributes ();
392 print OUT ' <measure number
="'.$meas.'">
394 if ($barline =~ /^\/\/:$/) {
395 print OUT ' <barline location
="left">
396 <bar
-style
>heavy
-light
</bar
-style
>
397 <repeat direction
="forward"/>
400 } elsif ($barline =~ /^:\/\/:$/) {
401 print OUT ' <barline location
="left">
402 <repeat direction
="forward"/>
411 $toprint .= "bar line\n";
412 } #elsif ($notes =~ /^(\d*\.*\-)(.*)$/) {
413 #($rst, $notes) = ($1, $2);
414 #$toprint .= "rest: $rst\n";
415 #$rst =~ /^(\d*)(\.*)\-$/;
416 #($rst, $dots) =($1,$2);
419 # <duration>'.duration($rst, $dots).'</duration>
420 #'.# <type>quarter</type>
424 elsif ($notes =~ /^\((\=)\)(.*)$/) { # a bar of rest with a fermata
425 ($rst, $notes) = ($1, $2);
426 $toprint .= "rest: $rst\n";
429 <duration>'.($beats*$divisions*4/$beattype).'</duration
>
431 <fermata type
="upright"/>
436 elsif ($notes =~ s/(\d+\.*)\(({?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?}?)\)/\($1$2\)/gs) { # pull duration into fermata parentheses
437 # print "after replacement: $notes\n"; exit;
439 elsif ($notes =~ /^ +(.*)$/) {
441 print("Invalid space encountered in notes before $notes\n");
444 print_error("got stuck with $notes\n");
449 print OUT " </measure>\n";
450 reset_measure_attributes ();
456 my($note, $keysig, $notation, $addition, $in_qq_group) = @_;
459 my ($actualnotes, $normalnotes) = (1,1);
461 if ($addition =~ /^\s*<time-modification>\s*<actual-notes>\s*(\d+)\s*<\/actual-notes>\s*<normal-notes>\s*(\d+)\s*<\/normal-notes>\s*<\/time-modification>\s*$/) {
462 ($actualnotes, $normalnotes) = ($1, $2);
465 if ($note =~ /^\((.*)\)(.*)$/) {
470 $note =~ /^({)?(\^)?(g|q)?((\,|\')*)(x|xx|b|bb|n)?(\d*)(\.*)(\-|A|B|C|D|E|F|G)(t?)(\+?)(}?)$/;
471 my ($beamstart, $chord, $gracecue, $oct, $acc, $dur, $dot, $pitch, $trill, $tie, $beamend) = ($1, $2, $3, $4, $6, $7, $8, $9, $10, $11, $12);
475 if ($gracecue eq "g") {
476 print OUT ' <grace slash
="yes" steal
-time-following
="33"/>
479 if ($gracecue eq "q" || $in_qq_group) {
484 print OUT " <rest />\n";
487 print OUT " <chord/>\n";
490 <step
>'.$pitch.'</step
>
491 '.alter($pitch, $acc, $keysig)
492 .' <octave
>'.octave($oct).'</octave
>
496 # We are using a rhythmic model, extract the correct duration
499 if (($dur.$dot eq "") && scalar(@rhythmic_model)) {
501 $rhythmic_model_index = ($rhythmic_model_index +1 ) % scalar(@rhythmic_model);
503 $this_duration = $rhythmic_model[$rhythmic_model_index][0];
504 $this_head = $rhythmic_model[$rhythmic_model_index][1];
505 } elsif ($dur.$dot ne "" && scalar(@rhythmic_model)) {
506 # The rhythmic model ends when a new new rhythmic value appears!
507 @rhythmic_model = ();
509 if ($gracecue ne "g") {
510 if (!$this_duration) {
511 $this_duration = duration ($dur, $dot);
513 print OUT ' <duration
>'.($this_duration*$normalnotes/$actualnotes).'</duration
>
520 $tienotation = " <tied type=\"stop\"/>\n";
522 $tienotation .= " <tied type=\"start\"/>\n";
525 print OUT ' <tie type
="start"/>
530 print OUT ' <tie type
="stop"/>
532 $tienotation = " <tied type=\"stop\"/>\n";
537 # Determine graphic notehead: acciaccaturas are always 8th, otherwise use duration
538 if ($gracecue eq "g") {
539 print OUT " <type>eighth</type>\n";
542 $this_head = notehead ($dur, $dot);
544 print OUT $this_head;
546 # If we have an explicit accidental on the note, print the <accidental> tag
547 print OUT accidental_explicit ($acc);
549 # addition is typically empty or a time-modification tag
552 # print out beaming information if needed:
553 if (($beamstart eq "{") && ($beamend eq "}")) {
554 # Single-note beam means a hook
555 print OUT " <beam>forward hook</beam>\n";
556 } elsif ($beamstart eq "{") {
558 print OUT " <beam number=\"$BEAM\">begin</beam>\n";
559 } elsif (($BEAM > 0) && ($beamend eq "}")) {
560 print OUT " <beam number=\"$BEAM\">end</beam>\n";
562 } elsif ($BEAM > 0) {
563 print OUT " <beam number=\"$BEAM\">continue</beam>\n";
566 my $notationbracket = $fermata || $tienotation || ($trill eq "t") || ($notation ne "");
567 if ($notationbracket) {
568 print OUT " <notations>\n";
571 print OUT $tienotation;
574 print OUT " <fermata type=\"upright\"/>\n";
577 print OUT ' <ornaments
>
582 if ($notation ne "") {
583 print OUT " $notation\n";
585 if ($notationbracket) {
586 print OUT " </notations>\n";
592 $toprint .= "note: oct. $oct/acc. $acc/dur. $dur/dots $dot/grace,cue $gracecue/pitch $pitch\n";
595 sub reset_measure_attributes {
596 %active_alterations = {};
597 # TODO: reset all measure-only attributes, like manual accidentals
601 my ($pitch, $acc, $keysig) = @_;
604 # If we had the same pitch with explicit alteration already in the current
605 # measure, that alteration goes on, unless the current note has an explicit
608 $acc = $active_alterations{$pitch};
610 # Store the explicit alteration of the current pitch!
611 $active_alterations{$pitch} = $acc;
614 if (index ($keysig,$pitch) > -1) {
615 $keysig =~ /^(.).*$/gs;
621 my %acc_alt = ("n", 0, "b", -1, "bb", -2, "x", 1, "xx", 2);
622 if ($acc_alt{$acc} ne "") {
623 $alt = $acc_alt{$acc};
627 return "\t\t\t\t\t<alter>$alt</alter>\n";
632 sub accidental_explicit {
634 my %accidentals = ("xx", "double-sharp", "x", "sharp", "n", "natural", "b", "flat", "bb", "flat-flat");
635 my $this_acc = $accidentals{$acc};
637 return "\t\t\t\t<accidental>$this_acc</accidental>\n";
644 my ($duration, $dots) = @_;
645 my %du=("0", "long", "9", "breve", "1", "whole", "2", "half", "4", "quarter",
646 "8", "eighth", "6", "16th", "3", "32nd", "5", "64th", "7", "128th");
647 if ($duration && $du{$duration}) {
648 my $res = " <type>$du{$duration}</type>\n";
649 $res .= repeat (" <dot/>\n", length ($dots));
654 my ($duration, $dots) = @_;
655 if ($duration.$dots ne "") {
656 my $head = raw_notehead ($duration, $dots);
657 $old_type = $head if $head;
662 sub parse_rhythmic_model {
665 while ($model =~ s/^([0-9])\s*(\.?)\s*([0-9\.\s]*)$/$3/) {
666 my ($this_dur, $this_dots) = ($1, $2);
667 my $dur = raw_duration ($this_dur, $this_dots);
668 my $notehead = raw_notehead ($this_dur, $this_dots);
669 push @m, [$dur, $notehead];
676 my ($duration, $dots) = @_;
677 my %du=("1",4*$divisions,"2",2*$divisions,"4",$divisions,
678 "8",$divisions/2,"6",$divisions/4,"3",$divisions/8,
679 "5",$divisions/16,"7",$divisions/32,
680 "9",$divisions*8,"0",$divisions*16); # breve/long
681 my $res = $du{$duration};
684 while ($dots ne "") {
687 $dots =~ /^.(.*)$/gs;
694 my ($duration, $dots) = @_;
695 if ($duration.$dots eq "7.") {
696 print_error ("Neumic notation is not supported by MusicXML!");
699 if ($duration.$dots ne "") {
700 $old_duration = raw_duration ($duration, $dots);
701 if ($old_duration eq "") {
702 print_error("strange duration '$duration'\n");
705 return $old_duration;
712 $octave =~ /^(.)(.*)$/gs;
714 $old_octave = 4 - length $octave;
716 $old_octave = 3 + length $octave;
725 if ($clef =~ /^(\w)(\-|\+)(\d)$/) {
726 ($clefsign, $clefline) = ($1, $3);
728 print "Warning: Mensural clefs are not supported by MusicXML, using modern clef (input: $clef)\n";
730 if ($clefsign eq 'g
') {
732 $clefoctave = " <clef-octave-change>-1</clef-octave-change>\n";
735 ($clefsign, $clefline) = ("G", 2);
738 <sign
>'.$clefsign.'</sign
>
739 <line
>'.$clefline.'</line
>
740 '.$clefoctave.' </clef
>
747 # TODO: How is a change to C major represented? by "$ " or "$x " or "$b "?
748 # At the beginning, the $ part is left out, but mid-piece key changes
749 # need to way to clear all accidentals! We accept all three cases above!
750 my %fif=("", 0, "x", 0, "b", 0, "xF", 1, "xFC", 2, "xFCG",3, "xFCGD",4, "xFCGDA",5, "xFCGDAE",6, "xFCGDAEB",7, "bB",-1, "bBE",-2, "bBEA",-3, "bBEAD",-4, "bBEADG",-5, "bBEADGC",-6, "bBEADGCF",-7);
751 $keysig =~ s/(\s+)|&//gs; # it is unclear what the & means, so we'll ignore it
for now
.
752 $keysig =~ s/\[|\]//gs; # IGNORING brackets around a key sig.
753 $fifths = $fif{$keysig};
756 print_error
("Strange key signature '$keysig'.\n");
759 <fifths>'.$fifths.'</fifths>
769 if ($timesig =~ /^(o(\.)?)$/) {
775 print "Mensural time signature \"$1\" not supported, using $timesig.\n";
777 if ($timesig =~ /^(\d+\/\d
+)( \d
+\
/\d+)+$/ ) {
778 print "Alternating time signature \"$timesig\" not supported by MusicXML, falling back to $1.\n";
781 if ($timesig =~ /^c((\d+)(\/(\d
+))?
)$/gs
) {
782 print "Time signature \"$timesig\" not supported by MusicXML, falling back to $1.\n";
783 $timesig = "$1"; # TODO: it would be better to show the "C". Example: 451.023.814
786 # For missing timesignature, fall back to "c"
787 if ($timesig eq "0" || $timesig eq "" || $timesig eq "c" ) {
789 ($beats, $beattype) = (4,4);
790 } elsif ($timesig =~ /^c\/$/gi
) {
792 ($beats, $beattype) = (2,2);
793 } elsif ($timesig =~ /^(\d+)\/(\d
+)$/gs
) {
794 ($beats, $beattype) = ($1, $2);
795 } elsif ($timesig =~/^(\d+)$/gs) {
796 $symbol = "single-number";
797 ($beats, $beattype) = ($1,2);
799 print_error
("Time signature '$timesig' looks strange, falling back to 4/4.\n");
800 ($beats, $beattype) = (4,4);
803 $symbol = " symbol=\"$symbol\"";
805 $timesig = " <time$symbol>
806 <beats>$beats</beats>
807 <beat-type>$beattype</beat-type>
816 print "\nAn error occurred; context:\n\n$toprint\n
824 while (<STDIN
>) { $res .= $_; } # read all lines
826 if (!(open FH
, $fn)) {
829 while (<FH
>) { $res .= $_; } # read all lines