-number_accidentals (SCM localsig, Note_req * note_l, SCM accidentals_l,
- SCM curbarnum) {
- int number=0;
- int diff=0;
- while(gh_pair_p(accidentals_l)) {
- if(gh_pair_p(ly_car(accidentals_l))) {
- SCM type = gh_caar(accidentals_l);
- SCM lazyness = gh_cdar(accidentals_l);
- bool measure_same_octave_b =
- gh_eq_p(ly_symbol2scm("measure-same-octave"),type);
- bool measure_any_octave_b =
- gh_eq_p(ly_symbol2scm("measure-any-octave"),type);
- if(measure_same_octave_b || measure_any_octave_b) {
- int n = number_accidentals
- (localsig,note_l,curbarnum,lazyness,measure_any_octave_b);
- diff |= n<0;
- number = max(number,abs(n));
- }
- else warning(_f("unknown accidental typesetting: %s",
- ly_symbol2string(type).ch_C()));
+number_accidentals_from_sig (bool *different, SCM sig, Pitch *pitch,
+ int bar_number, SCM laziness, bool ignore_octave)
+{
+ int n = pitch->get_notename ();
+ int o = pitch->get_octave ();
+
+ SCM previous_alteration = SCM_BOOL_F;
+
+
+ SCM from_same_octave = ly_assoc_get (scm_cons (scm_int2num (o),
+ scm_int2num (n)), sig, SCM_BOOL_F);
+ SCM from_key_signature = ly_assoc_get (scm_int2num (n), sig, SCM_BOOL_F);
+ SCM from_other_octaves = SCM_BOOL_F;
+ for (SCM s = sig ; scm_is_pair (s); s = scm_cdr (s))
+ {
+ SCM entry = scm_car (s);
+ if (scm_is_pair (scm_car (entry))
+ && scm_cdar (entry) == scm_int2num (n))
+ from_other_octaves = scm_cdr (entry);
+ }
+
+
+ if (from_same_octave != SCM_BOOL_F
+ && recent_enough (bar_number, from_same_octave, laziness))
+ {
+ previous_alteration = from_same_octave;
+ }
+ else if (ignore_octave
+ && from_other_octaves != SCM_BOOL_F
+ && recent_enough (bar_number, from_other_octaves, laziness))
+ {
+ previous_alteration = from_other_octaves;
+ }
+ else if (from_key_signature != SCM_BOOL_F)
+ {
+ previous_alteration = from_key_signature;
+ }
+
+ int num = 1;
+ if (is_tied (previous_alteration))
+ {
+ num = 1;
+ *different = true;