Debian Codegraph @

texk/gregorio/gregorio-src/src/gabc/gabc-notes-determination.l

raw
1 %{
2 /*
3 * Gregorio is a program that translates gabc files to GregorioTeX
4 * This file implements the note parser.
5 *
6 * Copyright (C) 2006-2025 The Gregorio Project (see CONTRIBUTORS.md)
7 *
8 * This file is part of Gregorio.
9 *
10 * This program is free software: you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation, either version 3 of the License, or (at your option)
13 * any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * more details.
19 *
20 * You should have received a copy of the GNU General Public License along with
21 * this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24 #include "config.h"
25 #include <stdio.h>
26 #include <ctype.h> /* for tolower */
27 #include "bool.h"
28 #include "struct.h"
29 #include "messages.h"
30 #include "support.h"
31
32 #include "gabc.h"
33
34 #define YY_NO_INPUT
35
36 #define YY_USER_ACTION gabc_update_location(&notes_lloc, \
37 gabc_notes_determination_text, gabc_notes_determination_leng);
38
39 static gregorio_scanner_location notes_lloc;
40 static gregorio_note *current_note;
41 static char char_for_brace;
42 static unsigned int nbof_isolated_episema;
43 static char *notesmacros[10];
44 static char tempstr[256];
45 static unsigned short overbrace_var = 0, underbrace_var = 0;
46 static const char *overbrace_var_kind;
47 static int before_ledger_type;
48 static char *before_ledger_length = NULL;
49 static unsigned short ledger_var[2] = { 0, 0 };
50 static unsigned char staff_lines;
51 static signed char highest_pitch;
52 static signed char high_ledger_line_pitch;
53 static bool legacy_oriscus_orientation;
54 static unsigned short he_adjustment_index[2] = { 0, 0 };
55 static signed char bracket_low_pitch, bracket_high_pitch;
56 static unsigned short left_bracket_texverb = 0;
57
58 #define LEDGER(WHICH, SPECIFICITY, VALUE) \
59 if (LEDGER_##SPECIFICITY > current_note->WHICH##_ledger_specificity) { \
60 current_note->WHICH##_ledger_line = VALUE; \
61 current_note->WHICH##_ledger_specificity = LEDGER_##SPECIFICITY; \
62 }
63
64 typedef struct slur_info {
65 unsigned short var;
66 char shift;
67 gregorio_note *start;
68 } slur_info;
69
70 static slur_info slur[2] = { { 0, '\0', NULL }, { 0, '\0', NULL } };
71
72 static __inline gregorio_sign_orientation letter_to_sign_orientation(
73 const char letter) {
74 switch (letter) {
75 case 'u': /* "u"under */
76 return SO_UNDER;
77 case 'o': /* "o"ver */
78 return SO_OVER;
79 }
80 /* not reachable unless there's a programming error */
81 /* LCOV_EXCL_START */
82 gregorio_fail2(letter_to_sign_orientation,
83 "invalid sign orientation letter: %c", letter);
84 return SO_OVER;
85 /* LCOV_EXCL_STOP */
86 }
87
88 static __inline int letter_to_pitch_adjustment(const char letter) {
89 switch (letter_to_sign_orientation(letter)) {
90 case SO_OVER:
91 return 1;
92 case SO_UNDER:
93 return -1;
94 }
95 /* not reachable unless there's a programming error */
96 /* LCOV_EXCL_START */
97 gregorio_fail2(letter_to_pitch_adjustment,
98 "invalid sign orientation letter: %c", letter);
99 return 0;
100 /* LCOV_EXCL_STOP */
101 }
102
103 static __inline signed char pitch_letter_to_height(const char pitch) {
104 char result = pitch - 'a' + LOWEST_PITCH;
105 if (pitch == 'p') {
106 --result;
107 }
108 if (result > highest_pitch) {
109 gregorio_messagef("pitch_letter_to_height", VERBOSITY_ERROR, 0,
110 _("invalid pitch for %u lines: %c"), (unsigned int)staff_lines,
111 pitch);
112 }
113 if (left_bracket_texverb) {
114 if (result < bracket_low_pitch) {
115 bracket_low_pitch = result;
116 }
117 if (result > bracket_high_pitch) {
118 bracket_high_pitch = result;
119 }
120 }
121 return result;
122 }
123
124 static gregorio_shape punctum_inclinatum(const char orientation)
125 {
126 switch (orientation) {
127 case '0':
128 return S_PUNCTUM_INCLINATUM_DESCENDENS;
129
130 case '2':
131 return S_PUNCTUM_INCLINATUM_STANS;
132
133 case '1':
134 return S_PUNCTUM_INCLINATUM_ASCENDENS;
135 }
136
137 return S_PUNCTUM_INCLINATUM_UNDETERMINED;
138 }
139
140 static __inline void lex_add_note(int i, gregorio_shape shape, char signs,
141 char liquescentia)
142 {
143 signed char height = pitch_letter_to_height(tolower(
144 (unsigned char)gabc_notes_determination_text[i]));
145
146 nbof_isolated_episema = 0;
147 gregorio_add_note(&current_note, height, shape, signs, liquescentia, NULL,
148 &notes_lloc);
149 current_note->he_adjustment_index[SO_OVER] = he_adjustment_index[SO_OVER];
150 current_note->he_adjustment_index[SO_UNDER] = he_adjustment_index[SO_UNDER];
151
152 if (height >= high_ledger_line_pitch) {
153 LEDGER(high, DRAWN, true);
154 } else if (ledger_var[SO_OVER]) {
155 LEDGER(high, EXPLICIT, true);
156 }
157
158 if (height <= LOW_LEDGER_LINE_PITCH) {
159 LEDGER(low, DRAWN, true);
160 } else if (ledger_var[SO_UNDER]) {
161 LEDGER(low, EXPLICIT, true);
162 }
163 }
164
165 static __inline void add_bar_as_note(gregorio_bar bar)
166 {
167 nbof_isolated_episema = 0;
168 gregorio_add_bar_as_note(&current_note, bar, &notes_lloc);
169 }
170
171 static __inline void error(void)
172 {
173 gregorio_messagef("gabc_notes_determination", VERBOSITY_ERROR, 0,
174 _("undefined macro used: m%d"),
175 gabc_notes_determination_text[3] - '0');
176 }
177
178 static void add_h_episema(void)
179 {
180 grehepisema_size size = H_NORMAL;
181 gregorio_vposition vposition = VPOS_AUTO;
182 bool disable_bridge = false;
183
184 char *ptr = gabc_notes_determination_text;
185 char current;
186 /* first character is the underscore */
187 while ((current = *(++ptr))) {
188 switch(current) {
189 case '0':
190 vposition = VPOS_BELOW;
191 break;
192 case '1':
193 vposition = VPOS_ABOVE;
194 break;
195 case '2':
196 disable_bridge = true;
197 break;
198 case '3':
199 size = H_SMALL_LEFT;
200 break;
201 case '4':
202 size = H_SMALL_CENTRE;
203 break;
204 case '5':
205 size = H_SMALL_RIGHT;
206 break;
207 default:
208 /* not reachable unless there's a programming error */
209 /* LCOV_EXCL_START */
210 gregorio_fail2(gabc_notes_determination,
211 "unrecognized horizontal episema modifier: %c", current);
212 break;
213 /* LCOV_EXCL_STOP */
214 };
215 }
216
217 gregorio_add_h_episema(current_note, size, vposition, disable_bridge,
218 &nbof_isolated_episema);
219 }
220
221 static void add_sign(gregorio_sign sign)
222 {
223 gregorio_vposition vposition = VPOS_AUTO;
224 switch(gabc_notes_determination_text[1]) {
225 case '0':
226 vposition = VPOS_BELOW;
227 break;
228 case '1':
229 vposition = VPOS_ABOVE;
230 break;
231 }
232 gregorio_add_sign(current_note, sign, vposition);
233 }
234
235 static void save_before_ledger(const char *const before_ledger)
236 {
237 if (strcmp(before_ledger, "0") == 0) {
238 before_ledger_type = 0;
239 before_ledger_length = "";
240 } else if (strcmp(before_ledger, "1") == 0) {
241 before_ledger_type = 1;
242 before_ledger_length = "";
243 } else {
244 before_ledger_type = 2;
245 before_ledger_length = gregorio_strdup(before_ledger);
246 }
247 }
248
249 static void add_static_ledger(const gregorio_sign_orientation type,
250 const char *length) {
251 gregorio_snprintf(tempstr, sizeof tempstr,
252 "\\GreDrawAdditionalLine{%d}{%s}{%d}{%s}{0}{}",
253 type, length + 1, before_ledger_type, before_ledger_length);
254
255 if (before_ledger_type == 2) {
256 free(before_ledger_length);
257 before_ledger_length = NULL;
258 }
259
260 gregorio_add_texverb_as_note(&current_note, gregorio_strdup(tempstr),
261 GRE_TEXVERB_GLYPH, &notes_lloc);
262 }
263
264 static __inline const char *over_or_under(
265 const gregorio_sign_orientation type) {
266 switch (type) {
267 case SO_OVER:
268 return "over";
269 case SO_UNDER:
270 return "under";
271 }
272 /* not reachable unless there's a programming error */
273 /* LCOV_EXCL_START */
274 gregorio_fail2(over_or_under, "invalid ledger type %d", type);
275 return "";
276 /* LCOV_EXCL_STOP */
277 }
278
279 static void add_variable_ledger(const gregorio_sign_orientation type,
280 const char *after_ledger)
281 {
282 if (ledger_var[type]) {
283 const char *const typename = over_or_under(type);
284 gregorio_messagef("add_variable_ledger", VERBOSITY_ERROR, 0,
285 _("variable %s-staff ledger line without termination of "
286 "previous %s-staff ledger line"), typename, typename);
287 } else {
288 int after_ledger_type;
289 const char *after_ledger_length;
290
291 ++after_ledger;
292
293 if (strcmp(after_ledger, "0") == 0) {
294 after_ledger_type = 0;
295 after_ledger_length = "";
296 } else if (strcmp(after_ledger, "1") == 0) {
297 after_ledger_type = 1;
298 after_ledger_length = "";
299 } else {
300 after_ledger_type = 2;
301 after_ledger_length = after_ledger;
302 }
303
304 ledger_var[type] = ++tex_position_id;
305 gregorio_snprintf(tempstr, sizeof tempstr,
306 "\\GreVarBraceSavePos{%hu}{0}{1}"
307 "\\GreDrawAdditionalLine{%d}{\\GreVarBraceLength{%hu}}"
308 "{%d}{%s}{%d}{%s}",
309 ledger_var[type], type, ledger_var[type], before_ledger_type,
310 before_ledger_length, after_ledger_type, after_ledger_length);
311
312 if (before_ledger_type == 2) {
313 free(before_ledger_length);
314 before_ledger_length = NULL;
315 }
316
317 gregorio_add_texverb_as_note(&current_note, gregorio_strdup(tempstr),
318 GRE_TEXVERB_GLYPH, &notes_lloc);
319 }
320 }
321
322 static void end_variable_ledger(const gregorio_sign_orientation type)
323 {
324 if (!ledger_var[type]) {
325 const char *const typename = over_or_under(type);
326 gregorio_messagef("end_variable_ledger", VERBOSITY_ERROR, 0,
327 _("variable %s-staff ledger line termination without variable "
328 "%s-staff ledger line start"), typename, typename);
329 } else {
330 gregorio_snprintf(tempstr, sizeof tempstr,
331 "\\GreVarBraceSavePos{%hu}{0}{2}", ledger_var[type]);
332 ledger_var[type] = 0;
333 gregorio_add_texverb_as_note(&current_note, gregorio_strdup(tempstr),
334 GRE_TEXVERB_GLYPH, &notes_lloc);
335 }
336 }
337
338 static __inline int parse_clef_line(char line)
339 {
340 line -= '0';
341 if (line < 0 || line > staff_lines) {
342 gregorio_messagef("parse_clef_line", VERBOSITY_ERROR, 0,
343 _("invalid clef line for %u lines: %d"),
344 (unsigned int)staff_lines, (int)line);
345 return 1;
346 }
347 return line;
348 }
349
350 static __inline gregorio_bar parse_dominican_bar(char bar)
351 {
352 bar -= '0';
353 if (bar < 1 || bar > (2 * (staff_lines - 1))) {
354 gregorio_messagef("parse_dominican_line", VERBOSITY_ERROR, 0,
355 _("invalid Dominican bar for %u lines: ;%d"),
356 (unsigned int)staff_lines, (int)bar);
357 }
358
359 switch (bar) {
360 case 1:
361 return B_DIVISIO_MINOR_D1;
362 case 2:
363 return B_DIVISIO_MINOR_D2;
364 case 3:
365 return B_DIVISIO_MINOR_D3;
366 case 4:
367 return B_DIVISIO_MINOR_D4;
368 case 5:
369 return B_DIVISIO_MINOR_D5;
370 case 6:
371 return B_DIVISIO_MINOR_D6;
372 case 7:
373 return B_DIVISIO_MINOR_D7;
374 case 8:
375 return B_DIVISIO_MINOR_D8;
376 }
377 /* not reachable unless there's a programming error */
378 /* LCOV_EXCL_START */
379 gregorio_fail2(check_dominican_line, "invalid dominican bar: %d", (int)bar);
380 return B_NO_BAR;
381 /* LCOV_EXCL_STOP */
382 }
383
384 static __inline gregorio_clef letter_to_clef(char letter)
385 {
386 switch (letter) {
387 case 'c':
388 return CLEF_C;
389 case 'f':
390 return CLEF_F;
391 }
392 /* not reachable unless there's a programming error */
393 /* LCOV_EXCL_START */
394 gregorio_fail2(letter_to_clef, "invalid clef: %c", letter);
395 return CLEF_C;
396 /* LCOV_EXCL_STOP */
397 }
398
399 /* this assertion should only fail if the lex rules are incorrect */
400 static __inline void slur_assert(char *fn, bool test) {
401 if (!test) {
402 /* not reachable unless there's a programming error */
403 /* LCOV_EXCL_START */
404 gregorio_message(_("invalid slur text"), fn, VERBOSITY_FATAL, 0);
405 exit(1);
406 /* LCOV_EXCL_STOP */
407 }
408 }
409
410 static char *parse_slur_shift(char *shift)
411 {
412 char *c;
413
414 c = strchr(gabc_notes_determination_text, ':');
415 slur_assert("parse_slur_shift", c != NULL);
416 slur_assert("parse_slur_shift", *(++c) != '\0');
417 *shift = *c;
418 return c;
419 }
420
421 static void parse_slur(void)
422 {
423 const int direction = letter_to_pitch_adjustment(
424 gabc_notes_determination_text[1]);
425 char shift, *width, *height, *end;
426
427 if (!current_note || current_note->type != GRE_NOTE) {
428 gregorio_message(
429 _("cannot add a slur to something that is not a note"),
430 "parse_slur", VERBOSITY_ERROR, 0);
431 return;
432 }
433
434 end = parse_slur_shift(&shift);
435 width = strchr(end, ';');
436 slur_assert("parse_slur", width != NULL);
437 height = strchr(++width, ',');
438 slur_assert("parse_slur", height != NULL);
439 *height = '\0';
440 end = strchr(++height, ']');
441 slur_assert("parse_slur", end != NULL);
442 *end = '\0';
443
444 gregorio_snprintf(tempstr, sizeof tempstr,
445 "\\GreSlur{%d}{%d}{%c}{%s}{%s}{}",
446 current_note->u.note.pitch + direction, direction, shift, width,
447 height);
448 gregorio_add_texverb_to_note(current_note, gregorio_strdup(tempstr));
449 }
450
451 static void start_var_slur(void)
452 {
453 const gregorio_sign_orientation index = letter_to_sign_orientation(
454 gabc_notes_determination_text[1]);
455
456 if (!current_note || current_note->type != GRE_NOTE) {
457 gregorio_message(
458 _("cannot add a slur to something that is not a note"),
459 "start_var_slur", VERBOSITY_ERROR, 0);
460 return;
461 }
462
463 if (slur[index].var) {
464 gregorio_messagef("start_var_slur", VERBOSITY_ERROR, 0,
465 _("variable %s-note slur without termination of previous slur"),
466 over_or_under(index));
467 return;
468 }
469
470 slur[index].var = ++tex_position_id;
471 parse_slur_shift(&(slur[index].shift));
472 slur[index].start = current_note;
473 }
474
475 static void end_var_slur(void)
476 {
477 const int direction = letter_to_pitch_adjustment(
478 gabc_notes_determination_text[1]);
479 const gregorio_sign_orientation index = letter_to_sign_orientation(
480 gabc_notes_determination_text[1]);
481 char shift;
482
483 if (!current_note || current_note->type != GRE_NOTE) {
484 gregorio_message(
485 _("cannot add a slur to something that is not a note"),
486 "end_var_slur", VERBOSITY_ERROR, 0);
487 return;
488 }
489
490 if (!slur[index].var || !slur[index].shift || !slur[index].start) {
491 gregorio_messagef("end_var_slur", VERBOSITY_ERROR, 0,
492 _("variable %s-note slur end without start"),
493 over_or_under(index));
494 return;
495 }
496
497 parse_slur_shift(&shift);
498
499 gregorio_snprintf(tempstr, sizeof tempstr,
500 "\\GreVarBraceSavePos{%hu}{%c}{1}"
501 "\\GreSlur{%d}{%d}{%c}{\\GreVarBraceLength{%hu}}{}{%d}",
502 slur[index].var, slur[index].shift,
503 slur[index].start->u.note.pitch + direction, direction,
504 slur[index].shift, slur[index].var,
505 current_note->u.note.pitch + direction);
506 gregorio_add_texverb_to_note(slur[index].start, gregorio_strdup(tempstr));
507
508 gregorio_snprintf(tempstr, sizeof tempstr,
509 "\\GreVarBraceSavePos{%hu}{%c}{2}", slur[index].var, shift);
510 gregorio_add_texverb_to_note(current_note, gregorio_strdup(tempstr));
511
512
513 slur[index].var = 0;
514 slur[index].shift = '\0';
515 slur[index].start = NULL;
516 }
517
518 static void left_bracket(void)
519 {
520 if (left_bracket_texverb) {
521 gregorio_message(
522 _("cannot add a left bracket before closing the previous one"),
523 "left_bracket", VERBOSITY_ERROR, 0);
524 return;
525 }
526
527 /* when setting the left bracket, temporarily store the point-and-click
528 * information in the texverb */
529 if (notes_lloc.generate_point_and_click) {
530 gregorio_snprintf(tempstr, sizeof tempstr, "%u:%u:%u",
531 notes_lloc.first_line, notes_lloc.first_offset,
532 notes_lloc.first_column + 1);
533 } else {
534 tempstr[0] = '\0';
535 }
536 left_bracket_texverb = gregorio_add_texverb_as_note(&current_note,
537 gregorio_strdup(tempstr), GRE_TEXVERB_GLYPH, &notes_lloc);
538 bracket_low_pitch = MAX_PITCH;
539 bracket_high_pitch = LOWEST_PITCH;
540 }
541
542 static void right_bracket(void)
543 {
544 if (!left_bracket_texverb) {
545 gregorio_message(
546 _("cannot add a right bracket without a matching left bracket"),
547 "right_bracket", VERBOSITY_ERROR, 0);
548 return;
549 }
550
551 if (bracket_high_pitch < bracket_low_pitch) {
552 gregorio_message(
553 _("cannot add brackets without notes between them"),
554 "right_bracket", VERBOSITY_ERROR, 0);
555 return;
556 }
557
558 gregorio_snprintf(tempstr, sizeof tempstr, "\\GreBracket{0}{%d}{%d}{%s}",
559 bracket_low_pitch, bracket_high_pitch,
560 gregorio_texverb(left_bracket_texverb));
561 gregorio_change_texverb(left_bracket_texverb, gregorio_strdup(tempstr));
562
563 if (notes_lloc.generate_point_and_click) {
564 gregorio_snprintf(tempstr, sizeof tempstr,
565 "\\GreBracket{1}{%d}{%d}{%u:%u:%u}", bracket_low_pitch,
566 bracket_high_pitch, notes_lloc.first_line,
567 notes_lloc.first_offset, notes_lloc.first_column + 1);
568 } else {
569 gregorio_snprintf(tempstr, sizeof tempstr,
570 "\\GreBracket{1}{%d}{%d}{}", bracket_low_pitch,
571 bracket_high_pitch);
572 }
573 gregorio_add_texverb_as_note(&current_note, gregorio_strdup(tempstr),
574 GRE_TEXVERB_GLYPH, &notes_lloc);
575
576 left_bracket_texverb = 0;
577 }
578
579 static void parse_hepisema_adjustment(void)
580 {
581 /* See https://github.com/gregorio-project/gregorio/issues/872
582 *
583 * [xh:yzw]
584 *
585 * - x is o(ver) or u(under)
586 * - y is optional and is
587 * - l for low in the space (chooses ol or ul depending on x)
588 * - m for middle of the space
589 * - h for high in the space (chooses oh or uh depending on x)
590 * - ol for low in the space as if the episema were over the note
591 * - oh for high in the space as if the episema were over the note
592 * - ul for low in the space as if the episema were under the note
593 * - uh for high in the space as if the episema were under the note
594 * - z is an optional nudge and must start with + or -
595 * - w is optional and may be { to start a range or } to end a range.
596 *
597 * at least one of y, z, or w must be provided
598 * if y and z are omitted, the : may be omitted
599 * y and z are not permitted when w is }
600 */
601
602 const gregorio_sign_orientation index = letter_to_sign_orientation(
603 gabc_notes_determination_text[1]);
604 gregorio_sign_orientation det_index = index;
605 char *ch = gabc_notes_determination_text + 3;
606 gregorio_hepisema_vbasepos vbasepos = HVB_AUTO;
607 char *nudge = NULL;
608 char save;
609 short hepisema_adjustment_id;
610
611 if (he_adjustment_index[index]) {
612 gregorio_messagef("parse_hepisema_adustment", VERBOSITY_ERROR, 0,
613 _("horizontal %s-episema adjustment start before ending the "
614 "previous adjustment"), over_or_under(index));
615 return;
616 }
617
618 if (*ch == ':') {
619 ++ch;
620 if (*ch == 'm') {
621 vbasepos = HVB_MIDDLE;
622 } else {
623 switch (*ch) {
624 case 'o':
625 ++ch;
626 det_index = SO_OVER;
627 break;
628 case 'u':
629 ++ch;
630 det_index = SO_UNDER;
631 break;
632 }
633
634 switch (*ch) {
635 case 'l':
636 switch (det_index) {
637 case SO_OVER:
638 vbasepos = HVB_O_LOW;
639 break;
640 case SO_UNDER:
641 vbasepos = HVB_U_LOW;
642 break;
643 }
644 break;
645 case 'h':
646 switch (det_index) {
647 case SO_OVER:
648 vbasepos = HVB_O_HIGH;
649 break;
650 case SO_UNDER:
651 vbasepos = HVB_U_HIGH;
652 break;
653 }
654 break;
655 }
656 }
657 if (vbasepos) {
658 ++ch;
659 }
660 if (*ch == '+' || *ch == '-') {
661 nudge = ch;
662 do {
663 ++ch;
664 } while (*ch && *ch != '{' && *ch != ']');
665 save = *ch;
666 *ch = '\0';
667 nudge = gregorio_strdup(nudge);
668 *ch = save;
669 }
670 }
671
672 hepisema_adjustment_id = gregorio_add_hepisema_adjustment(vbasepos, nudge);
673
674 if (*ch == '{') {
675 he_adjustment_index[index] = hepisema_adjustment_id;
676 } else {
677 if (!current_note || current_note->type != GRE_NOTE) {
678 gregorio_message(_("cannot add a horizontal episema adjustment to "
679 "something that is not a note"),
680 "parse_hepisema_adjustment", VERBOSITY_ERROR, 0);
681 return;
682 }
683 current_note->he_adjustment_index[index] = hepisema_adjustment_id;
684 }
685 }
686
687 static void end_hepisema_adjustment(void)
688 {
689 /* [xh:}]
690 * - x indicates l(ow) or h(igh) episema
691 * - : is optional
692 */
693
694 const gregorio_sign_orientation index = letter_to_sign_orientation(
695 gabc_notes_determination_text[1]);
696
697 if (!he_adjustment_index[index]) {
698 gregorio_messagef("end_hepisema_adustment", VERBOSITY_ERROR, 0,
699 _("horizontal %s-episema adjustment end with no matching "
700 "start"), over_or_under(index));
701 return;
702 }
703
704 he_adjustment_index[index] = 0;
705 }
706
707 void gabc_det_notes_finish(void)
708 {
709 gregorio_sign_orientation orientation;
710 if (overbrace_var) {
711 gregorio_message(_("unclosed variable over-staff brace"),
712 "gabc_det_notes_finish", VERBOSITY_ERROR, 0);
713 overbrace_var = 0;
714 }
715 if (underbrace_var) {
716 gregorio_message(_("unclosed variable under-staff brace"),
717 "gabc_det_notes_finish", VERBOSITY_ERROR, 0);
718 underbrace_var = 0;
719 }
720 for (orientation = SO_OVER; orientation <= SO_UNDER; ++orientation) {
721 const char *name = over_or_under(orientation);
722 if (ledger_var[orientation]) {
723 gregorio_messagef("gabc_det_notes_finish", VERBOSITY_ERROR, 0,
724 _("unclosed variable %s-staff ledger line"), name);
725 ledger_var[orientation] = 0;
726 }
727 if (slur[orientation].var) {
728 gregorio_messagef("gabc_det_notes_finish", VERBOSITY_ERROR, 0,
729 _("unclosed variable %s-note slur"), name);
730 slur[orientation].var = 0;
731 slur[orientation].shift = '\0';
732 slur[orientation].start = NULL;
733 }
734 if (he_adjustment_index[orientation]) {
735 gregorio_messagef("gabc_det_notes_finish", VERBOSITY_ERROR, 0,
736 _("unclosed horizontal %s-episema adjustment"),
737 over_or_under(orientation));
738 ledger_var[orientation] = 0;
739 }
740 }
741 if (left_bracket_texverb) {
742 gregorio_message(_("unclosed left bracket"),
743 "gabc_det_notes_finish", VERBOSITY_ERROR, 0);
744 left_bracket_texverb = 0;
745 }
746 }
747
748 %}
749
750 %option stack
751 %option 8bit
752 %option pointer
753 %option nounput
754 %option noyy_push_state
755 %option noyy_pop_state
756 %option noyy_top_state
757 %option full
758 %option noread
759 %option nomain
760 %option align
761 %option noyylineno
762 %option prefix="gabc_notes_determination_"
763 %option noyywrap
764
765 %x texverbnote
766 %x texverbglyph
767 %x texverbelement
768 %x choralsign
769 %x choralnabc
770 %x alt
771 %x comments
772 %x overbrace
773 %x underbrace
774 %x overcurlybrace
775 %x overcurlyaccentusbrace
776 %x space
777 %x nbspace
778 %x overledger overledger2
779 %x underledger underledger2
780 %x endledger
781 %x shapehint
782
783 %%
784 <INITIAL>\% {
785 BEGIN(comments);
786 }
787 <comments>(\n|\r)+ {
788 BEGIN(INITIAL);
789 }
790 <comments>[^\n\r]* {
791 /* ignored */
792 }
793 <INITIAL>\[cs: {
794 BEGIN(choralsign);
795 }
796 <INITIAL>\[cn: {
797 BEGIN(choralnabc);
798 }
799 <INITIAL>\[ob:[01]; {
800 char_for_brace = gabc_notes_determination_text[4]-'0';
801 BEGIN(overbrace);
802 }
803 <INITIAL>\[ub:[01]; {
804 char_for_brace = gabc_notes_determination_text[4]-'0';
805 BEGIN(underbrace);
806 }
807 <INITIAL>\[ocb:[01]; {
808 char_for_brace = gabc_notes_determination_text[5]-'0';
809 BEGIN(overcurlybrace);
810 }
811 <INITIAL>\[ocba:[01]; {
812 char_for_brace = gabc_notes_determination_text[6]-'0';
813 BEGIN(overcurlyaccentusbrace);
814 }
815 <INITIAL>\[ob:[01]\{\] {
816 if (overbrace_var) {
817 gregorio_messagef("gabc_notes_determination", VERBOSITY_ERROR, 0,
818 _("variable overbrace without termination of "
819 "previous overbrace"));
820 } else {
821 char_for_brace = gabc_notes_determination_text[4]-'0';
822 overbrace_var = ++tex_position_id;
823 overbrace_var_kind = "ob";
824 gregorio_snprintf(tempstr, sizeof tempstr,
825 "\\GreVarBraceSavePos{%hu}{%d}{1}"
826 "\\GreOverBrace{\\GreVarBraceLength{%hu}}{0pt}{0pt}{%d}",
827 overbrace_var, char_for_brace, overbrace_var, char_for_brace);
828 gregorio_add_texverb_to_note(current_note, gregorio_strdup(tempstr));
829 }
830 }
831 <INITIAL>\[ub:[01]\{\] {
832 if (underbrace_var) {
833 gregorio_messagef("gabc_notes_determination", VERBOSITY_ERROR, 0,
834 _("variable underbrace without termination of "
835 "previous underbrace"));
836 } else {
837 char_for_brace = gabc_notes_determination_text[4]-'0';
838 underbrace_var = ++tex_position_id;
839 gregorio_snprintf(tempstr, sizeof tempstr,
840 "\\GreVarBraceSavePos{%hu}{%d}{1}"
841 "\\GreUnderBrace{\\GreVarBraceLength{%hu}}{0pt}{0pt}{%d}",
842 underbrace_var, char_for_brace, underbrace_var, char_for_brace);
843 gregorio_add_texverb_to_note(current_note, gregorio_strdup(tempstr));
844 }
845 }
846 <INITIAL>\[ocb:[01]\{\] {
847 if (overbrace_var) {
848 gregorio_messagef("gabc_notes_determination", VERBOSITY_ERROR, 0,
849 _("variable overbrace without termination of "
850 "previous overbrace"));
851 } else {
852 char_for_brace = gabc_notes_determination_text[5]-'0';
853 overbrace_var = ++tex_position_id;
854 overbrace_var_kind = "ocb";
855 gregorio_snprintf(tempstr, sizeof tempstr,
856 "\\GreVarBraceSavePos{%hu}{%d}{1}"
857 "\\GreOverCurlyBrace{\\GreVarBraceLength{%hu}}{0pt}{0pt}{%d}{0}",
858 overbrace_var, char_for_brace, overbrace_var, char_for_brace);
859 gregorio_add_texverb_to_note(current_note, gregorio_strdup(tempstr));
860 }
861 }
862 <INITIAL>\[ocba:[01]\{\] {
863 if (overbrace_var) {
864 gregorio_messagef("gabc_notes_determination", VERBOSITY_ERROR, 0,
865 _("variable overbrace without termination of "
866 "previous overbrace"));
867 } else {
868 char_for_brace = gabc_notes_determination_text[6]-'0';
869 overbrace_var = ++tex_position_id;
870 overbrace_var_kind = "ocba";
871 gregorio_snprintf(tempstr, sizeof tempstr,
872 "\\GreVarBraceSavePos{%hu}{%d}{1}"
873 "\\GreOverCurlyBrace{\\GreVarBraceLength{%hu}}{0pt}{0pt}{%d}{1}",
874 overbrace_var, char_for_brace, overbrace_var, char_for_brace);
875 gregorio_add_texverb_to_note(current_note, gregorio_strdup(tempstr));
876 }
877 }
878 <INITIAL>\[ob:[01]\}\] {
879 if (!overbrace_var) {
880 gregorio_messagef("gabc_notes_determination", VERBOSITY_ERROR, 0,
881 _("variable overbrace termination without "
882 "variable overbrace start"));
883 } else if (strcmp (overbrace_var_kind, "ob")) {
884 gregorio_messagef("gabc_notes_determination", VERBOSITY_ERROR, 0,
885 _("variable overbrace started with %s "
886 "and terminated with ob"),
887 overbrace_var_kind);
888 } else {
889 char_for_brace = gabc_notes_determination_text[4]-'0';
890 gregorio_snprintf(tempstr, sizeof tempstr,
891 "\\GreVarBraceSavePos{%hu}{%d}{2}", overbrace_var,
892 char_for_brace);
893 overbrace_var = 0;
894 gregorio_add_texverb_to_note(current_note, gregorio_strdup(tempstr));
895 }
896 }
897 <INITIAL>\[ub:[01]\}\] {
898 if (!underbrace_var) {
899 gregorio_messagef("gabc_notes_determination", VERBOSITY_ERROR, 0,
900 _("variable underbrace termination without "
901 "variable underbrace start"));
902 } else {
903 char_for_brace = gabc_notes_determination_text[4]-'0';
904 gregorio_snprintf(tempstr, sizeof tempstr,
905 "\\GreVarBraceSavePos{%hu}{%d}{2}", underbrace_var,
906 char_for_brace);
907 underbrace_var = 0;
908 gregorio_add_texverb_to_note(current_note, gregorio_strdup(tempstr));
909 }
910 }
911 <INITIAL>\[ocb:[01]\}\] {
912 if (!overbrace_var) {
913 gregorio_messagef("gabc_notes_determination", VERBOSITY_ERROR, 0,
914 _("variable overbrace termination without "
915 "variable overbrace start"));
916 } else if (strcmp (overbrace_var_kind, "ocb")) {
917 gregorio_messagef("gabc_notes_determination", VERBOSITY_ERROR, 0,
918 _("variable overbrace started with %s "
919 "and terminated with ocb"),
920 overbrace_var_kind);
921 } else {
922 char_for_brace = gabc_notes_determination_text[5]-'0';
923 gregorio_snprintf(tempstr, sizeof tempstr,
924 "\\GreVarBraceSavePos{%hu}{%d}{2}", overbrace_var,
925 char_for_brace);
926 overbrace_var = 0;
927 gregorio_add_texverb_to_note(current_note, gregorio_strdup(tempstr));
928 }
929 }
930 <INITIAL>\[ocba:[01]\}\] {
931 if (!overbrace_var) {
932 gregorio_messagef("gabc_notes_determination", VERBOSITY_ERROR, 0,
933 _("variable overbrace termination without "
934 "variable overbrace start"));
935 } else if (strcmp (overbrace_var_kind, "ocba")) {
936 gregorio_messagef("gabc_notes_determination", VERBOSITY_ERROR, 0,
937 _("variable overbrace started with %s "
938 "and terminated with ocba"),
939 overbrace_var_kind);
940 } else {
941 char_for_brace = gabc_notes_determination_text[6]-'0';
942 gregorio_snprintf(tempstr, sizeof tempstr,
943 "\\GreVarBraceSavePos{%hu}{%d}{2}", overbrace_var,
944 char_for_brace);
945 overbrace_var = 0;
946 gregorio_add_texverb_to_note(current_note, gregorio_strdup(tempstr));
947 }
948 }
949 <INITIAL>\[nm[1-9]\] {
950 if (notesmacros[gabc_notes_determination_text[3]-'0']) {
951 gregorio_add_texverb_to_note(current_note, gregorio_strdup(
952 notesmacros[gabc_notes_determination_text[3]-'0']));
953 } else error();
954 }
955 <INITIAL>\[gm[1-9]\] {
956 if (notesmacros[gabc_notes_determination_text[3]-'0']) {
957 gregorio_add_texverb_as_note(&current_note, gregorio_strdup(
958 notesmacros[gabc_notes_determination_text[3]-'0']),
959 GRE_TEXVERB_GLYPH, &notes_lloc);
960 } else error();
961 }
962 <INITIAL>\[em[1-9]\] {
963 if (notesmacros[gabc_notes_determination_text[3]-'0']) {
964 gregorio_add_texverb_as_note(&current_note, gregorio_strdup(
965 notesmacros[gabc_notes_determination_text[3]-'0']),
966 GRE_TEXVERB_ELEMENT, &notes_lloc);
967 } else error();
968 }
969 <INITIAL>\[altm[1-9]\] {
970 if (notesmacros[gabc_notes_determination_text[5]-'0']) {
971 gregorio_add_texverb_as_note(&current_note, gregorio_strdup(
972 notesmacros[gabc_notes_determination_text[5]-'0']),
973 GRE_TEXVERB_ELEMENT, &notes_lloc);
974 } else error();
975 }
976 <INITIAL>\[nv: {
977 BEGIN(texverbnote);
978 }
979 <INITIAL>\[gv: {
980 BEGIN(texverbglyph);
981 }
982 <INITIAL>\[ev: {
983 BEGIN(texverbelement);
984 }
985 <INITIAL>\[alt: {
986 BEGIN(alt);
987 }
988 <INITIAL><nlba> {
989 gregorio_add_nlba_as_note(&current_note, NLBA_BEGINNING, &notes_lloc);
990 }
991 <INITIAL><\/nlba> {
992 gregorio_add_nlba_as_note(&current_note, NLBA_END, &notes_lloc);
993 }
994 <INITIAL>@\[ {
995 gregorio_start_autofuse(&current_note, &notes_lloc);
996 }
997 <INITIAL>\] {
998 gregorio_end_autofuse(&current_note, &notes_lloc);
999 }
1000 <overbrace>(\$.|[^\]])+ {
1001 gregorio_snprintf(tempstr, sizeof tempstr,
1002 "\\GreOverBrace{%s}{0pt}{0pt}{%d}",
1003 gabc_notes_determination_text, char_for_brace);
1004 gregorio_add_texverb_to_note(current_note, gabc_unescape(tempstr));
1005 }
1006 <underbrace>(\$.|[^\]])+ {
1007 gregorio_snprintf(tempstr, sizeof tempstr,
1008 "\\GreUnderBrace{%s}{0pt}{0pt}{%d}",
1009 gabc_notes_determination_text, char_for_brace);
1010 gregorio_add_texverb_to_note(current_note, gabc_unescape(tempstr));
1011 }
1012 <overcurlybrace>(\$.|[^\]])+ {
1013 gregorio_snprintf(tempstr, sizeof tempstr,
1014 "\\GreOverCurlyBrace{%s}{0pt}{0pt}{%d}{0}",
1015 gabc_notes_determination_text, char_for_brace);
1016 gregorio_add_texverb_to_note(current_note, gabc_unescape(tempstr));
1017 }
1018 <overcurlyaccentusbrace>(\$.|[^\]])+ {
1019 gregorio_snprintf(tempstr, sizeof tempstr,
1020 "\\GreOverCurlyBrace{%s}{0pt}{0pt}{%d}{1}",
1021 gabc_notes_determination_text, char_for_brace);
1022 gregorio_add_texverb_to_note(current_note, gabc_unescape(tempstr));
1023 }
1024 <choralsign>(\$.|[^\]])+ {
1025 gregorio_add_cs_to_note(current_note,
1026 gabc_unescape(gabc_notes_determination_text), false);
1027 }
1028 <choralnabc>(\$.|[^\]])+ {
1029 gregorio_add_cs_to_note(current_note,
1030 gabc_unescape(gabc_notes_determination_text), true);
1031 }
1032 <texverbnote>(\$.|[^\]])+ {
1033 gregorio_add_texverb_to_note(current_note,
1034 gabc_unescape(gabc_notes_determination_text));
1035 }
1036 <texverbglyph>(\$.|[^\]])+ {
1037 gregorio_add_texverb_as_note(&current_note,
1038 gabc_unescape(gabc_notes_determination_text),
1039 GRE_TEXVERB_GLYPH, &notes_lloc);
1040 }
1041 <texverbelement>(\$.|[^\]])+ {
1042 gregorio_add_texverb_as_note(&current_note,
1043 gabc_unescape(gabc_notes_determination_text),
1044 GRE_TEXVERB_ELEMENT, &notes_lloc);
1045 }
1046 <alt>(\$.|[^\]])+ {
1047 gregorio_add_texverb_as_note(&current_note,
1048 gabc_unescape(gabc_notes_determination_text), GRE_ALT,
1049 &notes_lloc);
1050 }
1051 <INITIAL>\/\[ {
1052 BEGIN(space);
1053 }
1054 <space>-?(\.[0-9]+|[0-9]+(\.[0-9]*)?)/\] {
1055 gregorio_add_space_as_note(&current_note, SP_AD_HOC_SPACE,
1056 gregorio_strdup(gabc_notes_determination_text), &notes_lloc);
1057 }
1058 <INITIAL>!\/\[ {
1059 BEGIN(nbspace);
1060 }
1061 <nbspace>-?(\.[0-9]+|[0-9]+(\.[0-9]*)?)/\] {
1062 gregorio_add_space_as_note(&current_note, SP_AD_HOC_SPACE_NB,
1063 gregorio_strdup(gabc_notes_determination_text), &notes_lloc);
1064 }
1065 <INITIAL>\[oll:1\] {
1066 LEDGER(high, EXPLICITLY_DRAWN, true);
1067 }
1068 <INITIAL>\[oll:0\] {
1069 LEDGER(high, EXPLICITLY_DRAWN, false);
1070 }
1071 <INITIAL>\[oll:\}\] {
1072 end_variable_ledger(SO_OVER);
1073 }
1074 <INITIAL>\[oll: {
1075 BEGIN(overledger);
1076 }
1077 <overledger>[^;{]+ {
1078 save_before_ledger(gabc_notes_determination_text);
1079 BEGIN(overledger2);
1080 }
1081 <overledger2>;[^\]]+ {
1082 add_static_ledger(SO_OVER, gabc_notes_determination_text);
1083 BEGIN(endledger);
1084 }
1085 <overledger2>\{[^\]]+ {
1086 add_variable_ledger(SO_OVER, gabc_notes_determination_text);
1087 BEGIN(endledger);
1088 }
1089 <INITIAL>\[ull:1\] {
1090 LEDGER(low, EXPLICITLY_DRAWN, true);
1091 }
1092 <INITIAL>\[ull:0\] {
1093 LEDGER(low, EXPLICITLY_DRAWN, false);
1094 }
1095 <INITIAL>\[ull:\}\] {
1096 end_variable_ledger(SO_UNDER);
1097 }
1098 <INITIAL>\[ull: {
1099 BEGIN(underledger);
1100 }
1101 <underledger>[^;{]+ {
1102 save_before_ledger(gabc_notes_determination_text);
1103 BEGIN(underledger2);
1104 }
1105 <underledger2>;[^\]]+ {
1106 add_static_ledger(SO_UNDER, gabc_notes_determination_text);
1107 BEGIN(endledger);
1108 }
1109 <underledger2>\{[^\]]+ {
1110 add_variable_ledger(SO_UNDER, gabc_notes_determination_text);
1111 BEGIN(endledger);
1112 }
1113 <INITIAL>\[shape: {
1114 BEGIN(shapehint);
1115 }
1116 <shapehint>(\$.|[^\]])+ {
1117 gregorio_add_shape_hint_to_note(current_note,
1118 gabc_unescape(gabc_notes_determination_text));
1119 }
1120 <texverbnote,texverbglyph,texverbelement,choralsign,choralnabc,alt,overcurlyaccentusbrace,overcurlybrace,overbrace,underbrace,space,nbspace,endledger,shapehint>\] {
1121 BEGIN(INITIAL);
1122 }
1123 <INITIAL>\[[ou]slur:[012];[^,]+,[^\]]+\] {
1124 parse_slur();
1125 }
1126 <INITIAL>\[[ou]slur:[012]\{\] {
1127 start_var_slur();
1128 }
1129 <INITIAL>\[[ou]slur:[012]\}\] {
1130 end_var_slur();
1131 }
1132 <INITIAL>\[[ou]h(?x:
1133 :(m|[ou]?[lh])\{?
1134 | :(m|[ou]?[lh])?[+-][^\]\{]+\{?
1135 | :?\{
1136 )\] {
1137 parse_hepisema_adjustment();
1138 }
1139 <INITIAL>\[[ou]h:?\}\] {
1140 end_hepisema_adjustment();
1141 }
1142 <INITIAL>\[\[ {
1143 left_bracket();
1144 }
1145 <INITIAL>\]\] {
1146 right_bracket();
1147 }
1148 \{ {
1149 gregorio_add_texverb_as_note(&current_note,
1150 gregorio_strdup("\\hbox to 0pt{"), GRE_TEXVERB_ELEMENT,
1151 &notes_lloc);
1152 }
1153 \} {
1154 gregorio_add_texverb_as_note(&current_note,
1155 gregorio_strdup("\\hss%\n}%\n\\GreNoBreak\\relax "),
1156 GRE_TEXVERB_ELEMENT, &notes_lloc);
1157 }
1158 [a-np]\+ {
1159 gregorio_add_manual_custos_as_note(&current_note,
1160 pitch_letter_to_height(gabc_notes_determination_text[0]),
1161 &notes_lloc);
1162 }
1163 [\t\r\n]+ /* ignore ends of line and tabs */;
1164 <INITIAL>\[nocustos\] {
1165 gregorio_add_suppress_custos_as_note(&current_note, &notes_lloc);
1166 }
1167 z0 {
1168 gregorio_add_custos_as_note(&current_note, &notes_lloc);
1169 }
1170 z {
1171 gregorio_add_end_of_line_as_note(&current_note, false, false, false,
1172 &notes_lloc);
1173 }
1174 z\+ {
1175 gregorio_add_end_of_line_as_note(&current_note, false, true, true,
1176 &notes_lloc);
1177 }
1178 z- {
1179 gregorio_add_end_of_line_as_note(&current_note, false, true, false,
1180 &notes_lloc);
1181 }
1182 Z {
1183 gregorio_add_end_of_line_as_note(&current_note, true, false, false,
1184 &notes_lloc);
1185 }
1186 Z\+ {
1187 gregorio_add_end_of_line_as_note(&current_note, true, true, true,
1188 &notes_lloc);
1189 }
1190 Z- {
1191 gregorio_add_end_of_line_as_note(&current_note, true, true, false,
1192 &notes_lloc);
1193 }
1194 [cf][1-5] {
1195 gregorio_add_clef_as_note(&current_note,
1196 letter_to_clef(gabc_notes_determination_text[0]),
1197 parse_clef_line(gabc_notes_determination_text[1]), false,
1198 &notes_lloc);
1199 }
1200 [cf]b[1-5] {
1201 gregorio_add_clef_as_note(&current_note,
1202 letter_to_clef(gabc_notes_determination_text[0]),
1203 parse_clef_line(gabc_notes_determination_text[2]), true,
1204 &notes_lloc);
1205 }
1206 @[cf][1-5] {
1207 gregorio_add_secondary_clef_to_note(current_note,
1208 letter_to_clef(gabc_notes_determination_text[1]),
1209 parse_clef_line(gabc_notes_determination_text[2]), false);
1210 }
1211 @[cf]b[1-5] {
1212 gregorio_add_secondary_clef_to_note(current_note,
1213 letter_to_clef(gabc_notes_determination_text[1]),
1214 parse_clef_line(gabc_notes_determination_text[3]), true);
1215 }
1216 ` {
1217 add_bar_as_note(B_VIRGULA);
1218 }
1219 `0 {
1220 add_bar_as_note(B_VIRGULA_HIGH);
1221 }
1222 `\? {
1223 add_bar_as_note(B_VIRGULA_PAREN);
1224 }
1225 `0\?|`\?0 {
1226 add_bar_as_note(B_VIRGULA_PAREN_HIGH);
1227 }
1228 \^ {
1229 add_bar_as_note(B_DIVISIO_MINIMIS);
1230 }
1231 \^0 {
1232 add_bar_as_note(B_DIVISIO_MINIMIS_HIGH);
1233 }
1234 , {
1235 add_bar_as_note(B_DIVISIO_MINIMA);
1236 }
1237 ,0 {
1238 add_bar_as_note(B_DIVISIO_MINIMA_HIGH);
1239 }
1240 ,\? {
1241 add_bar_as_note(B_DIVISIO_MINIMA_PAREN);
1242 }
1243 ,0\?|,\?0 {
1244 add_bar_as_note(B_DIVISIO_MINIMA_PAREN_HIGH);
1245 }
1246 [,;][1-8] {
1247 add_bar_as_note(parse_dominican_bar(gabc_notes_determination_text[1]));
1248 }
1249 ; {
1250 add_bar_as_note(B_DIVISIO_MINOR);
1251 }
1252 : {
1253 add_bar_as_note(B_DIVISIO_MAIOR);
1254 }
1255 :: {
1256 add_bar_as_note(B_DIVISIO_FINALIS);
1257 }
1258 :\? {
1259 add_bar_as_note(B_DIVISIO_MAIOR_DOTTED);
1260 }
1261 r {
1262 gregorio_add_cavum(current_note);
1263 }
1264 R {
1265 gregorio_change_shape(current_note, S_LINEA_PUNCTUM,
1266 legacy_oriscus_orientation);
1267 }
1268 r0 {
1269 gregorio_change_shape(current_note, S_LINEA_PUNCTUM,
1270 legacy_oriscus_orientation);
1271 gregorio_add_cavum(current_note);
1272 }
1273 r1 {
1274 gregorio_add_special_sign(current_note, _ACCENTUS);
1275 }
1276 r2 {
1277 gregorio_add_special_sign(current_note, _ACCENTUS_REVERSUS);
1278 }
1279 r3 {
1280 gregorio_add_special_sign(current_note, _CIRCULUS);
1281 }
1282 r4 {
1283 gregorio_add_special_sign(current_note, _SEMI_CIRCULUS);
1284 }
1285 r5 {
1286 gregorio_add_special_sign(current_note, _SEMI_CIRCULUS_REVERSUS);
1287 }
1288 r6 {
1289 gregorio_add_special_sign(current_note, _MUSICA_FICTA_FLAT);
1290 }
1291 r7 {
1292 gregorio_add_special_sign(current_note, _MUSICA_FICTA_NATURAL);
1293 }
1294 r8 {
1295 gregorio_add_special_sign(current_note, _MUSICA_FICTA_SHARP);
1296 }
1297 x {
1298 gregorio_change_shape(current_note, S_FLAT,
1299 legacy_oriscus_orientation);
1300 }
1301 x\? {
1302 gregorio_change_shape(current_note, S_FLAT_PAREN,
1303 legacy_oriscus_orientation);
1304 }
1305 X {
1306 gregorio_change_shape(current_note, S_FLAT_SOFT,
1307 legacy_oriscus_orientation);
1308 }
1309 # {
1310 gregorio_change_shape(current_note, S_SHARP,
1311 legacy_oriscus_orientation);
1312 }
1313 #\? {
1314 gregorio_change_shape(current_note, S_SHARP_PAREN,
1315 legacy_oriscus_orientation);
1316 }
1317 ## {
1318 gregorio_change_shape(current_note, S_SHARP_SOFT,
1319 legacy_oriscus_orientation);
1320 }
1321 y {
1322 gregorio_change_shape(current_note, S_NATURAL,
1323 legacy_oriscus_orientation);
1324 }
1325 y\? {
1326 gregorio_change_shape(current_note, S_NATURAL_PAREN,
1327 legacy_oriscus_orientation);
1328 }
1329 Y {
1330 gregorio_change_shape(current_note, S_NATURAL_SOFT,
1331 legacy_oriscus_orientation);
1332 }
1333 !?\/0 {
1334 gregorio_add_space_as_note(&current_note, SP_HALF_SPACE, NULL,
1335 &notes_lloc);
1336 }
1337 !?\/! {
1338 gregorio_add_space_as_note(&current_note, SP_INTERGLYPH_SPACE, NULL,
1339 &notes_lloc);
1340 }
1341 \/ {
1342 gregorio_add_space_as_note(&current_note, SP_NEUMATIC_CUT, NULL,
1343 &notes_lloc);
1344 }
1345 \//\/\[ {
1346 gregorio_add_space_as_note(&current_note, SP_NEUMATIC_CUT, NULL,
1347 &notes_lloc);
1348 }
1349 \/\/ {
1350 gregorio_add_space_as_note(&current_note, SP_LARGER_SPACE, NULL,
1351 &notes_lloc);
1352 }
1353 \ {
1354 gregorio_add_space_as_note(&current_note, SP_GLYPH_SPACE, NULL,
1355 &notes_lloc);
1356 }
1357 !\/ {
1358 gregorio_add_space_as_note(&current_note, SP_NEUMATIC_CUT_NB, NULL,
1359 &notes_lloc);
1360 }
1361 !\//\/\[ {
1362 gregorio_add_space_as_note(&current_note, SP_NEUMATIC_CUT_NB, NULL,
1363 &notes_lloc);
1364 }
1365 !\/\/ {
1366 gregorio_add_space_as_note(&current_note, SP_LARGER_SPACE_NB, NULL,
1367 &notes_lloc);
1368 }
1369 !\ {
1370 gregorio_add_space_as_note(&current_note, SP_GLYPH_SPACE_NB, NULL,
1371 &notes_lloc);
1372 }
1373 !/[^\/ ] {
1374 gregorio_add_space_as_note(&current_note, SP_ZERO_WIDTH, NULL,
1375 &notes_lloc);
1376 }
1377 = {
1378 gregorio_change_shape(current_note, S_LINEA,
1379 legacy_oriscus_orientation);
1380 }
1381 [a-npA-NP]vv {
1382 lex_add_note(0, S_BIVIRGA, _NO_SIGN, L_NO_LIQUESCENTIA);
1383 }
1384 [a-npA-NP]vvv {
1385 lex_add_note(0, S_TRIVIRGA, _NO_SIGN, L_NO_LIQUESCENTIA);
1386 }
1387 [a-npA-NP]VV {
1388 lex_add_note(0, S_BIVIRGA, _NO_SIGN, L_NO_LIQUESCENTIA);
1389 }
1390 [a-npA-NP]VVV {
1391 lex_add_note(0, S_TRIVIRGA, _NO_SIGN, L_NO_LIQUESCENTIA);
1392 }
1393 [a-npA-NP]ss {
1394 lex_add_note(0, S_DISTROPHA, _NO_SIGN, L_NO_LIQUESCENTIA);
1395 }
1396 [a-npA-NP]ss(\<|\>) {
1397 lex_add_note(0, S_DISTROPHA, _NO_SIGN, L_AUCTUS_ASCENDENS);
1398 }
1399 [a-npA-NP]sss {
1400 lex_add_note(0, S_TRISTROPHA, _NO_SIGN, L_NO_LIQUESCENTIA);
1401 }
1402 [a-npA-NP]sss(\<|\>) {
1403 lex_add_note(0, S_TRISTROPHA, _NO_SIGN, L_AUCTUS_ASCENDENS);
1404 }
1405 [a-np] {
1406 lex_add_note(0, S_PUNCTUM, _NO_SIGN, L_NO_LIQUESCENTIA);
1407 }
1408 -[a-np] {
1409 lex_add_note(1, S_PUNCTUM, _NO_SIGN, L_INITIO_DEBILIS);
1410 }
1411 @[a-np] {
1412 lex_add_note(1, S_PUNCTUM, _NO_SIGN, L_FUSED);
1413 }
1414 [A-NP][012]? {
1415 lex_add_note(0, punctum_inclinatum(gabc_notes_determination_text[1]),
1416 _NO_SIGN, L_NO_LIQUESCENTIA);
1417 }
1418 -[A-NP][012]? {
1419 lex_add_note(1, punctum_inclinatum(gabc_notes_determination_text[2]),
1420 _NO_SIGN, L_INITIO_DEBILIS);
1421 }
1422 @[A-NP][012]? {
1423 lex_add_note(1, punctum_inclinatum(gabc_notes_determination_text[2]),
1424 _NO_SIGN, L_FUSED);
1425 }
1426 \'[01]? {
1427 add_sign(_V_EPISEMA);
1428 }
1429 _[0-5]* {
1430 add_h_episema();
1431 }
1432 \.[01]? {
1433 add_sign(_PUNCTUM_MORA);
1434 }
1435 ~ {
1436 gregorio_add_tail_liquescentia(current_note, L_DEMINUTUS,
1437 legacy_oriscus_orientation);
1438 }
1439 > {
1440 gregorio_add_tail_liquescentia(current_note, L_AUCTUS_DESCENDENS,
1441 legacy_oriscus_orientation);
1442 }
1443 \< {
1444 gregorio_add_tail_liquescentia(current_note, L_AUCTUS_ASCENDENS,
1445 legacy_oriscus_orientation);
1446 }
1447 q {
1448 gregorio_change_shape(current_note, S_QUADRATUM,
1449 legacy_oriscus_orientation);
1450 }
1451 o {
1452 gregorio_change_shape(current_note, S_ORISCUS_UNDETERMINED,
1453 legacy_oriscus_orientation);
1454 }
1455 o0 {
1456 gregorio_change_shape(current_note, S_ORISCUS_DESCENDENS,
1457 legacy_oriscus_orientation);
1458 }
1459 o1 {
1460 gregorio_change_shape(current_note, S_ORISCUS_ASCENDENS,
1461 legacy_oriscus_orientation);
1462 }
1463 O {
1464 gregorio_change_shape(current_note, S_ORISCUS_SCAPUS_UNDETERMINED,
1465 legacy_oriscus_orientation);
1466 }
1467 O0 {
1468 gregorio_change_shape(current_note, S_ORISCUS_SCAPUS_DESCENDENS,
1469 legacy_oriscus_orientation);
1470 }
1471 O1 {
1472 gregorio_change_shape(current_note, S_ORISCUS_SCAPUS_ASCENDENS,
1473 legacy_oriscus_orientation);
1474 }
1475 w {
1476 gregorio_change_shape(current_note, S_QUILISMA,
1477 legacy_oriscus_orientation);
1478 }
1479 W {
1480 gregorio_change_shape(current_note, S_QUILISMA_QUADRATUM,
1481 legacy_oriscus_orientation);
1482 }
1483 v {
1484 gregorio_change_shape(current_note, S_VIRGA,
1485 legacy_oriscus_orientation);
1486 }
1487 V {
1488 gregorio_change_shape(current_note, S_VIRGA_REVERSA,
1489 legacy_oriscus_orientation);
1490 }
1491 s {
1492 gregorio_change_shape(current_note, S_STROPHA,
1493 legacy_oriscus_orientation);
1494 }
1495 \[hl:1\] {
1496 LEDGER(high, EXPLICIT, true);
1497 }
1498 \[hl:0\] {
1499 LEDGER(high, EXPLICIT, false);
1500 }
1501 \[ll:1\] {
1502 LEDGER(low, EXPLICIT, true);
1503 }
1504 \[ll:0\] {
1505 LEDGER(low, EXPLICIT, false);
1506 }
1507 .|\n {
1508 gregorio_messagef("det_notes_from_string", VERBOSITY_ERROR, 0,
1509 _("unrecognized character: \"%c\""),
1510 gabc_notes_determination_text[0]);
1511 }
1512
1513 %%
1514
1515 gregorio_note *gabc_det_notes_from_string(char *str, char *newmacros[10],
1516 gregorio_scanner_location *loc, const gregorio_score *const score)
1517 {
1518 int i;
1519 YY_BUFFER_STATE buf;
1520
1521 notes_lloc.first_line = loc->first_line;
1522 notes_lloc.first_column = loc->first_column;
1523 notes_lloc.first_offset = loc->first_offset;
1524 /* yes... I do mean to set values from loc->first_* */
1525 notes_lloc.last_line = loc->first_line;
1526 notes_lloc.last_column = loc->first_column;
1527 notes_lloc.last_offset = loc->first_offset;
1528 notes_lloc.generate_point_and_click = loc->generate_point_and_click;
1529
1530 staff_lines = score->staff_lines;
1531 highest_pitch = score->highest_pitch;
1532 high_ledger_line_pitch = score->high_ledger_line_pitch;
1533 legacy_oriscus_orientation = score->legacy_oriscus_orientation;
1534
1535 /* a small optimization could uccur here: we could do it only once at the
1536 * beginning of the score, not at each syllable */
1537 for (i = 0; i < 10; i++) {
1538 notesmacros[i] = newmacros[i];
1539 }
1540 nbof_isolated_episema = 0;
1541 current_note = NULL;
1542 buf = yy_scan_string(str);
1543 yylex();
1544 yy_flush_buffer(buf);
1545 yy_delete_buffer(buf);
1546 gregorio_go_to_first_note(&current_note);
1547 return current_note;
1548 }