Debian Codegraph @

utils/autosp/autosp-src/spacing_note.c

raw
1
2 /* Copyright (C) 2014-23 R. D. Tennent School of Computing,
3 * Queen's University, [email protected]
4 *
5 * This program is free software; you can redistribute it
6 * and/or modify it under the terms of the GNU General
7 * Public License as published by the Free Software
8 * Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will
12 * be useful, but WITHOUT ANY WARRANTY; without even the
13 * implied warranty of MERCHANTABILITY or FITNESS FOR A
14 * PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU General
18 * Public License along with this program; if not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22
23 # include "process_command.h"
24
25 PRIVATE
26 void update_global_skip (int n)
27 /* global skips may be used in more than one staff */
28 {
29 if (n>6)
30 { warning ("Too many commas."); n = 6; }
31 if (global_skip < n) global_skip = n;
32 }
33
34 PRIVATE
35 int collective_note (int i)
36 { char *s = current[i];
37 int spacing = cspacing[i];
38 if (debug)
39 { fprintf (logfile, "\nEntering collective_note:\n");
40 status (i);
41 status_beam (i);
42 status_collective (i);
43 }
44 if (beaming[i] > 0 && spacing != beaming[i])
45 { /* adjust cspacing for new beaming */
46 cspacing[i] = beaming[i];
47 }
48 while (true) /* search for alphabetic or numeric note (or asterisk) */
49 { int n = 0;
50 while (*s == ',')
51 { n++; s++; } /* global skips */
52 update_global_skip (n);
53 /* commas will be discarded by filter_output (i) */
54 if (*s == '.' && new_beaming == 0 && !dottedbeamnotes)
55 spacing = spacing * 1.50;
56 else if ( (*s == '^' || *s == '_' || *s == '=' || *s == '>')
57 && !vspacing_active[i] /* is additional spacing needed? */
58 )
59 /* leave space for normal accidentals */
60 { update_global_skip (3) ;
61 if (debug)
62 { fprintf (logfile, "\nLeave space for accidental\n");
63 status (i);
64 status_beam (i);
65 status_collective (i);
66 }
67 }
68 else if ( (*s == '<') /* double-flat */
69 && !vspacing_active[i] /* is additional spacing needed? */
70 )
71 { update_global_skip (5);
72 if (debug)
73 { fprintf (logfile, "\nLeave space for double-flat\n");
74 status (i);
75 status_beam (i);
76 status_collective (i);
77 }
78 }
79 else if (isdigit (*s) )
80 {
81 s++;
82 while ( isdigit (*s) ) /* numerical note >= 10? */
83 s++;
84 current[i] = s;
85 if (debug)
86 { fprintf (logfile, "\nAfter collective_note:\n");
87 status (i);
88 status_collective (i);
89 }
90 vspacing_active[i] = false;
91 return spacing;
92 }
93 else if (isalpha (*s) || *s == '*')
94 {
95 s++;
96 while (*s == '\'' || *s == '`' || *s == '!')
97 /* transposition characters */
98 s++;
99 current[i] = s;
100 if (debug)
101 { fprintf (logfile, "\nAfter collective_note:\n");
102 status (i);
103 status_collective (i);
104 }
105 vspacing_active[i] = false;
106 return spacing;
107 }
108 s++;
109 }
110 }
111
112
113 PRIVATE
114 void beam_initiation (char *s, int i)
115 {
116 if ( prefix ("\\ibbbbbb", s)
117 || prefix ("\\Ibbbbbb", s)
118 || prefix ("\\nbbbbbb", s) )
119 beaming[i] = SP(256);
120 else if ( prefix ("\\ibbbbb", s)
121 || prefix ("\\Ibbbbb", s)
122 || prefix ("\\nbbbbb", s) )
123 beaming[i] = SP(128);
124 else if ( prefix ("\\ibbbb", s)
125 || prefix ("\\Ibbbb", s)
126 || prefix ("\\nbbbb", s) )
127 beaming[i] = SP(64);
128 else if ( prefix ("\\ibbb", s)
129 || prefix ("\\Ibbb", s)
130 || prefix ("\\nbbb", s) )
131 beaming[i] = SP(32);
132 else if ( prefix ("\\ibb", s)
133 || prefix ("\\uibb", s)
134 || prefix ("\\Ibb", s)
135 || prefix ("\\nbb", s)
136 || prefix ("\\unbb", s) )
137 beaming[i] = SP(16);
138 else if ( prefix ("\\ib", s)
139 || prefix ("\\uib", s)
140 || prefix ("\\Ib", s) )
141 beaming[i] = SP(8);
142 if (debug)
143 { fprintf (logfile, "\nAfter beam_initiation:\n");
144 status (i);
145 status_beam (i);
146 }
147 }
148
149 PRIVATE
150 void beam_termination (char *s, int i)
151 {
152 if (debug)
153 { fprintf (logfile, "\nEntering beam_termination:\n");
154 status (i);
155 status_beam (i);
156 }
157 if ( prefix ("\\tbbbbbb", s) )
158 {
159 new_beaming = SP(128);
160 if (beaming[i] > SP(256))
161 beaming[i] = SP(256);
162 }
163 else if ( prefix ("\\tbbbbb", s) )
164 {
165 new_beaming = SP(64);
166 if (beaming[i] > SP(128))
167 beaming[i] = SP(128);
168 }
169 else if ( prefix ("\\tbbbb", s) )
170 {
171 new_beaming = SP(32);
172 if (beaming[i] > SP(64))
173 beaming[i] = SP(64);
174 }
175 else if ( prefix ("\\tbbb", s) )
176 {
177 new_beaming = SP(16);
178 if (beaming[i] > SP(32))
179 beaming[i] = SP(32);
180 }
181 else if ( prefix ("\\tbb", s)
182 || prefix ("\\utbb", s) )
183 {
184 new_beaming = SP(8);
185 if (beaming[i] > SP(16))
186 beaming[i] = SP(16);
187 }
188 else if ( prefix ("\\tb", s)
189 || prefix ("\\utb", s) )
190 {
191 new_beaming = 0;
192 }
193 if (debug)
194 { fprintf (logfile, "\nAfter beam_termination:\n");
195 status (i);
196 status_beam (i);
197 }
198 }
199
200 PRIVATE
201 char *skip_balanced_text (char *s)
202 {
203 char *t;
204 do
205 {
206 t = strpbrk (s, "{}");
207 if (t == NULL) error ("Expected '}'");
208 if (*t == '{') t = skip_balanced_text (t+1);
209 }
210 while (*t != '}');
211 return t+1;
212 }
213
214 PRIVATE
215 char *skip_arg (char *s)
216 {
217 while (*s == ' ') s++;
218 if (*s == '{')
219 { s++;
220 skip_balanced_text (s);
221 }
222 else
223 s++;
224 return s;
225 }
226
227 int spacing_note (int i)
228 /* Search from current[i] for the next spacing note in the ith staff.
229 * Returns the spacing value and updates current[i].
230 */
231 {
232 int spacing = MAX_SPACING;
233 char *s, *t;
234 bool tinynotesize = false;
235 bool doubledotted = false;
236 bool dotted = false;
237 new_beaming = 0;
238 if (!active[i]) return spacing;
239 if (vspacing[i] > 0)
240 { /* virtual note (i.e., a skip) */
241 return vspacing[i];
242 }
243 if (collective[i][0])
244 {
245 nonvirtual_notes = true;
246 return collective_note (i);
247 }
248 if (semiauto_beam_notes[i] > 0)
249 { if (debug)
250 fprintf (logfile, "\nsemiauto_beam_notes reduced\n");
251 semiauto_beam_notes[i]--;
252 current[i]++;
253 if (debug) status (i);
254 nonvirtual_notes = true;
255 return beaming[i];
256 }
257 s = strpbrk (current[i], "\\&|$");
258 if (*s != '\\')
259 { return spacing; }
260 if (debug)
261 { fprintf (logfile, "\nIn spacing_note:\n");
262 status (i);
263 }
264 while (true)
265 {
266 if ( prefix ("\\wh", s)
267 || prefix ("\\breve", s)
268 || prefix ("\\pause", s)
269 || prefix ("\\wq", s) )
270 { spacing = SP(1); break; }
271
272 if ( prefix ("\\ha", s)
273 || (prefix ("\\hl", s) && !prefix ( "\\hloff", s) )
274
275 || prefix ("\\hu", s)
276 || prefix ("\\hp", s)
277 || prefix ("\\hpause", s) )
278 { spacing = SP(2); break;}
279
280 if ( prefix ("\\qa", s)
281 || prefix ("\\uq", s)
282 || prefix ("\\qu", s)
283 || prefix ("\\qp", s)
284 || prefix ("\\ql", s) )
285 { spacing = SP(4); break; }
286
287 if ( ( prefix ("\\ca", s)
288 || prefix ("\\uc", s)
289 || prefix ("\\cu", s)
290 || prefix ("\\cl", s) )
291 && !prefix ("\\caesura", s ) )
292 { spacing = SP(8); break; }
293
294 if ( prefix ("\\ds", s )
295 && !prefix ("\\dsh", s) )
296 { spacing = SP(8); break; }
297
298 if ( prefix ("\\cccc", s) )
299 { spacing = SP(64); break; }
300
301 if ( prefix ("\\ccc", s) )
302 { spacing = SP(32); break; }
303
304 if ( ( prefix ("\\cc", s)
305 || prefix ("\\ucc", s) )
306 && !prefix ("\\ccn", s)
307 && !prefix ("\\cchar", s) )
308 { spacing = SP(16); break; }
309
310 if ( prefix ("\\qs", s)
311 && !prefix ("\\qsk", s)
312 && !prefix ("\\qspace", s) )
313 { spacing = SP(16); break; }
314
315 if ( prefix ("\\hs", s)
316 && !prefix ("\\hsk", s)
317 && !prefix ("\\hsp", s) )
318 { spacing = SP(32); break;}
319
320 if ( prefix ("\\qqs", s )
321 && !prefix ("\\qqsk", s) )
322 { spacing = SP(64); break; }
323
324 if ( prefix ("\\ub", s)
325 || prefix ("\\qb", s)) /* beam note */
326 { spacing = beaming[i];
327 if (new_beaming != 0) /* set by preceding \tb... */
328 { beaming[i] = new_beaming;
329 new_beaming = 0;
330 }
331 if (debug)
332 { fprintf (logfile, "\nBeam note:\n");
333 status (i);
334 status_beam (i);
335 }
336 break;
337 }
338
339 if ( prefix ("\\Cpause", s)
340 || prefix ("\\Cp", s))
341 { /* bar-centered rest */
342 bar_rest[i] = true;
343 spacing = MAX_SPACING;
344 break;
345 }
346
347 if (prefix("\\tqqq", s) )
348 { if (beaming[i] > SP(32))
349 beaming[i] = SP(32);
350 spacing = beaming[i];
351 beaming[i] = 0;
352 new_beaming = 0;
353 if (debug)
354 { fprintf (logfile, "\nAfter beam completion:\n");
355 status (i);
356 status_beam (i);
357 }
358 break;
359 }
360
361 if (prefix("\\nqqq", s) )
362 { if (beaming[i] > SP(32))
363 beaming[i] = SP(32);
364 spacing = beaming[i];
365 beaming[i] = SP(16);
366 new_beaming = 0;
367 if (debug)
368 { fprintf (logfile, "\nAfter beam completion:\n");
369 status (i);
370 status_beam (i);
371 }
372 break;
373 }
374
375 if (prefix("\\tqq", s) )
376 { if (beaming[i] > SP(16))
377 beaming[i] = SP(16);
378 spacing = beaming[i];
379 beaming[i] = 0;
380 new_beaming = 0;
381 if (debug)
382 { fprintf (logfile, "\nAfter beam completion:\n");
383 status (i);
384 status_beam (i);
385 }
386 break;
387 }
388
389 if (prefix("\\nqq", s) )
390 { if (beaming[i] > SP(16))
391 beaming[i] = SP(16);
392 spacing = beaming[i];
393 beaming[i] = SP(8);
394 new_beaming = 0;
395 if (debug)
396 { fprintf (logfile, "\nAfter beam completion:\n");
397 status (i);
398 status_beam (i);
399 }
400 break;
401 }
402
403 if ( ( prefix("\\tq", s) && !prefix("\\tqsk", s))
404 || prefix("\\utq", s) )
405 { spacing = beaming[i];
406 beaming[i] = 0;
407 new_beaming = 0;
408 if (debug)
409 { fprintf (logfile, "\nAfter beam completion:\n");
410 status (i);
411 status_beam (i);
412 }
413 break;
414 }
415
416
417 /* non-spacing commands: */
418
419 if ( prefix ("\\ib", s)
420 || prefix ("\\uib", s)
421 || prefix ("\\Ib", s)
422 || prefix ("\\nb", s)
423 || prefix ("\\unb", s) )
424 beam_initiation (s, i);
425
426 else if ( prefix("\\tb", s)
427 || prefix("\\utb", s) )
428 beam_termination (s, i);
429
430 else if ( prefix("\\ztq", s) )
431 /* non-spacing beam termination */
432 new_beaming = 0;
433
434 else if ( prefix("\\xtuplet", s) ||
435 prefix("\\xxtuplet", s)||
436 prefix("\\Xtuplet", s) )
437 { char *t = s+1;
438 while (!isdigit(*t)) t++;
439 xtuplet[i] = atoi(t);
440 }
441 else
442 if ( prefix("\\triolet", s)
443 || prefix("\\Triolet", s)
444 || prefix("\\uptrio", s)
445 || prefix("\\downtrio", s)
446 || prefix("\\uptuplet", s)
447 || prefix("\\downtuplet", s) )
448 {
449 xtuplet[i] = 3;
450 }
451
452 else if ( prefix("\\zchar", s)
453 || prefix("\\lchar", s)
454 || prefix("\\cchar", s)
455 || prefix("\\zcn", s)
456 || prefix("\\lcn", s)
457 || prefix("\\ccn", s) )
458 { /* need to skip two arguments, possibly with embedded commands */
459 char *t;
460 t = strpbrk (s+1, " {");
461 if (t == NULL) error ("Argument expected");
462 t = skip_arg (t);
463 t = skip_arg (t);
464 }
465
466 else if ( prefix("\\tinynotesize", s) )
467 {
468 tinynotesize = true;
469 appoggiatura = true;
470 }
471
472 else if (prefix("\\ppt", s)
473 || prefix("\\pppt", s) )
474 {
475 doubledotted = true; /* triple-dotted spaced as double-dotted */
476 }
477 else if (prefix("\\pt", s) && !prefix("\\ptr", s))
478 {
479 dotted = true;
480 }
481 else if ( prefix ("\\Dqbb", s) )
482 { semiauto_beam_notes[i] = 1;
483 beaming[i] = SP(16);
484 current[i] = current[i] + 8;
485 nonvirtual_notes = true;
486 return beaming[i];
487 }
488 else if ( prefix ("\\Dqb", s) )
489 { if (debug) fprintf (logfile, "\nFound \\Dqb\n");
490 semiauto_beam_notes[i] = 1;
491 beaming[i] = SP(8);
492 current[i] = current[i] + 7;
493 nonvirtual_notes = true;
494 if (debug) status (i);
495 return beaming[i];
496 }
497 else if ( prefix ("\\Tqbb", s) )
498 { semiauto_beam_notes[i] = 2;
499 beaming[i] = SP(16);
500 current[i] = current[i] + 8;
501 nonvirtual_notes = true;
502 return beaming[i];
503 }
504 else if ( prefix ("\\Tqb", s) )
505 { semiauto_beam_notes[i] = 2;
506 beaming[i] = SP(8);
507 current[i] = current[i] + 7;
508 nonvirtual_notes = true;
509 return beaming[i];
510 }
511 else if ( prefix ("\\Qqbb", s) )
512 { semiauto_beam_notes[i] = 3;
513 beaming[i] = SP(16);
514 current[i] = current[i] + 8;
515 nonvirtual_notes = true;
516 return beaming[i];
517 }
518 else if ( prefix ("\\Qqb", s) )
519 { semiauto_beam_notes[i] = 3;
520 beaming[i] = SP(8);
521 current[i] = current[i] + 7;
522 nonvirtual_notes = true;
523 return beaming[i];
524 }
525 else if (prefix ("\\rlap", s) )
526 /* skip the argument, as it must be regarded as non-spacing */
527 { char *t;
528 t = strpbrk (s+1, " {\\");
529 if (t == NULL) error ("Argument expected");
530 if (*t == '\\')
531 s = t+1;
532 else
533 s = skip_arg(t);
534 }
535 else if (prefix ("\\Hsk", s) )
536 update_global_skip (5);
537 else if (prefix ("\\Qsk", s) )
538 update_global_skip (4);
539 else if (prefix ("\\TQsk", s) )
540 update_global_skip (3);
541 else if (prefix ("\\HQsk", s) )
542 update_global_skip (2);
543 else if (prefix ("\\QQsk", s) )
544 update_global_skip (1);
545
546 /* Command is non-spacing. */
547 /* Skip ahead to the next command. */
548 s = strpbrk (s+1, "\\&|$");
549
550 if ( *s != '\\')
551 { current[i] = s;
552 if (debug)
553 { fprintf (logfile, "\nAfter spacing_note:\n");
554 status (i);
555 }
556 return spacing;
557 }
558 } /* end of while (true) loop */
559
560 if (spacing < MAX_SPACING)
561 nonvirtual_notes = true;
562 if (prefix ("\\whpp", s)
563 || prefix ("\\hupp", s)
564 || prefix ("\\hlpp", s)
565 || prefix ("\\happ", s)
566 || prefix ("\\hspp", s)
567 || prefix ("\\hppp", s)
568 || prefix ("\\hpausepp", s)
569 || prefix ("\\qupp", s)
570 || prefix ("\\qlpp", s)
571 || prefix ("\\qapp", s)
572 || prefix ("\\qspp", s)
573 || prefix ("\\qppp", s)
574 || prefix ("\\qqspp", s)
575 || prefix ("\\cupp", s)
576 || prefix ("\\clpp", s)
577 || prefix ("\\ccupp", s)
578 || prefix ("\\cclpp", s)
579 || prefix ("\\cccupp", s)
580 || prefix ("\\ccclpp", s)
581 || prefix ("\\qbpp", s)
582 || prefix ("\\dspp", s)
583 || doubledotted )
584 { spacing *= 1.75; doubledotted = false;}
585 else
586 if (prefix ("\\whp", s)
587 || prefix ("\\hup", s)
588 || prefix ("\\hlp", s)
589 || prefix ("\\hap", s)
590 || prefix ("\\hsp", s)
591 || prefix ("\\hpp", s)
592 || prefix ("\\hpausep", s)
593 || prefix ("\\qup", s)
594 || prefix ("\\qlp", s)
595 || prefix ("\\qap", s)
596 || prefix ("\\qsp", s)
597 || prefix ("\\qqsp", s)
598 || prefix ("\\qpp", s)
599 || prefix ("\\cup", s)
600 || prefix ("\\clp", s)
601 || prefix ("\\ccup", s)
602 || prefix ("\\cclp", s)
603 || prefix ("\\cccup", s)
604 || prefix ("\\ccclp", s)
605 || prefix ("\\qbp", s)
606 || prefix ("\\dsp", s)
607 || dotted )
608 { spacing *= 1.5; dotted = false; }
609
610 t = strpbrk (s+1, "{\\&|$"); /* collective coding? */
611 if (*t == '{' ) /* {...} */
612 { /* Save prefix in collective[i].
613 * It will be output for every note in the collective */
614 char *ss = s;
615 char *tt = collective[i];
616 while (ss <= t)
617 { *tt = *ss; tt++, ss++; }
618 *tt = '\0';
619 current[i] = t+1;
620 if (tinynotesize) spacing = APPOGG_SPACING;
621 cspacing[i] = spacing;
622 first_collective[i] = true;
623 return collective_note (i);
624 }
625 if (tinynotesize) spacing = APPOGG_SPACING;
626 current[i] = strpbrk (s+1, "\\&|$");
627 if (debug)
628 { fprintf (logfile, "\nAfter spacing_note:\n");
629 status (i);
630 }
631 vspacing_active[i] = false;
632 return spacing;
633 }