- SCM accidentals = get_property ("autoAccidentals");
- SCM cautionaries = get_property ("autoCautionaries");
- int barnum = get_bar_number ();
-
- for (int i = 0; i < accidentals_.size (); i++)
- {
- if (accidentals_[i].done_)
- continue;
- accidentals_[i].done_ = true;
-
- Music *note = accidentals_[i].melodic_;
- Context *origin = accidentals_[i].origin_;
-
- Pitch *pitch = unsmob_pitch (note->get_property ("pitch"));
- if (!pitch)
- continue;
-
- bool different = false;
- bool different_caut = false;
-
- int num = number_accidentals (&different,
- pitch, origin,
- accidentals, barnum);
- int num_caut = number_accidentals (&different_caut,
- pitch, origin,
- cautionaries, barnum);
-
- bool cautionary = to_boolean (note->get_property ("cautionary"));
-
- if (num_caut > num)
- {
- num = num_caut;
- different = different_caut;
- cautionary = true;
- }
-
- if (num == 0 && to_boolean (note->get_property ("force-accidental")))
- num = 1;
-
- /* Cannot look for ties: it's not guaranteed that they reach
- us before the notes. */
- if (num)
- create_accidental (&accidentals_[i], num > 1, cautionary);
- }
+ SCM accidental_rules = get_property ("autoAccidentals");
+ SCM cautionary_rules = get_property ("autoCautionaries");
+ SCM measure_position = get_property ("measurePosition");
+ int barnum = measure_number (context ());
+
+ for (vsize i = 0; i < accidentals_.size (); i++)
+ {
+ if (accidentals_[i].done_)
+ continue;
+ accidentals_[i].done_ = true;
+
+ Stream_event *note = accidentals_[i].melodic_;
+ Context *origin = accidentals_[i].origin_;
+
+ Pitch *pitch = unsmob_pitch (note->get_property ("pitch"));
+ if (!pitch)
+ continue;
+
+ Accidental_result acc = check_pitch_against_rules (*pitch, origin, accidental_rules,
+ barnum, measure_position);
+ Accidental_result caut = check_pitch_against_rules (*pitch, origin, cautionary_rules,
+ barnum, measure_position);
+
+ bool cautionary = to_boolean (note->get_property ("cautionary"));
+ if (caut.score () > acc.score ())
+ {
+ acc.need_acc |= caut.need_acc;
+ acc.need_restore |= caut.need_restore;
+
+ cautionary = true;
+ }
+
+ bool forced = to_boolean (note->get_property ("force-accidental"));
+ if (!acc.need_acc && forced)
+ acc.need_acc = true;
+
+ /*
+ Cannot look for ties: it's not guaranteed that they reach
+ us before the notes.
+ */
+ if (!note->in_event_class ("trill-span-event"))
+ {
+ if (acc.need_acc)
+ create_accidental (&accidentals_[i], acc.need_restore, cautionary);
+
+ if (forced || cautionary)
+ accidentals_[i].accidental_->set_property ("forced", SCM_BOOL_T);
+ }
+ }