-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmuscript_pl
More file actions
executable file
·4831 lines (4622 loc) · 172 KB
/
muscript_pl
File metadata and controls
executable file
·4831 lines (4622 loc) · 172 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/perl
#
# muscript: typesets music scores into PostScript. Peter Billam, may1994
# www.pjb.com.au/muscript - and into MIDI apr2005, and into XML jan2007
#
#########################################################################
# This Perl script is Copyright (c) 1994, Peter J Billam #
# c/o P J B Computing, GPO Box 669, Hobart TAS 7001, Australia #
# #
# Permission is granted to any individual or institution to use, copy, #
# modify or redistribute this software, so long as it is not resold for #
# profit, and provided this notice is retained. Neither Peter Billam #
# nor P J B Computing make any representations about the suitability #
# of this software for any purpose. It is provided "as is", without any #
# express or implied warranty. http://www.pjb.com.au/muscript #
#########################################################################
# still unused in syntax: ` ! @ % ^ & * : ;
# needs hard syntax for: 1a 2a :|| 8va DalSegno HairpinCresc
# needs IndentingStaves TitleInMidpage cha3&4 vol85&105
# "z" for rest ? "Z" for blank ?
# -arp note-option prints apregg-sign in ps, arpeggiates at say .06 sec in midi
# candidate notations for smooth midi changes (or pan or vol etc) 3.0h?
# =1 8 ben25++ blank ben50 2.. blank
# =1 8 ben25-- blank --ben50 2.. blank
# =1 8 ben25( blank ben50) 2.. blank
# 20120308
# The I<midi barlines on> global-midi command, generate barline-markers,
# This allows I<muscript -midi> to generate barline-markers,
# more conveniently than with B<%> comments every bar
# For example, I<midichord> can have its chord-channels generated thus.
# midi only \n midi off \n midi on \n
# 20120926
# we need {} for e.g. =3 8 $Br)1 =3 8 ${B}r)1
# or do we just swallow all the [A-Z]+ after a $ ? even inside a string ?
# 20150611 need a loopset effect, for piping into aplaymidi -p midiloop -
# If it's in midisox you can convert an impro into a loop,
# but if it's in muscript, then we know where the barlines are :-)
# I think it should be in muscript; impros can use midi2muscript ...
# A command-line option would allow -loopset 49 or -loopset 88
require Data::Dumper;
$Data::Dumper::Indent = 1;
$Data::Dumper::Quotekeys = 0;
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Terse = 1;
$debug = 0;
if ($debug) {$|=1;} # so you can 'tail -f' on the output file
$Version = '3.3e for Perl'; # no change; keeping in sync with Lua version
$VersionDate = '09mar2018';
no warnings; # Use of assignment to $[ is deprecated in perl 5.14
# if it becomes illegal, it may be easier to translate to Lua than to fix
$[=1; # awk (and a2p) legacy, needed by $Isyst $Ibar and $Istave
# Beginning of Configuration Stuff: mostly relative to stave height ...
$SpaceAtBeginningOfBar = 0.60;
$AccidentalBeforeNote = 0.40;
$AccidentalDxInKeysig = 0.20;
$BlackBlobHalfWidth = 0.17;
$BlackBlobHalfHeight = 0.113; # gives -w warning, but needed in DATA
$BlackBlobHalfHeight += 0.0; # avoids warning, I hate being forced to this
$WhiteBlobHalfWidth = 0.183;
$BlobQuarterWidth = 0.085; # 2.8z
$WhiteBlobHalfHeight = 0.122;
$SmallNoteRatio = 0.61;
$SmallStemRatio = 0.76;
$StemFromBlobCentre = 0.176;
$DotRightOfNote = 0.36; # 3.2m
$DotRightOfRest = 0.29; # 3.2m
$DotAboveNote = 0.06;
$NoteShift = 0.28;
$AccidentalShift = 0.19;
$DoubleFlatSpacing = 0.25;
$SpaceLeftOfClef = 0.40;
$SpaceRightOfClef = 0.90;
$SpaceForClef = 0.80;
$SpaceForTimeSig = 0.50;
$SpaceForFatTimeSig = 0.60;
$SpaceAfterKeySig = 0.10;
$SpaceForStartRepeat = 0.35;
$SpaceForEndRepeat = 0.10;
$SpaceAtEndOfBar = 0.00;
$TieAfterNote = 0.17;
$TieAboveNote = 0.20;
$TieShift = 0.60;
$TieDy = 0.30;
$TieOverhang = 0.32;
$MustSquashTie = 0.80;
$MustReallySquashTie = 0.50;
$MaxTieGradient = 0.55; # dimensionless; dy/dx
$TextBelowStave = 0.50;
$TextSize = 0.55;
$SmallFontRatio = 0.707;
$StemLength = 0.85;
$OptionClearance = 0.19; # 0.38
$OptionDy = 0.35;
%OptionDy = (dot=>0.25, tenuto=>0.26, upbow=>0.43, gs=>0.55,
blank=>0.25, Is=>0.35, is=>0.33, bs=>0.35, rs=>0.33, I=>0.47, i=>0.45,
b=>0.47, r=>0.45, dim=>0.0, cre=>0.0, '*'=>0.35); # should be in initialise
$MinBeamClearance = 0.70;
$FlatHalfHeight = 0.42; # 3.2p
$SharpHalfHeight = 0.28; # 3.2p
$BeamWidth = 0.13; # used in ps_beam and in DATA
# $BeamWidth += 0.0; # avoids warning, I hate being forced to this
$BeamSpacing = 0.22;
$MaxBeamStub = 0.35;
$BeamGapMult = 0.85; # 3.2p
$TailSpacing = 0.24;
$MaxBeamGradient = 0.45; # dimensionless; dy/dx
$SegnoHeight = 0.90;
$RegularFont = 'Times-Roman-ISO';
$BoldFont = 'Times-Bold-ISO';
$ItalicFont = 'Times-Italic-ISO';
$BoldItalicFont = 'Times-BoldItalic-ISO';
$PedalFont = 'ZapfChancery-MediumItalic';
# XXX the next two should scale with systemsize, or boundarybox ?
$HeaderFontSize = 9; # in point
$TitleFontSize = 17.5; # in point
$AmpleSysGap = 0.15; # relative to page height
$LetterFactor = 0.94074; # US letter paper height relative to A4
$LetterInnerMargin = 8.4; # in point
$LetterOuterMargin = 8.4; # in point
# MIDI stuff ....
$TPC = 96; # MIDI Ticks Per Crochet
$DefaultLegato = 0.85; # MIDI default length of a crochet
$DefaultVolume = 100; # MIDI default volume (0..127)
# End of Configuration Stuff.
use Text::ParseWords;
# Command-line options ...
my $PageSize = 'a4';
my $Strip = 0;
my $Quiet = 0;
my $Midi = 0;
my $XmlOpt = 0;
my $PrePro = 0;
my $MidiBarlines = 0;
while (1) {
my $arg = $ARGV[$[];
if ($arg eq '-v') { # version
print <<EOT;
Muscript $Version $VersionDate http://www.pjb.com.au/muscript
For home page see http://www.pjb.com.au/muscript/index.html
For sample source see http://www.pjb.com.au/muscript/samples
EOT
exit;
} elsif ($arg eq '-letter' || $arg eq '-us') { shift; $PageSize='letter';
} elsif ($arg eq '-a4') { shift; $PageSize = 'a4';
} elsif ($arg eq '-auto') { shift; $PageSize = 'auto';
} elsif ($arg eq '-b') { shift; $MidiBarlines = 1;
} elsif ($arg eq '-compromise') { shift; $PageSize = 'compromise';
} elsif ($arg =~ /^-s/) { shift; $Strip = 1;
} elsif ($arg eq '-p') { shift; ps_prolog(); exit 0;
} elsif ($arg eq '-pp') {
shift; $PrePro=1; $XmlOpt=0; $Midi=0; $Strip=1; $Quiet=1;
# 3.2 but Midi=0 is destructive! e.g. what about the #P lines ?
} elsif ($arg =~ /^-q/) { shift; $Quiet = 1;
} elsif ($arg eq '-xml') { shift; $XmlOpt=1; $Midi=0; $Quiet=1;
} elsif ($arg eq '-midi') { shift; $Midi=1; $XmlOpt=0; $Quiet=1;
eval 'require MIDI'; if ($@) { die
"you'll need to install the MIDI-Perl module from www.cpan.org\n";
}
} elsif ($arg =~ /^-/) {
print <<'EOT';
Usage: muscript [filenames] # converts filenames to PostScript
muscript -a4 # forces A4 output (default)
muscript -us # forces US Letter output
muscript -compromise # forces A4 width and Letter height
muscript -auto # Autodetects PageSize of US Letter printers
muscript -s # Strips off the PS prolog (for concatenating)
muscript -p # just outputs the PS Prolog
muscript -q # Quiet
muscript -midi # converts to MIDI
muscript -xml # converts to MusicXML
muscript -pp # PreProcessor only (expands variables)
muscript -v # prints Version information
muscript -h # prints this Helpful message
For home page see http://www.pjb.com.au/muscript/index.html
For sample source see http://www.pjb.com.au/muscript/samples/
For sample output see http://www.pjb.com.au/mus/comp.html
EOT
exit;
} else { last;
}
}
# Other globals
my $Epsilon; # a small number
my $NoTTY;
my $PageNum;
my $Ibar;
my $Istave;
my @Nstaves;
my %BarType;
my %Stave2clef;
my %Stave2channels; # 3.1v now a hash of lists
my %Stave2volume;
my %Stave2pan;
my %Stave2bend; # 3.2
my %Stave2transpose;
my %Stave2legato;
my %Stave2nullkeysigDx = (); # 2.9y
my %Cha2transpose; # 3.1u see midi_global
my @MidiScore;
my $MidiTempo; # needed by "midi pause" and &midi_timesig
my $MidiTimesig;
my $TicksPerMidiBeat;
my $TicksPerCro;
my $CrosSoFar;
my $CrosPerPart;
my %Nbeats;
my $TicksAtBarStart;
my $TicksThisBar;
my %MidiExpression;
my %Intl2en;
my $XmlTimesig;
my $StartBeamUp; # &ps_event and &ps_note
my $StartBeamDown; # &ps_event and &ps_note
my %StartedSlurs = ();
my %StartedTies = (); # 3.2b cha3+4, $StartedTies{"$Istave $starttie $cha"}
my @BeamUp;
my @BeamDown;
my $LineNum = 0;
my %Accidentalled;
my %Options;
my %Opt_Cache = (); # orcish hash of lists
my %OptionMustGoBelow = map { $_, 1 } qw(P Ped * Sos *Sos Una Tre); # 3.1n
my $OldMidiTempo;
my $DefaultStem; # for this stave
my %Ystave;
my $Ystv; # timesaver
my %MaxStaveHeight;
my %StaveHeight;
my $StvHgt; # timesaver
my %YblineBot; my %YblineTop; my %Nblines; # barlines on this system
my $Isyst = 0; # my $Nsystems = 0;
my $RememberSystemsSizes; my $RememberNsystems; my %RememberHeader=();
my %Xstart; my %Ystart; # $Xstart{'tie',$Isyst,$Istave,$itie}; (or 'slur')
my $JustDidNewsystem = 0;
my %Xml;
my %XmlAccidental;
my %XmlDuration;
my %Accidental2alter;
my %XmlDynamics = map { $_, 1 } qw(p pp ppp pppp ppppp pppppp
f ff fff ffff fffff ffffff mp mf sf sfp sfpp fp rf rfz sfz sffz fz);
my @XmlCache; # cache for music-data in a measure, to count staves
my %Midline; my %Line2step; # for shifting rests in xml
my %SlurOrTie;
my %SlurOrTieShift;
my $PSprologAlready = 0;
my $Midi_off = 0;
my %MidiPedal = (); # 3.0b
my %MidiSosPed = (); # 3.0g
my %MidiUnaPed = (); # 3.1n
my %Vars = (); # set by set_var, sets up generators etc
my @RabbitSequence = (0,1,0,0,1,0,1,0, 0,1,0,0,1);
my @OldRabbitSequence = (0,1,0,0,1,0,1,0);
my @AabaSequence = (0,0,1,0, 0,0,1,0, 1,1,0,1, 0,0,1,0);
my $VariableSetRE = '^\$([A-Z][A-Z0-9]*)\s*(==?)\s*(.+)$';
my $VariableGetRE = '\$([A-Z][A-Z0-9]*)';
my $VarArraySetRE = '^\$([A-Z][A-Z0-9]*)(\d)-(\d)\s*(==?)\s*(.+)$';
# "boundingbox" can override these ...
$lmar=40; $rmar=565; $BotMar=60; $TopMar=781; # for systems
$FootMar=30; $HeadMar=811; # for header and footer text
initialise();
my @Stack = <>; # slurp onto the Stack.
while (@Stack) { # the main loop through the input-file
$LineNum++;
my $line = shift @Stack;
while ($line =~ s{\\\n$}{}) {
my $nxt = shift @Stack; $line .= $nxt; $LineNum++;
}
chop $line;
if ($line =~ /^\s*$/) { next; }
if ($line =~ /^\s*#P/) { # reused in 3.2u
if (! $PrePro) { # 3.2c keep #P and expand them
if ($Midi) { next; } $line =~ s/^\s*#P//; # 3.1h 3.2c
}
} elsif ($line =~ /^\s*#M/) {
if (! $PrePro) { # 3.2c keep #M and expand them
if (! $Midi) { next; } $line =~ s/^\s*#M//; # 3.2c
}
} elsif ($line =~ /^\s*#/) {
if ($PrePro) { print $line."\n"; } # 3.2c
next; # 3.1c
}
if ($line =~ /^\s*%/) { interpret_syntax($line); next; } # 3.1c
if ($line =~ /$VariableSetRE/o) { # 3.0g
unshift @Stack, $line; set_var(\@Stack); next;
}
if ($line =~ /$VarArraySetRE/o) { # 3.1m
set_array($1,$2,$3,$4,$5); next;
}
my @lines = substitute($line,1); # now here in mainloop
while (@lines) {
my $line = shift @lines;
if ($line =~ /^\s*$/) { next; }
if ($line =~ /$VariableSetRE/o) {
die "a \$VAR= line remains in the text:\n$line\n";
} else {
interpret_syntax($line);
}
}
}
sub interpret_syntax { my $line = $_[$[];
$line =~ s{^\s+}{}; # strip leading space
$line =~ s{\s+$}{}; # strip trailing space # 3.1f
# invoked both per input-line, and from each line within a multiline var
if ($PrePro) { print $line,"\n"; return; }
if ($line =~ s/^=\s*//) {
if (!$Midi or !$Midi_off) { newstave($line); }
return; # 3.2g
}
if ($line =~ /^boundingbox\s+(\d+)\s+(\d+)$/) {boundingbox($1,$2); return;}
if (!$Midi && !$XmlOpt && !$PSprologAlready) { ps_prolog(); }
if ($line =~ /^([1-9][0-9]*)\s+systems?\s+(.*)$/) {systems($1,$2); return;}
if ($line =~ /^midi\s*(.*)$/) { # 3.1f
if ($1 eq 'on') { $Midi_off = 0;
} elsif ($1 eq 'off') { $Midi_off = 1;
} elsif (! $Midi_off) { midi_global($1); # 2.9l
}
return; # 3.2g
}
if ($Midi && $Midi_off) { return; }
if ($XmlOpt && !$Xml{'header finished'}) {
# for xml, the header lines must be consecutive ...
if (!&xml_header($line)) { $Xml{'header finished'} = 1; redo; }
}
my $ps = !$Midi && !$XmlOpt; # either PS or EPS
if ($line =~ /^rightfoot\s(.*)$/) { if ($ps) {ps_rightfoot($1);} return; }
if ($line =~ /^leftfoot\s(.*)$/) { if ($ps) {ps_leftfoot($1);} return; }
if ($line =~ /^innerhead\s(.*)$/) { if ($ps) {ps_innerhead($1);} return; }
if ($line =~ /^lefthead\s(.*)$/) { if ($ps) {ps_lefthead($1);} return; }
if ($line =~ /^righthead\s(.*)$/) { if ($ps) {ps_righthead($1);} return; }
if ($line =~ /^pagenum\s?(.*)$/) { if ($ps) {ps_pagenum($1);} return; }
if ($line =~ /^title/) { title($line); return; }
if ($line =~ /^%\s*(.*)/) { comment($1); return; }
if ($line =~ /^#|^muscript\s|^EOT$/) { return; } # 3.0g
if ($line =~ m{^/\s*$}) { newsystem($line); return; }
if ($line =~ m{^/\s*([1-9][0-9]*)\s*bars?\s*(.*)$}) { # both on same line
newsystem('/'); bars($1,$2); $Ibar=0; return;
}
if ($line =~ /^([1-9][0-9]*)\s*bars?\s*(.*)$/) {bars($1,$2);$Ibar=0;return;}
if ($line =~ /^\|\s*([^=]*)(\s*=(\d.*)$)?/) { # 2.9j
newbar($1); if ($3) { newstave($3); } return; # 3.2g
}
if ($line =~ /^([rbiI])([ls]?)(\d?\.?\d*)\s(.*)$/) {
if ($XmlOpt) { xml_text($1,$2,$3,$4); return; }
if ($Midi) { return; }
ps_text($1,$2,$3,$4); return;
}
if ($line =~ /^play\s+(.*)$/) { if ($Midi) {midi_play_wav($1);} return; }
warn "line $LineNum not recognised: $line\n"; # 2.9j
}
if ($Midi) {
midi_write();
} elsif ($XmlOpt) {
xml_print_cache();
print "\t\t</measure>\n\t</part>\n</score-partwise>\n";
} elsif (!$PrePro) {
ps_finish_ties(); # put in any unfinished ties ... 2.7j
print "pgsave restore\nshowpage\n%%EOF\n"; # XXX shouldn't showpage in EPS
print TTY "\n" unless $NoTTY;
}
exit 0;
# ------------------------ Subroutines -------------------------------
sub initialise {
if (!$Quiet) {
open(TTY, '>/dev/tty') || ($NoTTY = 1);
select TTY; $|=1; select STDOUT;
}
$Epsilon = 0.0005; # should be less than .001 for correct word spacing
$ipage = 0;
# pitch to height-on-stave assocarray is defined for the alto clef ...
my %raw_notetable;
if ($Midi) {
%raw_notetable = ( # defined for alto clef
'f~~'=>89, 'e~~'=>88, 'd~~'=>86, 'c~~'=>84, 'b~'=>83,
'a~'=>81, 'g~'=>79, 'f~'=>77, 'e~'=>76, 'd~'=>74, 'c~'=>72,
b=>71, a=>69, g=>67, f=>65, e=>64, d=>62, c=>60,
B=>59, A=>57, G=>55, F=>53, E=>52, D=>50, C=>48,
B_=>47, A_=>45, G_=>43, F_=>41, E_=>40, D_=>38, C_=>36,
B__=>12, A__=>10,
);
foreach (keys %raw_notetable) {
$notetable{$_} = $raw_notetable{$_};
$notetable{$_ . '#'} = $raw_notetable{$_} + 1;
$notetable{$_ . 'b'} = $raw_notetable{$_} - 1;
$notetable{$_ . '##'} = $raw_notetable{$_} + 2;
$notetable{$_ . 'bb'} = $raw_notetable{$_} - 2;
$notetable{$_ . 'n'} = $raw_notetable{$_};
if (/^([A-Ga-g])([~_]+)/) { # cope with A#__ order too
$notetable{"$1#$2"} = $raw_notetable{$_} + 1;
$notetable{"$1b$2"} = $raw_notetable{$_} - 1;
$notetable{"$1n$2"} = $raw_notetable{$_};
}
}
}
# ytable also needed by Midi, to keep track of stemup e.g. for slurs/ties
%ytable = (
'f~~'=>1.625, 'e~~'=>1.5, 'd~~'=>1.375, 'c~~'=>1.25, 'b~'=>1.125,
'a~'=>1.0, 'g~'=>0.875, 'f~'=>0.75, 'e~'=>0.625, 'd~'=>0.5,
'c~'=>0.375, b=>0.25, a=>0.125, g=>0.01, f=>-0.125, e=>-0.25,
d=>-0.375, c=>-0.5, B=>-0.625, A=>-0.75, G=>-0.875, F=>-1.0,
E=>-1.125, D=>-1.25, C=>-1.375, B_=>-1.5, A_=>-1.625, G_=>-1.75,
F_=>-1.875, E_=>-2.0, D_=>-2.125, C_=>-2.25, B__=>-2.375, A__=>-2.5,
);
# note durations ... # 3.2 hds is .0625, not .0725
my %en = (hds=>.0625,dsq=>.125,smq=>.25,
qua=>.5,cro=>1.0,min=>2.0,smb=>4.0,bre=>8.0);
foreach my $key (keys %en) {
$Nbeats{$key} = $en{$key};
$Nbeats{$key.'2'} = $en{$key}*0.75; # duplet
$Nbeats{$key.'3'} = $en{$key}*0.66667; # triplet
$Nbeats{$key.'4'} = $en{$key}*0.75; # quadruplet
$Nbeats{$key.'5'} = $en{$key}*0.8; # quintuplet
$Nbeats{$key.'6'} = $en{$key}*0.66667; # sextuplet
$Nbeats{$key.'7'} = $en{$key}*0.57142857; # septuplet 3.1z
}
foreach my $key (keys %Nbeats) { # dotted notes
$Nbeats{$key . '.' } = $Nbeats{$key} * 1.5;
$Nbeats{$key . '..' } = $Nbeats{$key} * 1.75;
$Nbeats{$key . '...'} = $Nbeats{$key} * 1.875;
}
foreach my $key (grep /^cro|^min|^smb/, keys %Nbeats) {
$Nbeats{$key . '/' } = $Nbeats{$key}; # tremolandi
$Nbeats{$key . '//' } = $Nbeats{$key};
$Nbeats{$key . '///'} = $Nbeats{$key};
}
foreach my $key (keys %Nbeats) { # small notes
$Nbeats{$key . '-s'} = $Nbeats{$key};
}
my %en2intl=(hds=>'64',dsq=>'32',smq=>'16',
qua=>'8', cro=>'4',min=>'2',smb=>'1');
foreach my $key (sort keys %Nbeats) { # International-style rhythm notation
# sort means smb gets overwritten by smq, so 16-s maps to smq-s, 2.9n
if ($key =~ /^([a-u][a-u][a-u])([2-7].*)$/) {
my $intl = $en2intl{$1};
next unless $intl;
$Intl2en{"$intl$2"} = $key;
next;
} elsif ($key =~ /^([a-u][a-u][a-u])(.*)$/) {
my $intl = $en2intl{$1};
next unless $intl;
$Intl2en{"$intl$2"} = $key;
next;
}
}
# foreach (sort keys %Intl2en) { warn "Intl2en{$_}=$Intl2en{$_}\n"; }
%Options = (
'down'=>'downbow', '.'=>'dot', 'emph'=>'emphasis', 'gs'=>'gs',
'mordent'=>'mordent', 'stac'=>'dot', 'stacc'=>'dot',
'ten'=>'tenuto', 'tenuto'=>'tenuto',
'tr'=>'trill', 'tr#'=>'trsharp', 'trb'=>'trflat', 'trn'=>'trnat',
'turn'=>'turn', 'up'=>'upbow',
);
%SlurOrTie = (
'('=>'starttie',
'{'=>'startslur',
')'=>'endtie',
'}'=>'endslur',
);
%SlurOrTieShift = (
""=>0, "'"=>1, "''"=>2, "'''"=>3, "''''"=>4,
","=>-1, ",,"=>-2, ",,,"=>-3, ",,,,"=>-4,
);
if ($Midi) {
@MidiScore = (); # a LoL
$MidiTimesig = q{};
$TicksPerMidiBeat = $TPC;
$TicksAtBarStart = 0;
$TicksThisBar = 0; # so as not to delay the start
$midibarparts = '2.4'; # default guesses 4/4 at 100 cro/min
%Stave2channels = ();
$currentstavenum = '1';
} elsif ($XmlOpt) {
%Stave2channels = ();
$XmlTimesig = '4/4';
%XmlDuration=(
hds=>'64th',dsq=>'32nd',smq=>'16th',qua=>'eighth',
cro=>'quarter', min=>'half',smb=>'whole',bre=>'breve'
);
foreach my $key (keys %XmlDuration) {
$XmlDuration{$key.q{3}} = "$XmlDuration{$key}";
$XmlDuration{$key.q{4}} = "$XmlDuration{$key}"; # 3.3d
}
foreach my $key (keys %XmlDuration) {
$XmlDuration{$key} = "<type>$XmlDuration{$key}</type>";
}
foreach my $key (keys %XmlDuration) { # dotted notes
$XmlDuration{$key.'.' }=$XmlDuration{$key}.'<dot/>';
$XmlDuration{$key.'..' }=$XmlDuration{$key}.'<dot/><dot/>';
$XmlDuration{$key.'...'}=$XmlDuration{$key}.'<dot/><dot/><dot/>';
}
foreach my $key (grep (/^cro|^min|^smb/, keys %XmlDuration)) {
$XmlDuration{$key . '/' } = $XmlDuration{$key};
$XmlDuration{$key . '//' } = $XmlDuration{$key};
$XmlDuration{$key . '///'} = $XmlDuration{$key};
}
foreach my $key
(grep (/^hds|^dsq|^smq|^qua|^cro|^min|^smb/, keys %XmlDuration)) {
$XmlDuration{$key . '-s'} = $XmlDuration{$key}; # small notes
}
%XmlAccidental = (
'#'=>'sharp', '##'=>'double-sharp',
'b'=>'flat', 'bb'=>'flat-flat', 'n'=>'natural',
);
%Accidental2alter = (
'#'=>1, '##'=>2, 'b'=>-1, 'bb'=>-2, 'n'=>0, ''=>0,
);
%Midline = (
treble8va=>41, treble=>34, treble8vab=>27, alto=>28,
tenor=>26, bass8va=>29, bass=>22, bass8va=>15,
);
%Line2step = (
'0'=>'C', '1'=>'D', '2'=>'E', '3'=>'F',
'4'=>'G', '5'=>'A', '6'=>'B',
);
$Xml{measure_number} = 0;
$Xml{backup} = 0;
}
}
#-----------------------------------------------------
sub set_var { my ($stackref, $infinite_depth) = @_;
my $line = shift @$stackref;
$line =~ /$VariableSetRE/o;
my $var = $1; my $substitute_now = ($2 eq '=='); my $val = $3;
if ($val =~ /^{(\s*#.*)?$/) { # allow comments 3.1b
# loop until closing brace, then set_var; store in %Vars as an arrayref
my @lines_of_var = ();
while (@$stackref) {
my $line = shift @$stackref;
while ($line=~s{\\\n$}{}) {my $nxt=shift @$stackref; $line.=$nxt;}
if ($line =~ /^\s*#P/) { # 3.2u
if (! $PrePro) { # 3.2c keep #P and expand them
if ($Midi) { next; } $line =~ s/^\s*#P//; # 3.1h 3.2c
}
} elsif ($line =~ /^\s*#M/) {
if (! $PrePro) { # 3.2c keep #M and expand them
if (! $Midi) { next; } $line =~ s/^\s*#M//; # 3.2c
}
}
chop $line;
$line =~ s{^\s+}{}; # strip leading space
if ($line =~ /^}/ or ! defined $line) { last; }
if (!$substitute_now) { push @lines_of_var, $line; next; }
if ($line =~ /$VariableSetRE/o) {
if ($substitute_now or $infinite_depth) {
unshift @$stackref, $line;
set_var($stackref, $infinite_depth);
} else {
warn "setvarline $line\n";
}
} elsif ($substitute_now or $infinite_depth) {
push @lines_of_var, substitute($line, $infinite_depth);
}
}
$Vars{$var} = \@lines_of_var;
} elsif ($val =~
/^(cycle|morse_thue|thue_morse|leibnitz|rabbit|fibonacci|random|aaba)
\?\s*(.*\S)\s*\?/x) {
my $f = $1; my @rhs = $2;
if ($substitute_now or $infinite_depth) { # 3.1i
@rhs = substitute($2, $infinite_depth); # 3.1i
}
if ($f eq 'thue_morse') { $f = 'morse_thue'; # 3.2g synonyms...
} elsif ($f eq 'fibonacci') { $f = 'rabbit';
}
my @a = split(/\s*:\s*/,$rhs[$[]);
if (! @a) {warn "line $LineNum: empty argument list in $val\n"; last;}
my $e = '$Vars{$var} = '.$f.'(@a);';
eval $e; if ($@) { warn "line $LineNum: can't eval $e: $@\n"; }
} else {
if ($substitute_now or $infinite_depth) {
my @lines = ();
# the arrayref logic is here, not in &substitute
if (ref $val eq 'ARRAY') {
foreach my $line (@{$val}) {
# one of those lines might involve a variable setting...
if ($line =~ /$VariableSetRE/o) {
unshift @$stackref, $val;
set_var($stackref, $infinite_depth);
} elsif ($line =~ /^}/) { last;
} else { push @lines, substitute($line);
}
}
} else {
if ($val =~ /$VariableSetRE/o) {
unshift @$stackref, $val;
set_var($stackref, $infinite_depth);
} else { @lines = substitute($val);
}
}
if (@lines == 1) { $Vars{$var} = $lines[$[];
} elsif (@lines > 1) { $Vars{$var} = \@lines;
}
} else {
$Vars{$var} = $val;
}
}
}
sub set_array { my ($base, $digit1, $digit2, $equals, $values) = @_; # 3.1m
# 20130305 XXX should we just expand and let set_var take care of it ?
# or should we impose a no-frills, end-of-line constraint ?
if ($digit1 >= $digit2) {
warn_ln("$digit1-$digit2 is not a valid range"); return;
}
my $n = $digit2 - $digit1 + 1;
my @vals = split /\s*:\s*/, $values;
if ($n > scalar @vals) {
@vals = split /\s+/, $values;
if ($n > scalar @vals) {
warn_ln("can't see $n variables in \"$values\""); return;
}
}
foreach my $i ($digit1 .. $digit2) { $Vars{"$base$i"} = shift @vals; }
}
sub boundingbox { my ($w, $h) = @_;
my $a4w = 210 * 72/25.4;
my $a4h = 297 * 72/25.4;
$lmar =40*$w/$a4w; $rmar =565*$w/$a4w;
$BotMar =60*$h/$a4h; $TopMar =781*$h/$a4h;
$FootMar=30*$h/$a4h; $HeadMar=811*$h/$a4h; # for header and footer text
$Box_H = $h;
$Box_W = $w;
}
sub systems { $[=1; $nsystems = shift; my $sizes = shift;
# sets globals: lmargin, rmargin, nsystems, Nstaves, ystave,
# staveheight, gapheight, Nblines, ybline, blineheight, Isyst
return if $Midi;
if ($nsystems && ! $sizes) { # impose some defaults
if ($nsystems > 6) { $sizes = '/19/';
} elsif ($nsystems > 4) { $sizes = '/19 30 19/';
} elsif ($nsystems > 3) { $sizes = '/19 30 19 30 19/';
} elsif ($nsystems > 2) { $sizes = '/19 30 19 30 19 30 19/';
} else { $sizes = '/19 30 19 30 19 30 19 30 19 30 19/';
}
} elsif (!$nsystems && !$sizes &&
$RememberNsystems && $RememberSystemsSizes) {
$sizes = $RememberSystemsSizes;
$nsystems = $RememberNsystems;
} else {
$RememberSystemsSizes = $sizes; # global
$RememberNsystems = $nsystems; # global
%RememberHeader = (); # global
}
my @systems = split(m{\s*/\s*}, $sizes, 9999);
my $topgap = 0 + shift @systems;
my $botgap = 0 + pop @systems; # $botgap not yet used ...
if ($XmlOpt) { # Xml: see layout.dtd -
$ipage++;
my @barlinesandgaps; my $istave;
my $isyst = $[;
for ($isyst = $[; $isyst <= $nsystems-1+$[; $isyst++) { # ugly
$istave = 0;
my $igap = 1;
my $isastave = 1; # the first number will be a stave height
@barlinesandgaps = split('\s+', $systems[$isyst], 9999);
foreach my $word (@barlinesandgaps) {
my @stavesandgaps = split(/-/, $word, 9999);
foreach $staveorgap (@stavesandgaps) {
if ($isastave) {
$istave++;
$StaveHeight{$isyst, $istave} = $staveorgap;
$isastave = 0; # the next will be a gap
} else { # its a gap
$gapheight{$isyst, $igap} = $staveorgap;
$isastave = 1; # the next will be a stave
$igap++;
}
}
}
$Nstaves{$isyst} = $istave;
}
$Isyst = 0;
return;
}
if ($ipage > 0) {
&ps_finish_ties();
printf "pgsave restore\nshowpage\n";
print TTY "\n" unless $NoTTY;
}
$ipage++;
print "%%Page: $ipage $ipage\n";
print "%%BeginPageSetup\n/pgsave save def\n%%EndPageSetup\n";
if ($PageSize eq 'letter') {
printf "%g 0 translate 1.0 %g scale\n", ($PageNum % 2) ?
$LetterInnerMargin : $LetterOuterMargin, $LetterFactor;
} elsif ($PageSize eq 'compromise' ) { # a4 width, letter height
print "4 0 translate 1.0 0.95 scale\n";
} elsif ($PageSize eq 'auto') { # autodetect
print "/pageheight currentpagedevice (PageSize) get 1 get def\n";
print "pageheight 800 lt pageheight 785 gt and {\n";
printf "\t%g 0 translate 1.0 %g scale\n} if\n", ($PageNum % 2) ?
$LetterInnerMargin : $LetterOuterMargin, $LetterFactor;
}
print TTY "page $ipage, system" unless $NoTTY;
my $shortfall = $nsystems - scalar @systems;
if ($shortfall > 0) {
my $last_syst = pop @systems;
push (@systems, $last_syst);
while ($shortfall > 0) { push (@systems, $last_syst); $shortfall--; }
}
my $totsyswidth = 0.0; # initialise counter for all systems on page
my @barlinesandgaps;
for (my $isyst = $[; $isyst <= $nsystems-1+$[; $isyst++) { # each system
my $syswidth = 0.0; # this system width (includes all gaps)
$lmargin{$isyst} = $lmar;
$rmargin{$isyst} = $rmar;
@barlinesandgaps = split('\s+', $systems[$isyst], 9999);
my $istave = 0;
my $igap = 1;
my $ibline = 0;
my $isastave = 1; # the first number will be a stave height
foreach my $word (@barlinesandgaps) { # loop over barlines & gaps
if ($isastave) {
$ibline++;
$YblineTop{$isyst, $ibline} = $syswidth; # will invert later
}
my @stavesandgaps = split(/-/, $word, 9999);
foreach $staveorgap (@stavesandgaps) {
$totsyswidth += $staveorgap;
$syswidth += $staveorgap;
if ($isastave) {
$istave++;
$StaveHeight{$isyst, $istave} = $staveorgap;
if (! defined $MaxStaveHeight{$isyst}) { # defeat -w
$MaxStaveHeight{$isyst} = 0; # makes me puke to do this
}
if ($StaveHeight{$isyst,$istave}>$MaxStaveHeight{$isyst}) {
$MaxStaveHeight{$isyst} = $StaveHeight{$isyst,$istave};
}
$isastave = 0; # the next will be a gap
} else { # its a gap
$gapheight{$isyst, $igap} = $staveorgap;
$isastave = 1; # the next will be a stave
$igap++;
}
}
if (! $isastave) {
$YblineBot{$isyst, $ibline} = $syswidth; # will invert later
}
}
$Nstaves{$isyst} = $istave;
$Nblines{$isyst} = $ibline;
$ngaps{$isyst} = $igap-1;
}
# adjust according to the average MaxStaveHeight
my $total = 0; my $num = 0; # 3.1r
while (my ($k, $v) = each %MaxStaveHeight) { $total += $v; $num += 1; }
if ($num) {
my $av = $total / $num;
$HeaderFontSize = $av * 9 / 19; # 3.1r
$TitleFontSize = $av * 17.5 / 19; # 3.1r
}
# so do the systems fit on the page ?
if ($nsystems == 1) {
$systemgap = ($TopMar-$BotMar-$totsyswidth-$topgap);
} else {
$systemgap = ($TopMar-$BotMar-$totsyswidth-$topgap) / ($nsystems-1);
}
if ($systemgap < 0) {
printf STDERR "\nSorry, won't fit: systemgap=%g\n", $systemgap; exit 1;
}
# if systemgap is large, space is left also above top sys & below bot.
my $Y;
my $excess = $systemgap - $AmpleSysGap*($TopMar-$BotMar);
if ($nsystems == 1) {
$Y = 0.5 * ($TopMar+$BotMar+$totsyswidth) - $topgap; # 2.9m
} elsif ($excess > 0) {
$adjustment = $excess * ($nsystems-1) / ($nsystems+1);
$systemgap = $systemgap - $excess + $adjustment;
$Y = $TopMar - $adjustment - $topgap;
} else {
$Y = $TopMar - $topgap;
}
# for each system ...
for (my $isyst=$[; $isyst<=$nsystems-1+$[; $isyst++) {
print "% system $isyst staves, initial barline, and brackets:\n";
my $istave = 1; my $igap = 1;
my $max_staveheight = 0;
while (1) { # print the staves ...
$Ystave{$isyst,$istave} = $Y;
if ($StaveHeight{$isyst,$istave} > $max_staveheight) {
$max_staveheight = $StaveHeight{$isyst,$istave};
}
printf "%g %g %g %g stave\n", $lmargin{$isyst},
$rmargin{$isyst}, $Y, $StaveHeight{$isyst,$istave};
$Y -= $StaveHeight{$isyst,$istave};
if ($istave >= $Nstaves{$isyst}) {
printf "%g %g %g %g barline\n", $lmargin{$isyst},
$Ystave{$isyst,1}, $Y, $StaveHeight{$isyst,$istave};
if ($igap<=$ngaps{$isyst}) { $Y-=$gapheight{$isyst,$igap}; }
last;
}
$istave++;
$Y -= $gapheight{$isyst, $igap};
$igap++;
}
# invert and adjust the barline tops and bottoms
# $Nblines{$isyst}-- unless $YblineBot{$isyst,$ibline};
for ($ibline = 1; $ibline <= $Nblines{$isyst}; $ibline++) {
$YblineTop{$isyst, $ibline} =
$Ystave{$isyst, 1} - $YblineTop{$isyst, $ibline};
$YblineBot{$isyst, $ibline} =
$Ystave{$isyst, 1} - $YblineBot{$isyst, $ibline};
}
# and print the brackets
# should use average (or max) staveheight
for ($i = 1; $i <= $Nblines{$isyst}; $i++) {
printf "%g %g %g %g bracket\n",
$lmargin{$isyst} - $max_staveheight*0.225,
$YblineTop{$isyst,$i}, $YblineBot{$isyst,$i}, $max_staveheight;
}
$Y -= $systemgap;
}
$Isyst = 0;
# $Nsystems = 0 + $nsystems;
}
sub newsystem {
return if $Midi;
if ($XmlOpt) { $Isyst++; $Xml{staves} = 1; return 1;
# could also add <print new-system="yes"/>
# See Mario Lang in ~/Mail/musicxml ...
}
ps_finish_ties(); # first put in any unfinished ties ...
# 20100424 In order to carry beams over barline, we'll need to
# remember a separate @BeamUp etc per stavenum :-(
undef @BeamUp; undef @BeamDown;
$StartBeamUp = 0; $StartBeamDown = 0; # 2.9z
if ($Isyst >= $RememberNsystems-1+$[) {
systems();
# regurgitate remembered header lines (except for title) ...
if ($RememberHeader{'pagenum'}) {
ps_pagenum();
ps_innerhead('');
} else {
ps_lefthead('');
ps_righthead('');
}
ps_leftfoot('');
ps_rightfoot('');
}
$Isyst++; # then move on to next system ...
$JustDidNewsystem = 1; # so if no bars cmd follows, barlines get drawn
print TTY " $Isyst" unless $NoTTY;
print "% system $Isyst\n";
}
sub bars { my $nbars = shift; my $str = shift; # eg. $str='| 4.5 | 2 3 | 4 ||'
return if $Midi;
# prints the barlines, and set the following global variables :
# $BarType{$Isyst,$Ibar}, $spaceatstart{$Ibar}, $nparts{$Isyst,$Ibar},
# $proportion{$Ibar}, $partshare{$Ibar,$ipart}, $nbars{$Isyst} and $Ibar
# BarType bits mean: missing,segno,start-repeat,end-repeat,double
if ($nbars && ! $str) {
$str = '|1|';
$remember_bars_string = $str; # global
$remember_nbars = $nbars; # global
} elsif (!$nbars && !$str && $remember_nbars && $remember_bars_string) {
$str = $remember_bars_string;
$nbars = $remember_nbars;
} else {
$remember_bars_string = $str; # global
$remember_nbars = $nbars; # global
}
# could extract strings for a leftgap from this ...
$str =~ s/^[^|]*\|+\s*//; # throw away stuff up to first barline
# XXX this deletes the first barline as well ?! is this intended?
$str =~ s/\s*$//;
my $last_terminator;
if ($str =~ s/^:\s*//) { $BarType{$Isyst,0}=4; $last_terminator='|:';
} else { $BarType{$Isyst,0} = 0; $last_terminator = '|'
}
my $maxstaveheight = $MaxStaveHeight{$Isyst};
my $ibar = 0; # we use it initially for a local loop...
my %spaceatstart = ();
my $sumofproportions = 0.0; # sum of proportions of all bars in line
my $sumofspaceatstarts = 0.0; # sum of spaceatstarts of all bars in line
my @bars = split /\s*(:?\|\|?:?)\s*/, $str; # 2.7g
if (@bars % 2 && $bars[$#bars] eq q{}) { pop @bars; }
while (1) {
last unless @bars;
my @tokens = split(/\s+/, shift @bars);
my $terminator = shift @bars; $ibar++;
$BarType{$Isyst,$ibar} = 0;
$spaceatstart{$ibar} = $SpaceAtBeginningOfBar*$maxstaveheight; # 2.4c
if (! $terminator) { $BarType{$Isyst,$ibar} = 16; } # 2.7g
if ($terminator =~ /\|\|/) { $BarType{$Isyst,$ibar} |= 1; }
if ($terminator =~ /^:/) { $BarType{$Isyst,$ibar} |= 3; }
if ($terminator =~ /:$/) { $BarType{$Isyst,$ibar} |= 5; }
if ($last_terminator =~ /:$/) {
$spaceatstart{$ibar} += $SpaceForStartRepeat*$maxstaveheight;
}
$last_terminator = $terminator; # ready for next bar
if ($tokens[$[] =~ /Segno/i) { # skip segno ?
$BarType{$Isyst,$ibar-1} |= 8;
shift @tokens;
}
next if $XmlOpt;
if ($tokens[$[] =~ /(\d+)[b#n]/) { # leave space for keysig ?
$spaceatstart{$ibar} +=
$1 * $AccidentalDxInKeysig * $maxstaveheight;
$spaceatstart{$ibar} += $SpaceAfterKeySig * $maxstaveheight;
shift @tokens;
}
if ($tokens[$[] =~ m{\d+/\d+}) { # leave space for timesig ?
my ($topnum, $botnum) = split ('/', $tokens[$[], 2);
if ($topnum>9 or $botnum>9) { # 2.0z
$spaceatstart{$ibar} += $SpaceForFatTimeSig * $maxstaveheight;
} else {
$spaceatstart{$ibar} += $SpaceForTimeSig * $maxstaveheight;
}
shift @tokens;
}
# this will be wrong if one of the tokens is a non-numeric syntax err
$nparts{$Isyst, $ibar} = scalar @tokens; # relative spacing
# tot up the given proportions of the bars ...
my $itoken = $[;
$proportion{$ibar} = 0.0;
my $ipart = 1;
while (1) {
last if $ipart > $nparts{$Isyst,$ibar};
if ($tokens[$itoken] == 0) {
warn_ln("bars: '$tokens[$itoken]' should be numeric and nonzero");
$nparts{$Isyst,$ibar} --;
$itoken++;
}
$partshare{$ibar, $ipart} = $tokens[$itoken];
$proportion{$ibar} += $tokens[$itoken];
$itoken++; $ipart++;
}
$sumofproportions += $proportion{$ibar};
$sumofspaceatstarts += $spaceatstart{$ibar};
}
if ($nbars > $ibar) { # 2.0g ; expand "5 bars | 8 |"
my $ib = $ibar; # Remember the last specified bar
while (1) {
$ibar++;
$BarType{$Isyst,$ibar} = $BarType{$Isyst,$ib};
if (!$XmlOpt) {
$spaceatstart{$ibar} = $spaceatstart{$ib};
$nparts{$Isyst,$ibar} = $nparts{$Isyst,$ib};
my $ipart;
$proportion{$ibar} = 0.0;
for ($ipart=1; $ipart <= $nparts{$Isyst,$ib}; $ipart++) {
$partshare{$ibar,$ipart} = $partshare{$ib,$ipart};
$proportion{$ibar} += $partshare{$ib,$ipart};
}
$sumofproportions += $proportion{$ib};
$sumofspaceatstarts += $spaceatstart{$ibar};
}
last if $ibar >= $nbars;
}
}
$nbars{$Isyst} = $ibar;
if ($XmlOpt) { $Ibar = 0; $Istave = 0; return; }
# 3.1f avoid division by zero
if ($sumofproportions == 0) { $sumofproportions = 1; }
# divide up the line between the bars according to these proportions ...
my $lmargin = $lmargin{$Isyst}+$SpaceForClef*$maxstaveheight;
$xperproportion = ($rmargin{$Isyst}-$lmargin{$Isyst}-$sumofspaceatstarts
- $SpaceForClef*$maxstaveheight) / $sumofproportions;
my $X = $lmargin;
$xbar{$Isyst, 0} = $lmargin{$Isyst}; # YYY bug? why not = $lmargin;
if (8 & $BarType{$Isyst,0}) { # Segno at first bar ?
printf "%g %g %g segno\n", $lmargin,