~ubuntu-branches/ubuntu/utopic/texlive-bin/utopic

« back to all changes in this revision

Viewing changes to utils/mtx/mtx-0.60d/status.c

  • Committer: Package Import Robot
  • Author(s): Norbert Preining
  • Date: 2012-05-07 10:47:49 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20120507104749-p00ot5sajjbkp1hp
Tags: 2011.20120507-1
* new upstream checkout: uptex 1.10
* drop patches for config file inclusion in (x)dvipdfmx, included upstream
* add man page for etex
* include pmpost patches and build it
* adapt/unfuzzify patches for current sources
* disable mtx building, we have prepmx package in Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */
 
2
/* From input file "status.pas" */
 
3
 
 
4
 
 
5
#include "p2c.h"
 
6
 
 
7
 
 
8
#define STATUS_G
 
9
#include "status.h"
 
10
 
 
11
 
 
12
#ifndef GLOBALS_H
 
13
#include "globals.h"
 
14
#endif
 
15
 
 
16
#ifndef STRINGS_H
 
17
#include "strings.h"
 
18
#endif
 
19
 
 
20
#ifndef MTXLINE_H
 
21
#include "mtxline.h"
 
22
#endif
 
23
 
 
24
#ifndef CONTROL_H
 
25
#include "control.h"
 
26
#endif
 
27
 
 
28
#ifndef UTILITY_H
 
29
#include "utility.h"
 
30
#endif
 
31
 
 
32
#ifndef NOTES_H
 
33
#include "notes.h"
 
34
#endif
 
35
 
 
36
 
 
37
#define lowest_pitch    (-9)
 
38
#define highest_pitch   61
 
39
 
 
40
 
 
41
typedef struct line_status {
 
42
  short pitch, chord_pitch, octave_adjust, beam_level, slur_level, after_slur;
 
43
  Char octave, lastnote, chord_lastnote, duration, slurID, tieID;
 
44
  boolean beamnext, beamed, slurnext, slurred, no_beam_melisma;
 
45
  boolean no_slur_melisma[12];
 
46
  int5 chord_tie_pitch;
 
47
  Char chord_tie_label[6];
 
48
} line_status;
 
49
 
 
50
 
 
51
Static Char init_oct[256] = "";
 
52
Static line_status current[maxvoices];
 
53
Static Char lastdur[maxvoices];
 
54
 
 
55
 
 
56
Void chordTie(voice, lab)
 
57
short voice;
 
58
Char *lab;
 
59
{
 
60
  short n;
 
61
  line_status *WITH;
 
62
 
 
63
  WITH = &current[voice-1];
 
64
  n = strlen(WITH->chord_tie_label);
 
65
  if (n == 5)
 
66
    error3(voice, "Only five slur ties allowed per voice");
 
67
  if (n == 0)
 
68
    *lab = 'T';
 
69
  else
 
70
    *lab = WITH->chord_tie_label[n-1];
 
71
  (*lab)++;
 
72
  sprintf(WITH->chord_tie_label + strlen(WITH->chord_tie_label), "%c", *lab);
 
73
/* p2c: status.pas, line 66:
 
74
 * Note: Possible string truncation in assignment [145] */
 
75
  n++;
 
76
  WITH->chord_tie_pitch[n-1] = WITH->chord_pitch;
 
77
}
 
78
 
 
79
 
 
80
Void getChordTies(voice, pitches, labels)
 
81
short voice;
 
82
short *pitches;
 
83
Char *labels;
 
84
{
 
85
  line_status *WITH;
 
86
 
 
87
  WITH = &current[voice-1];
 
88
  memcpy(pitches, WITH->chord_tie_pitch, sizeof(int5));
 
89
  strcpy(labels, WITH->chord_tie_label);
 
90
  *WITH->chord_tie_label = '\0';
 
91
}
 
92
 
 
93
 
 
94
Void rememberDurations()
 
95
{
 
96
  voice_index v, FORLIM;
 
97
 
 
98
  FORLIM = nvoices;
 
99
  for (v = 1; v <= FORLIM; v++)
 
100
    lastdur[v-1] = duration(v);
 
101
}
 
102
 
 
103
 
 
104
Void restoreDurations()
 
105
{
 
106
  voice_index v, FORLIM;
 
107
 
 
108
  FORLIM = nvoices;
 
109
  for (v = 1; v <= FORLIM; v++)
 
110
    resetDuration(v, lastdur[v-1]);
 
111
}
 
112
 
 
113
 
 
114
Char duration(voice)
 
115
short voice;
 
116
{
 
117
  return (current[voice-1].duration);
 
118
}
 
119
 
 
120
 
 
121
Void resetDuration(voice, dur)
 
122
short voice;
 
123
Char dur;
 
124
{
 
125
  if (pos1(dur, durations) == 0) {
 
126
    printf("Trying to set duration to %c; ", dur);
 
127
    error3(voice, "M-Tx system error: resetDuration");
 
128
  }
 
129
  current[voice-1].duration = dur;
 
130
}
 
131
 
 
132
 
 
133
Void activateBeamsAndSlurs(voice)
 
134
short voice;
 
135
{
 
136
  line_status *WITH;
 
137
 
 
138
  WITH = &current[voice-1];
 
139
  if (WITH->beamnext) {
 
140
    WITH->beamed = true;
 
141
    WITH->beamnext = false;
 
142
  }
 
143
  if (WITH->slurnext) {
 
144
    WITH->slurred = true;
 
145
    WITH->slurnext = false;
 
146
  }
 
147
  if (WITH->slurred)
 
148
    WITH->after_slur++;
 
149
}
 
150
 
 
151
 
 
152
Void saveStatus(voice)
 
153
short voice;
 
154
{
 
155
  line_status *WITH;
 
156
 
 
157
  WITH = &current[voice-1];
 
158
  WITH->chord_pitch = WITH->pitch;
 
159
  WITH->chord_lastnote = WITH->lastnote;
 
160
}
 
161
 
 
162
 
 
163
boolean noBeamMelisma(voice)
 
164
short voice;
 
165
{
 
166
  return (current[voice-1].no_beam_melisma);
 
167
}
 
168
 
 
169
 
 
170
short afterSlur(voice)
 
171
short voice;
 
172
{
 
173
  short Result;
 
174
  line_status *WITH;
 
175
 
 
176
  WITH = &current[voice-1];
 
177
  Result = WITH->after_slur;
 
178
  if (WITH->after_slur > 0 && WITH->slur_level < 1)
 
179
    error3(voice, "M-Tx system error: afterSlur and slur_level incompatible)");
 
180
  return Result;
 
181
}
 
182
 
 
183
 
 
184
Char octave(voice)
 
185
short voice;
 
186
{
 
187
  return (current[voice-1].octave);
 
188
}
 
189
 
 
190
 
 
191
Void resetOctave(voice)
 
192
short voice;
 
193
{
 
194
  current[voice-1].octave = ' ';
 
195
}
 
196
 
 
197
 
 
198
Void initOctaves(octaves)
 
199
Char *octaves;
 
200
{
 
201
  short i = 1;
 
202
 
 
203
  strcpy(init_oct, octaves);
 
204
  while (i <= strlen(init_oct)) {
 
205
    if (init_oct[i-1] == ' ')
 
206
      delete1(init_oct, i);
 
207
    else
 
208
      i++;
 
209
  }
 
210
}
 
211
 
 
212
 
 
213
Static Char initOctave(voice_stave)
 
214
stave_index voice_stave;
 
215
{
 
216
  if (voice_stave > strlen(init_oct)) {
 
217
    if (pos1(clef[voice_stave-1], "Gt08") > 0)
 
218
      return '4';
 
219
    else
 
220
      return '3';
 
221
  } else
 
222
    return (init_oct[voice_stave-1]);
 
223
}
 
224
 
 
225
 
 
226
Void setOctave(voice)
 
227
short voice;
 
228
{
 
229
  current[voice-1].octave = initOctave(voiceStave(voice));
 
230
}
 
231
 
 
232
 
 
233
Void newOctave(voice, dir)
 
234
short voice;
 
235
Char dir;
 
236
{
 
237
  line_status *WITH;
 
238
 
 
239
  WITH = &current[voice-1];
 
240
  switch (dir) {
 
241
 
 
242
  case '+':
 
243
    WITH->octave++;
 
244
    break;
 
245
 
 
246
  case '-':
 
247
    WITH->octave--;
 
248
    break;
 
249
  }
 
250
}
 
251
 
 
252
 
 
253
Static short newPitch(voice, note_, pitch, lastnote)
 
254
short voice;
 
255
Char *note_;
 
256
short pitch;
 
257
Char lastnote;
 
258
{
 
259
  Char note[256];
 
260
  short interval, npitch;
 
261
  Char oct;
 
262
 
 
263
  strcpy(note, note_);
 
264
  /*if debugMode then
 
265
    write('New pitch for note ',note,' relative to ',lastnote,
 
266
       ' at pitch ',pitch);*/
 
267
  oct = octaveCode(note);
 
268
  if (oct == '=')
 
269
    oct = initOctave(voiceStave(voice));
 
270
  if (isdigit(oct)) {
 
271
    pitch = (oct - '0') * 7 - 3;
 
272
    lastnote = 'f';
 
273
    removeOctaveCode(oct, note);
 
274
    oct = octaveCode(note);
 
275
  }
 
276
  interval = note[0] - lastnote;
 
277
  if (interval > 3)
 
278
    interval -= 7;
 
279
  if (interval < -3)
 
280
    interval += 7;
 
281
  npitch = pitch + interval;   /*if debugMode then write(' was ',npitch);*/
 
282
  while (oct != ' ') {
 
283
    if (oct == '+')
 
284
      npitch += 7;
 
285
    else if (oct == '-')
 
286
      npitch -= 7;
 
287
    removeOctaveCode(oct, note);
 
288
    oct = octaveCode(note);
 
289
  }
 
290
  /*if debugMode then writeln(' is ',npitch);*/
 
291
  return npitch;
 
292
}
 
293
 
 
294
 
 
295
Local Void delins(note, c1, c2, l)
 
296
Char *note;
 
297
Char c1, c2;
 
298
short l;
 
299
{
 
300
  short i, n;
 
301
 
 
302
  n = strlen(note);
 
303
  i = pos1(c1, note);
 
304
  if (i == 0)
 
305
    i = n + 1;
 
306
  while (l > 0 && i <= n) {
 
307
    delete1(note, i);
 
308
    n--;
 
309
    l--;
 
310
  }
 
311
  i = pos1(c2, note);
 
312
  if (i == 0) {
 
313
    if (strlen(note) < 2)
 
314
      error("M-Tx program error", print);
 
315
    else
 
316
      i = 3;
 
317
  }
 
318
  while (l > 0) {
 
319
    insertChar(c2, note, i);
 
320
    l--;
 
321
  }
 
322
}
 
323
 
 
324
 
 
325
Static Void repitch(note, diff)
 
326
Char *note;
 
327
short diff;
 
328
{
 
329
  diff /= 7;
 
330
  if (diff > 0)
 
331
    delins(note, '-', '+', diff);
 
332
  else
 
333
    delins(note, '+', '-', -diff);
 
334
}
 
335
 
 
336
 
 
337
Void setUnbeamed(voice)
 
338
short voice;
 
339
{
 
340
  current[voice-1].beamed = false;
 
341
}
 
342
 
 
343
 
 
344
Void setUnslurred(voice)
 
345
short voice;
 
346
{
 
347
  line_status *WITH;
 
348
 
 
349
  WITH = &current[voice-1];
 
350
  WITH->slurred = false;
 
351
  WITH->after_slur = 0;
 
352
}
 
353
 
 
354
 
 
355
Void beginBeam(voice, note)
 
356
short voice;
 
357
Char *note;
 
358
{
 
359
  line_status *WITH;
 
360
 
 
361
  WITH = &current[voice-1];
 
362
  if (WITH->beamed)
 
363
    error3(voice, "Starting a forced beam while another is open");
 
364
  if (WITH->beam_level > 0)
 
365
    error3(voice,
 
366
           "Starting a forced beam while another is open (beamlevel>0)");
 
367
  WITH->beam_level++;
 
368
  WITH->beamnext = true;
 
369
  WITH->no_beam_melisma = startsWith(note, "[[");
 
370
  if (WITH->no_beam_melisma)
 
371
    predelete(note, 1);
 
372
}
 
373
 
 
374
 
 
375
Void endBeam(voice)
 
376
short voice;
 
377
{
 
378
  line_status *WITH;
 
379
 
 
380
  WITH = &current[voice-1];
 
381
  if (WITH->beam_level < 1)
 
382
    error3(voice, "Closing a beam that was never opened");
 
383
  WITH->beam_level--;
 
384
  setUnbeamed(voice);
 
385
}
 
386
 
 
387
 
 
388
short slurLevel(voice)
 
389
short voice;
 
390
{
 
391
  return (current[voice-1].slur_level);
 
392
}
 
393
 
 
394
 
 
395
short beamLevel(voice)
 
396
short voice;
 
397
{
 
398
  return (current[voice-1].beam_level);
 
399
}
 
400
 
 
401
 
 
402
boolean noSlurMelisma(voice, history)
 
403
short voice, history;
 
404
{
 
405
  line_status *WITH;
 
406
 
 
407
  WITH = &current[voice-1];
 
408
  return (WITH->no_slur_melisma[WITH->slur_level + history - 1]);
 
409
}
 
410
 
 
411
 
 
412
Static Char *slurLabel(Result, voice, note)
 
413
Char *Result;
 
414
short voice;
 
415
Char *note;
 
416
{
 
417
  Char sl;
 
418
 
 
419
  if (*note == '\0')
 
420
    return strcpy(Result, "");
 
421
  if (strlen(note) < 2)
 
422
    return strcpy(Result, " ");
 
423
  if (note[1] >= '0' && note[1] <= 'Z')
 
424
    sl = note[1];
 
425
  else
 
426
    sl = ' ';
 
427
  if (sl >= 'I' && sl <= 'T')
 
428
    warning3(voice, "Slur label in the range I..T may cause conflict");
 
429
  sprintf(Result, "%c", sl);
 
430
  return Result;
 
431
}
 
432
 
 
433
 
 
434
Static Void labelSlur(voice, note)
 
435
short voice;
 
436
Char *note;
 
437
{
 
438
  Char sl;
 
439
  line_status *WITH;
 
440
 
 
441
  if (*note == '\0')
 
442
    return;
 
443
  WITH = &current[voice-1];
 
444
  if (note[0] == ')')
 
445
    WITH->slurID += 2;
 
446
  else if (note[0] == '}')
 
447
    WITH->tieID += 2;
 
448
  /** CMO 0.60a: replace assigning tieID to sl by space charater
 
449
    if (note[1]='(') or (note[1]=')') then sl:=slurID else sl:=tieID; */
 
450
  if (note[0] == '(' || note[0] == ')')
 
451
    sl = WITH->slurID;
 
452
  else
 
453
    sl = ' ';
 
454
  /** CMO 0.60d: omit insertchar in case of tie
 
455
    insertchar(sl,note,2); */
 
456
  if (note[0] == '(' || note[0] == ')')
 
457
    insertChar(sl, note, 2);
 
458
  if (note[0] == '(')
 
459
    WITH->slurID -= 2;
 
460
  else if (note[0] == '{')
 
461
    WITH->tieID -= 2;
 
462
  if (WITH->slurID < 'I')
 
463
    warning3(voice, "Too many nested slurs may cause conflict");
 
464
  if (WITH->tieID < 'I')
 
465
    warning3(voice, "Too many nested ties may cause conflict");
 
466
}
 
467
 
 
468
 
 
469
Void beginSlur(voice, note)
 
470
short voice;
 
471
Char *note;
 
472
{
 
473
  short posblind;
 
474
  line_status *WITH;
 
475
  Char STR1[256], STR2[256];
 
476
 
 
477
  WITH = &current[voice-1];
 
478
  WITH->slur_level++;
 
479
  if (WITH->slur_level > 12)
 
480
    error3(voice, "Too many open slurs");
 
481
  WITH->no_slur_melisma[WITH->slur_level - 1] = (startsWith(note, "((") ||
 
482
                                                 startsWith(note, "{{"));
 
483
  if (WITH->no_slur_melisma[WITH->slur_level - 1])
 
484
    predelete(note, 1);
 
485
  if (!strcmp(slurLabel(STR1, voice, note), "0"))
 
486
    delete1(note, 2);
 
487
  else {
 
488
    if (!strcmp(slurLabel(STR2, voice, note), " "))
 
489
      labelSlur(voice, note);
 
490
  }
 
491
  posblind = pos1('~', note);
 
492
  if (posblind > 0) {
 
493
    if (hideBlindSlurs())
 
494
      *note = '\0';
 
495
    else
 
496
      delete1(note, posblind);
 
497
  }
 
498
  WITH->slurnext = true;
 
499
}
 
500
 
 
501
 
 
502
Void endSlur(voice, note)
 
503
short voice;
 
504
Char *note;
 
505
{
 
506
  short poscontinue, posblind;
 
507
  Char contslur[256];
 
508
  line_status *WITH;
 
509
  Char STR1[256], STR2[256];
 
510
 
 
511
  WITH = &current[voice-1];
 
512
  *contslur = '\0';
 
513
  if (WITH->slur_level < 1)
 
514
    error3(voice, "Ending a slur that was never started");
 
515
  if (note[0] == ')')
 
516
    poscontinue = pos1('(', note);
 
517
  else if (note[0] == '}')
 
518
    poscontinue = pos1('{', note);
 
519
  if (poscontinue == 0)
 
520
    WITH->slur_level--;
 
521
  else {
 
522
    poscontinue--;
 
523
    strcpy(contslur, note);
 
524
    predelete(contslur, poscontinue);
 
525
    shorten(note, poscontinue);
 
526
  }
 
527
  if (WITH->slur_level == 0)
 
528
    setUnslurred(voice);
 
529
  if (!strcmp(slurLabel(STR1, voice, note), "0"))
 
530
    delete1(note, 2);
 
531
  else {
 
532
    if (!strcmp(slurLabel(STR2, voice, note), " "))
 
533
      labelSlur(voice, note);
 
534
  }
 
535
  if (!strcmp(slurLabel(STR1, voice, contslur), "0"))
 
536
    delete1(contslur, 2);
 
537
  else {
 
538
    if (!strcmp(slurLabel(STR2, voice, contslur), " "))
 
539
      labelSlur(voice, contslur);
 
540
  }
 
541
  if (poscontinue > 0) {
 
542
    if (note[0] == '}')
 
543
      strcat(note, "t");
 
544
    note[0] = 's';
 
545
    if (contslur[0] == '{')
 
546
      strcat(contslur, "t");
 
547
    contslur[0] = 's';
 
548
  }
 
549
  posblind = pos1('~', note);
 
550
  if (posblind > 0) {
 
551
    if (hideBlindSlurs())
 
552
      *note = '\0';
 
553
    else
 
554
      delete1(note, posblind);
 
555
  }
 
556
  if (*note != '\0' && *contslur != '\0')
 
557
    sprintf(note + strlen(note), " %s", contslur);
 
558
}
 
559
 
 
560
 
 
561
Void renewPitch(voice, note)
 
562
short voice;
 
563
Char *note;
 
564
{
 
565
  short pstat;
 
566
  line_status *WITH;
 
567
 
 
568
  WITH = &current[voice-1];
 
569
  pstat = newPitch(voice, note, WITH->chord_pitch, WITH->chord_lastnote);
 
570
  if (debugMode())
 
571
    printf("Current pitch in voice %d is %d, last note was %c, this note is %s",
 
572
           voice, WITH->pitch, WITH->lastnote, note);
 
573
  WITH->pitch = newPitch(voice, note, WITH->pitch, WITH->lastnote);
 
574
  if (WITH->pitch != pstat)
 
575
    repitch(note, WITH->pitch - pstat);
 
576
  if (WITH->pitch < lowest_pitch && checkPitch()) {
 
577
    printf("Pitch of note %s following %c reported as %d",
 
578
           note, WITH->lastnote, WITH->pitch);
 
579
    error3(voice, "Pitch too low");
 
580
  }
 
581
  if (WITH->pitch > highest_pitch && checkPitch()) {
 
582
    printf("Pitch of note %s following %c reported as %d",
 
583
           note, WITH->lastnote, WITH->pitch);
 
584
    error3(voice, "Pitch too high");
 
585
  }
 
586
  WITH->lastnote = note[0];
 
587
  if (debugMode())
 
588
    printf(", repitched to %d\n", WITH->pitch);
 
589
  if (debugMode() && WITH->pitch != pstat)
 
590
    printf("Pitch from melodic line = %d   from last chordal note = %d\n",
 
591
           WITH->pitch, pstat);
 
592
}
 
593
 
 
594
 
 
595
short chordPitch(voice)
 
596
short voice;
 
597
{
 
598
  return (current[voice-1].chord_pitch);
 
599
}
 
600
 
 
601
 
 
602
Void renewChordPitch(voice, note)
 
603
short voice;
 
604
Char *note;
 
605
{
 
606
  line_status *WITH;
 
607
 
 
608
  WITH = &current[voice-1];
 
609
  WITH->chord_pitch = newPitch(voice, note, WITH->chord_pitch,
 
610
                               WITH->chord_lastnote);
 
611
  if (WITH->chord_pitch < lowest_pitch)
 
612
    error3(voice, "Pitch in chord too low");
 
613
  if (WITH->chord_pitch > highest_pitch)
 
614
    error3(voice, "Pitch in chord too high");
 
615
  WITH->chord_lastnote = note[0];
 
616
}
 
617
 
 
618
 
 
619
Void initStatus()
 
620
{
 
621
  short voice, FORLIM;
 
622
  line_status *WITH;
 
623
 
 
624
  FORLIM = nvoices;
 
625
  for (voice = 1; voice <= FORLIM; voice++) {
 
626
    WITH = &current[voice-1];
 
627
    WITH->duration = default_duration;
 
628
    WITH->octave_adjust = 0;
 
629
    WITH->slur_level = 0;
 
630
    WITH->beam_level = 0;
 
631
    WITH->beamed = false;
 
632
    WITH->beamnext = false;
 
633
    WITH->slurred = false;
 
634
    WITH->slurnext = false;
 
635
    WITH->after_slur = 0;
 
636
    WITH->octave = initOctave(voiceStave(voice));
 
637
    WITH->slurID = 'S';
 
638
    WITH->tieID = 'T';
 
639
    WITH->lastnote = 'f';
 
640
    WITH->pitch = (WITH->octave - '0') * 7 - 3;
 
641
    *WITH->chord_tie_label = '\0';
 
642
    saveStatus(voice);
 
643
  }
 
644
}
 
645
 
 
646
 
 
647
 
 
648
 
 
649
/* End. */