summaryrefslogtreecommitdiff
path: root/Build/source/texk/gregorio/gregorio-src/src/struct.c
diff options
context:
space:
mode:
authorAkira Kakuto <kakuto@fuk.kindai.ac.jp>2016-02-09 02:13:53 +0000
committerAkira Kakuto <kakuto@fuk.kindai.ac.jp>2016-02-09 02:13:53 +0000
commit77471d966e7252229e6379968b18a7ad789b56da (patch)
tree5e6ff026566c8f7443f132bb097e7325b7b5acee /Build/source/texk/gregorio/gregorio-src/src/struct.c
parenta286a15b8e122724c858631a30ad23e0e9bff1a1 (diff)
gregorio 4.1.0-beta2
git-svn-id: svn://tug.org/texlive/trunk@39632 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/gregorio/gregorio-src/src/struct.c')
-rw-r--r--Build/source/texk/gregorio/gregorio-src/src/struct.c325
1 files changed, 138 insertions, 187 deletions
diff --git a/Build/source/texk/gregorio/gregorio-src/src/struct.c b/Build/source/texk/gregorio/gregorio-src/src/struct.c
index d11366949c1..b1826f66df1 100644
--- a/Build/source/texk/gregorio/gregorio-src/src/struct.c
+++ b/Build/source/texk/gregorio/gregorio-src/src/struct.c
@@ -179,7 +179,9 @@ void gregorio_add_clef_as_note(gregorio_note **current_note,
void gregorio_add_secondary_clef_to_note(gregorio_note *current_note,
gregorio_clef clef, signed char clef_line, bool flatted)
{
- if (!current_note || current_note->type != GRE_CLEF) {
+ gregorio_not_null(current_note, gregorio_add_secondary_clef_to_note,
+ return);
+ if (current_note->type != GRE_CLEF) {
gregorio_message(_("trying to add a secondary clef to something that "
"is not a clef"), "gregorio_add_secondary_clef_to_note",
VERBOSITY_ERROR, 0);
@@ -219,9 +221,7 @@ void gregorio_add_texverb_as_note(gregorio_note **current_note, char *str,
gregorio_type type, const gregorio_scanner_location *const loc)
{
gregorio_note *element;
- if (str == NULL) {
- return;
- }
+ gregorio_not_null(str, gregorio_add_texverb_as_note, return);
element = create_and_link_note(current_note, loc);
assert(type == GRE_TEXVERB_GLYPH || type == GRE_TEXVERB_ELEMENT
|| type == GRE_ALT);
@@ -255,9 +255,7 @@ void gregorio_add_texverb_to_note(gregorio_note *current_note, char *str)
{
size_t len;
char *res;
- if (str == NULL) {
- return;
- }
+ gregorio_not_null(str, gregorio_add_texverb_as_note, return);
if (current_note) {
if (current_note->texverb) {
len = strlen(current_note->texverb) + strlen(str) + 1;
@@ -284,8 +282,10 @@ void gregorio_add_cs_to_note(gregorio_note *const*const current_note,
void gregorio_add_special_sign(gregorio_note *note, gregorio_sign sign)
{
- if (!note) {
- /* error */
+ if (!note || note->type != GRE_NOTE) {
+ gregorio_message(_("trying to add a special sign to something that is "
+ "not a note"), "gregorio_add_special_sign", VERBOSITY_ERROR,
+ 0);
return;
}
note->special_sign = sign;
@@ -381,22 +381,26 @@ static void fix_oriscus_cavum_liquescentia(gregorio_note *const note,
}
}
-void gregorio_change_shape(gregorio_note *note, gregorio_shape shape,
- const bool legacy_oriscus_orientation)
+void gregorio_change_shape(gregorio_note *const note,
+ const gregorio_shape shape, const bool legacy_oriscus_orientation)
{
+ gregorio_shape old_shape;
if (!note || note->type != GRE_NOTE) {
gregorio_message(_("trying to change the shape of something that is "
- "not a note"), "change_shape", VERBOSITY_ERROR, 0);
+ "not a note"), "change_shape", VERBOSITY_ERROR, 0);
return;
}
- if (shape == S_PUNCTUM_CAVUM) {
+ old_shape = note->u.note.shape;
+ note->u.note.shape = shape;
+ switch (shape) {
+ case S_PUNCTUM_CAVUM:
/* S_PUNCTUM_CAVUM morphs other shapes */
- switch (note->u.note.shape) {
+ switch (old_shape) {
case S_PUNCTUM_INCLINATUM:
note->u.note.shape = S_PUNCTUM_CAVUM_INCLINATUM;
fix_punctum_cavum_inclinatum_liquescentia(note);
- return;
+ break;
case S_ORISCUS_UNDETERMINED:
case S_ORISCUS_ASCENDENS:
@@ -404,15 +408,13 @@ void gregorio_change_shape(gregorio_note *note, gregorio_shape shape,
case S_ORISCUS_DEMINUTUS:
note->u.note.shape = S_ORISCUS_CAVUM_UNDETERMINED;
fix_oriscus_cavum_liquescentia(note, legacy_oriscus_orientation);
- return;
+ break;
default:
break;
}
- }
+ break;
- note->u.note.shape = shape;
- switch (shape) {
case S_STROPHA:
case S_DISTROPHA:
case S_TRISTROPHA:
@@ -420,53 +422,21 @@ void gregorio_change_shape(gregorio_note *note, gregorio_shape shape,
break;
case S_ORISCUS_UNDETERMINED:
- fix_oriscus_liquescentia(note, legacy_oriscus_orientation);
- break;
-
- case S_ORISCUS_ASCENDENS:
- note->u.note.liquescentia =
- (note->u.note.liquescentia & ~TAIL_LIQUESCENTIA_MASK)
- | L_AUCTUS_ASCENDENS;
- fix_oriscus_liquescentia(note, legacy_oriscus_orientation);
- break;
-
- case S_ORISCUS_DESCENDENS:
- note->u.note.liquescentia =
- (note->u.note.liquescentia & ~TAIL_LIQUESCENTIA_MASK)
- | L_AUCTUS_DESCENDENS;
- fix_oriscus_liquescentia(note, legacy_oriscus_orientation);
- break;
-
- case S_ORISCUS_DEMINUTUS:
- note->u.note.liquescentia =
- (note->u.note.liquescentia & ~TAIL_LIQUESCENTIA_MASK)
- | L_DEMINUTUS;
- fix_oriscus_liquescentia(note, legacy_oriscus_orientation);
- break;
-
- case S_ORISCUS_CAVUM_UNDETERMINED:
- fix_oriscus_cavum_liquescentia(note, legacy_oriscus_orientation);
- break;
-
- case S_ORISCUS_CAVUM_ASCENDENS:
- note->u.note.liquescentia =
- (note->u.note.liquescentia & ~TAIL_LIQUESCENTIA_MASK)
- | L_AUCTUS_ASCENDENS;
- fix_oriscus_cavum_liquescentia(note, legacy_oriscus_orientation);
- break;
-
- case S_ORISCUS_CAVUM_DESCENDENS:
- note->u.note.liquescentia =
- (note->u.note.liquescentia & ~TAIL_LIQUESCENTIA_MASK)
- | L_AUCTUS_DESCENDENS;
- fix_oriscus_cavum_liquescentia(note, legacy_oriscus_orientation);
- break;
+ switch (old_shape) {
+ case S_PUNCTUM_CAVUM:
+ case S_PUNCTUM_CAVUM_INCLINATUM:
+ case S_ORISCUS_CAVUM_UNDETERMINED:
+ case S_ORISCUS_CAVUM_ASCENDENS:
+ case S_ORISCUS_CAVUM_DESCENDENS:
+ case S_ORISCUS_CAVUM_DEMINUTUS:
+ note->u.note.shape = S_ORISCUS_CAVUM_UNDETERMINED;
+ fix_oriscus_cavum_liquescentia(note, legacy_oriscus_orientation);
+ break;
- case S_ORISCUS_CAVUM_DEMINUTUS:
- note->u.note.liquescentia =
- (note->u.note.liquescentia & ~TAIL_LIQUESCENTIA_MASK)
- | L_DEMINUTUS;
- fix_oriscus_cavum_liquescentia(note, legacy_oriscus_orientation);
+ default:
+ fix_oriscus_liquescentia(note, legacy_oriscus_orientation);
+ break;
+ }
break;
default:
@@ -559,20 +529,13 @@ static void apply_auto_h_episema(gregorio_note *const note,
static void gregorio_activate_isolated_h_episema(gregorio_note *note,
const grehepisema_size size, const bool disable_bridge, int n)
{
- if (!note) {
- gregorio_message(ngt_("isolated horizontal episema at the beginning "
- "of a note sequence, ignored",
- "isolated horizontal episema at the beginning of a note "
- "sequence, ignored", n), "activate_h_isolated_episema",
- VERBOSITY_WARNING, 0);
- return;
- }
+ gregorio_not_null(note, gregorio_activate_isolated_h_episema, return);
if (note->type != GRE_NOTE) {
gregorio_message(ngt_("isolated horizontal episema after something "
"that is not a note, ignored",
"isolated horizontal episema after something that is not "
"a note, ignored", n), "activate_h_isolated_episema",
- VERBOSITY_WARNING, 0);
+ VERBOSITY_ERROR, 0);
return;
}
for (; n > 0; --n) {
@@ -580,7 +543,7 @@ static void gregorio_activate_isolated_h_episema(gregorio_note *note,
if (!note || note->type != GRE_NOTE) {
gregorio_message(_("found more horizontal episema than notes "
"able to be under"), "activate_h_isolated_episema",
- VERBOSITY_WARNING, 0);
+ VERBOSITY_ERROR, 0);
return;
}
}
@@ -597,11 +560,7 @@ void gregorio_add_h_episema(gregorio_note *note,
VERBOSITY_ERROR, 0);
return;
}
- if (!nbof_isolated_episema) {
- gregorio_message(_("NULL argument nbof_isolated_episema"),
- "add_h_episema", VERBOSITY_FATAL, 0);
- return;
- }
+ gregorio_not_null(nbof_isolated_episema, gregorio_add_h_episema, return);
if (vposition && *nbof_isolated_episema) {
gregorio_message(_("trying to add a forced horizontal episema on a "
"note which already has an automatic horizontal "
@@ -634,7 +593,8 @@ void gregorio_add_sign(gregorio_note *note, gregorio_sign sign,
gregorio_vposition vposition)
{
if (!note) {
- /* error */
+ gregorio_message(_("trying to add a sign to something that is "
+ "not a note"), "gregorio_add_sign", VERBOSITY_ERROR, 0);
return;
}
switch (sign) {
@@ -680,16 +640,19 @@ void gregorio_add_sign(gregorio_note *note, gregorio_sign sign,
break;
default:
+ /* not reachable unless there's a programming error */
+ /* LCOV_EXCL_START */
+ gregorio_fail2(gregorio_add_sign, "unexpected sign to add: %s",
+ gregorio_sign_to_string(sign));
break;
+ /* LCOV_EXCL_STOP */
}
}
void gregorio_go_to_first_note(gregorio_note **note)
{
gregorio_note *tmp;
- if (!*note) {
- return;
- }
+ gregorio_not_null_ptr(note, gregorio_go_to_first_note, return);
tmp = *note;
while (tmp->previous) {
tmp = tmp->previous;
@@ -710,9 +673,7 @@ static __inline void free_one_note(gregorio_note *note)
void gregorio_free_one_note(gregorio_note **note)
{
gregorio_note *next = NULL;
- if (!note || !*note) {
- return;
- }
+ gregorio_not_null_ptr(note, gregorio_free_one_note, return);
if ((*note)->next) {
(*note)->next->previous = (*note)->previous;
next = (*note)->next;
@@ -798,9 +759,7 @@ void gregorio_add_unpitched_element_as_glyph(gregorio_glyph **current_glyph,
void gregorio_go_to_first_glyph(gregorio_glyph **glyph)
{
gregorio_glyph *tmp;
- if (!*glyph) {
- return;
- }
+ gregorio_not_null_ptr(glyph, gregorio_go_to_first_glyph, return);
tmp = *glyph;
while (tmp->previous) {
tmp = tmp->previous;
@@ -828,9 +787,7 @@ static __inline void free_one_glyph(gregorio_glyph *glyph)
void gregorio_free_one_glyph(gregorio_glyph **glyph)
{
gregorio_glyph *next = NULL;
- if (!glyph || !*glyph) {
- return;
- }
+ gregorio_not_null_ptr(glyph, gregorio_free_one_glyph, return);
if ((*glyph)->next) {
(*glyph)->next->previous = NULL;
next = (*glyph)->next;
@@ -845,9 +802,7 @@ void gregorio_free_one_glyph(gregorio_glyph **glyph)
static void gregorio_free_glyphs(gregorio_glyph **glyph)
{
gregorio_glyph *next_glyph;
- if (!glyph || !*glyph) {
- return;
- }
+ gregorio_not_null(glyph, gregorio_free_glyphs, return);
while (*glyph) {
next_glyph = (*glyph)->next;
free_one_glyph(*glyph);
@@ -917,16 +872,18 @@ static __inline void free_one_element(gregorio_element *element)
static void gregorio_free_one_element(gregorio_element **element)
{
gregorio_element *next = NULL;
- if (!element || !*element) {
- return;
- }
+ gregorio_not_null_ptr(element, gregorio_free_one_element, return);
if ((*element)->next) {
(*element)->next->previous = NULL;
next = (*element)->next;
}
if ((*element)->previous) {
+ /* this doesn't currently happen, but it's safer to leave this in */
+ /* LCOV_EXCL_START */
(*element)->previous->next = NULL;
}
+ /* The previous line is probably optimized out */
+ /* LCOV_EXCL_STOP */
free_one_element(*element);
*element = next;
}
@@ -967,9 +924,7 @@ static void gregorio_free_one_character(gregorio_character *current_character)
void gregorio_free_characters(gregorio_character *current_character)
{
gregorio_character *next_character;
- if (!current_character) {
- return;
- }
+ gregorio_not_null(current_character, gregorio_free_characters, return);
while (current_character) {
next_character = current_character->next_character;
gregorio_free_one_character(current_character);
@@ -980,9 +935,7 @@ void gregorio_free_characters(gregorio_character *current_character)
void gregorio_go_to_first_character(const gregorio_character **character)
{
const gregorio_character *tmp;
- if (!character || !*character) {
- return;
- }
+ gregorio_not_null_ptr(character, gregorio_free_characters, return);
tmp = *character;
while (tmp->previous_character) {
tmp = tmp->previous_character;
@@ -1057,14 +1010,10 @@ void gregorio_add_syllable(gregorio_syllable **current_syllable,
gregorio_syllable *next;
gregorio_element **tab;
int i;
- if (number_of_voices > MAX_NUMBER_OF_VOICES) {
- gregorio_message(_("too many voices"), "add_syllable", VERBOSITY_FATAL,
- 0);
- return;
- }
+ gregorio_not_null(elements, gregorio_add_syllable, return);
+ gregorio_assert(number_of_voices == 1, gregorio_add_syllable,
+ "gregorio only supports one voice", return);
next = gregorio_calloc(1, sizeof(gregorio_syllable));
- next->type = GRE_SYLLABLE;
- next->special_sign = _NO_SIGN;
next->position = position;
next->no_linebreak_area = no_linebreak_area;
next->euouae = euouae;
@@ -1082,14 +1031,8 @@ void gregorio_add_syllable(gregorio_syllable **current_syllable,
next->previous_syllable = *current_syllable;
tab = (gregorio_element **) gregorio_malloc(number_of_voices *
sizeof(gregorio_element *));
- if (elements) {
- for (i = 0; i < number_of_voices; i++) {
- tab[i] = elements[i];
- }
- } else {
- for (i = 0; i < number_of_voices; i++) {
- tab[i] = NULL;
- }
+ for (i = 0; i < number_of_voices; i++) {
+ tab[i] = elements[i];
}
next->elements = tab;
if (*current_syllable) {
@@ -1103,11 +1046,7 @@ static void gregorio_free_one_syllable(gregorio_syllable **syllable,
{
int i;
gregorio_syllable *next;
- if (!syllable || !*syllable) {
- gregorio_message(_("function called with NULL argument"),
- "free_one_syllable", VERBOSITY_WARNING, 0);
- return;
- }
+ gregorio_not_null_ptr(syllable, gregorio_free_one_syllable, return);
for (i = 0; i < number_of_voices; i++) {
gregorio_free_elements((struct gregorio_element **)
&((*syllable)->elements[i]));
@@ -1128,11 +1067,7 @@ static void gregorio_free_one_syllable(gregorio_syllable **syllable,
static void gregorio_free_syllables(gregorio_syllable **syllable,
int number_of_voices)
{
- if (!syllable || !*syllable) {
- gregorio_message(_("function called with NULL argument"),
- "free_syllables", VERBOSITY_WARNING, 0);
- return;
- }
+ gregorio_not_null_ptr(syllable, gregorio_free_one_syllable, return);
while (*syllable) {
gregorio_free_one_syllable(syllable, number_of_voices);
}
@@ -1149,11 +1084,7 @@ gregorio_score *gregorio_new_score(void)
static void gregorio_free_score_infos(gregorio_score *score)
{
- if (!score) {
- gregorio_message(_("function called with NULL argument"),
- "gregorio_free_score_infos", VERBOSITY_WARNING, 0);
- return;
- }
+ gregorio_not_null(score, gregorio_free_score_infos, return);
/* don't free the strings coming from headers; they will be freed when the
* headers themselves are freed */
if (score->first_voice_info) {
@@ -1174,12 +1105,11 @@ static void free_headers(gregorio_score *score) {
void gregorio_free_score(gregorio_score *score)
{
- if (!score) {
- gregorio_message(_("function called with NULL argument"),
- "free_one_syllable", VERBOSITY_WARNING, 0);
- return;
+ gregorio_not_null(score, gregorio_free_score, return);
+ if (score->first_syllable) {
+ gregorio_free_syllables(&(score->first_syllable),
+ score->number_of_voices);
}
- gregorio_free_syllables(&(score->first_syllable), score->number_of_voices);
gregorio_free_score_infos(score);
free_headers(score);
free(score);
@@ -1188,20 +1118,16 @@ void gregorio_free_score(gregorio_score *score)
void gregorio_add_voice_info(gregorio_voice_info **current_voice_info)
{
gregorio_voice_info *next = gregorio_calloc(1, sizeof(gregorio_voice_info));
- if (*current_voice_info) {
- (*current_voice_info)->next_voice_info = next;
- }
+ gregorio_assert(!*current_voice_info, gregorio_add_voice_info,
+ "since gregorio only supports once voice, this should only be "
+ "called once", (*current_voice_info)->next_voice_info = next);
*current_voice_info = next;
}
void gregorio_free_voice_infos(gregorio_voice_info *voice_info)
{
gregorio_voice_info *next;
- if (!voice_info) {
- gregorio_message(_("function called with NULL argument"),
- "free_voice_info", VERBOSITY_WARNING, 0);
- return;
- }
+ gregorio_not_null(voice_info, gregorio_free_voice_infos, return);
while (voice_info) {
next = voice_info->next_voice_info;
free(voice_info);
@@ -1212,11 +1138,7 @@ void gregorio_free_voice_infos(gregorio_voice_info *voice_info)
void gregorio_set_score_annotation(gregorio_score *score, char *annotation)
{
int annotation_num;
- if (!score) {
- gregorio_message(_("function called with NULL argument"),
- "gregorio_set_annotation", VERBOSITY_WARNING, 0);
- return;
- }
+ gregorio_not_null(score, gregorio_set_score_annotation, return);
/* save the annotation in the first spare place. */
for (annotation_num = 0; annotation_num < MAX_ANNOTATIONS; ++annotation_num) {
if (score->annotation[annotation_num] == NULL) {
@@ -1233,11 +1155,7 @@ void gregorio_set_score_annotation(gregorio_score *score, char *annotation)
void gregorio_set_score_staff_lines(gregorio_score *const score,
const char staff_lines)
{
- if (!score) {
- gregorio_message(_("function called with NULL argument"),
- "gregorio_set_score_staff_lines", VERBOSITY_WARNING, 0);
- return;
- }
+ gregorio_not_null(score, gregorio_set_score_staff_lines, return);
if (staff_lines < 2 || staff_lines > 5) {
gregorio_message(_("invalid number of staff lines"),
"gregorio_set_score_staff_lines", VERBOSITY_ERROR, 0);
@@ -1251,11 +1169,7 @@ void gregorio_set_score_staff_lines(gregorio_score *const score,
void gregorio_add_score_header(gregorio_score *score, char *name, char *value)
{
gregorio_header *header;
- if (!score) {
- gregorio_message(_("function called with NULL argument"),
- "gregorio_add_score_header", VERBOSITY_WARNING, 0);
- return;
- }
+ gregorio_not_null(score, gregorio_add_score_header, return);
header = (gregorio_header *)gregorio_malloc(sizeof(gregorio_header));
header->name = name;
header->value = value;
@@ -1299,9 +1213,11 @@ int gregorio_calculate_new_key(gregorio_clef_info clef)
return (2 * clef.line) - 4;
break;
default:
- gregorio_message(_("can't calculate key"),
- "gregorio_calculate_new_key", VERBOSITY_ERROR, 0);
+ /* not reachable unless there's a programming error */
+ /* LCOV_EXCL_START */
+ gregorio_fail(gregorio_calculate_new_key, "can't calculate key");
return NO_KEY;
+ /* LCOV_EXCL_STOP */
}
}
@@ -1309,10 +1225,7 @@ static signed char gregorio_syllable_first_note(gregorio_syllable *syllable)
{
gregorio_element *element;
gregorio_glyph *glyph;
- if (!syllable) {
- gregorio_message(_("called with a NULL argument"),
- "gregorio_syllable_first_note", VERBOSITY_ERROR, 0);
- }
+ gregorio_not_null(syllable, gregorio_syllable_first_note, return 0);
element = syllable->elements[0];
while (element) {
if (element->type == GRE_CUSTOS) {
@@ -1339,11 +1252,10 @@ signed char gregorio_determine_next_pitch(gregorio_syllable *syllable,
gregorio_element *element, gregorio_glyph *glyph)
{
signed char temp;
- if (!element || !syllable) {
- gregorio_message(_("called with a NULL argument"),
- "gregorio_determine_next_pitch", VERBOSITY_ERROR, 0);
- return DUMMY_PITCH;
- }
+ gregorio_not_null(element, gregorio_determine_next_pitch,
+ return DUMMY_PITCH);
+ gregorio_not_null(syllable, gregorio_determine_next_pitch,
+ return DUMMY_PITCH);
/* we first explore the next glyphs to find a note, if there is one */
if (glyph) {
glyph = glyph->next;
@@ -1374,7 +1286,7 @@ signed char gregorio_determine_next_pitch(gregorio_syllable *syllable,
}
glyph = glyph->next;
}
- }
+ } /* I think this is optimized out; LCOV_EXCL_LINE */
element = element->next;
}
@@ -1401,7 +1313,7 @@ signed char gregorio_determine_next_pitch(gregorio_syllable *syllable,
* it and we update the score->voice-info->initial_key. Works in
* polyphony.
*
- *********************************/
+ ******************************/
void gregorio_fix_initial_keys(gregorio_score *score,
gregorio_clef_info default_clef)
@@ -1411,18 +1323,17 @@ void gregorio_fix_initial_keys(gregorio_score *score,
int i;
char to_delete = 1;
- if (!score || !score->first_syllable || !score->first_voice_info) {
- gregorio_message(_("score is not available"),
- "gregorio_fix_initial_keys", VERBOSITY_WARNING, 0);
+ gregorio_not_null(score, gregorio_fix_initial_keys, return);
+ gregorio_not_null(score->first_voice_info, gregorio_fix_initial_keys,
+ return);
+ if (!score->first_syllable) {
+ /* valid but almost nonsense: a score with no syllables */
return;
}
voice_info = score->first_voice_info;
for (i = 0; i < score->number_of_voices; i++) {
element = score->first_syllable->elements[i];
- if (!element) {
- continue;
- }
- if (element->type == GRE_CLEF) {
+ if (element && element->type == GRE_CLEF) {
voice_info->initial_clef = element->u.misc.clef;
gregorio_free_one_element(&(score->first_syllable->elements[i]));
gregorio_messagef("gregorio_fix_initial_keys", VERBOSITY_INFO, 0,
@@ -1472,9 +1383,7 @@ void gregorio_fix_initial_keys(gregorio_score *score,
bool gregorio_is_only_special(gregorio_element *element)
{
- if (!element) {
- return 0;
- }
+ gregorio_not_null(element, gregorio_is_only_special, return 0);
while (element) {
if (element->type == GRE_ELEMENT) {
return 0;
@@ -1490,6 +1399,48 @@ const char *gregorio_unknown(int value) {
return buf;
}
+/*
+ * A small helper for the following function
+ */
+
+static __inline bool is_clef(gregorio_type x)
+{
+ return x == GRE_CLEF;
+}
+
+/*
+ * This function is used in write_syllable, it detects if the syllable is like
+ * (c4), (::c4), (z0c4) or (z0::c4). It returns the gregorio_element of the
+ * clef change.
+ */
+gregorio_element *gregorio_get_clef_change(gregorio_syllable *syllable)
+{
+ gregorio_element *element;
+ gregorio_assert(syllable && syllable->elements && syllable->elements[0],
+ gregoriotex_syllable_is_clef_change, "invalid syllable",
+ return NULL);
+ element = syllable->elements[0];
+ /* we just detect the foud cases */
+ if (element->type == GRE_CUSTOS && element->next
+ && (is_clef(element->next->type)) && !element->next->next) {
+ return element->next;
+ }
+ if (element->type == GRE_BAR && element->next
+ && (is_clef(element->next->type)) && !element->next->next) {
+ return element->next;
+ }
+ if ((is_clef(element->type)) && !element->next) {
+ return element;
+ }
+ if (element->type == GRE_CUSTOS && element->next
+ && element->next->type == GRE_BAR && element->next->next
+ && (is_clef(element->next->next->type))
+ && !element->next->next->next) {
+ return element->next->next;
+ }
+ return NULL;
+}
+
ENUM_TO_STRING(gregorio_type, GREGORIO_TYPE)
ENUM_TO_STRING(gregorio_shape, GREGORIO_SHAPE)
ENUM_TO_STRING(gregorio_bar, GREGORIO_BAR)
@@ -1500,7 +1451,7 @@ ENUM_TO_STRING(grehepisema_size, GREHEPISEMA_SIZE)
ENUM_TO_STRING(gregorio_vposition, GREGORIO_VPOSITION)
ENUM_TO_STRING(gregorio_glyph_type, GREGORIO_GLYPH_TYPE)
ENUM_TO_STRING(grestyle_style, GRESTYLE_STYLE)
-ENUM_TO_STRING(grestyle_type, GRESTYLE_TYPE)
+/* ENUM_TO_STRING(grestyle_type, GRESTYLE_TYPE) */
ENUM_TO_STRING(gregorio_tr_centering, GREGORIO_TR_CENTERING)
ENUM_TO_STRING(gregorio_nlba, GREGORIO_NLBA)
ENUM_TO_STRING(gregorio_euouae, GREGORIO_EUOUAE)