Debian Codegraph @

texk/gregorio/gregorio-src/src/gabc/gabc-glyphs-determination.c

raw
1 /*
2 * Gregorio is a program that translates gabc files to GregorioTeX
3 * This file provides functions for determining glyphs from notes.
4 *
5 * Copyright (C) 2006-2025 The Gregorio Project (see CONTRIBUTORS.md)
6 *
7 * This file is part of Gregorio.
8 *
9 * This program is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #include "config.h"
24 #include <stdio.h>
25 #include <assert.h>
26 #include "bool.h"
27 #include "struct.h"
28 #include "messages.h"
29
30 #include "gabc.h"
31
32 static __inline gregorio_scanner_location *copy_note_location(
33 const gregorio_note *const note, gregorio_scanner_location *const loc)
34 {
35 loc->first_line = note->src_line;
36 loc->first_column = note->src_column;
37 loc->first_offset = note->src_offset;
38 loc->last_line = note->src_line;
39 loc->last_column = note->src_column;
40 loc->last_offset = note->src_offset;
41 return loc;
42 }
43
44 static __inline bool is_normal_punctum(const gregorio_note *const note)
45 {
46 return note->u.note.shape == S_PUNCTUM
47 && note->u.note.liquescentia != L_INITIO_DEBILIS;
48 }
49
50 static __inline bool is_punctum_inclinatum(const gregorio_shape shape,
51 const bool determined_only)
52 {
53 switch (shape) {
54 case S_PUNCTUM_INCLINATUM_ASCENDENS:
55 case S_PUNCTUM_INCLINATUM_STANS:
56 case S_PUNCTUM_INCLINATUM_DESCENDENS:
57 return true;
58 case S_PUNCTUM_INCLINATUM_UNDETERMINED:
59 return !determined_only;
60 default:
61 return false;
62 }
63 }
64
65 /****************************
66 *
67 * This function is the basis of all the determination of glyphs. The
68 * phylosophy of the function is to say : We have a glyph that we have
69 * determined, and we have the following note, can we "add" it to the
70 * glyph, or will it be the first note of another glyph ?
71 *
72 * current_glyph_type is the type of the current_glyph (current_glyph
73 * as meant in gabc_det_glyphs_from_notes). curent_pitch
74 * is the height of the note that we want to "add" to the glyph.
75 * last_pitch is the height of the last note of current_glyph. shape
76 * is the shape of the note we want to "add" to the glyph.
77 *
78 * The function returns a char, which meaning is explained below.
79 *
80 * end_of_glyph is a pointer to the result of the determination, here
81 * are the meanings :
82 *
83 * DET_NO_END: we have successfully added the note to the glyph, and
84 * we return the new type of the glyph. We may again add notes to the
85 * glyph.
86 *
87 * DET_END_OF_PREVIOUS: we have not been able to add the note to the
88 * glyph, so we will have to close the glyph.
89 *
90 * DET_END_OF_CURRENT: we have been able to add the note to the glyph,
91 * but we won't be able to add more notes to the glyph, we can close
92 * it. The new type is returned.
93 *
94 * DET_END_OF_BOTH: we haven't been able to add the note to the glyph,
95 * and we won't be able to add notes to the new glyph. This special
96 * case is quite rare, we use it for trivirga, tristropha, etc.
97 *
98 * When we encouter a S_QUADRATUM (or S_QUILISMA_QUADRATUM), we build
99 * a new glyph with the (temporary) shape G_PES_QUADRATUM_FIRST_PART
100 * (or G_PES_QUILISMA_QUADRATUM_FIRST_PART), and we wait for the next
101 * note.
102 *
103 ****************************/
104
105 static char add_note_to_a_glyph(gregorio_glyph_type current_glyph_type,
106 char current_pitch, char last_pitch, gregorio_shape shape,
107 gregorio_liquescentia liquescentia,
108 gregorio_note *current_glyph_first_note,
109 gabc_determination *end_of_glyph,
110 gregorio_shape *punctum_inclinatum_orientation)
111 {
112 #define this_note_starts_new_glyph { \
113 next_glyph_type = G_PUNCTUM; \
114 *end_of_glyph = DET_END_OF_PREVIOUS; \
115 }
116
117 /* next glyph type is the type of the glyph that will be returned (the
118 * new type of the glyph with the note added to it, or the type of the
119 * new glyph with the note alone. */
120 gregorio_glyph_type next_glyph_type = G_UNDETERMINED;
121
122 *end_of_glyph = DET_NO_END;
123
124 /* here we separate notes that would be logically in the same glyph
125 * but that are too far to be so */
126 if (last_pitch) {
127 if (current_pitch - last_pitch > MAX_AMBITUS
128 || current_pitch - last_pitch < -MAX_AMBITUS) {
129 current_glyph_type = G_UNDETERMINED;
130 }
131 }
132
133 switch (shape) {
134 case S_LINEA_PUNCTUM:
135 case S_LINEA:
136 next_glyph_type = G_PUNCTUM;
137 *end_of_glyph = DET_END_OF_BOTH;
138 break;
139 case S_FLAT:
140 case S_FLAT_PAREN:
141 case S_FLAT_SOFT:
142 case S_SHARP:
143 case S_SHARP_PAREN:
144 case S_SHARP_SOFT:
145 case S_NATURAL:
146 case S_NATURAL_PAREN:
147 case S_NATURAL_SOFT:
148 next_glyph_type = G_ALTERATION;
149 *end_of_glyph = DET_END_OF_BOTH;
150 break;
151 case S_PUNCTUM:
152 /*
153 * we determine here the shape of the thing if it is made of puncta
154 */
155 if (current_pitch == last_pitch) {
156 this_note_starts_new_glyph;
157 break;
158 }
159 switch (current_glyph_type) {
160 case G_PUNCTUM:
161 if (current_pitch > last_pitch) {
162 next_glyph_type = G_PODATUS;
163 } else {
164 next_glyph_type = G_FLEXA;
165 }
166 break;
167 case G_PODATUS:
168 if (current_pitch > last_pitch) {
169 if (is_normal_punctum(current_glyph_first_note)) {
170 next_glyph_type = G_SCANDICUS;
171 *end_of_glyph = DET_END_OF_CURRENT;
172 } else {
173 this_note_starts_new_glyph;
174 }
175 } else {
176 next_glyph_type = G_TORCULUS;
177 }
178 break;
179 case G_PES_QUADRATUM_FIRST_PART:
180 if (current_pitch > last_pitch) {
181 next_glyph_type = G_PES_QUADRATUM;
182 *end_of_glyph = DET_END_OF_CURRENT;
183 } else {
184 next_glyph_type = G_FLEXA;
185 }
186 break;
187 case G_PES_QUILISMA_QUADRATUM_FIRST_PART:
188 if (current_pitch > last_pitch) {
189 next_glyph_type = G_PES_QUADRATUM;
190 *end_of_glyph = DET_END_OF_CURRENT;
191 } else {
192 this_note_starts_new_glyph;
193 }
194 break;
195 case G_PES_ASCENDENS_ORISCUS:
196 case G_PES_DESCENDENS_ORISCUS:
197 if (current_pitch > last_pitch) {
198 next_glyph_type = G_SALICUS;
199 } else {
200 this_note_starts_new_glyph;
201 }
202 break;
203 case G_SALICUS:
204 if (current_pitch < last_pitch) {
205 next_glyph_type = G_SALICUS_FLEXUS;
206 *end_of_glyph = DET_END_OF_CURRENT;
207 } else {
208 this_note_starts_new_glyph;
209 }
210 break;
211 case G_FLEXA:
212 if (current_pitch > last_pitch) {
213 if (is_normal_punctum(current_glyph_first_note)) {
214 next_glyph_type = G_PORRECTUS;
215 } else {
216 this_note_starts_new_glyph;
217 }
218 } else {
219 if (liquescentia & L_DEMINUTUS) {
220 *end_of_glyph = DET_END_OF_CURRENT;
221 next_glyph_type = G_ANCUS;
222 } else {
223 this_note_starts_new_glyph;
224 }
225 }
226 break;
227 case G_TORCULUS:
228 if (current_pitch > last_pitch) {
229 next_glyph_type = G_TORCULUS_RESUPINUS;
230 } else if (liquescentia == L_DEMINUTUS) {
231 *end_of_glyph = DET_END_OF_CURRENT;
232 next_glyph_type = G_TORCULUS_LIQUESCENS;
233 } else {
234 this_note_starts_new_glyph;
235 }
236 break;
237 case G_TORCULUS_RESUPINUS:
238 if (current_pitch > last_pitch) {
239 this_note_starts_new_glyph;
240 } else {
241 *end_of_glyph = DET_END_OF_CURRENT;
242 next_glyph_type = G_TORCULUS_RESUPINUS_FLEXUS;
243 }
244 break;
245 case G_PORRECTUS:
246 if (current_pitch > last_pitch) {
247 this_note_starts_new_glyph;
248 } else {
249 *end_of_glyph = DET_END_OF_CURRENT;
250 next_glyph_type = G_PORRECTUS_FLEXUS;
251 }
252 break;
253 default:
254 this_note_starts_new_glyph;
255 break;
256 }
257 break;
258 case S_ORISCUS_UNDETERMINED:
259 case S_ORISCUS_ASCENDENS:
260 case S_ORISCUS_DESCENDENS:
261 case S_ORISCUS_DEMINUTUS:
262 case S_QUILISMA:
263 this_note_starts_new_glyph;
264 break;
265 case S_VIRGA:
266 if (current_glyph_type == G_VIRGA && last_pitch == current_pitch) {
267 next_glyph_type = G_BIVIRGA;
268 } else {
269 if (current_glyph_type == G_BIVIRGA && last_pitch == current_pitch) {
270 next_glyph_type = G_TRIVIRGA;
271 } else {
272 *end_of_glyph = DET_END_OF_PREVIOUS;
273 next_glyph_type = G_VIRGA;
274 }
275 }
276 break;
277 case S_VIRGA_REVERSA:
278 *end_of_glyph = DET_END_OF_PREVIOUS;
279 next_glyph_type = G_VIRGA_REVERSA;
280 break;
281 case S_BIVIRGA:
282 if (current_glyph_type == G_VIRGA && last_pitch == current_pitch) {
283 *end_of_glyph = DET_END_OF_CURRENT;
284 next_glyph_type = G_TRIVIRGA;
285 } else {
286 *end_of_glyph = DET_END_OF_PREVIOUS;
287 next_glyph_type = G_BIVIRGA;
288 }
289 break;
290 case S_TRIVIRGA:
291 *end_of_glyph = DET_END_OF_BOTH;
292 next_glyph_type = G_TRIVIRGA;
293 break;
294 case S_QUADRATUM:
295 *end_of_glyph = DET_END_OF_PREVIOUS;
296 next_glyph_type = G_PES_QUADRATUM_FIRST_PART;
297 break;
298 case S_QUILISMA_QUADRATUM:
299 *end_of_glyph = DET_END_OF_PREVIOUS;
300 next_glyph_type = G_PES_QUILISMA_QUADRATUM_FIRST_PART;
301 break;
302 case S_ORISCUS_SCAPUS_UNDETERMINED:
303 case S_ORISCUS_SCAPUS_ASCENDENS:
304 if (current_glyph_type == G_PUNCTUM && last_pitch < current_pitch) {
305 next_glyph_type = G_PES_ASCENDENS_ORISCUS;
306 /* Therefore G_PES_ASCENDENS_ORISCUS might be fronting an
307 * undetermined oriscus scapus. This will be resolved during
308 * oriscus orientation determination */
309 } else {
310 this_note_starts_new_glyph;
311 }
312 break;
313 case S_ORISCUS_SCAPUS_DESCENDENS:
314 if (current_glyph_type == G_PUNCTUM && last_pitch < current_pitch) {
315 next_glyph_type = G_PES_DESCENDENS_ORISCUS;
316 } else {
317 this_note_starts_new_glyph;
318 }
319 break;
320 case S_PUNCTUM_INCLINATUM_UNDETERMINED:
321 case S_PUNCTUM_INCLINATUM_ASCENDENS:
322 case S_PUNCTUM_INCLINATUM_STANS:
323 case S_PUNCTUM_INCLINATUM_DESCENDENS:
324 /*
325 * Warning : this part of the code is specific to the
326 * declarations of the header file
327 */
328 if (current_glyph_type > G_PUNCTA_INCLINATA) {
329 /*
330 * meaning that the previous glyph is not a combination of puncta
331 * inclinata, see header file for details
332 */
333 *end_of_glyph = DET_END_OF_PREVIOUS;
334 next_glyph_type = G_PUNCTUM_INCLINATUM;
335 break;
336 }
337 if (current_pitch == last_pitch) {
338 *end_of_glyph = DET_END_OF_PREVIOUS;
339 next_glyph_type = G_PUNCTUM_INCLINATUM;
340 break;
341 }
342 if (is_punctum_inclinatum(shape, true)
343 && *punctum_inclinatum_orientation != shape
344 && *punctum_inclinatum_orientation
345 != S_PUNCTUM_INCLINATUM_UNDETERMINED) {
346 /* change of orientation ends the glyph */
347 *end_of_glyph = DET_END_OF_PREVIOUS;
348 next_glyph_type = G_PUNCTUM_INCLINATUM;
349 break;
350 }
351 switch (current_glyph_type) {
352 case G_PUNCTUM_INCLINATUM:
353 if (last_pitch < current_pitch) {
354 next_glyph_type = G_2_PUNCTA_INCLINATA_ASCENDENS;
355 } else {
356 next_glyph_type = G_2_PUNCTA_INCLINATA_DESCENDENS;
357 }
358 break;
359 case G_2_PUNCTA_INCLINATA_ASCENDENS:
360 if (last_pitch < current_pitch) {
361 next_glyph_type = G_3_PUNCTA_INCLINATA_ASCENDENS;
362 } else {
363 next_glyph_type = G_PUNCTA_INCLINATA;
364 }
365 break;
366 case G_3_PUNCTA_INCLINATA_ASCENDENS:
367 if (last_pitch < current_pitch) {
368 next_glyph_type = G_4_PUNCTA_INCLINATA_ASCENDENS;
369 } else {
370 next_glyph_type = G_PUNCTA_INCLINATA;
371 }
372 break;
373 case G_4_PUNCTA_INCLINATA_ASCENDENS:
374 if (last_pitch < current_pitch) {
375 next_glyph_type = G_5_PUNCTA_INCLINATA_ASCENDENS;
376 } else {
377 next_glyph_type = G_PUNCTA_INCLINATA;
378 }
379 break;
380 case G_2_PUNCTA_INCLINATA_DESCENDENS:
381 if (last_pitch < current_pitch) {
382 next_glyph_type = G_PUNCTA_INCLINATA;
383 } else {
384 next_glyph_type = G_3_PUNCTA_INCLINATA_DESCENDENS;
385 }
386 break;
387 case G_3_PUNCTA_INCLINATA_DESCENDENS:
388 if (last_pitch < current_pitch) {
389 next_glyph_type = G_PUNCTA_INCLINATA;
390 } else {
391 next_glyph_type = G_4_PUNCTA_INCLINATA_DESCENDENS;
392 }
393 break;
394 case G_4_PUNCTA_INCLINATA_DESCENDENS:
395 if (last_pitch < current_pitch) {
396 next_glyph_type = G_PUNCTA_INCLINATA;
397 } else {
398 next_glyph_type = G_5_PUNCTA_INCLINATA_DESCENDENS;
399 }
400 break;
401 default:
402 next_glyph_type = G_PUNCTA_INCLINATA;
403 break;
404 }
405 break;
406 case S_STROPHA:
407 if (last_pitch != current_pitch) {
408 *end_of_glyph = DET_END_OF_PREVIOUS;
409 next_glyph_type = G_STROPHA;
410 break;
411 }
412 switch (current_glyph_type) {
413 case G_STROPHA:
414 next_glyph_type = G_DISTROPHA;
415 break;
416 case G_DISTROPHA:
417 *end_of_glyph = DET_END_OF_CURRENT;
418 next_glyph_type = G_TRISTROPHA;
419 break;
420 default:
421 *end_of_glyph = DET_END_OF_PREVIOUS;
422 next_glyph_type = G_STROPHA;
423 break;
424 }
425 break;
426 case S_DISTROPHA:
427 if (last_pitch == current_pitch && current_glyph_type == G_STROPHA) {
428 *end_of_glyph = DET_END_OF_CURRENT;
429 next_glyph_type = G_TRISTROPHA;
430 } else {
431 *end_of_glyph = DET_END_OF_PREVIOUS;
432 next_glyph_type = G_DISTROPHA;
433 }
434 break;
435 case S_TRISTROPHA:
436 *end_of_glyph = DET_END_OF_BOTH;
437 next_glyph_type = G_TRISTROPHA;
438 break;
439 default:
440 /* not reachable unless there's a programming error */
441 /* LCOV_EXCL_START */
442 gregorio_fail2(add_note_to_a_glyph, "unexpected shape: %s",
443 gregorio_shape_to_string(shape));
444 break;
445 /* LCOV_EXCL_STOP */
446 }
447 /* end of the main switch */
448
449 if (current_glyph_type == G_UNDETERMINED) {
450 /*
451 * means that this is the first glyph or that the previous glyph has
452 * already been added
453 */
454 if (*end_of_glyph == DET_END_OF_PREVIOUS) {
455 *end_of_glyph = DET_NO_END;
456 } else {
457 if (*end_of_glyph == DET_END_OF_BOTH) {
458 *end_of_glyph = DET_END_OF_CURRENT;
459 }
460 }
461 }
462
463 /*
464 * WARNING : Ugly section of the code, just some kind of patch for it to work
465 * with fonts that can't handle large intervals.
466 */
467 /* here we separate notes that would be logically in the same glyph
468 * but that are too far to be so, we already said to the function that
469 * it was not the same glyph, there we must say that the previous
470 * glyph has ended. */
471 if (last_pitch) {
472 if (current_pitch - last_pitch > MAX_AMBITUS
473 || current_pitch - last_pitch < -MAX_AMBITUS) {
474 if (*end_of_glyph == DET_END_OF_CURRENT
475 || *end_of_glyph == DET_END_OF_BOTH) {
476 /* There is no current way for the code to end up here, but
477 * we'll leave it in because it's a good safety precaution in
478 * case something new is added in the future */
479 /* LCOV_EXCL_START */
480 gregorio_message(_("Encountered the need to switch "
481 "DET_END_OF_CURRENT to DET_END_OF_BOTH because of "
482 "overly large ambitus"),
483 "add_note_to_a_glyph", VERBOSITY_WARNING,
484 __LINE__);
485 *end_of_glyph = DET_END_OF_BOTH;
486 } else {
487 /* LCOV_EXCL_STOP */
488 *end_of_glyph = DET_END_OF_PREVIOUS;
489 }
490 }
491 }
492
493 switch (shape) {
494 case S_PUNCTUM_INCLINATUM_ASCENDENS:
495 case S_PUNCTUM_INCLINATUM_STANS:
496 case S_PUNCTUM_INCLINATUM_DESCENDENS:
497 *punctum_inclinatum_orientation = shape;
498 break;
499 case S_PUNCTUM_INCLINATUM_UNDETERMINED:
500 break;
501 default:
502 *punctum_inclinatum_orientation = S_PUNCTUM_INCLINATUM_UNDETERMINED;
503 break;
504 }
505
506 return next_glyph_type;
507 }
508
509 static bool is_cavum(gregorio_note *note, gregorio_note *last_note)
510 {
511 bool is_cavum = false;
512 for (; note; note = note->next) {
513 if (note->type == GRE_NOTE) {
514 is_cavum = is_cavum || note->u.note.is_cavum;
515 }
516 /* don't look past the last note */
517 if (note == last_note) {
518 break;
519 }
520 }
521 return is_cavum;
522 }
523
524 /****************************
525 *
526 * First see the comments of
527 * gabc_det_glyphs_from_notes. This function is used when
528 * we have finished to determine a glyph. We have the last glyph that
529 * have been added: last_glyph. The glyph we want to add is given by
530 * glyph_type and liquescentia.
531 *
532 * The glyph we want to add goes from first_note to current_note, we
533 * isolate these notes from the notes that won't be in the glyph, and
534 * we add the glyph to the list_of_glyphs.
535 *
536 ****************************/
537
538 static gregorio_note *close_normal_glyph(gregorio_glyph **last_glyph,
539 gregorio_glyph_type glyph_type, gregorio_note **first_note,
540 gregorio_liquescentia liquescentia, gregorio_note *current_note)
541 {
542 gregorio_note *new_current_note = current_note;
543 gregorio_scanner_location loc;
544
545 /* patch to have good glyph type in the case where a glyph ends by a note
546 * with shape S_QUADRATUM */
547 if (glyph_type == G_PES_QUADRATUM_FIRST_PART
548 || glyph_type == G_PES_QUILISMA_QUADRATUM_FIRST_PART) {
549 glyph_type = G_PUNCTUM;
550 }
551
552 gregorio_add_glyph(last_glyph, glyph_type, *first_note, liquescentia,
553 is_cavum(*first_note, current_note));
554
555 if (current_note->next) {
556 current_note->next->previous = NULL;
557 *first_note = current_note->next;
558 current_note->next = NULL;
559 }
560 /* here we "patch" the structure for bivirga, tristropha, etc. */
561 /* the idea is not to have a S_BIVIRGA in the shape of the note (which is
562 * dirty) but rather a G_BIVIRGA in the glyph (which is the case now) and
563 * two virgas */
564
565 if (glyph_type == G_BIVIRGA || glyph_type == G_DISTROPHA
566 || glyph_type == G_TRIVIRGA || glyph_type == G_TRISTROPHA
567 || glyph_type == G_DISTROPHA_AUCTA
568 || glyph_type == G_TRISTROPHA_AUCTA) {
569 gregorio_go_to_first_note(&current_note);
570 while (current_note) {
571 /* a variable necessary for the patch for G_BIVIRGA & co. */
572 gregorio_note *added_notes = NULL;
573 gregorio_note *next_note = NULL;
574 if (current_note->type == GRE_NOTE) {
575 switch (current_note->u.note.shape) {
576 case S_TRIVIRGA:
577 gregorio_add_note(&added_notes, current_note->u.note.pitch,
578 S_VIRGA, _NO_SIGN, L_NO_LIQUESCENTIA, current_note,
579 copy_note_location(current_note, &loc));
580 /* fall through */
581 case S_BIVIRGA:
582 gregorio_add_note(&added_notes, current_note->u.note.pitch,
583 S_VIRGA, _NO_SIGN, L_NO_LIQUESCENTIA, current_note,
584 copy_note_location(current_note, &loc));
585 gregorio_add_note(&added_notes, current_note->u.note.pitch,
586 S_VIRGA, current_note->signs,
587 current_note->u.note.liquescentia, current_note,
588 copy_note_location(current_note, &loc));
589 break;
590 case S_TRISTROPHA:
591 gregorio_add_note(&added_notes, current_note->u.note.pitch,
592 S_STROPHA, _NO_SIGN, L_NO_LIQUESCENTIA,
593 current_note,
594 copy_note_location(current_note, &loc));
595 /* fall through */
596 case S_DISTROPHA:
597 gregorio_add_note(&added_notes, current_note->u.note.pitch,
598 S_STROPHA, _NO_SIGN, L_NO_LIQUESCENTIA,
599 current_note,
600 copy_note_location(current_note, &loc));
601 gregorio_add_note(&added_notes, current_note->u.note.pitch,
602 S_STROPHA, current_note->signs,
603 current_note->u.note.liquescentia, current_note,
604 copy_note_location(current_note, &loc));
605 break;
606 default:
607 break;
608 }
609 }
610 if (!added_notes) {
611 /* nothing added, but we must go on in case it's
612 * virga+bivirga = trivirga or stropa+bistropha = tristropha */
613 if (current_note->next) {
614 current_note = current_note->next;
615 continue;
616 } else {
617 break;
618 }
619 }
620 next_note = current_note->next;
621 /* now we have what we want, we set up the links and free the old
622 * note */
623 if (next_note) {
624 current_note->next->previous = added_notes;
625 added_notes->next = next_note;
626 }
627 if (current_note == new_current_note) {
628 new_current_note = added_notes;
629 }
630 gregorio_go_to_first_note(&added_notes);
631 if (current_note->previous) {
632 current_note->previous->next = added_notes;
633 added_notes->previous = current_note->previous;
634 }
635 /* Detaching current_note is not strictly necessary here because we
636 * are effectively plucking out added_notes into its own glyph;
637 * however, detaching the note is safer if this behavior changes in
638 * the future because gregorio_free_one_note nullifies surrounding
639 * pointers */
640 current_note->next = NULL;
641 current_note->previous = NULL;
642 gregorio_free_one_note(&current_note);
643 if (!next_note) {
644 current_note = added_notes;
645 break;
646 }
647 current_note = next_note;
648 }
649 gregorio_go_to_first_note(&current_note);
650 /* finally we set the just added glyph first_note to current_note */
651 (*last_glyph)->u.notes.first_note = current_note;
652 }
653 return new_current_note;
654 }
655
656 static gregorio_note *close_fused_glyph(gregorio_glyph **last_glyph,
657 gregorio_glyph_type glyph_type, gregorio_note **first_note,
658 gregorio_liquescentia liquescentia, gregorio_note *current_note)
659 {
660 (*first_note)->u.note.liquescentia |= (liquescentia & L_FUSED);
661 return close_normal_glyph(last_glyph, glyph_type, first_note, liquescentia,
662 current_note);
663 }
664
665 static gregorio_note *next_non_texverb_note(gregorio_note *first_note,
666 gregorio_note *last_note)
667 {
668 gregorio_not_null(first_note, gregorio_note, return NULL);
669
670 if (first_note == last_note) {
671 /* not reachable unless there's a programming error */
672 /* LCOV_EXCL_START */
673 gregorio_assert_only(first_note->type != GRE_TEXVERB_GLYPH,
674 next_non_texverb_note, "Unexpected texverb at start of iteration");
675 return first_note;
676 /* LCOV_EXCL_STOP */
677 }
678
679 for (first_note = first_note->next; first_note && first_note != last_note;
680 first_note = first_note->next) {
681 if (first_note->type != GRE_TEXVERB_GLYPH) {
682 return first_note;
683 }
684 }
685
686 gregorio_assert_only(!first_note || first_note->type != GRE_TEXVERB_GLYPH,
687 next_non_texverb_note, "Unexpected texverb at end of iteration");
688
689 return last_note;
690 }
691
692 static void add_intervening_texverbs(gregorio_glyph **last_glyph,
693 gregorio_note *first_note, gregorio_note *last_note)
694 {
695 for ( ; first_note && first_note->type == GRE_TEXVERB_GLYPH; ) {
696 bool on_last_note = (first_note == last_note);
697
698 gregorio_add_unpitched_element_as_glyph(last_glyph, first_note->type,
699 &(first_note->u.other), _NO_SIGN, first_note->texverb);
700 first_note->texverb = 0;
701 gregorio_free_one_note(&first_note);
702
703 if (on_last_note) {
704 break;
705 }
706 }
707 }
708
709 static gregorio_note *close_fusion_glyph(gregorio_glyph **last_glyph,
710 gregorio_note **first_note, gregorio_liquescentia liquescentia,
711 gregorio_note *real_last_note,
712 gregorio_shape *const punctum_inclinatum_orientation)
713 {
714 bool first = true;
715 gregorio_note *last_note, *texverb_tail;
716 gregorio_note *next;
717 int prev_shift = 0, shift, shift2;
718 gregorio_note *result;
719
720 gregorio_assert((*first_note)->type != GRE_TEXVERB_GLYPH,
721 close_fusion_glyph, "Unexpected texverb at start of fusion",
722 return real_last_note);
723
724 for (last_note = real_last_note;
725 last_note != *first_note && last_note->type == GRE_TEXVERB_GLYPH;
726 last_note = last_note->previous) {
727 /* skip over the trailing texverbs */
728 }
729 texverb_tail = (last_note == real_last_note)? NULL : last_note->next;
730
731 for (;;) {
732 bool processed = false;
733
734 /* fusion must work through glyph-level texverbs */
735 if ((*first_note)->type == GRE_TEXVERB_GLYPH) {
736 gregorio_add_unpitched_element_as_glyph(last_glyph,
737 (*first_note)->type, &((*first_note)->u.other), _NO_SIGN,
738 (*first_note)->texverb);
739 (*first_note)->texverb = 0;
740 gregorio_assert(*first_note != last_note,
741 close_fusion_glyph, "Unexpected texverb at end of fusion",
742 return last_note);
743 gregorio_free_one_note(first_note);
744 }
745
746 if (*first_note == last_note) {
747 close_fused_glyph(last_glyph, G_PUNCTUM, first_note,
748 liquescentia & ~TAIL_LIQUESCENTIA_MASK, last_note);
749 return last_note;
750 }
751
752 gregorio_assert((*first_note)->next, close_fusion_glyph,
753 "Unexpected single note during fusion", return last_note);
754
755 next = next_non_texverb_note(*first_note, last_note);
756
757 shift = next->u.note.pitch - (*first_note)->u.note.pitch;
758 if (shift != 0 && next == last_note) {
759 /* there are exactly two notes left, so we end fusion */
760 add_intervening_texverbs(last_glyph, (*first_note)->next, next);
761 result = close_fused_glyph(last_glyph,
762 shift < 0? G_FLEXA : G_PODATUS, first_note,
763 liquescentia, last_note);
764 if (texverb_tail) {
765 add_intervening_texverbs(last_glyph, texverb_tail,
766 real_last_note);
767 }
768 return result;
769 }
770 if (prev_shift >= 0 && shift < 0) {
771 /* check for a porrectus-like flexus */
772 gregorio_note *next_next = next_non_texverb_note(next, last_note);
773 gregorio_assert(next_next, close_fusion_glyph,
774 "Unexpected end of notes during fusion", return last_note);
775 shift2 = next_next->u.note.pitch - next->u.note.pitch;
776 if (shift2 > 0) {
777 if (next_next == last_note) {
778 /* there are exactly three notes left in a porrectus shape,
779 * so we end fusion */
780 add_intervening_texverbs(last_glyph, (*first_note)->next,
781 next);
782 add_intervening_texverbs(last_glyph, next->next, next_next);
783 result = close_fused_glyph(last_glyph,
784 G_PORRECTUS, first_note,
785 liquescentia, last_note);
786 add_intervening_texverbs(last_glyph, texverb_tail,
787 real_last_note);
788 return result;
789 }
790 /* found a porrectus-like flexus */
791 add_intervening_texverbs(last_glyph, *first_note, next);
792 close_fused_glyph(last_glyph,
793 shift < 0? G_FLEXA : G_PODATUS, first_note,
794 liquescentia & ~TAIL_LIQUESCENTIA_MASK, next);
795 prev_shift = shift2;
796 processed = true;
797 }
798 }
799
800 if (!processed) {
801 /* didn't find anything interesting, so fuse the single note */
802 gabc_determination ignored;
803 gregorio_glyph_type next_glyph_type =
804 add_note_to_a_glyph(G_UNDETERMINED,
805 (*first_note)->u.note.pitch, 0, (*first_note)->u.note.shape,
806 (*first_note)->u.note.liquescentia, *first_note, &ignored,
807 punctum_inclinatum_orientation);
808 close_fused_glyph(last_glyph, next_glyph_type, first_note,
809 liquescentia & ~TAIL_LIQUESCENTIA_MASK, *first_note);
810 prev_shift = shift;
811 }
812
813 if (first) {
814 first = false;
815 liquescentia = (liquescentia & TAIL_LIQUESCENTIA_MASK) | L_FUSED;
816 }
817 }
818 }
819
820 static gregorio_note *close_glyph(gregorio_glyph **last_glyph,
821 gregorio_glyph_type glyph_type, gregorio_note **first_note,
822 gregorio_liquescentia liquescentia, gregorio_note *current_note,
823 gregorio_shape *const punctum_inclinatum_orientation)
824 {
825 /* special case for fusion when rarer shapes don't exist */
826 if (glyph_type == G_TORCULUS) {
827 switch ((*first_note)->u.note.shape) {
828 case S_ORISCUS_UNDETERMINED:
829 case S_ORISCUS_ASCENDENS:
830 case S_ORISCUS_DESCENDENS:
831 case S_ORISCUS_SCAPUS_UNDETERMINED:
832 case S_ORISCUS_SCAPUS_ASCENDENS:
833 case S_ORISCUS_SCAPUS_DESCENDENS:
834 glyph_type = G_FUSED;
835 break;
836 default:
837 break;
838 }
839 }
840
841 if (glyph_type == G_FUSED) {
842 return close_fusion_glyph(last_glyph, first_note, liquescentia,
843 current_note, punctum_inclinatum_orientation);
844 } else {
845 return close_normal_glyph(last_glyph, glyph_type, first_note,
846 liquescentia, current_note);
847 }
848 }
849
850 /* a small function to automatically determine the pitch of a custo : it is
851 * the pitch of the next note, but we must take care of the clef changes, as
852 * custo are (normally and for now) only present before clef changes. */
853 /* TODO: there may be a side effect with the flated keys... */
854
855 static char gabc_determine_custo_pitch(gregorio_note *current_note,
856 int current_key, const gregorio_score *const score)
857 {
858 int pitch_difference = 0;
859 int newkey;
860 for (; current_note; current_note = current_note->next) {
861 switch (current_note->type) {
862 case GRE_CLEF:
863 newkey = gregorio_calculate_new_key(current_note->u.clef);
864 pitch_difference = newkey - current_key;
865 break;
866
867 case GRE_NOTE:
868 pitch_difference =
869 (int) current_note->u.note.pitch - pitch_difference;
870 while (pitch_difference < LOWEST_PITCH) {
871 pitch_difference += 7;
872 }
873 while (pitch_difference > score->highest_pitch) {
874 pitch_difference -= 7;
875 }
876 assert(pitch_difference >= LOWEST_PITCH
877 && pitch_difference <= score->highest_pitch);
878 return (char) pitch_difference;
879
880 default:
881 break;
882 }
883 }
884 return DUMMY_PITCH;
885 }
886
887 /****************************
888 *
889 * Function called with a list of gregorio_notes as argument, this
890 * list is determined from gabc notation by the function
891 * gabc_det_notes_from_string.
892 *
893 * In this function we create a list of glyphs, by determining their
894 * type according to the sequence of notes (we look at their height,
895 * shape, etc.). Each glyph has a pointer gregorio_note *first_note
896 * that will be filled with the good note (and notes will be cut as
897 * explained in the comments on close_glyph function).
898 *
899 * Here is how it works :
900 * current_glyph is the glyph we are currently determining, that is to
901 * say a glyph whose type may change according to the note we will add
902 * to it.
903 * current_note is the note we are currently dealing with.
904 * Let's take an example, if the list of notes is ab, the first step
905 * (current_glyph: undetermined, current_note: a) will be to add a to
906 * nothing, that will give a glyph "punctum" containing only one note:
907 * a. In the second step (current_glyph: punctum, current_note: b) we
908 * transform the glyph in "pes".
909 * For special notes like a key change or something, we stop the
910 * determination of the current glyph, we delete the note and we add
911 * it as a glyph.
912 *
913 * When we determine the glyphs we can encounter the shapes
914 * S_QUADRATUM and S_QUILISMA_QUADRATUM, which means that the
915 * corresponding note is the first note of a pes quadratum (it can
916 * have the shape quilisma for very rare forms). But these shapes must
917 * not appear in the final form of the score, and we transform them
918 * respectively in punctum and quilisma (and the glyph type must be
919 * pes_quadratum, but it is done in add_note_to_a_glyph).
920 *
921 ****************************/
922
923 /* this function updates current_key with the new values (with clef changes) */
924
925 gregorio_glyph *gabc_det_glyphs_from_notes(gregorio_note *current_note,
926 int *current_key, gregorio_shape *const punctum_inclinatum_orientation,
927 const gregorio_score *const score)
928 {
929 /* the first note of the current glyph, to be able to close it well:
930 * later we will cut the link (next_notes and previous_note) between
931 * this note and the previous one */
932 gregorio_note *current_glyph_first_note = current_note;
933
934 /* the last glyph we have totally determined. It is automatically
935 * updated by close_glyph(). */
936 gregorio_glyph *last_glyph = NULL;
937
938 /* type of the glyph we are currently determining */
939 gregorio_glyph_type current_glyph_type = G_UNDETERMINED;
940 gregorio_glyph_type next_glyph_type = G_UNDETERMINED;
941 char last_pitch = USELESS_VALUE;
942 gregorio_note *next_note = NULL;
943
944 /* determination of end of glyphs, see comments on
945 * add_note_to_a_glyph */
946 gabc_determination end_of_glyph = DET_NO_END;
947
948 /* a char representing the liquescentia of the current glyph */
949 gregorio_liquescentia liquescentia = L_NO_LIQUESCENTIA;
950 gregorio_liquescentia head_liquescentia;
951 bool autofuse = false, first_autofused_note = false;
952
953 gregorio_assert(current_note, gabc_det_glyphs_from_notes,
954 "current_note may not be NULL", return NULL);
955
956 gregorio_go_to_first_note(&current_note);
957
958 while (current_note) {
959 bool add = true;
960
961 next_note = current_note->next;
962 if (current_note->type != GRE_NOTE) {
963 gregorio_type type = current_note->type;
964 char pitch = USELESS_VALUE;
965 bool force = false;
966 gregorio_sign sign = _NO_SIGN;
967
968 if (current_glyph_type == G_FUSED
969 && (type == GRE_TEXVERB_GLYPH || type == GRE_TEXVERB_ELEMENT)) {
970 current_note = next_note;
971 continue;
972 }
973
974 if (current_glyph_type != G_UNDETERMINED) {
975 close_glyph(&last_glyph, next_glyph_type,
976 &current_glyph_first_note, liquescentia,
977 current_note->previous, punctum_inclinatum_orientation);
978 current_glyph_type = G_UNDETERMINED;
979 liquescentia = L_NO_LIQUESCENTIA;
980 }
981
982 switch (type) {
983 case GRE_CLEF:
984 pitch = current_note->u.note.pitch;
985 *current_key = gregorio_calculate_new_key(current_note->u.clef);
986 break;
987
988 case GRE_CUSTOS:
989 pitch = gabc_determine_custo_pitch(current_note->next,
990 *current_key, score);
991 break;
992
993 case GRE_MANUAL_CUSTOS:
994 pitch = current_note->u.note.pitch;
995 type = GRE_CUSTOS;
996 force = true;
997 break;
998
999 case GRE_BAR:
1000 /* we calculate the signs of the bars */
1001 if (current_note->signs == _V_EPISEMA) {
1002 sign = _V_EPISEMA;
1003 } else {
1004 sign = current_note->special_sign;
1005 }
1006 if (current_note->h_episema_above) {
1007 if (sign == _V_EPISEMA) {
1008 sign = _V_EPISEMA_BAR_H_EPISEMA;
1009 } else {
1010 sign = _BAR_H_EPISEMA;
1011 }
1012 }
1013 break;
1014
1015 case GRE_AUTOFUSE_START:
1016 autofuse = true;
1017 first_autofused_note = true;
1018 add = false;
1019 break;
1020
1021 case GRE_AUTOFUSE_END:
1022 autofuse = false;
1023 add = false;
1024 break;
1025
1026 default:
1027 /* do nothing */
1028 break;
1029 }
1030
1031 if (add) {
1032 if (pitch == USELESS_VALUE) {
1033 gregorio_add_unpitched_element_as_glyph(&last_glyph, type,
1034 &(current_note->u.other), sign,
1035 current_note->texverb);
1036 } else if (type == GRE_CLEF) {
1037 gregorio_add_clef_as_glyph(&last_glyph,
1038 current_note->u.clef, current_note->texverb);
1039 } else {
1040 gregorio_add_pitched_element_as_glyph(&last_glyph, type,
1041 pitch, force, current_note->texverb);
1042 }
1043 }
1044 current_glyph_first_note = current_note->next;
1045 current_note->texverb = 0;
1046 gregorio_free_one_note(&current_note);
1047 last_pitch = USELESS_VALUE;
1048 continue;
1049 }
1050
1051 /* first we do what must be done with liquescentia */
1052 head_liquescentia = current_note->u.note.liquescentia
1053 & (L_INITIO_DEBILIS | L_FUSED);
1054 if (head_liquescentia) {
1055 /* initio debilis or fused */
1056 if (current_glyph_type != G_UNDETERMINED) {
1057 /* if it is not the first glyph */
1058 close_glyph(&last_glyph, current_glyph_type,
1059 &current_glyph_first_note,
1060 liquescentia, current_note->previous,
1061 punctum_inclinatum_orientation);
1062 current_glyph_type = G_UNDETERMINED;
1063 }
1064 liquescentia = head_liquescentia;
1065 }
1066
1067 if (autofuse) {
1068 if (current_glyph_first_note == current_note) {
1069 if (first_autofused_note) {
1070 first_autofused_note = false;
1071 } else {
1072 if (!(current_note->u.note.liquescentia & L_INITIO_DEBILIS)) {
1073 current_note->u.note.liquescentia |= L_FUSED;
1074 liquescentia |= L_FUSED;
1075 }
1076 }
1077 } else {
1078 /* only handle the multi-note case here; the single-note
1079 * case will be added normally by the state machine */
1080 if (is_tail_liquescentia(current_note->u.note.liquescentia)
1081 && current_glyph_type > G_PUNCTA_INCLINATA) {
1082 /* once we hit a liquescent, that's the end of a string of
1083 * fused notes */
1084 liquescentia |= current_note->u.note.liquescentia;
1085 current_note = close_glyph(&last_glyph, G_FUSED,
1086 &current_glyph_first_note, liquescentia,
1087 current_note, punctum_inclinatum_orientation);
1088 current_glyph_type = G_UNDETERMINED;
1089 liquescentia = L_NO_LIQUESCENTIA;
1090 add = false;
1091 } else {
1092 switch (current_note->u.note.shape) {
1093 case S_PUNCTUM:
1094 case S_ORISCUS_UNDETERMINED:
1095 case S_ORISCUS_ASCENDENS:
1096 case S_ORISCUS_DESCENDENS:
1097 case S_ORISCUS_SCAPUS_UNDETERMINED:
1098 case S_ORISCUS_SCAPUS_ASCENDENS:
1099 case S_ORISCUS_SCAPUS_DESCENDENS:
1100 case S_QUILISMA:
1101 case S_QUADRATUM:
1102 case S_QUILISMA_QUADRATUM:
1103 case S_VIRGA:
1104 /* these are fusible */
1105 if (current_glyph_type <= G_PUNCTA_INCLINATA
1106 || current_note->u.note.shape != S_PUNCTUM) {
1107 /* if we had some puncta inclinata, then end them */
1108 /* if the current shape is not a punctum, start a
1109 * new shape */
1110 close_glyph(&last_glyph, current_glyph_type,
1111 &current_glyph_first_note,
1112 liquescentia, current_note->previous,
1113 punctum_inclinatum_orientation);
1114 if (!(current_note->u.note.liquescentia
1115 & L_INITIO_DEBILIS)) {
1116 current_note->u.note.liquescentia |= L_FUSED;
1117 liquescentia |= L_FUSED;
1118 }
1119 }
1120 next_glyph_type = current_glyph_type = G_FUSED;
1121 add = false;
1122 break;
1123
1124 default:
1125 /* not fusible; will be added normally by the state
1126 * machine */
1127 break;
1128 }
1129 }
1130 }
1131 }
1132
1133 if (add) {
1134 next_glyph_type = add_note_to_a_glyph(current_glyph_type,
1135 current_note->u.note.pitch, last_pitch,
1136 current_note->u.note.shape,
1137 current_note->u.note.liquescentia,
1138 current_glyph_first_note, &end_of_glyph,
1139 punctum_inclinatum_orientation);
1140 }
1141
1142 /* patch to have good shapes in the special cases of pes quadratum and
1143 * pes quilisma quadratum. */
1144 switch (current_note->u.note.shape) {
1145 case S_QUADRATUM:
1146 current_note->u.note.shape = S_PUNCTUM;
1147 break;
1148
1149 case S_QUILISMA_QUADRATUM:
1150 current_note->u.note.shape = S_QUILISMA;
1151 break;
1152
1153 default:
1154 /* do nothing */
1155 break;
1156 }
1157
1158 if (add) {
1159 /* see comments on add_note_to_a_glyph for the meaning of
1160 * end_of_glyph */
1161 switch (end_of_glyph) {
1162 case DET_NO_END:
1163 current_glyph_type = next_glyph_type;
1164 /*
1165 * we deal with liquescentia
1166 */
1167 if (is_tail_liquescentia(current_note->u.note.liquescentia)) {
1168 /* special cases of oriscus descendens, treated like normal
1169 * oriscus in some cases. */
1170 if (score->legacy_oriscus_orientation) {
1171 if (current_note->u.note.shape == S_ORISCUS_DESCENDENS
1172 && current_note->next
1173 && current_note->next->type == GRE_NOTE
1174 && current_note->next->u.note.pitch <
1175 current_note->u.note.pitch) {
1176 last_pitch = current_note->u.note.pitch;
1177 current_note->u.note.shape = S_ORISCUS_ASCENDENS;
1178 current_note->u.note.liquescentia =
1179 L_NO_LIQUESCENTIA;
1180 current_note = next_note;
1181 continue;
1182 }
1183 }
1184 /* special cases of the punctum inclinatum deminutus and
1185 * auctus */
1186 if (is_punctum_inclinatum(current_note->u.note.shape, false)) {
1187 if (current_note->u.note.liquescentia == L_DEMINUTUS) {
1188 current_note->u.note.shape =
1189 S_PUNCTUM_INCLINATUM_DEMINUTUS;
1190 }
1191 if (current_note->u.note.liquescentia
1192 == L_AUCTUS_DESCENDENS
1193 || current_note->u.note.liquescentia
1194 == L_AUCTUS_ASCENDENS) {
1195 current_note->u.note.shape =
1196 S_PUNCTUM_INCLINATUM_AUCTUS;
1197 }
1198
1199 if (current_note->next
1200 && current_note->next->type == GRE_NOTE
1201 && is_punctum_inclinatum(
1202 current_note->next->u.note.shape, false)
1203 && current_note->next->u.note.liquescentia
1204 == L_DEMINUTUS) {
1205 last_pitch = current_note->u.note.pitch;
1206 current_note = next_note;
1207 continue;
1208 }
1209 }
1210 liquescentia |= current_note->u.note.liquescentia;
1211 /* once again, only works with the good values in the header
1212 * file */
1213 current_note = close_glyph(&last_glyph, current_glyph_type,
1214 &current_glyph_first_note, liquescentia,
1215 current_note, punctum_inclinatum_orientation);
1216 current_glyph_type = G_UNDETERMINED;
1217 liquescentia = L_NO_LIQUESCENTIA;
1218 }
1219 break;
1220 case DET_END_OF_PREVIOUS:
1221 if (current_note->previous)
1222 {
1223 /* we don't want to close previous glyph twice */
1224 close_glyph(&last_glyph, current_glyph_type,
1225 &current_glyph_first_note, liquescentia,
1226 current_note->previous,
1227 punctum_inclinatum_orientation);
1228 }
1229 current_glyph_type = next_glyph_type;
1230 liquescentia = L_NO_LIQUESCENTIA;
1231 last_pitch = USELESS_VALUE;
1232 /* we deal with liquescentia */
1233 if (is_tail_liquescentia(current_note->u.note.liquescentia))
1234 /* not an initio debilis, because we considered it in the first
1235 * part... */
1236 {
1237 /* special cases of the punctum inclinatum deminutus and
1238 * auctus */
1239 if (is_punctum_inclinatum(current_note->u.note.shape, false)) {
1240 if (current_note->u.note.liquescentia == L_DEMINUTUS) {
1241 current_note->u.note.shape =
1242 S_PUNCTUM_INCLINATUM_DEMINUTUS;
1243 }
1244 if (current_note->u.note.liquescentia ==
1245 L_AUCTUS_DESCENDENS
1246 || current_note->u.note.liquescentia ==
1247 L_AUCTUS_ASCENDENS) {
1248 current_note->u.note.shape =
1249 S_PUNCTUM_INCLINATUM_AUCTUS;
1250 }
1251 if (current_note->next
1252 && current_note->next->type == GRE_NOTE
1253 && is_punctum_inclinatum(
1254 current_note->next->u.note.shape, false)
1255 && current_note->next->u.note.liquescentia ==
1256 L_DEMINUTUS) {
1257 current_note = next_note;
1258 continue;
1259 }
1260 }
1261 current_note = close_glyph(&last_glyph, current_glyph_type,
1262 &current_glyph_first_note,
1263 current_note->u.note.liquescentia, current_note,
1264 punctum_inclinatum_orientation);
1265 current_glyph_type = G_UNDETERMINED;
1266 }
1267 break;
1268 case DET_END_OF_CURRENT:
1269 liquescentia += current_note->u.note.liquescentia;
1270 /* once again, only works with the good values in the header file */
1271 current_note = close_glyph(&last_glyph, next_glyph_type,
1272 &current_glyph_first_note, liquescentia, current_note,
1273 punctum_inclinatum_orientation);
1274 current_glyph_type = G_UNDETERMINED;
1275 liquescentia = L_NO_LIQUESCENTIA;
1276 break;
1277 case DET_END_OF_BOTH:
1278 if (current_note->previous)
1279 {
1280 /* we don't want to close previous glyph twice */
1281 close_glyph(&last_glyph, current_glyph_type,
1282 &current_glyph_first_note, liquescentia,
1283 current_note->previous,
1284 punctum_inclinatum_orientation);
1285 }
1286 current_glyph_type = G_UNDETERMINED;
1287 liquescentia = L_NO_LIQUESCENTIA;
1288 current_note = close_glyph(&last_glyph, next_glyph_type,
1289 &current_glyph_first_note,
1290 current_note->u.note.liquescentia, current_note,
1291 punctum_inclinatum_orientation);
1292 break;
1293 }
1294 }
1295
1296 if ((!next_note && current_glyph_type != G_UNDETERMINED)
1297 || (autofuse && current_note
1298 && current_note->u.note.shape == S_VIRGA)) {
1299 /* we must end the determination here */
1300 current_note = close_glyph(&last_glyph, current_glyph_type,
1301 &current_glyph_first_note, liquescentia, current_note,
1302 punctum_inclinatum_orientation);
1303 next_glyph_type = current_glyph_type = G_UNDETERMINED;
1304 liquescentia = L_NO_LIQUESCENTIA;
1305 }
1306
1307 last_pitch = current_note->u.note.pitch;
1308 current_note = next_note;
1309 }
1310 /* end of while */
1311
1312 gregorio_go_to_first_glyph(&last_glyph);
1313 return last_glyph;
1314 }