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
259 $notes =~ s/(\{)(\d\.*(\d\.*)+)/$2$1/gs; # pull beaming inside a rhythmic model
261 # Beam starts/endings are handled by the first/last note of the beam, since
262 # we need to know for the first note the <beam>begin</beam> and for the
263 # last note that the <beam>end</beam> tag should be used!
264 # Thus, the RegExp for a note contains the beam start/end tags { and }
265 while ($notes ne "") {
266 if ($notes =~ /^(\'+|\,+)(.*)$/) { # Octave marks
267 ($oct, $notes) = ($1, $2);
269 } elsif ($notes =~ /^qq(.*)$/) { # Begin grace
272 } elsif ($notes =~ /^r(.*)$/) { # End grace
275 } elsif ($notes =~ /^([0-9]\.?(?:\s?[0-9]+\.?)+)\s*(.*)$/) { # Rhythmic model
276 ($model, $notes) = ($1, $2);
277 @rhythmic_model = parse_rhythmic_model
($1);
278 $rhythmic_model_index = -1;
279 } elsif ($notes =~ /^\=(\d*)(\/.*)$/) { # multi-measure rests
282 if ($measrest eq '') {
285 $toprint .= "$measrest measures of rest.\n";
287 # Create a real multi-bar rest
288 print OUT
' <attributes>
290 <multiple-rest>'.$measrest.'</multiple-rest>
295 # Now create the measures
296 for $n (1..$measrest) {
299 <duration>'.($beats*$divisions*4/$beattype).'</duration
>
302 if ($n < $measrest) {
303 print OUT " </measure>\n";
304 reset_measure_attributes ();
306 print OUT ' <measure number
="'.$meas.'">
314 } elsif ($notes =~ /^({?(\^)?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?}?)(.*)$/) { # a note
315 ($note, $notes) = ($1,$7);
316 parse_note($note, $keysig, "", "", $qq);
317 } elsif ($notes =~ /^({?\((g|q)?{?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)[t\+]*\)[t\+}]*)(.*)$/) { # one note with a fermata
318 ($note, $notes) = ($1,$6);
319 parse_note($note, $keysig, "", "", $qq);
320 } elsif ($notes =~ /^(\(({?(\^)?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?}?){3}\))(.*)$/) { # a triplet
321 ($triplet, $notes) = ($1,$8);
322 $triplet =~ /^\(({?(\^)?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?}?)(.*)\)$/gs;
323 ($note, $triplet) = ($1,$7);
324 my $time_mod = " <time-modification>
325 <actual-notes>3</actual-notes>
326 <normal-notes>2</normal-notes>
327 </time-modification>\n";
328 parse_note($note, $keysig, '<tuplet type
="start"/>', $time_mod, $qq);
329 $triplet =~ /^({?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?}?)(.*)$/gs;
330 ($note, $triplet) = ($1,$6);
331 parse_note($note, $keysig, '', $time_mod, $qq);
332 parse_note($triplet, $keysig, '<tuplet type
="stop"/>', $time_mod, $qq);
333 } elsif ($notes =~ /^((\d+)\(({?(\^)?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?}?)+\;(\d+)\))(.*)$/) { # an n-tuplet
334 ($tuplet, $notes) = ($1,$10);
335 $tuplet =~ /^(\d+)\(({?(\,|\')*(x|xx|b|bb|n)?(\d*\.*)(g|q)?(\-|A|B|C|D|E|F|G)t?\+?}?)(.*);(\d)\)$/gs;
336 ($combdur, $note, $notedur, $tuplet, $numval) = ($1,$2,$5, $8,$9);
337 my $act_notes = $numval;
338 my $norm_notes = duration($combdur)/duration($notedur);
339 my $time_mod = " <time-modification>
340 <actual-notes>$act_notes</actual-notes>
341 <normal-notes>$norm_notes</normal-notes>
342 </time-modification>\n";
343 parse_note($note, $keysig, '<tuplet type
="start"/>', $time_mod, $qq);
344 while ($tuplet =~ /^({?(g|q)?(\,|\')*(x|xx|b|bb|n)?\d*\.*(\-|A|B|C|D|E|F|G)t?\+?\}?)([^}]+}?)$/gs) {
345 ($note, $tuplet) = ($1,$6);
346 parse_note($note, $keysig, '', $time_mod, $qq);
348 parse_note($tuplet, $keysig, '<tuplet type
="stop"/>', $time_mod, $qq);
349 } elsif ($notes =~ /^(%(\w(-|\+)\d))(.*)$/) { # Clef change
350 ($clef,$notes) = ($2,$4);
351 print OUT " <attributes>\n";
352 print OUT clef ($clef);
353 print OUT " </attributes>\n";
354 } elsif ($notes =~ /^@(c?\d+(\/\d+)?( \d+\/\d+)*|c\/?|o\.?)\s*(.*)$/) { # time signatue change
355 ($timesig,$notes) = ($1,$4);
356 print OUT " <attributes>\n";
357 print OUT timesignature($timesig);
358 print OUT " </attributes>\n";
359 } elsif ($notes =~ /^\$((b|x)[ABCDEFG]*)\s*(.*)$/) { # key signature change
360 ($keysig, $notes) = ($1, $3);
361 print OUT " <attributes>\n";
362 print OUT keysignature ($keysig);
363 print OUT " </attributes>\n";
364 } elsif ($notes =~ /^(:?\/+:?)(.*)$/) { # Barline (and repeats)
367 if ($barline =~ /^:\/\/:/) {
368 print OUT ' <barline location
="right">
369 <bar
-style
>light
-light
</bar
-style
>
370 <repeat direction
="backward"/>
373 } elsif ($barline =~ /^:\/\/$/ ) {
374 print OUT ' <barline location
="right">
375 <bar
-style
>light
-heavy
</bar
-style
>
376 <repeat direction
="backward"/>
379 } elsif ($barline =~ /^\/\/$/) {
380 $type = "light-light";
381 # At the end of a piece use a light-heavy barline
383 $type = "light-heavy";
385 print OUT " <barline location=\"right\">
386 <bar-style>$type</bar-style>
390 print OUT " </measure>\n";
391 reset_measure_attributes ();
393 print OUT ' <measure number
="'.$meas.'">
395 if ($barline =~ /^\/\/:$/) {
396 print OUT ' <barline location
="left">
397 <bar
-style
>heavy
-light
</bar
-style
>
398 <repeat direction
="forward"/>
401 } elsif ($barline =~ /^:\/\/:$/) {
402 print OUT ' <barline location
="left">
403 <repeat direction
="forward"/>
412 $toprint .= "bar line\n";
414 } elsif ($notes =~ /^\((\=)\)(.*)$/) { # a bar of rest with a fermata
415 ($rst, $notes) = ($1, $2);
416 $toprint .= "rest: $rst\n";
419 <duration
>'.($beats*$divisions*4/$beattype).'</duration
>
421 <fermata type
="upright"/>
425 } 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
426 # print "after replacement: $notes\n"; exit;
427 } elsif ($notes =~ /^ +(.*)$/) {
429 print("Invalid space encountered in notes before $notes\n");
431 print_error("got stuck with $notes\n");
436 print OUT " </measure>\n";
437 reset_measure_attributes ();
443 my($note, $keysig, $notation, $addition, $in_qq_group) = @_;
446 my ($actualnotes, $normalnotes) = (1,1);
448 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*$/) {
449 ($actualnotes, $normalnotes) = ($1, $2);
452 if ($note =~ /^\((.*)\)(.*)$/) {
457 $note =~ /^({)?(\^)?(g|q)?((\,|\')*)(x|xx|b|bb|n)?(\d*)(\.*)(\-|A|B|C|D|E|F|G)(t?)(\+?)(}?)$/;
458 my ($beamstart, $chord, $gracecue, $oct, $acc, $dur, $dot, $pitch, $trill, $tie, $beamend) = ($1, $2, $3, $4, $6, $7, $8, $9, $10, $11, $12);
462 if ($gracecue eq "g") {
463 print OUT ' <grace slash
="yes" steal
-time-following
="33"/>
466 if ($gracecue eq "q" || $in_qq_group) {
471 print OUT " <rest />\n";
474 print OUT " <chord/>\n";
477 <step
>'.$pitch.'</step
>
478 '.alter($pitch, $acc, $keysig)
479 .' <octave
>'.octave($oct).'</octave
>
483 # We are using a rhythmic model, extract the correct duration
486 if (($dur.$dot eq "") && scalar(@rhythmic_model)) {
488 $rhythmic_model_index = ($rhythmic_model_index +1 ) % scalar(@rhythmic_model);
490 $this_duration = $rhythmic_model[$rhythmic_model_index][0];
491 $this_head = $rhythmic_model[$rhythmic_model_index][1];
492 } elsif ($dur.$dot ne "" && scalar(@rhythmic_model)) {
493 # The rhythmic model ends when a new new rhythmic value appears!
494 @rhythmic_model = ();
496 if ($gracecue ne "g") {
497 if (!$this_duration) {
498 $this_duration = duration ($dur, $dot);
500 print OUT ' <duration
>'.($this_duration*$normalnotes/$actualnotes).'</duration
>
507 $tienotation = " <tied type=\"stop\"/>\n";
509 $tienotation .= " <tied type=\"start\"/>\n";
512 print OUT ' <tie type
="start"/>
517 print OUT ' <tie type
="stop"/>
519 $tienotation = " <tied type=\"stop\"/>\n";
524 # Determine graphic notehead: acciaccaturas are always 8th, otherwise use duration
525 if ($gracecue eq "g") {
526 print OUT " <type>eighth</type>\n";
529 $this_head = notehead ($dur, $dot);
531 print OUT $this_head;
533 # If we have an explicit accidental on the note, print the <accidental> tag
534 print OUT accidental_explicit ($acc);
536 # addition is typically empty or a time-modification tag
539 # print out beaming information if needed:
540 if (($beamstart eq "{") && ($beamend eq "}")) {
541 # Single-note beam means a hook
542 print OUT " <beam>forward hook</beam>\n";
543 } elsif ($beamstart eq "{") {
545 print OUT " <beam number=\"$BEAM\">begin</beam>\n";
546 } elsif (($BEAM > 0) && ($beamend eq "}")) {
547 print OUT " <beam number=\"$BEAM\">end</beam>\n";
549 } elsif ($BEAM > 0) {
550 print OUT " <beam number=\"$BEAM\">continue</beam>\n";
553 my $notationbracket = $fermata || $tienotation || ($trill eq "t") || ($notation ne "");
554 if ($notationbracket) {
555 print OUT " <notations>\n";
558 print OUT $tienotation;
561 print OUT " <fermata type=\"upright\"/>\n";
564 print OUT ' <ornaments
>
569 if ($notation ne "") {
570 print OUT " $notation\n";
572 if ($notationbracket) {
573 print OUT " </notations>\n";
579 $toprint .= "note: oct. $oct/acc. $acc/dur. $dur/dots $dot/grace,cue $gracecue/pitch $pitch\n";
582 sub reset_measure_attributes {
583 %active_alterations = {};
584 # TODO: reset all measure-only attributes, like manual accidentals
588 my ($pitch, $acc, $keysig) = @_;
591 # If we had the same pitch with explicit alteration already in the current
592 # measure, that alteration goes on, unless the current note has an explicit
595 $acc = $active_alterations{$pitch};
597 # Store the explicit alteration of the current pitch!
598 $active_alterations{$pitch} = $acc;
601 if (index ($keysig,$pitch) > -1) {
602 $keysig =~ /^(.).*$/gs;
608 my %acc_alt = ("n", 0, "b", -1, "bb", -2, "x", 1, "xx", 2);
609 if ($acc_alt{$acc} ne "") {
610 $alt = $acc_alt{$acc};
614 return "\t\t\t\t\t<alter>$alt</alter>\n";
619 sub accidental_explicit {
621 my %accidentals = ("xx", "double-sharp", "x", "sharp", "n", "natural", "b", "flat", "bb", "flat-flat");
622 my $this_acc = $accidentals{$acc};
624 return "\t\t\t\t<accidental>$this_acc</accidental>\n";
631 my ($duration, $dots) = @_;
632 my %du=("0", "long", "9", "breve", "1", "whole", "2", "half", "4", "quarter",
633 "8", "eighth", "6", "16th", "3", "32nd", "5", "64th", "7", "128th");
634 if (($duration ne "") && $du{$duration}) {
635 my $res = " <type>$du{$duration}</type>\n";
636 $res .= repeat (" <dot/>\n", length ($dots));
641 my ($duration, $dots) = @_;
642 if ($duration.$dots ne "") {
643 my $head = raw_notehead ($duration, $dots);
644 $old_type = $head if $head;
649 sub parse_rhythmic_model {
652 while ($model =~ s/^([0-9])\s*(\.?)\s*([0-9\.\s]*)$/$3/) {
653 my ($this_dur, $this_dots) = ($1, $2);
654 my $dur = raw_duration ($this_dur, $this_dots);
655 my $notehead = raw_notehead ($this_dur, $this_dots);
656 push @m, [$dur, $notehead];
663 my ($duration, $dots) = @_;
664 my %du=("1",4*$divisions,"2",2*$divisions,"4",$divisions,
665 "8",$divisions/2,"6",$divisions/4,"3",$divisions/8,
666 "5",$divisions/16,"7",$divisions/32,
667 "9",$divisions*8,"0",$divisions*16); # breve/long
668 my $res = $du{$duration};
671 while ($dots ne "") {
674 $dots =~ /^.(.*)$/gs;
681 my ($duration, $dots) = @_;
682 if ($duration.$dots eq "7.") {
683 print_error ("Neumic notation is not supported by MusicXML!");
686 if ($duration.$dots ne "") {
687 $old_duration = raw_duration ($duration, $dots);
688 if ($old_duration eq "") {
689 print_error("strange duration '$duration'\n");
692 return $old_duration;
699 $octave =~ /^(.)(.*)$/gs;
701 $old_octave = 4 - length $octave;
703 $old_octave = 3 + length $octave;
712 if ($clef =~ /^(\w)(\-|\+)(\d)$/) {
713 ($clefsign, $clefline) = ($1, $3);
715 print "Warning: Mensural clefs are not supported by MusicXML, using modern clef (input: $clef)\n";
717 if ($clefsign eq 'g
') {
719 $clefoctave = " <clef-octave-change>-1</clef-octave-change>\n";
722 ($clefsign, $clefline) = ("G", 2);
725 <sign
>'.$clefsign.'</sign
>
726 <line
>'.$clefline.'</line
>
727 '.$clefoctave.' </clef
>
734 # TODO: How is a change to C major represented? by "$ " or "$x " or "$b "?
735 # At the beginning, the $ part is left out, but mid-piece key changes
736 # need to way to clear all accidentals! We accept all three cases above!
737 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);
738 $keysig =~ s/(\s+)|&//gs; # it is unclear what the & means, so we'll ignore it
for now
.
739 $keysig =~ s/\[|\]//gs; # IGNORING brackets around a key sig.
740 $fifths = $fif{$keysig};
743 print_error
("Strange key signature '$keysig'.\n");
746 <fifths>'.$fifths.'</fifths>
756 if ($timesig =~ /^(o(\.)?)$/) {
762 print "Mensural time signature \"$1\" not supported, using $timesig.\n";
764 if ($timesig =~ /^(\d+\/\d
+)( \d
+\
/\d+)+$/ ) {
765 print "Alternating time signature \"$timesig\" not supported by MusicXML, falling back to $1.\n";
768 if ($timesig =~ /^c((\d+)(\/(\d
+))?
)$/gs
) {
769 print "Time signature \"$timesig\" not supported by MusicXML, falling back to $1.\n";
770 $timesig = "$1"; # TODO: it would be better to show the "C". Example: 451.023.814
773 # For missing timesignature, fall back to "c"
774 if ($timesig eq "0" || $timesig eq "" || $timesig eq "c" ) {
776 ($beats, $beattype) = (4,4);
777 } elsif ($timesig =~ /^c\/$/gi
) {
779 ($beats, $beattype) = (2,2);
780 } elsif ($timesig =~ /^(\d+)\/(\d
+)$/gs
) {
781 ($beats, $beattype) = ($1, $2);
782 } elsif ($timesig =~/^(\d+)$/gs) {
783 $symbol = "single-number";
784 ($beats, $beattype) = ($1,2);
786 print_error
("Time signature '$timesig' looks strange, falling back to 4/4.\n");
787 ($beats, $beattype) = (4,4);
790 $symbol = " symbol=\"$symbol\"";
792 $timesig = " <time$symbol>
793 <beats>$beats</beats>
794 <beat-type>$beattype</beat-type>
803 print "\nAn error occurred; context:\n\n$toprint\n
811 while (<STDIN
>) { $res .= $_; } # read all lines
813 if (!(open FH
, $fn)) {
816 while (<FH
>) { $res .= $_; } # read all lines