- SCM pitchlist = key_req_l_->get_mus_property ("pitch-alist");
- SCM proc = scm_primitive_eval (ly_symbol2scm ("accidentals-in-key"));
- SCM acc = gh_call1 (proc, pitchlist);
- proc = scm_primitive_eval (ly_symbol2scm ("major-key"));
-
- Pitch my_do (0,
- gh_scm2int (ly_caar (pitchlist)),
- gh_scm2int (ly_cdar (pitchlist)));
-
- Pitch to_c (-1,
- (7 - gh_scm2int (ly_caar (pitchlist))) % 7,
- -gh_scm2int (ly_cdar (pitchlist)));
-
- my_do.transpose (to_c);
- to_c.alteration_i_ -= my_do.alteration_i_;
-
- Key_change_req *key = new Key_change_req;
- key->set_mus_property ("pitch-alist", scm_list_copy (pitchlist));
- ((Music*)key)->transpose (to_c);
- SCM c_pitchlist = key->get_mus_property ("pitch-alist");
- SCM major = gh_call1 (proc, c_pitchlist);
-
- audio_p_ = new Audio_key (gh_scm2int (acc), major == SCM_BOOL_T);
- Audio_element_info info (audio_p_, key_req_l_);
+ SCM pitchlist = key_ev_->get_property ("pitch-alist");
+ SCM proc = ly_lily_module_constant ("alterations-in-key");
+
+ SCM acc = scm_call_1 (proc, pitchlist);
+
+ Pitch key_do (0,
+ scm_to_int (scm_caar (pitchlist)),
+ scm_to_int (scm_cdar (pitchlist)));
+
+ Pitch c_do (0, 0, 0);
+
+ SCM c_pitchlist
+ = ly_transpose_key_alist (pitchlist,
+ pitch_interval (key_do, c_do).smobbed_copy ());
+
+ /* MIDI keys are too limited for lilypond scales.
+ We check for minor scale and assume major otherwise. */
+
+ SCM third = scm_assoc (scm_from_int (2),
+ c_pitchlist);
+ bool minor = (scm_is_pair (third)
+ && scm_is_integer (scm_cdr (third))
+ && scm_to_int (scm_cdr (third)) == FLAT);
+
+ audio_ = new Audio_key (scm_to_int (acc),
+ !minor);
+
+ Audio_element_info info (audio_, key_ev_);