| 1 |
/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ |
| 2 |
/* From input file "prepmx.pas" */ |
| 3 |
|
| 4 |
|
| 5 |
#include "p2c.h" |
| 6 |
|
| 7 |
|
| 8 |
#ifndef CONTROL_H |
| 9 |
#include "control.h" |
| 10 |
#endif |
| 11 |
|
| 12 |
#ifndef STRINGS_H |
| 13 |
#include "strings.h" |
| 14 |
#endif |
| 15 |
|
| 16 |
#ifndef GLOBALS_H |
| 17 |
#include "globals.h" |
| 18 |
#endif |
| 19 |
|
| 20 |
#ifndef PREAMBLE_H |
| 21 |
#include "preamble.h" |
| 22 |
#endif |
| 23 |
|
| 24 |
#ifndef LYRICS_H |
| 25 |
#include "lyrics.h" |
| 26 |
#endif |
| 27 |
|
| 28 |
#ifndef MTX_H |
| 29 |
#include "mtx.h" |
| 30 |
#endif |
| 31 |
|
| 32 |
#ifndef ANALYZE_H |
| 33 |
#include "analyze.h" |
| 34 |
#endif |
| 35 |
|
| 36 |
#ifndef MTXLINE_H |
| 37 |
#include "mtxline.h" |
| 38 |
#endif |
| 39 |
|
| 40 |
#ifndef STATUS_H |
| 41 |
#include "status.h" |
| 42 |
#endif |
| 43 |
|
| 44 |
#ifndef UPTEXT_H |
| 45 |
#include "uptext.h" |
| 46 |
#endif |
| 47 |
|
| 48 |
#ifndef NOTES_H |
| 49 |
#include "notes.h" |
| 50 |
#endif |
| 51 |
|
| 52 |
#ifndef MULTFILE_H |
| 53 |
#include "multfile.h" |
| 54 |
#endif |
| 55 |
|
| 56 |
#ifndef FILES_H |
| 57 |
#include "files.h" |
| 58 |
#endif |
| 59 |
|
| 60 |
#ifndef UTILITY_H |
| 61 |
#include "utility.h" |
| 62 |
#endif |
| 63 |
|
| 64 |
|
| 65 |
/* CMO: addition/change by Christian Mondrup */ |
| 66 |
|
| 67 |
/** M-Tx preprocessor to PMX Dirk Laurie */ |
| 68 |
|
| 69 |
#define version "0.63d" |
| 70 |
#define version_date "<26 July 2022>" |
| 71 |
|
| 72 |
/** See file "Corrections" for updates */ |
| 73 |
|
| 74 |
/** To do next: |
| 75 |
{* Current bugs: |
| 76 |
{* Old bugs: |
| 77 |
Does not check PMX syntax |
| 78 |
{* Weaknesses that may later cause bugs: |
| 79 |
Decisions sometimes made on note, sometimes on scan |
| 80 |
Can 'here' overrun? |
| 81 |
Where does one note stop and the next begin? |
| 82 |
See comment on '!' in uptext |
| 83 |
*/ |
| 84 |
|
| 85 |
#define chord_flat 't' |
| 86 |
#define chord_left 'l' |
| 87 |
|
| 88 |
#define blind true |
| 89 |
#define visible false |
| 90 |
|
| 91 |
|
| 92 |
Static boolean last_bar; |
| 93 |
Static Char repeat_sign[256]; |
| 94 |
/*, bars_of_rest*/ |
| 95 |
Static short bar_of_line; |
| 96 |
|
| 97 |
|
| 98 |
/* --------------- Bars and rests --------------- */ |
| 99 |
|
| 100 |
Static void writeRepeat(Char *bar) |
| 101 |
{ |
| 102 |
Char repcode[256]; |
| 103 |
Char STR1[256]; |
| 104 |
|
| 105 |
if (*bar == '\0') |
| 106 |
return; |
| 107 |
*repcode = '\0'; |
| 108 |
if (!strcmp(bar, "||")) |
| 109 |
strcpy(repcode, "Rd"); |
| 110 |
else if (!strcmp(bar, "|]")) |
| 111 |
strcpy(repcode, "RD"); |
| 112 |
else if (!strcmp(bar, "|:")) |
| 113 |
strcpy(repcode, "Rl"); |
| 114 |
else if (!strcmp(bar, ":|:")) |
| 115 |
strcpy(repcode, "Rlr"); |
| 116 |
else if (!strcmp(bar, ":|")) |
| 117 |
strcpy(repcode, "Rr"); |
| 118 |
else if (last_bar && !strcmp(bar, "|")) |
| 119 |
strcpy(repcode, "Rb"); |
| 120 |
if (*repcode != '\0') { |
| 121 |
sprintf(STR1, " %s", repcode); |
| 122 |
putLine(STR1); |
| 123 |
} |
| 124 |
*bar = '\0'; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
Static void supplyRests(voice_index voice) |
| 129 |
{ |
| 130 |
Char STR2[4]; |
| 131 |
Char STR3[256]; |
| 132 |
|
| 133 |
if (bar_of_line == 1 && pedanticWarnings()) { |
| 134 |
printf("Bar %d Voice %d", bar_no, voice); |
| 135 |
warning(" Filling missing voice with rests", !print); |
| 136 |
} |
| 137 |
if (pickup > 0) |
| 138 |
put(rests(STR3, pickup, meterdenom, visible), nospace); |
| 139 |
sprintf(STR2, "%s ", pause); |
| 140 |
put(STR2, putspace); |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
/* Local variables for processLine: */ |
| 145 |
struct LOC_processLine { |
| 146 |
voice_index voice; |
| 147 |
Char chords[256], note[256], cutnote[256], pretex[256]; |
| 148 |
short ngrace, nmulti; |
| 149 |
boolean no_chords, no_uptext; |
| 150 |
|
| 151 |
short l; |
| 152 |
boolean in_group; |
| 153 |
} ; |
| 154 |
|
| 155 |
Local void output(Char *note_, struct LOC_processLine *LINK) |
| 156 |
{ |
| 157 |
Char note[256]; |
| 158 |
Char STR2[256]; |
| 159 |
|
| 160 |
strcpy(note, note_); |
| 161 |
if (*note != '\0') |
| 162 |
{ /* pretex is saved up until a spacing note or rest comes */ |
| 163 |
if (endsWith(note, "\\") && note[1] != '\\') { |
| 164 |
curtail(note, '\\'); |
| 165 |
strcat(LINK->pretex, note); |
| 166 |
*note = '\0'; |
| 167 |
return; |
| 168 |
} |
| 169 |
if (*LINK->pretex != '\0' && isNoteOrRest(note)) { |
| 170 |
sprintf(note, "%s\\ %s", LINK->pretex, strcpy(STR2, note)); |
| 171 |
*LINK->pretex = '\0'; |
| 172 |
} |
| 173 |
if (outlen > 0 && note[0] != ' ') |
| 174 |
sprintf(note, " %s", strcpy(STR2, note)); |
| 175 |
put(note, nospace); |
| 176 |
} |
| 177 |
if (thisNote(LINK->voice) == nextvoice) |
| 178 |
putLine(""); |
| 179 |
} |
| 180 |
|
| 181 |
Local void maybeDotted(Char *note, struct LOC_processLine *LINK) |
| 182 |
{ |
| 183 |
if (strlen(note) < 2) |
| 184 |
return; |
| 185 |
if (note[1] == '"') { |
| 186 |
note[1] = note[0]; |
| 187 |
strcat(LINK->pretex, "\\mtxDotted"); |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
/* Local variables for addChords: */ |
| 192 |
struct LOC_addChords { |
| 193 |
struct LOC_processLine *LINK; |
| 194 |
Char nt[256], labels[256]; |
| 195 |
boolean tieme; |
| 196 |
Char lab; |
| 197 |
int5 pitches; |
| 198 |
} ; |
| 199 |
|
| 200 |
Local void outChord(struct LOC_addChords *LINK) |
| 201 |
{ |
| 202 |
short k; |
| 203 |
Char STR2[256]; |
| 204 |
short FORLIM; |
| 205 |
|
| 206 |
if (*LINK->nt == '\0') |
| 207 |
return; |
| 208 |
LINK->tieme = (LINK->nt[0] == '{'); |
| 209 |
if (LINK->tieme) |
| 210 |
predelete(LINK->nt, 1); |
| 211 |
if (*LINK->nt == '\0' || LINK->nt[0] < 'a' || LINK->nt[0] > 'g') { |
| 212 |
sprintf(STR2, "Must have a note name at the start of \"%s\", not \"%c\"", |
| 213 |
LINK->nt, LINK->nt[0]); |
| 214 |
error(STR2, print); |
| 215 |
} |
| 216 |
renewChordPitch(LINK->LINK->voice, LINK->nt); |
| 217 |
sprintf(LINK->LINK->chords + strlen(LINK->LINK->chords), " z%s", LINK->nt); |
| 218 |
*LINK->nt = '\0'; |
| 219 |
FORLIM = strlen(LINK->labels); |
| 220 |
for (k = 0; k <= FORLIM - 1; k++) { |
| 221 |
if (chordPitch(LINK->LINK->voice) == LINK->pitches[k]) { |
| 222 |
sprintf(LINK->LINK->chords + strlen(LINK->LINK->chords), " s%ct", |
| 223 |
LINK->labels[k]); |
| 224 |
LINK->labels[k] = ' '; |
| 225 |
} |
| 226 |
} |
| 227 |
if (LINK->tieme) { |
| 228 |
chordTie(LINK->LINK->voice, &LINK->lab); |
| 229 |
sprintf(LINK->LINK->chords + strlen(LINK->LINK->chords), " s%ct", |
| 230 |
LINK->lab); |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
Local void addChords(struct LOC_processLine *LINK) |
| 235 |
{ |
| 236 |
struct LOC_addChords V; |
| 237 |
Char w[256]; |
| 238 |
short j = 1; |
| 239 |
short mus_line; |
| 240 |
paragraph_index0 chord_line; |
| 241 |
boolean arpeggio; |
| 242 |
Char STR1[256]; |
| 243 |
short FORLIM; |
| 244 |
|
| 245 |
V.LINK = LINK; |
| 246 |
saveStatus(LINK->voice); |
| 247 |
getChordTies(LINK->voice, V.pitches, V.labels); |
| 248 |
*LINK->chords = '\0'; |
| 249 |
chord_line = chordLineNo(LINK->voice); |
| 250 |
if (chord_line == 0) |
| 251 |
LINK->no_chords = true; |
| 252 |
if (LINK->no_chords) |
| 253 |
return; |
| 254 |
GetNextWord(w, P[chord_line-1], blank, dummy); |
| 255 |
sprintf(STR1, "%c", barsym); |
| 256 |
if (!strcmp(w, STR1) || *w == '\0') |
| 257 |
LINK->no_chords = true; |
| 258 |
sprintf(STR1, "%c", tilde); |
| 259 |
if (!strcmp(w, STR1) || LINK->no_chords) |
| 260 |
return; |
| 261 |
mus_line = line_no; |
| 262 |
line_no = orig_line_no[chord_line-1]; |
| 263 |
arpeggio = (w[0] == '?'); |
| 264 |
if (arpeggio) { |
| 265 |
strcpy(LINK->chords, " ?"); |
| 266 |
predelete(w, 1); |
| 267 |
} |
| 268 |
*V.nt = '\0'; |
| 269 |
while (j <= strlen(w)) { |
| 270 |
if (w[j-1] == '{' || strcmp(V.nt, "{") && w[j-1] >= 'a' && w[j-1] <= 'g') |
| 271 |
outChord(&V); |
| 272 |
else if (w[j-1] == chord_flat) |
| 273 |
w[j-1] = 'f'; |
| 274 |
else if (w[j-1] == chord_left) |
| 275 |
w[j-1] = 'e'; |
| 276 |
sprintf(V.nt + strlen(V.nt), "%c", w[j-1]); |
| 277 |
j++; |
| 278 |
} |
| 279 |
if (*V.nt != '\0') |
| 280 |
outChord(&V); |
| 281 |
if (arpeggio) |
| 282 |
strcat(LINK->chords, " ?"); |
| 283 |
strcat(LINK->note, LINK->chords); |
| 284 |
FORLIM = strlen(V.labels); |
| 285 |
for (j = 0; j <= FORLIM - 1; j++) { |
| 286 |
if (V.labels[j] != ' ') |
| 287 |
error("Tie on chord note started but not finished", print); |
| 288 |
} |
| 289 |
line_no = mus_line; |
| 290 |
} |
| 291 |
|
| 292 |
Local Char *processOther(Char *Result, Char *note_, |
| 293 |
struct LOC_processLine *LINK) |
| 294 |
{ |
| 295 |
Char note[256]; |
| 296 |
|
| 297 |
strcpy(note, note_); |
| 298 |
switch (thisNote(LINK->voice)) { |
| 299 |
|
| 300 |
case other: |
| 301 |
if (note[0] == grace_group) { |
| 302 |
if (strlen(note) == 1) |
| 303 |
LINK->ngrace = 1; |
| 304 |
else |
| 305 |
LINK->ngrace = pos1(note[1], digits); |
| 306 |
if (LINK->ngrace > 0) |
| 307 |
LINK->ngrace--; |
| 308 |
} |
| 309 |
break; |
| 310 |
|
| 311 |
/* For a zword, take note of pitch but do not change the contents */ |
| 312 |
/* Add spurious duration because repitch expects duration to be present */ |
| 313 |
case zword: |
| 314 |
strcpy(LINK->cutnote, note); |
| 315 |
predelete(LINK->cutnote, 1); |
| 316 |
insertChar('4', LINK->cutnote, 2); |
| 317 |
checkOctave(LINK->voice, LINK->cutnote); |
| 318 |
renewPitch(LINK->voice, LINK->cutnote); |
| 319 |
break; |
| 320 |
|
| 321 |
case lyrtag: |
| 322 |
extractLyrtag(LINK->voice, note); |
| 323 |
break; |
| 324 |
|
| 325 |
case rbrac: |
| 326 |
endBeam(LINK->voice); |
| 327 |
break; |
| 328 |
|
| 329 |
case rparen: |
| 330 |
case rlparen: |
| 331 |
endSlur(LINK->voice, note); |
| 332 |
break; |
| 333 |
|
| 334 |
case lbrac: |
| 335 |
beginBeam(LINK->voice, note); |
| 336 |
break; |
| 337 |
|
| 338 |
case lparen: |
| 339 |
maybeDotted(note, LINK); |
| 340 |
beginSlur(LINK->voice, note); |
| 341 |
break; |
| 342 |
|
| 343 |
case mword: |
| 344 |
error3(LINK->voice, "Meter change must be the first word of its bar"); |
| 345 |
break; |
| 346 |
|
| 347 |
case atword: |
| 348 |
lyricsAdjust(LINK->voice, note); |
| 349 |
break; |
| 350 |
} |
| 351 |
return strcpy(Result, note); |
| 352 |
} |
| 353 |
|
| 354 |
Local void lookahead(struct LOC_processLine *LINK) |
| 355 |
{ |
| 356 |
Char STR2[256]; |
| 357 |
Char STR3[256]; |
| 358 |
|
| 359 |
while (bind_left[(long)nextNote(LINK->voice)]) |
| 360 |
sprintf(LINK->note + strlen(LINK->note), " %s", |
| 361 |
processOther(STR2, getMusicWord(STR3, LINK->voice), LINK)); |
| 362 |
} |
| 363 |
|
| 364 |
Local void processUsual(struct LOC_processLine *LINK) |
| 365 |
{ |
| 366 |
if (hasVerseNumber(LINK->voice)) |
| 367 |
strcat(LINK->pretex, "\\mtxVerse"); |
| 368 |
LINK->l = pos1(multi_group, LINK->note); |
| 369 |
if (LINK->l > 0) |
| 370 |
scan1(LINK->note, LINK->l + 1, &LINK->nmulti); |
| 371 |
activateBeamsAndSlurs(LINK->voice); |
| 372 |
LINK->in_group = false; |
| 373 |
if (LINK->ngrace > 0) { |
| 374 |
LINK->in_group = true; |
| 375 |
LINK->ngrace--; |
| 376 |
} else { |
| 377 |
if (LINK->nmulti > 0) { |
| 378 |
LINK->in_group = true; |
| 379 |
LINK->nmulti--; |
| 380 |
} |
| 381 |
} |
| 382 |
checkOctave(LINK->voice, LINK->note); |
| 383 |
renewPitch(LINK->voice, LINK->note); |
| 384 |
if (!LINK->in_group) { |
| 385 |
resetDuration(LINK->voice, durationCode(LINK->note)); |
| 386 |
markDebeamed(LINK->voice, LINK->note); |
| 387 |
} |
| 388 |
lookahead(LINK); |
| 389 |
getSyllable(LINK->voice, LINK->pretex); |
| 390 |
addUptext(LINK->voice, &LINK->no_uptext, LINK->pretex); |
| 391 |
addChords(LINK); |
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
/* ---------------------------------------------------------------- */ |
| 396 |
|
| 397 |
Static void processLine(voice_index voice_, short bar_no) |
| 398 |
{ |
| 399 |
struct LOC_processLine V; |
| 400 |
paragraph_index par_line; |
| 401 |
Char STR1[256]; |
| 402 |
|
| 403 |
V.voice = voice_; |
| 404 |
*V.pretex = '\0'; |
| 405 |
V.no_chords = false; |
| 406 |
V.no_uptext = false; |
| 407 |
par_line = musicLineNo(V.voice); |
| 408 |
V.nmulti = 0; |
| 409 |
V.ngrace = 0; |
| 410 |
line_no = orig_line_no[par_line-1]; |
| 411 |
do { |
| 412 |
getMusicWord(V.note, V.voice); |
| 413 |
if (*V.note == '\0') |
| 414 |
return; |
| 415 |
/* if debugMode then writeln(voice,' ',note); */ |
| 416 |
switch (thisNote(V.voice)) { |
| 417 |
|
| 418 |
case rword: |
| 419 |
if (*multi_bar_rest != '\0') { |
| 420 |
if (uptextOnRests()) |
| 421 |
addUptext(V.voice, &V.no_uptext, V.pretex); |
| 422 |
} else { |
| 423 |
V.l = pos1(multi_group, V.note); |
| 424 |
if (V.l > 0) |
| 425 |
scan1(V.note, V.l + 1, &V.nmulti); |
| 426 |
if (V.nmulti > 0) { |
| 427 |
V.in_group = true; |
| 428 |
V.nmulti--; |
| 429 |
} |
| 430 |
if (uptextOnRests()) |
| 431 |
addUptext(V.voice, &V.no_uptext, V.pretex); |
| 432 |
if (!(isPause(V.note) || V.in_group)) |
| 433 |
/*0.63: allow rests in xtuples*/ |
| 434 |
resetDuration(V.voice, durationCode(V.note)); |
| 435 |
} |
| 436 |
break; |
| 437 |
|
| 438 |
case abcdefg: |
| 439 |
processUsual(&V); |
| 440 |
break; |
| 441 |
|
| 442 |
case barword: |
| 443 |
if (V.voice == nvoices) { |
| 444 |
if (endOfBar(V.voice, bar_no)) |
| 445 |
strcpy(repeat_sign, V.note); |
| 446 |
else |
| 447 |
writeRepeat(V.note); |
| 448 |
} |
| 449 |
sprintf(STR1, "%c", barsym); |
| 450 |
if (strcmp(V.note, STR1)) |
| 451 |
*V.note = '\0'; |
| 452 |
V.no_chords = false; |
| 453 |
break; |
| 454 |
|
| 455 |
case FirstOnly: |
| 456 |
if (V.voice != nvoices) |
| 457 |
*V.note = '\0'; |
| 458 |
else |
| 459 |
strcpy(V.note, processOther(STR1, V.note, &V)); |
| 460 |
break; |
| 461 |
|
| 462 |
default: |
| 463 |
strcpy(V.note, processOther(STR1, V.note, &V)); |
| 464 |
break; |
| 465 |
} |
| 466 |
output(V.note, &V); |
| 467 |
} while (!endOfBar(V.voice, bar_no)); |
| 468 |
if (!V.no_chords) |
| 469 |
skipChordBar(V.voice); |
| 470 |
} |
| 471 |
|
| 472 |
|
| 473 |
/* ------------------------------------------------------------------- */ |
| 474 |
|
| 475 |
Static void getMeterChange(voice_index voice, Char *new_meter) |
| 476 |
{ |
| 477 |
short pn1, pn2; |
| 478 |
Char w[256], new_command[256]; |
| 479 |
|
| 480 |
if (nextNote(voice) != mword) |
| 481 |
return; |
| 482 |
getMusicWord(w, voice); |
| 483 |
getMeter(w, &meternum, &meterdenom, &pn1, &pn2); |
| 484 |
full_bar = meternum * (64 / meterdenom); |
| 485 |
/* CMO: process denominator value with function PMXmeterdenom */ |
| 486 |
meterWord(new_command, meternum, PMXmeterdenom(meterdenom), pn1, pn2); |
| 487 |
if (*new_meter != '\0' && strcmp(new_meter, new_command)) |
| 488 |
error3(voice, "The same meter change must appear in all voices"); |
| 489 |
strcpy(new_meter, new_command); |
| 490 |
} |
| 491 |
|
| 492 |
|
| 493 |
/* Local variables for musicParagraph: */ |
| 494 |
struct LOC_musicParagraph { |
| 495 |
Char new_meter[256]; |
| 496 |
} ; |
| 497 |
|
| 498 |
Local void putPMXlines(struct LOC_musicParagraph *LINK) |
| 499 |
{ |
| 500 |
paragraph_index i, FORLIM; |
| 501 |
|
| 502 |
FORLIM = para_len; |
| 503 |
for (i = 0; i <= FORLIM - 1; i++) { |
| 504 |
if (startsWith(P[i], double_comment)) { |
| 505 |
predelete(P[i], 2); |
| 506 |
putLine(P[i]); |
| 507 |
strcpy(P[i], "%"); |
| 508 |
} |
| 509 |
} |
| 510 |
} |
| 511 |
|
| 512 |
Local void processOneBar(struct LOC_musicParagraph *LINK) |
| 513 |
{ |
| 514 |
paragraph_index0 m, cm; |
| 515 |
voice_index voice, cvoice; |
| 516 |
boolean ignore_voice; |
| 517 |
boolean wrote_repeat = false; |
| 518 |
boolean alone; |
| 519 |
Char STR2[256]; |
| 520 |
Char STR3[256]; |
| 521 |
|
| 522 |
if (bar_of_line > 1) { |
| 523 |
sprintf(STR3, "%cBar %s", comment, toString(STR2, bar_no)); |
| 524 |
putLine(STR3); |
| 525 |
} |
| 526 |
last_bar = (bar_of_line == nbars && final_paragraph); |
| 527 |
if (last_bar && !strcmp(repeat_sign, "|")) |
| 528 |
*repeat_sign = '\0'; |
| 529 |
writeRepeat(repeat_sign); |
| 530 |
*LINK->new_meter = '\0'; |
| 531 |
for (voice = nvoices; voice >= 1; voice--) { |
| 532 |
if (musicLineNo(voice) > 0) { |
| 533 |
gotoBar(voice, bar_of_line); |
| 534 |
getMeterChange(voice, LINK->new_meter); |
| 535 |
} |
| 536 |
} |
| 537 |
if (last_bar && *LINK->new_meter == '\0' && nleft > pickup && meternum > 0) |
| 538 |
meterChange(LINK->new_meter, nleft, 64, true); |
| 539 |
if (*LINK->new_meter != '\0') |
| 540 |
putLine(LINK->new_meter); |
| 541 |
for (voice = nvoices; voice >= 1; voice--) { |
| 542 |
ignore_voice = !selected[voice-1]; |
| 543 |
cvoice = companion(voice); |
| 544 |
m = musicLineNo(voice); |
| 545 |
cm = musicLineNo(cvoice); |
| 546 |
alone = (voice == cvoice || m > 0 && cm == 0 || |
| 547 |
m == 0 && cm == 0 && voice < cvoice || !selected[cvoice-1]); |
| 548 |
if (selected[voice-1]) { |
| 549 |
if (m > 0) |
| 550 |
processLine(voice, bar_of_line); |
| 551 |
else if (alone) |
| 552 |
supplyRests(voice); |
| 553 |
else |
| 554 |
ignore_voice = true; |
| 555 |
if (last_bar && *repeat_sign != '\0' && !wrote_repeat) { |
| 556 |
writeRepeat(repeat_sign); |
| 557 |
wrote_repeat = true; |
| 558 |
} |
| 559 |
if (!ignore_voice) { |
| 560 |
if (alone || voicePos(voice) == 1) |
| 561 |
putLine(" /"); |
| 562 |
else |
| 563 |
putLine(" //"); |
| 564 |
} |
| 565 |
} |
| 566 |
} |
| 567 |
bar_no++; |
| 568 |
pickup = 0; |
| 569 |
putLine(""); |
| 570 |
} |
| 571 |
|
| 572 |
Local void putMeter(Char *new_meter_word, struct LOC_musicParagraph *LINK) |
| 573 |
{ |
| 574 |
if (strcmp(new_meter_word, old_meter_word)) |
| 575 |
putLine(new_meter_word); |
| 576 |
strcpy(old_meter_word, new_meter_word); |
| 577 |
} |
| 578 |
|
| 579 |
Local void processMBR(struct LOC_musicParagraph *LINK) |
| 580 |
{ |
| 581 |
short s, bars_of_rest; |
| 582 |
Char mbr[256]; |
| 583 |
short FORLIM; |
| 584 |
Char STR1[256]; |
| 585 |
Char STR3[256]; |
| 586 |
|
| 587 |
strcpy(mbr, multi_bar_rest); |
| 588 |
predelete(mbr, 2); |
| 589 |
getNum(mbr, &bars_of_rest); |
| 590 |
bar_no += bars_of_rest; |
| 591 |
FORLIM = nstaves; |
| 592 |
for (s = 1; s <= FORLIM; s++) { |
| 593 |
if (pickup > 0) |
| 594 |
put(rests(STR1, pickup, meterdenom, visible), nospace); |
| 595 |
sprintf(STR3, "rm%s /", toString(STR1, bars_of_rest)); |
| 596 |
putLine(STR3); |
| 597 |
} |
| 598 |
putLine(""); |
| 599 |
} |
| 600 |
|
| 601 |
|
| 602 |
Static void musicParagraph(void) |
| 603 |
{ |
| 604 |
struct LOC_musicParagraph V; |
| 605 |
voice_index0 j, nvoice; |
| 606 |
Char lyrassign[256]; |
| 607 |
Char STR1[256]; |
| 608 |
Char STR2[256]; |
| 609 |
Char STR3[256], STR4[256], STR5[256]; |
| 610 |
voice_index0 FORLIM; |
| 611 |
short FORLIM1; |
| 612 |
|
| 613 |
paragraphSetup(&nvoice); |
| 614 |
if (nvoice == 0) { |
| 615 |
nonMusic(); |
| 616 |
return; |
| 617 |
} |
| 618 |
if (nvoice > nvoices) { |
| 619 |
if (nvoice == 0) |
| 620 |
error("No voices! Did you remember to to supply a Style?", !print); |
| 621 |
sprintf(STR4, "Paragraph has %s voices but Style allows only %s", |
| 622 |
toString(STR1, nvoice), toString(STR2, nvoices)); |
| 623 |
error(STR4, !print); |
| 624 |
return; |
| 625 |
} |
| 626 |
if (first_paragraph) |
| 627 |
includeStartString(); |
| 628 |
if (pmx_preamble_done && (!final_paragraph || nvoice > 0)) { |
| 629 |
sprintf(STR5, "%c Paragraph %s line %s bar %s", |
| 630 |
comment, toString(STR1, paragraph_no), |
| 631 |
toString(STR2, orig_line_no[0]), toString(STR3, bar_no)); |
| 632 |
putLine(STR5); |
| 633 |
} |
| 634 |
testParagraph(); |
| 635 |
rememberDurations(); |
| 636 |
if (beVerbose()) |
| 637 |
describeParagraph(); |
| 638 |
/* ---- Knowing the score, we can start setting music ---------------- */ |
| 639 |
if (!pmx_preamble_done) { |
| 640 |
doPMXpreamble(); |
| 641 |
sprintf(STR3, "%c Paragraph %s line %s bar ", |
| 642 |
comment, toString(STR1, paragraph_no), |
| 643 |
toString(STR2, orig_line_no[0])); |
| 644 |
put(STR3, putspace); |
| 645 |
if (pickup > 0) |
| 646 |
putLine("0"); |
| 647 |
else |
| 648 |
putLine("1"); |
| 649 |
} |
| 650 |
putPMXlines(&V); |
| 651 |
if (must_restyle) |
| 652 |
restyle(); |
| 653 |
if (some_vocal && (nvoice > 0 || !final_paragraph)) { |
| 654 |
FORLIM = ninstr; |
| 655 |
for (j = 1; j <= FORLIM; j++) { |
| 656 |
assignLyrics(j, lyrassign); |
| 657 |
if (*lyrassign != '\0') { |
| 658 |
sprintf(STR2, "\\\\%s\\", lyrassign); |
| 659 |
putLine(STR2); |
| 660 |
} |
| 661 |
} |
| 662 |
} |
| 663 |
if (must_respace) |
| 664 |
respace(); |
| 665 |
if (meternum == 0) |
| 666 |
putMeter(meterChange(STR2, beatsPerLine(), meterdenom, true), &V); |
| 667 |
if (nleft > 0) |
| 668 |
nbars++; |
| 669 |
if (nbars == 0 && *multi_bar_rest != '\0') |
| 670 |
processMBR(&V); |
| 671 |
else { |
| 672 |
FORLIM1 = nbars; |
| 673 |
for (bar_of_line = 1; bar_of_line <= FORLIM1; bar_of_line++) |
| 674 |
processOneBar(&V); |
| 675 |
} |
| 676 |
restoreDurations(); |
| 677 |
} |
| 678 |
|
| 679 |
|
| 680 |
/* ----------------------------------------------------------------------- */ |
| 681 |
|
| 682 |
Static boolean no_commands_yet; |
| 683 |
|
| 684 |
|
| 685 |
Static void doMusic(void) |
| 686 |
{ |
| 687 |
Char STR1[256], STR2[256]; |
| 688 |
Char STR4[256]; |
| 689 |
|
| 690 |
first_paragraph = true; |
| 691 |
pmx_preamble_done = false; |
| 692 |
bar_no = 1; |
| 693 |
*repeat_sign = '\0'; |
| 694 |
must_respace = false; |
| 695 |
must_restyle = false; |
| 696 |
do { |
| 697 |
final_paragraph = endOfInfile(); |
| 698 |
memcpy(orig_P, P, sizeof(paragraph)); |
| 699 |
if (para_len > 0 && !ignore_input && thisCase()) { |
| 700 |
if (no_commands_yet) { |
| 701 |
interpretCommands(); |
| 702 |
printFeatures(false); |
| 703 |
one_beat = 64 / meterdenom; |
| 704 |
full_bar = meternum * one_beat; |
| 705 |
if (nvoices > standardPMXvoices) { |
| 706 |
sprintf(STR4, "You have %s voices; standard PMX can only handle %s", |
| 707 |
toString(STR1, nvoices), toString(STR2, standardPMXvoices)); |
| 708 |
warning(STR4, !print); |
| 709 |
} |
| 710 |
initMTX(); |
| 711 |
initUptext(); |
| 712 |
initStatus(); |
| 713 |
initLyrics(); |
| 714 |
no_commands_yet = false; |
| 715 |
} |
| 716 |
if (startsWithBracedWord(P[0])) |
| 717 |
lyricsParagraph(); |
| 718 |
else { |
| 719 |
musicParagraph(); |
| 720 |
first_paragraph = false; |
| 721 |
writeRepeat(repeat_sign); |
| 722 |
} |
| 723 |
} |
| 724 |
readParagraph(P, orig_line_no, ¶_len); |
| 725 |
} while (para_len != 0); |
| 726 |
} |
| 727 |
|
| 728 |
|
| 729 |
Static boolean control_paragraph, no_report_errors; |
| 730 |
|
| 731 |
|
| 732 |
Static boolean isControlParagraph(Char (*P)[256], paragraph_index para_len) |
| 733 |
{ |
| 734 |
paragraph_index0 commands = 0, labels = 0, voices = 0, guff = 0; |
| 735 |
paragraph_index0 i; |
| 736 |
Char w[256]; |
| 737 |
|
| 738 |
/* p2c: prepmx.pas: Note: Eliminated unused assignment statement [338] */ |
| 739 |
for (i = 0; i <= para_len - 1; i++) { |
| 740 |
if (!startsWith(P[i], "%")) { |
| 741 |
NextWord(w, P[i], ' ', ':'); |
| 742 |
if (!endsWith(w, ":")) |
| 743 |
guff++; |
| 744 |
else if (strlen(w) < 3 || findVoice(w) > 0) |
| 745 |
voices++; |
| 746 |
else if (isCommand(w)) |
| 747 |
commands++; |
| 748 |
else |
| 749 |
labels++; |
| 750 |
} |
| 751 |
} |
| 752 |
if (voices + guff > commands) |
| 753 |
return false; |
| 754 |
return true; |
| 755 |
} |
| 756 |
|
| 757 |
|
| 758 |
Static void topOfPMXfile(void) |
| 759 |
{ |
| 760 |
Char STR2[24]; |
| 761 |
Char STR3[32]; |
| 762 |
|
| 763 |
putLine("---"); |
| 764 |
sprintf(STR2, "\\def\\mtxversion{%s}", version); |
| 765 |
putLine(STR2); |
| 766 |
sprintf(STR3, "\\def\\mtxdate{%s}", version_date); |
| 767 |
putLine(STR3); |
| 768 |
putLine("\\input mtx"); |
| 769 |
} |
| 770 |
|
| 771 |
|
| 772 |
int main(int argc, Char *argv[]) |
| 773 |
{ /* ---- Main program ------------------------ */ |
| 774 |
PASCAL_MAIN(argc, argv); |
| 775 |
strcpy(this_version, version); |
| 776 |
strcpy(this_version_date, version_date); |
| 777 |
printf("==> This is M-Tx %s (Music from TeXt) %s\n", version, version_date); |
| 778 |
|
| 779 |
mtxLevel(version); |
| 780 |
OpenFiles(); |
| 781 |
no_commands_yet = true; |
| 782 |
preambleDefaults(); |
| 783 |
no_report_errors = false; |
| 784 |
topOfPMXfile(); |
| 785 |
do { |
| 786 |
readParagraph(P, orig_line_no, ¶_len); |
| 787 |
control_paragraph = isControlParagraph(P, para_len); |
| 788 |
if (control_paragraph) { |
| 789 |
augmentPreamble(no_report_errors); |
| 790 |
no_report_errors = true; |
| 791 |
if (para_len == 0) |
| 792 |
error("No music paragraphs!", !print); |
| 793 |
} |
| 794 |
} while (control_paragraph); |
| 795 |
doPreamble(); |
| 796 |
doMusic(); |
| 797 |
if (!pmx_preamble_done) |
| 798 |
error("No music paragraphs!", !print); |
| 799 |
putLine("% Coded by M-Tx"); |
| 800 |
CloseFiles(); |
| 801 |
printf("PrePMX done. Now run PMX.\n"); |
| 802 |
_Escape(0); |
| 803 |
exit(EXIT_SUCCESS); |
| 804 |
} |
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
/* End. */ |