-int
-number_accidentals (Note_req * note_l, Translator_group * origin_l,
- SCM accidentals_sl, SCM curbarnum_s) {
- int number=0;
- int diff=0;
- if(gh_pair_p(accidentals_sl) && !gh_symbol_p(ly_car(accidentals_sl)))
- warning(_f("Accidental typesetting list must begin with context-name: %s",
- ly_scm2string(ly_car(accidentals_sl)).ch_C()));
- while(gh_pair_p(accidentals_sl) && origin_l) {
- // If pair then it is a new accidentals typesetting rule to be checked
- if(gh_pair_p(ly_car(accidentals_sl))) {
- SCM type = gh_caar(accidentals_sl);
- SCM lazyness = gh_cdar(accidentals_sl);
- SCM localsig = origin_l->get_property ("localKeySignature");
- bool same_octave_b =
- gh_eq_p(ly_symbol2scm("same-octave"),type);
- bool any_octave_b =
- gh_eq_p(ly_symbol2scm("any-octave"),type);
- if(same_octave_b || any_octave_b) {
- int n = number_accidentals
- (localsig,note_l,curbarnum_s,lazyness,any_octave_b);
- diff |= n<0;
- number = max(number,abs(n));
- }
- else warning(_f("unknown accidental typesetting: %s. Ignored",
- ly_symbol2string(type).ch_C()));
+bool
+is_tied (SCM alteration_def)
+{
+ SCM tied = ly_symbol2scm ("tied");
+ return (alteration_def == tied
+ || (scm_is_pair (alteration_def) && scm_car (alteration_def) == tied));
+}
+
+struct Accidental_result
+{
+ bool need_acc;
+ bool need_restore;
+
+ Accidental_result () {
+ need_restore = need_acc = false;
+ }
+
+ int score () const {
+ return need_acc ? 1 : 0
+ + need_restore ? 1 : 0;
+ }
+};
+
+Accidental_result
+check_pitch_against_signature (SCM key_signature, Pitch const &pitch,
+ int bar_number, SCM laziness, bool ignore_octave)
+{
+ Accidental_result result;
+ 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_from_int (o),
+ scm_from_int (n)), key_signature, SCM_BOOL_F);
+ SCM from_key_signature = ly_assoc_get (scm_from_int (n), key_signature, SCM_BOOL_F);
+ SCM from_other_octaves = SCM_BOOL_F;
+ for (SCM s = key_signature; scm_is_pair (s); s = scm_cdr (s))
+ {
+ SCM entry = scm_car (s);
+ if (scm_is_pair (scm_car (entry))
+ && scm_cdar (entry) == scm_from_int (n))
+ {
+ from_other_octaves = scm_cdr (entry);
+ break;
+ }