1
/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */
2
/* From input file "lyrics.pas" */
41
/* Symbols used in strings of melismatype */
43
#define beam_melisma '['
44
#define inhibit_beam_melisma '<'
45
#define slur_melisma '('
46
#define inhibit_slur_melisma '{'
49
typedef char other_index;
51
typedef char other_index0;
53
typedef Char melismatype[256];
68
typedef struct lyrinfotype {
69
short lyr_adjust, slur_level, slur_change, beam_level, beam_change;
75
none_given, global_lyrics, local_lyrics
78
typedef struct lyrtagtype {
79
lyrlinetype lyrsource;
80
haslyrtype has_lyrics;
82
assigntype new_assign;
90
#define lyrtaglength 40
93
#define lyr_adjust_undef (-12345)
97
Static short LyrNum = 0;
99
Static boolean lyrmodealter[maxstaves], oldlyrmodealter[maxstaves];
100
Static lyrtagtype tag[maxvoices], oldtag[maxvoices];
101
Static lyrinfotype lyrinfo[maxvoices];
102
Static Char numberedParagraph[maxLyrNums][lyrtaglength + 1];
105
/* Information flow for verse numbers: at the SetLyrics stage, the first
106
line of each lyrics paragraph is checked for a verse number, and if
107
found, the paragraph tag is remembered. At the AssignLyrics stage,
108
the first time that paragraph is encountered, the particular voice
109
is marked in lyrinfo as being numbered. When that voice is later processed,
110
the mark in lyrinfo is interrogated and turned off: if it was on, the
111
mtxVerse pre-TeX string is put into the output. */
113
boolean hasVerseNumber(voice)
118
Result = lyrinfo[voice-1].numbered;
119
lyrinfo[voice-1].numbered = false;
124
Static boolean isNumberedLyricsParagraph(tag)
130
for (i = 0; i <= FORLIM - 1; i++) {
131
if (!strcmp(tag, numberedParagraph[i]))
138
Static boolean anyTagNumbered(tags_)
146
/* p2c: lyrics.pas: Note: Eliminated unused assignment statement [338] */
147
if (curtail(tags, '}') > 0)
150
GetNextWord(s, tags, ',', dummy);
153
if (isNumberedLyricsParagraph(s))
160
/* Save the tag in the numberedParagraph list, stripping off braces if any */
161
Static Void markNumbered(tag_)
167
if (LyrNum >= maxLyrNums) {
168
error("Too many numbered lines in the lyrics", !print);
172
if (curtail(tag, '}') > 0)
174
strcpy(numberedParagraph[LyrNum-1], tag);
175
/* p2c: lyrics.pas, line 104:
176
* Note: Possible string truncation in assignment [145] */
180
/* --- end of procedures to keep track of verse numbering --- */
182
Void lyricsParagraph()
184
Char first[256], w[256];
185
paragraph_index0 l, line;
187
other_index0 nother = 0;
188
Char other_[10][lyrtaglength + 1];
190
Char STR1[256], STR3[256];
191
paragraph_index0 FORLIM;
197
NextWord(w, P[0], blank, dummy);
199
line_no = orig_line_no[0];
202
GetNextWord(first, w, dummy, '}');
207
sprintf(w, "{%s", strcpy(STR1, w));
209
GetNextWord(other_[nother-1], w, dummy, '}');
210
/* p2c: lyrics.pas, line 122:
211
* Note: Possible string truncation in assignment [145] */
214
printf("---- Paragraph %d starting at line %d has lyrics headed %s",
215
paragraph_no, line_no, first);
216
for (i = 0; i <= nother - 1; i++)
217
printf("=%s", other_[i]);
220
sprintf(STR5, "%c Paragraph %s line %s bar %s",
221
comment, toString(STR1, paragraph_no), toString(STR3, line_no),
222
toString(STR4, bar_no));
224
sprintf(STR3, "\\mtxSetLyrics%s{%%", first);
227
for (line = 2; line <= FORLIM; line++) {
228
lyrTranslate(P[line-1], &numbered);
231
warning("Verse number not in first line of paragraph treated as lyrics",
235
for (i = 0; i <= nother - 1; i++)
236
markNumbered(other_[i]);
239
line_no = orig_line_no[line-1];
240
if (strlen(P[line-1]) > max_lyrics_line_length && pmx_preamble_done)
241
error("Lyrics line too long", print);
242
if (pmx_preamble_done) {
244
sprintf(STR3, "\\\\\\:%s", P[line-1]);
247
sprintf(STR3, "\\\\\\ %s", P[line-1]);
251
put(P[line-1], putspace);
252
if (line < para_len) {
253
if (pmx_preamble_done)
257
} else if (pmx_preamble_done)
262
for (i = 0; i <= nother - 1; i++) {
263
sprintf(STR1, "\\mtxCopyLyrics%s%s", first, other_[i]);
269
Static Char *songraise(Result, voice)
276
Char STR1[256], STR3[256];
278
WITH = &tag[voice-1];
279
WITH1 = &lyrinfo[voice-1];
280
if (WITH->initialized == virgin && WITH1->lyr_adjust == 0)
281
return strcpy(Result, "");
283
if (WITH->auxiliary == aux)
287
sprintf(Result, "\\mtx%sLyricsAdjust{%s}{%s}",
288
s, toString(STR1, PMXinstr(voiceStave(voice))),
289
toString(STR3, WITH1->lyr_adjust));
295
Char *lyricsReport(Result, voice)
302
WITH = &tag[voice-1];
303
if (WITH->has_lyrics == nolyr ||
304
WITH->lyrsource == none_given && *WITH->tags == '\0')
305
return strcpy(Result, " but has no own lyrics");
308
if (WITH->auxiliary == aux)
309
strcat(l, "auxiliary ");
310
strcat(l, "lyrics ");
311
if (WITH->lyrsource == local_lyrics)
312
strcat(l, "locally defined as \"");
314
strcat(l, "labelled \"");
315
sprintf(l + strlen(l), "%s\"", WITH->tags);
316
if (anyTagNumbered(WITH->tags))
317
strcat(l, " with verse numbers");
318
return strcpy(Result, l);
325
/* at the start only */
327
voice_index voice, FORLIM;
333
for (voice = 0; voice <= FORLIM - 1; voice++) {
334
WITH = &lyrinfo[voice];
336
WITH1->has_lyrics = nolyr;
337
WITH->lyr_adjust = lyr_adjust_undef;
338
*WITH->melisma = '\0';
339
WITH->slur_level = 0;
340
WITH->beam_level = 0;
341
WITH1->auxiliary = aux;
342
WITH1->lyrsource = none_given;
343
WITH1->new_assign = asbefore;
344
WITH1->initialized = virgin;
347
for (stave = 0; stave <= FORLIM1 - 1; stave++)
348
oldlyrmodealter[stave] = false;
352
Static Void registerLyrics(voice, w)
358
WITH = &tag[voice-1];
359
strcpy(oldtag[voice-1].tags, WITH->tags);
360
oldtag[voice-1].lyrsource = WITH->lyrsource;
361
WITH->lyrsource = global_lyrics;
369
fatalerror("M-Tx system error in registerLyrics");
373
strcpy(WITH->tags, w);
379
Void extractLyrtag(voice, note)
383
/* inline lyrics change */
385
Char STR1[256], STR2[256];
387
WITH = &tag[voice-1];
388
if (WITH->has_lyrics == nolyr) {
389
error3(voice, "Inline lyrics change on no-lyrics line");
392
registerLyrics(voice, note); /* was: ''); */
393
sprintf(note, "\\mtxAssignLyrics{%s}%s",
394
toString(STR1, PMXinstr(voiceStave(voice))), strcpy(STR2, note));
395
if (WITH->auxiliary == aux)
396
sprintf(note, "\\mtxAuxLyr{%s}\\", strcpy(STR2, note));
404
/* at start of paragraph analyis */
405
voice_index voice, FORLIM;
408
memcpy(oldtag, tag, maxvoices * sizeof(lyrtagtype));
410
for (voice = 0; voice <= FORLIM - 1; voice++) {
412
WITH->lyrsource = none_given;
419
#define maxlyrlen (PMXlinelength - 15)
422
Local Void convertlyrics(lyn, voice, mx)
427
static Char setlyr[256] = "%%\\\\\\mtxSetLyrics";
428
Char btag[256], thistag[256], w[256];
434
NextWord(w, lyn, blank, dummy);
435
WITH = &tag[voice-1];
440
WITH->has_lyrics = haslyr;
441
WITH->auxiliary = mx;
443
registerLyrics(voice, w);
446
WITH->lyrsource = local_lyrics;
448
toString(thistag, voice * 10 + WITH->linecount);
449
sprintf(btag, "{%s}", thistag);
450
if (*WITH->tags == '\0')
451
strcpy(WITH->tags, btag);
453
WITH->tags[strlen(WITH->tags) - 1] = ',';
454
sprintf(WITH->tags + strlen(WITH->tags), "%s}", thistag);
457
lyrTranslate(lyn, &numbered);
459
markNumbered(thistag);
460
if (strlen(lyn) + strlen(btag) > maxlyrlen)
461
sprintf(lyn, "%s%s{\\\n\\\\\\:%s}\\", setlyr, btag, strcpy(STR2, lyn));
463
sprintf(lyn, "%s%s{%s}\\", setlyr, btag, strcpy(STR1, lyn));
469
Void maybeLyrics(voice, parline, w_)
471
paragraph_index parline;
474
/* during paragraph analysis, parline had L:, already stripped */
478
/** Labelled lyrics line -- */
482
if (strlen(w) == 1 && voice == 0)
483
warning("Lyrics line above top voice should be labelled", print);
484
if (strlen(w) == 1) { /** Standard lyrics line -------- */
488
convertlyrics(P[parline-1], k, normal);
494
error("Lyrics line belongs to unknown voice", print);
496
convertlyrics(P[parline-1], k, aux);
502
/* after paragraph analysis */
510
for (voice = 0; voice <= FORLIM - 1; voice++) {
512
if (oldtag[voice].lyrsource == global_lyrics &&
513
WITH->lyrsource == none_given) {
514
strcpy(WITH->tags, oldtag[voice].tags);
515
WITH->lyrsource = global_lyrics;
517
WITH->new_assign = (assigntype)(WITH->has_lyrics == haslyr &&
518
strcmp(WITH->tags, oldtag[voice].tags));
519
if (*WITH->tags == '\0')
520
WITH->has_lyrics = nolyr;
521
strcpy(oldtag[voice].tags, WITH->tags);
522
oldtag[voice].lyrsource = WITH->lyrsource;
525
for (stave = 1; stave <= FORLIM1; stave++) {
526
WITH = &tag[first_on_stave[stave-1] - 1];
527
lyrmodealter[stave-1] = (!aloneOnStave(stave) &&
528
WITH->has_lyrics == haslyr &&
529
WITH->auxiliary == normal);
534
Void assignLyrics(stave, lyrassign)
538
/* at start of new block */
539
Char atag[256], instr[256], l[256];
540
voice_index v1, v2, voice;
546
toString(instr, PMXinstr(stave));
547
v1 = first_on_stave[stave-1];
548
v2 = v1 + number_on_stave[stave-1] - 1;
549
/* don't reassign if other voice takes over */
550
if (tag[v1-1].auxiliary == tag[v2-1].auxiliary &&
551
tag[v1-1].has_lyrics != tag[v2-1].has_lyrics) {
552
for (voice = v1 - 1; voice <= v2 - 1; voice++) {
554
if (WITH->new_assign == newassign)
555
WITH->new_assign = (assigntype)WITH->has_lyrics;
558
for (voice = v1 - 1; voice <= v2 - 1; voice++)
559
lyrinfo[voice].numbered = false;
560
for (voice = v1; voice <= v2; voice++) {
561
WITH = &tag[voice-1];
562
if (WITH->new_assign == newassign) {
563
strcpy(atag, WITH->tags);
566
sprintf(l, "\\mtxAssignLyrics{%s}%s", instr, atag);
567
if (WITH->auxiliary == aux)
568
sprintf(l, "\\mtxAuxLyr{%s}", strcpy(STR2, l));
569
strcat(lyrassign, l);
570
if (*WITH->tags == '\0')
571
WITH->has_lyrics = nolyr;
572
if (WITH->has_lyrics == haslyr && WITH->initialized == virgin) {
573
WITH1 = &lyrinfo[voice-1];
574
if (WITH->auxiliary == aux && upper(voice))
575
WITH1->lyr_adjust = interstave;
577
WITH1->lyr_adjust = 0;
578
strcat(lyrassign, songraise(STR2, voice));
579
WITH->initialized = active;
581
if (anyTagNumbered(atag))
582
lyrinfo[voice-1].numbered = true;
585
if (lyrmodealter[stave-1] == oldlyrmodealter[stave-1])
587
if (lyrmodealter[stave-1])
588
sprintf(lyrassign + strlen(lyrassign), "\\mtxLyrModeAlter{%s}", instr);
590
sprintf(lyrassign + strlen(lyrassign), "\\mtxLyrModeNormal{%s}", instr);
591
oldlyrmodealter[stave-1] = lyrmodealter[stave-1];
595
Void lyricsAdjust(voice, note)
601
boolean force, put_above, put_below;
606
WITH = &lyrinfo[voice-1];
607
WITH1 = &tag[voice-1];
609
force = (note[0] == '=');
612
put_above = (note[0] == '^');
615
put_below = (note[0] == 'v');
622
if (WITH1->has_lyrics == nolyr) {
627
WITH->lyr_adjust = interstave;
629
WITH->lyr_adjust = 0;
631
WITH->lyr_adjust = adj;
633
WITH->lyr_adjust += adj;
634
songraise(note, voice);
636
sprintf(note, "\\\\%s\\", strcpy(STR2, note));
640
Void lyrTranslate(P, numbered)
643
{ /* Test for starting number */
647
NextWord(w, P, blank, dummy);
649
if (endsWith(w, ".")) {
651
*numbered = (number != 0);
653
/*Translate lyrics link */
656
for (k = 1; k <= l - 1; k++) {
657
if (P[k-1] != '_' || P[k] == '_' || P[k] == ' ' || pos1(P[k], digits) > 0)
658
sprintf(Q + strlen(Q), "%c", P[k-1]);
659
else if (k > 1 && P[k-2] == '\\')
660
strcat(Q, "mtxLowLyrlink ");
662
strcat(Q, "\\mtxLyrlink ");
664
sprintf(Q + strlen(Q), "%c", P[l-1]);
674
Static Char removeLast(s, t)
682
for (i = l; i >= 1; i--) {
683
if (pos1(s[i-1], t) > 0) {
693
Static boolean OpenMelisma(s)
696
return (pos1(slur_melisma, s) > 0 || pos1(beam_melisma, s) > 0);
700
/* Local variables for getSyllable: */
701
struct LOC_getSyllable {
706
Local Void startMelismas(t, LINK)
708
struct LOC_getSyllable *LINK;
710
boolean open_before, open_now;
715
for (i = 0; i <= k - 1; i++) {
716
WITH = &lyrinfo[LINK->voice-1];
717
open_before = OpenMelisma(WITH->melisma);
718
sprintf(WITH->melisma + strlen(WITH->melisma), "%c", t[i]);
719
open_now = OpenMelisma(WITH->melisma);
720
LINK->BM = (LINK->BM || open_now && !open_before);
724
Local boolean endMelisma(voice, LINK)
726
struct LOC_getSyllable *LINK;
737
count[(long)slur] = -lyrinfo[voice-1].slur_change;
738
count[(long)beam] = -lyrinfo[voice-1].beam_change;
739
for (t = beam; (long)t <= (long)slur; t = (melismaEnd)((long)t + 1)) {
740
FORLIM1 = count[(long)t];
741
for (i = 1; i <= FORLIM1; i++) {
742
WITH = &lyrinfo[voice-1];
746
sprintf(STR1, "%c%c", slur_melisma, inhibit_slur_melisma);
747
found = removeLast(WITH->melisma, STR1);
751
sprintf(STR1, "%c%c", beam_melisma, inhibit_beam_melisma);
752
found = removeLast(WITH->melisma, STR1);
756
error3(voice, "Ending a melisma that was never started");
757
LINK->EM = (LINK->EM ||
758
(!OpenMelisma(WITH->melisma) &&
759
pos1(found, (sprintf(STR1, "%c%c", slur_melisma, beam_melisma),
766
Local Void startSlurMelisma(voice, LINK)
768
struct LOC_getSyllable *LINK;
770
static Char start[2] = {
771
slur_melisma, inhibit_slur_melisma
779
FORLIM = lyrinfo[voice-1].slur_change;
780
for (k = 1; k <= FORLIM; k++)
781
sprintf(slurs, "%c%s",
782
start[noSlurMelisma(voice, 1 - k)], strcpy(STR1, slurs));
783
startMelismas(slurs, LINK);
786
Local Void startBeamMelisma(voice, LINK)
788
struct LOC_getSyllable *LINK;
790
static Char start[2] = {
791
beam_melisma, inhibit_beam_melisma
799
FORLIM = lyrinfo[voice-1].beam_change;
800
for (k = 1; k <= FORLIM; k++)
801
sprintf(beams, "%c%s", start[noBeamMelisma(voice)], strcpy(STR1, beams));
802
startMelismas(beams, LINK);
805
Local boolean startMelisma(voice, LINK)
807
struct LOC_getSyllable *LINK;
810
startSlurMelisma(voice, LINK);
811
startBeamMelisma(voice, LINK);
816
/* Append mtxBM or mtxEM to pretex when appropriate */
817
Void getSyllable(voice_, pretex)
821
struct LOC_getSyllable V;
827
WITH = &tag[V.voice-1];
828
WITH1 = &lyrinfo[V.voice-1];
829
if (WITH->has_lyrics != haslyr)
831
t = WITH1->slur_level;
832
WITH1->slur_level = slurLevel(V.voice);
833
WITH1->slur_change = WITH1->slur_level - t;
834
t = WITH1->beam_level;
835
WITH1->beam_level = beamLevel(V.voice);
836
WITH1->beam_change = WITH1->beam_level - t;
837
if (startMelisma(V.voice, &V)) {
838
if (WITH->auxiliary == aux)
839
strcat(pretex, "\\mtxAuxBM");
841
strcat(pretex, "\\mtxBM");
843
if (!endMelisma(V.voice, &V))
845
if (WITH->auxiliary == aux)
846
strcat(pretex, "\\mtxAuxEM");
848
strcat(pretex, "\\mtxEM");
852
Static Void getSyllable1(voice, pretex)
858
WITH = &lyrinfo[voice-1];
859
printf("voice=%d, slurchange=%d, melisma=%s, beamchange=%d\n",
860
voice, WITH->slur_change, WITH->melisma, WITH->beam_change);
861
getSyllable1(voice, pretex);
863
printf("pretex = %s\n", pretex);