Debian Codegraph @

utils/m-tx/mtx-src/preamble.pas

raw
1 unit preamble;
2 {$X+}
3 { Interpret preamble paragraph, compose PMX preamble }
4
5 interface uses globals;
6
7 function thisCase: boolean;
8 procedure preambleDefaults;
9 procedure interpretCommands;
10 procedure doPreamble;
11 procedure doPMXpreamble;
12 procedure respace;
13 procedure restyle;
14 function startString(voice: voice_index0): string;
15 procedure augmentPreamble(control_para: boolean);
16 function omitLine(line: paragraph_index): boolean;
17 procedure nonMusic;
18 procedure setOnly(line: string);
19 function isCommand(command: string): boolean;
20
21 const known = true;
22
23 implementation uses control, mtxline, strings, files, status, utility;
24
25 const blank = ' ';
26 colon = ':';
27 semicolon = ';';
28 comma = ',';
29 known_styles: integer = 12;
30 max_styles = 24;
31 warn_redefine: boolean = false;
32
33 type command_type =
34 ( none, title, composer, pmx, tex, options, msize, bars, shortnote,
35 style, sharps, flats, meter, space, pages, systems, width, height,
36 enable, disable, range, name, indent,
37 poet, part, only, octave, start );
38
39 line_type = ( unknown, colon_line, command_line, comment_line,
40 plain_line );
41
42 style_index = 1..max_styles;
43 style_index0 = 0..max_styles;
44
45 const c1 = title; cn = start;
46 commands: array[command_type] of string[16] =
47 ( 'NONE', 'TITLE', 'COMPOSER', 'PMX', 'TEX', 'OPTIONS',
48 'SIZE', 'BARS/LINE', 'SHORT',
49 'STYLE', 'SHARPS', 'FLATS', 'METER', 'SPACE', 'PAGES', 'SYSTEMS', 'WIDTH',
50 'HEIGHT', 'ENABLE', 'DISABLE', 'RANGE',
51 'NAME', 'INDENT', 'POET', 'PART', 'ONLY', 'OCTAVE', 'START');
52 cline: array[command_type] of string =
53 ( '', '', '', '', '', '', '', '', '1/4', (* short *)
54 '', '0', '', 'C', '', '1', '1', (* systems *)
55 '190mm', '260mm', '', '', '', '', '', '', '', '', '', '' );
56 redefined: array[command_type] of boolean =
57 ( false, false, false, false, false, false, false, false, false, false,
58 false, false, false, false, false, false, false, false, false,
59 false, false, false, false, false, false, false, false, false );
60
61 (** Known styles *)
62 known_style: array[style_index] of string = (
63 'SATB: Voices S,A T,B; Choral; Clefs G F',
64 'SATB4: Voices S A T B; Choral; Clefs G G G8 F',
65 'SINGER: Voices Voice; Vocal; Clefs G',
66 'PIANO: Voices RH LH; Continuo; Clefs G F',
67 'ORGAN: Voices RH LH Ped; Continuo; Clefs G F F',
68 'SOLO: Voices V; Clefs G',
69 'DUET: Voices V1 Vc; Clefs G F',
70 'TRIO: Voices V1 Va Vc; Clefs G C F',
71 'QUARTET: Voices V1 V2 Va Vc; Clefs G G C F',
72 'QUINTET: Voices V1 V2 Va Vc1 Vc2; Clefs G G C F F',
73 'SEXTET: Voices V1 V2 Va1 Va2 Vc1 Vc2; Clefs G G C C F F',
74 'SEPTET: Voices V1 V2 Va1 Va2 Vc1 Vc2 Cb; Clefs G G C C F F F',
75 '', '', '', '', '', '', '', '', '', '', '', '');
76
77 var old_known_styles: style_index;
78 style_used: array[style_index] of boolean;
79 omit_line: array[paragraph_index] of boolean;
80 orig_style_line: array[style_index] of style_index0;
81 orig_range_line: integer;
82
83 var nclefs, n_pages, n_systems, n_sharps, ngroups: integer;
84 part_line, title_line, composer_line, pmx_line, options_line,
85 start_line, voices, clefs: string;
86 group_start, group_stop: array[1..maxgroups] of integer;
87 instr_name: array[stave_index] of string[40];
88 style_supplied: boolean;
89
90 { ------------------ Styles ------------------ }
91
92 function voiceCount(s: string): voice_index0;
93 var i, l: integer;
94 begin l:=length(s); for i:=1 to l do if s[i]=comma then s[i]:=blank;
95 voiceCount:=wordCount(s);
96 end;
97
98 function findStyle(s: string): style_index0;
99 var i: style_index0;
100 begin
101 i:=0; s:=s+colon; findStyle:=0;
102 while i<known_styles do
103 begin inc(i);
104 if startsWithIgnoreCase(known_style[i],s) then
105 begin findStyle:=i; exit; end;
106 end;
107 end;
108
109 procedure addStyle (S: string);
110 var sn: style_index0;
111 begin
112 sn:=findStyle(NextWord(S,colon,dummy));
113 if sn>0 then known_style[sn] := S
114 else if known_styles < max_styles then
115 begin inc(known_styles);
116 known_style[known_styles] := S;
117 end
118 else error('Can''t add another style - table full',print);
119 end;
120
121 procedure readStyles;
122 var eofstyle: boolean;
123 S: string;
124 l: style_index0;
125 begin if styleFileFound then eofstyle:=true else eofstyle := eof(stylefile);
126 l:=0;
127 while not eofstyle do
128 begin readln(stylefile,S); if S<>'' then
129 begin addStyle(S); inc(l); orig_style_line[known_styles]:=l; end;
130 eofstyle := eof(stylefile);
131 end;
132 end;
133
134 procedure applyStyle(s, stylename: string;
135 first_inst, first_stave: stave_index);
136 var clef, subline, subcommand: string;
137 i, last_inst, last_stave: stave_index0;
138 continuo, toosoon, vocal: boolean;
139 begin last_inst:=first_inst-1;
140 toosoon := false; continuo:=false; vocal := false;
141 subline:=GetNextWord(s,blank,colon);
142 while s<>'' do
143 begin subline:=GetNextWord(s,semicolon,dummy);
144 i:=curtail(subline,semicolon);
145 subcommand:=GetNextWord(subline,blank,dummy);
146 if equalsIgnoreCase(subcommand,'VOICES') then
147 begin voices:=voices+' '+subline;
148 last_stave := first_stave + wordCount(subline) - 1;
149 last_inst := first_inst + voiceCount(subline) - 1;
150 end
151 else if equalsIgnoreCase(subcommand,'CLEFS')
152 then
153 begin clef:=subline; clefs:=clefs+' '+clef; end
154 else if equalsIgnoreCase(subcommand,'VOCAL') then
155 if last_inst<first_inst then toosoon:=true
156 else begin some_vocal := true; vocal := true;
157 for i:=first_inst to last_inst do setVocal(i,true);
158 end
159 else if equalsIgnoreCase(subcommand,'CHORAL') or
160 equalsIgnoreCase(subcommand,'GROUP') then
161 if last_inst<first_inst then toosoon:=true
162 else begin
163 if equalsIgnoreCase(subcommand,'CHORAL') then
164 begin some_vocal := true; vocal := true;
165 for i:=first_inst to last_inst do setVocal(i,true);
166 end;
167 if ngroups=maxgroups then error('Too many groups',print)
168 else begin inc(ngroups);
169 group_start[ngroups] := first_stave;
170 group_stop[ngroups] := last_stave;
171 end
172 end
173 else if equalsIgnoreCase(subcommand,'CONTINUO') then continuo := true
174 else error('Subcommand ' + subcommand + ' in STYLE unknown',print);
175 if toosoon then
176 error('You must first give VOICES before specifying ' + subcommand,
177 print);
178 end;
179 if vocal and continuo then error(
180 'A continuo instrument may not be vocal',print);
181 if wordCount(clef)<>last_stave-first_stave+1 then error(
182 'Number of clefs does not match number of voices',print);
183 if (first_stave=last_stave) or continuo
184 then instr_name[first_stave]:=stylename
185 else for i:=first_stave to last_stave do instr_name[i]:='';
186 if continuo then
187 begin inc(ninstr); stave[ninstr] := first_stave;
188 for i:=first_stave to last_stave do instr[i]:=ninstr;
189 end
190 else for i:=first_stave to last_stave do
191 begin inc(ninstr); stave[ninstr] := i; instr[i] := ninstr;
192 end;
193 end;
194
195 procedure applyStyles;
196 var n1, n2, sn: integer;
197 s: string;
198 begin voices:=''; clefs:=''; ninstr:=0;
199 while cline[style]<>'' do
200 begin n1:=voiceCount(voices)+1;
201 n2:=wordCount(voices)+1;
202 s:=GetNextWord(cline[style],blank,comma);
203 curtail(s,comma);
204 sn:=findStyle(s); if sn=0 then error ('Style ' + s +' unknown',print);
205 line_no := orig_style_line[sn]; applyStyle(known_style[sn],s,n1,n2);
206 style_used[sn] := true;
207 end;
208 end;
209
210 { ------------------------------------------------------------- }
211
212 procedure wipeCommands;
213 var c: command_type;
214 begin for c:=c1 to cn do cline[c]:='';
215 end;
216
217 function omitLine(line: paragraph_index): boolean;
218 begin omitLine := (line>0) and omit_line[line]
219 end;
220
221 procedure setName;
222 var i: integer;
223 begin if not redefined[name] then exit;
224 setFeature('instrumentNames',true);
225 for i:=1 to ninstr do
226 instr_name[i] := getNextWord(cline[name],blank,dummy);
227 end;
228
229 procedure setIndent;
230 begin if redefined[indent] then fracindent := cline[indent];
231 end;
232
233 procedure setInitOctave;
234 begin if redefined[octave] then initOctaves(cline[octave]);
235 end;
236
237 procedure setVoices(var line: string);
238 var k: integer;
239 s, w: string;
240 procedure checkLabel(w: string);
241 var j: voice_index;
242 begin
243 for j:=1 to nvoices do if w=voice_label[j] then
244 begin warning('Voice label '+w+' not unique',print); exit;
245 end;
246 if length(w)>2 then exit;
247 if pos1(w[1],'CLU')>0 then
248 if length(w)>1 then if pos1(w[2],'123456789')=0 then exit
249 else
250 else
251 else if pos1(w[1],'123456789')=0 then exit;
252 error('Voice label '+w+' conflicts with reserved label',print);
253 end;
254 begin nvoices:=0; nstaves:=0;
255 repeat s:=GetNextWord(line,blank,dummy);
256 if length(s)>0 then
257 begin inc(nstaves); k:=0;
258 first_on_stave[nstaves] := nvoices + 1;
259 repeat
260 w:=GetNextWord(s,blank,comma); curtail(w, comma);
261 if w<>'' then
262 begin
263 inc(k); if k<=2 then
264 begin inc(nvoices); checkLabel(w);
265 voice_label[nvoices]:=w;
266 if instr_name[nstaves]='' then instr_name[nstaves]:=w;
267 setStavePos(nvoices,nstaves,k);
268 end
269 end;
270 until w='';
271 if k>2 then error('More than two voices per stave: ' + s,print);
272 if k=2 then instr_name[nstaves]:='\mtxTwoInstruments{'
273 + voice_label[nvoices-1] + '}{'+ voice_label[nvoices] + '}';
274 number_on_stave[nstaves] := k;
275 end
276 until length(line)=0;
277 for k:=1 to nvoices do selected[k]:=true;
278 end;
279
280 procedure setClefs(line: string);
281 var s: string;
282 begin
283 nclefs:=0;
284 repeat
285 s:=getnextword(line,blank,dummy);
286 if s<>'' then
287 begin inc(nclefs);
288 if length(s)=1 then clef[nclefs]:=s[1] else clef[nclefs]:=s[2];
289 end;
290 until s='';
291 end;
292
293 procedure setDimension(line: string; lno: command_type);
294 var l, n, p: integer;
295 begin
296 if line = '' then exit;
297 l := length(line);
298 n := 0;
299 p := 0;
300 repeat n := n+1;
301 if line[n]='.' then p:=p+1;
302 until (n>l) or not ((line[n]='.') or (line[n]>='0') and (line[n]<='9'));
303 if (n=p) or (p>1) or
304 not ((line[n]='i') or (line[n]='m') or (line[n]='p')) then
305 error('Dimension must be a number followed by in, mm or pt',print);
306 cline[lno] := 'w' + substr(line,1,n);
307 end;
308
309 procedure setSize(line: string);
310 var i: stave_index0;
311 word: string;
312 begin i:=0;
313 while i<ninstr do
314 begin word:=GetNextWord(line,blank,dummy);
315 if word='' then break;
316 inc(i); getNum(word,musicsize);
317 stave_size[i] := musicsize;
318 end;
319 if not (musicsize in [16,20]) then
320 for i:=1 to ninstr do
321 if stave_size[i] = unspec then stave_size[i] := musicsize;
322 if musicsize<16 then musicsize:=16
323 else if musicsize>20 then musicsize:=20;
324 end;
325
326 function findCommand(var command: string): command_type;
327 var j: command_type;
328 begin curtail(command,':');
329 if equalsIgnoreCase(command,'STYLE') then style_supplied := true;
330 for j:=c1 to cn do if equalsIgnoreCase(command,commands[j]) then
331 begin findCommand:=j; exit; end;
332 findCommand:=none;
333 end;
334
335 function isCommand(command: string): boolean;
336 begin isCommand:=findCommand(command)<>none end;
337
338 function mustAppend(command: command_type): boolean;
339 begin mustAppend := command=tex end;
340
341 procedure doEnable(var line: string; choice: boolean);
342 var word: string;
343 begin
344 repeat word:=GetNextWord(line,blank,dummy);
345 if word<>'' then if not setFeature(word,choice) then
346 Error('No such feature: '+word,not print)
347 until word=''
348 end;
349
350 procedure setRange(line: string);
351 var v,p: integer;
352 vl: string;
353 begin
354 line_no := orig_range_line;
355 for v:=1 to nvoices do
356 begin vl := voice_label[v];
357 p:=pos(vl+'=',line);
358 if p>0 then
359 begin
360 if length(line)<p+6 then
361 error('At least five characters must follow "'+vl+'="',
362 print);
363 defineRange(v,substr(line,p+1+length(vl),5));
364 end
365 else begin
366 warning('No range defined for voice '+vl,print);
367 defineRange(v,'');
368 end
369 end;
370 end;
371
372 { TODO: This procedure should test for assertions in a comment
373 or be removed }
374 function isAssertion(var line: string): boolean;
375 begin
376 isAssertion := false
377 end;
378
379 function doCommand(line: string): line_type;
380 var command: string;
381 last_command: command_type;
382 starts_with_note: boolean;
383 begin
384 if (line[1]=comment) and not isAssertion(line) then
385 begin doCommand:=comment_line; exit; end;
386 starts_with_note := maybeMusicLine(line);
387 command:=GetNextWord(line,blank,colon);
388 if endsWith(command,colon) then
389 begin last_command:=findCommand(command);
390 doCommand:=command_line;
391 if last_command = enable then doEnable(line,true)
392 else if last_command = disable then doEnable(line,false)
393 else if last_command = range then orig_range_line := line_no;
394 if last_command<>none then
395 begin
396 if mustAppend(last_command) and redefined[last_command] then
397 begin
398 if length(cline[last_command])+length(line)>254 then
399 error('Total length of preamble command '+commands[last_command]+
400 ' must not exceed 255',not print);
401 cline[last_command]:=cline[last_command]+#10+line
402 end
403 else
404 begin cline[last_command]:=line;
405 if warn_redefine and redefined[last_command] then
406 warning('You have redefined preamble command '+command,print);
407 end;
408 if last_command=start then start_line:=line;
409 redefined[last_command]:=true;
410 end
411 else begin doCommand:=colon_line; addStyle(command+colon+' '+line);
412 orig_style_line[known_styles] := line_no;
413 end
414 end
415 else if starts_with_note then doCommand:=plain_line
416 else doCommand:=unknown;
417 end;
418
419 procedure setOnly(line: string);
420 var num, num1, num2, l: integer;
421 s: string;
422 begin if line='' then exit;
423 if startsWithIgnoreCase(line,'only') then GetNextWord(line,colon,dummy);
424 for l:=1 to lines_in_paragraph do omit_line[l]:=true;
425 repeat s:=GetNextWord(line,blank,comma); if s='' then exit;
426 curtail(s, comma);
427 if pos1('-',s)=0 then
428 begin getNum(s,num);
429 if (num>0) and (num<=lines_in_paragraph) then omit_line[num]:=false
430 else warning('Invalid line number in Only: is skipped',print);
431 end else
432 begin getTwoNums(s,num1,num2);
433 if (num1>0) and (num2<=lines_in_paragraph) then
434 for num:=num1 to num2 do omit_line[num]:=false
435 else warning('Invalid line range in Only: is skipped',print);
436 end;
437 until false;
438 end;
439
440 procedure interpretCommands;
441 var i, num, den, nbars: integer;
442 begin
443 title_line := cline[title];
444 part_line := cline[part];
445 if (cline[poet]<>'') or (cline[composer]<>'') then
446 composer_line:='\mtxComposerLine{'+cline[poet]+'}{'+cline[composer]+'}'
447 else composer_line:='';
448 pmx_line := cline[pmx];
449 options_line := GetNextWord(cline[options],blank,dummy);
450 for i:=1 to known_styles do style_used[i] := false;
451 applyStyles; setVoices(voices);
452 for i:=old_known_styles+1 to known_styles do
453 if not style_used[i] then
454 begin warning('The following style was supplied but not used',not print);
455 writeln(known_style[i]);
456 end;
457 setClefs(clefs);
458 if not redefined[meter] then warning(
459 'You have not defined Meter, assuming "'+cline[meter]+'" ',not print);
460 getMeter(cline[meter],meternum, meterdenom, pmnum, pmdenom);
461 setDefaultDuration(meterdenom);
462 if (meternum=0) and
463 not (redefined[pages] or redefined[systems] or redefined[bars])
464 then begin cline[bars] := '1'; redefined[bars]:=true; end;
465 if redefined[pages] or redefined[systems] then
466 begin if redefined[bars] then
467 warning('BARS/LINE ignored since you specified PAGES or SYSTEMS',print);
468 if redefined[systems] then getNum(cline[systems],n_systems)
469 else warning('PAGES specified but not SYSTEMS',not print);
470 if redefined[pages] then getNum(cline[pages],n_pages)
471 else warning('SYSTEMS specified but not PAGES',not print);
472 end
473 else if redefined[bars] then
474 begin getNum(cline[bars],nbars); if nbars>0 then
475 begin n_pages:=0; n_systems:=nbars end;
476 end;
477 getNum(cline[sharps],n_sharps);
478 setSpace(cline[space]);
479 setSize(cline[msize]);
480 getTwoNums(cline[shortnote],num, den); if den=0 then den:=1;
481 short_note := (num*64) div den;
482 if cline[flats]<>'' then
483 begin getNum(cline[flats],n_sharps); n_sharps:=-n_sharps; end;
484 setName; setIndent; setInitOctave; setOnly(cline[only]);
485 setRange(cline[range]);
486 setDimension(cline[width],width);
487 setDimension(cline[height],height);
488 if options_line <>'' then begin
489 warning('"Options" is cryptic and obsolescent.', not print);
490 writeln(' Use "Enable" and "Disable" instead.')
491 end;
492 for i:=1 to length(options_line) do processOption(options_line[i]);
493 end;
494
495 procedure preambleDefaults;
496 var i: integer;
497 begin
498 xmtrnum0:=0; fracindent:='0'; musicsize:=20; start_line:='';
499 some_vocal:=false; ngroups:=0;
500 style_supplied := false;
501 for i:=1 to maxvoices do setVocal(i,false);
502 for i:=1 to maxstaves do stave_size[i]:=unspec;
503 for i:=0 to maxstaves do nspace[i]:=unspec;
504 { next line seems to be spurious. 0.63a RDT }
505 { begin nspace[i]:=unspec; stave_size[i]:=unspec; end; }
506 n_pages:=1; n_systems:=1;
507 readStyles; old_known_styles := known_styles;
508 for i:=1 to lines_in_paragraph do omit_line[i]:=false;
509 end;
510
511 procedure preambleGuess(maybe_voices: voice_index);
512 begin
513 case maybe_voices of
514 1: cline[style] := 'Solo';
515 2: cline[style] := 'Duet';
516 3: cline[style] := 'Trio';
517 4: cline[style] := 'Quartet';
518 5: cline[style] := 'Quintet';
519 6: cline[style] := 'Sextet';
520 7: cline[style] := 'Septet';
521 else begin error('I cannot guess a style',not print); exit; end;
522 end;
523 writeln('I guess this piece is a ',cline[style],
524 ' for strings in C major.');
525 writeln(' Why not provide a STYLE in the setup paragraph to make sure?');
526 end;
527
528 { ------------------------------------------------------------------ }
529
530 procedure nonMusic;
531 var i: paragraph_index;
532 begin for i:=1 to para_len do doCommand(P[i]);
533 setOnly(cline[only]); wipeCommands;
534 end;
535
536 function thisCase: boolean;
537 begin thisCase:=true;
538 if not startsWithIgnoreCase(P[1],'case:') then exit;
539 thisCase:=(choice<>' ') and (pos1(choice,P[1])>0); P[1]:='%';
540 end;
541
542 procedure augmentPreamble(control_para: boolean);
543 var i: paragraph_index;
544 l: line_type;
545 s: array[line_type] of integer;
546 begin
547 if not thisCase then exit;
548 for l:=unknown to plain_line do s[l]:=0;
549 for i:=1 to para_len do
550 begin line_no:=orig_line_no[i]; l:=doCommand(P[i]);
551 inc(s[l]);
552 if (l=comment_line) and (P[i,2]=comment)
553 then begin predelete(P[i],2); putLine(P[i]); end;
554 if not control_para and (l=unknown) then
555 error('Unidentifiable line',print);
556 end;
557 if not control_para and (s[command_line]>0) and (s[plain_line]>0)
558 then error('Mixture of preamble commands and music',not print);
559 end;
560
561 procedure doPreamble;
562 var i: paragraph_index;
563 maybe_voices: voice_index0;
564 begin maybe_voices:=0;
565 if not style_supplied then
566 begin {augmentPreamble(not known);}
567 if not style_supplied then warning('No STYLE supplied',not print);
568 for i:=1 to para_len do if maybeMusicLine(P[i]) then
569 inc(maybe_voices);
570 if maybe_voices>0 then preambleGuess(maybe_voices)
571 else error('No voices found',not print);
572 end
573 end;
574
575 procedure respace;
576 var i, j: stave_index;
577 begin
578 for i:=ninstr downto 2 do
579 begin j:=ninstr-i+1;
580 if nspace[j]<>unspec then TeXtype2('\mtxInterInstrument{'+toString(i-1)+
581 '}{'+toString(nspace[j])+'}');
582 end;
583 if nspace[ninstr]<>unspec then TeXtype2('\mtxStaffBottom{'+
584 toString(nspace[ninstr])+'}');
585 must_respace:=false;
586 end;
587
588 procedure restyle;
589 begin
590 must_restyle:=false;
591 end;
592
593 function clefno ( cl: char ): integer;
594 begin
595 case cl of
596 'G','0','t','8': clefno:=0;
597 's','1': clefno:=1;
598 'm','2': clefno:=2;
599 'a','3': clefno:=3;
600 'n','4': clefno:=4;
601 'r','5': clefno:=5;
602 'F','b','6': clefno:=6;
603 'C': clefno:=3;
604 else
605 begin warning('Unknown clef code "' + cl + '" - replaced by treble',print);
606 clefno:=0;
607 end;
608 end
609 end;
610
611 procedure doTenorClefs;
612 var i: voice_index;
613 c: char;
614 begin for i:=1 to nclefs do
615 begin
616 c:=clef[i]; if (c='8') or (c='t') then
617 putLine('\\mtxTenorClef{' + toString(PMXinstr(i)) + '}\' );
618 end;
619 end;
620
621 procedure insertTeX;
622 begin
623 if redefined[tex] then TeXtype2(cline[tex]);
624 end;
625
626 procedure doPMXpreamble;
627 const clefcode: string[8]='0123456';
628 var i, j: integer;
629 clefs: string;
630 function pmxMeter: string;
631 var denom, num: integer;
632 begin if meternum=0 then
633 begin num := beatsPerLine; {* denom := 0; *}
634 old_meter_word := meterChange(num,meterdenom,true);
635 end
636 else begin num := meternum; {* denom := pmdenom; *} end;
637 { CMO: unconditonally assign value of pmdenom to denom }
638 denom := pmdenom;
639 pmxMeter := toString(num) + ' ' + toString(PMXmeterdenom(meterdenom)) +
640 ' ' + toString(pmnum) + ' ' + toString(denom);
641 end;
642 function sizecode(k: integer): string;
643 begin sizecode:='\mtxNormalSize';
644 case k of
645 13: if musicsize=20 then sizecode:='\mtxTinySize' else sizecode:='\mtxSmallSize';
646 16: if musicsize=20 then sizecode:='\mtxSmallSize';
647 20: if musicsize=16 then sizecode:='\mtxLargeSize';
648 24: if musicsize=20 then sizecode:='\mtxLargeSize' else sizecode:='\mtxHugeSize';
649 29: sizecode:='\mtxHugeSize';
650 else error('Valid sizes are 13, 16, 20, 24, 29',print);
651 end;
652 end;
653 begin
654 if composer_line <> '' then putline(composer_line);
655 if title_line <> '' then putline('\mtxTitleLine{'+title_line+'}');
656 putLine('---');
657 if instrumentNames and not redefined[indent] then fracindent:='0.12';
658 write(outfile, nstaves);
659 write(outfile, ' ', -ninstr);
660 stave[ninstr+1]:=nstaves+1;
661 for j:=ninstr downto 1 do write(outfile, ' ', stave[j+1] - stave[j]);
662 writeln(outfile, ' ', pmxMeter, ' ',xmtrnum0:8:5, ' ',n_sharps,
663 ' ', n_pages, ' ',n_systems, ' ',musicsize, ' ',fracindent);
664 for i:=1 to ninstr do if not instrumentNames then putLine('')
665 else putLine('\mtxInstrName{'+instr_name[ninstr+1-i]+'}');
666 clefs:='';
667 for i:=nclefs downto 1 do clefs:=clefs+clefcode[1+clefno(clef[i])];
668 putLine(clefs);
669 if texdir='' then texdir := './';
670 putLine(texdir);
671
672 pmx_preamble_done:=true; insertTeX; respace;
673
674 for j:=1 to ngroups do
675 writeln(outfile,'\\mtxGroup{'+toString(j)+'}{'
676 +toString(ninstr+1-group_start[j])+'}{'
677 +toString(ninstr+1-group_stop[j])+'}\');
678 for j:=1 to ninstr do
679 if (stave_size[j]<>unspec) then
680 putLine(
681 '\\mtxSetSize{'+toString(ninstr+1-j)+'}{'+sizecode(stave_size[j])+'}\');
682 if part_line <> '' then
683 begin putLine('Ti'); putLine(part_line); end;
684 if composer_line <> '' then
685 begin putLine('Tc'); putLine('\mtxPoetComposer'); end;
686 if title_line <> '' then
687 begin write(outfile,'Tt');
688 if nspace[0] <> unspec then write(outfile,toString(nspace[0]));
689 writeln(outfile);
690 putLine('\mtxTitle');
691 end;
692 if pmx_line <> '' then putLine(pmx_line);
693 doTenorClefs;
694 if cline[width] <> '' then putLine(cline[width]);
695 wipeCommands;
696 end;
697
698 function startString(voice: voice_index0): string;
699 var s, w: string;
700 j: voice_index;
701 begin s:=start_line;
702 for j:=1 to voice do w:=getNextWord(s,dummy,';');
703 curtail(w,';'); if w<>'' then startString:=w+' ' else startString:=w;
704 end;
705
706 end.