+
+ for (vsize i = accidentals_.size (); i--;)
+ {
+ Stream_event *note = accidentals_[i].melodic_;
+ Context *origin = accidentals_[i].origin_;
+
+ int barnum = measure_number (origin);
+
+ Pitch *pitch = unsmob_pitch (note->get_property ("pitch"));
+ if (!pitch)
+ continue;
+
+ int n = pitch->get_notename ();
+ int o = pitch->get_octave ();
+ Rational a = pitch->get_alteration ();
+ SCM key = scm_cons (scm_from_int (o), scm_from_int (n));
+
+ Moment end_mp = measure_position (context (),
+ unsmob_duration (note->get_property ("duration")));
+ SCM position = scm_cons (scm_from_int (barnum), end_mp.smobbed_copy ());
+
+ SCM localsig = SCM_EOL;
+ while (origin
+ && origin->where_defined (ly_symbol2scm ("localKeySignature"), &localsig))
+ {
+ bool change = false;
+ if (accidentals_[i].tied_
+ && !(to_boolean (accidentals_[i].accidental_->get_property ("forced"))))
+ {
+ /*
+ Remember an alteration that is different both from
+ that of the tied note and of the key signature.
+ */
+ localsig = ly_assoc_prepend_x (localsig, key,scm_cons (ly_symbol2scm ("tied"),
+ position));
+
+ change = true;
+ }
+ else
+ {
+ /*
+ not really really correct if there are more than one
+ noteheads with the same notename.
+ */
+ localsig = ly_assoc_prepend_x (localsig, key,
+ scm_cons (ly_rational2scm (a),
+ position));
+ change = true;
+ }
+
+ if (change)
+ origin->set_property ("localKeySignature", localsig);
+
+ origin = origin->get_parent_context ();
+ }