- else if (i == s - 1 && delta_pitch < 0)
- {
- // brevis; previous note must be turned into flexa
- if (duration_log == -1)
- {
- if (prev_brevis_shape)
- {
- prev_primitive->set_property
- ("primitive",
- scm_from_int
- (MLP_FLEXA
- | (scm_to_int (prev_primitive->get_property ("primitive"))
- & MLP_DOWN)));
- primitive->set_property ("primitive", scm_from_int (MLP_NONE));
- break; // no more notes, no join
- }
- else
- {
- nr->origin ()->warning
- (_ ("invalid ligatura ending:\n"
- "when the last note is a descending brevis,\n"
- "the penultimate note must be another one,\n"
- "or the ligatura must be LB or SSB"));
- primitive->set_property ("primitive", scm_from_int (MLP_NONE));
- break;
- }
- }
- // longa
- else if (duration_log == -2)
- {
- primitive->set_property ("primitive", scm_from_int (MLP_BREVIS));
- general_case = false;
- }
- // else maxima; fall through regular case below
- }
+ else if (i == s - 1 && pitch < prev_pitch)
+ {
+ // brevis; previous note must be turned into flexa
+ if (duration_log == -1)
+ {
+ if (prev_brevis_shape)
+ {
+ make_flexa = true;
+ general_case = false;
+ }
+ else
+ {
+ nr->origin ()->warning
+ (_ ("invalid ligatura ending:\n"
+ "when the last note is a descending brevis,\n"
+ "the penultimate note must be another one,\n"
+ "or the ligatura must be LB or SSB"));
+ prim = MLP_NONE;
+ break;
+ }
+ }
+ // longa
+ else if (duration_log == -2)
+ {
+ prim = MLP_BREVIS;
+ general_case = allow_flexa = false;
+ }
+ // else maxima; fall through to regular case below
+ }
+
+ if (allow_flexa
+ && to_boolean (primitive->get_property ("ligature-flexa")))
+ {
+ /*
+ flexa requested, check whether allowed:
+ - there should be a previous note
+ - both of the notes must be of brevis shape
+ (i.e. can't be maxima or flexa;
+ longa is forbidden as well - it's nonexistent anyway)
+ - no compulsory flexa for the next note,
+ i.e. it's not an ultimate descending breve
+ */
+ make_flexa = !at_beginning && prev_brevis_shape && duration_log > -2;
+ if (make_flexa && i == s - 2)
+ {
+ /*
+ check last condition: look ahead to next note
+ */
+ Grob_info next_info = primitives[i + 1];
+ Item *next_primitive = dynamic_cast<Item *> (next_info.grob ());
+ if (Rhythmic_head::duration_log (next_primitive) == -1)
+ {
+ /*
+ breve: check whether descending
+ */
+ int const next_pitch = unsmob<Pitch>
+ (next_info.event_cause ()->get_property ("pitch"))->steps ();
+ if (next_pitch < pitch)
+ /*
+ sorry, forbidden
+ */
+ make_flexa = false;
+ }
+ }
+ }