From: fred Date: Tue, 26 Mar 2002 23:22:53 +0000 (+0000) Subject: lilypond-1.3.59 X-Git-Tag: release/1.5.59~1585 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=efa6a204522eb886104aa200bdde38b847083f75;p=lilypond.git lilypond-1.3.59 --- diff --git a/lily/key-engraver.cc b/lily/key-engraver.cc index da00f72040..d5091eb70f 100644 --- a/lily/key-engraver.cc +++ b/lily/key-engraver.cc @@ -6,31 +6,50 @@ (c) 1997--2000 Han-Wen Nienhuys */ -#include "key-engraver.hh" + #include "key-item.hh" #include "command-request.hh" -#include "local-key-engraver.hh" #include "musical-request.hh" #include "local-key-item.hh" #include "bar.hh" #include "timing-translator.hh" #include "staff-symbol-referencer.hh" - -/* - this is a large mess. Please clean this to use Basic properties and - Scheme data structs. +#include "translator-group.hh" +#include "engraver.hh" +#include "musical-pitch.hh" +#include "protected-scm.hh" +#include "clef-item.hh" + +/** + Make the key signature. */ +class Key_engraver : public Engraver { + void create_key(bool); + void read_req (Key_change_req const * r); + +public: + Key_engraver(); + + VIRTUAL_COPY_CONS(Translator); + + Key_change_req * keyreq_l_; + Key_item * item_p_; + Protected_scm old_accs_; + +protected: + virtual void do_creation_processing(); + virtual bool do_try_music (Music *req_l); + virtual void do_process_music(); + virtual void do_pre_move_processing(); + virtual void do_post_move_processing(); + virtual void acknowledge_element (Score_element_info); +}; + Key_engraver::Key_engraver () { + keyreq_l_ = 0; item_p_ = 0; - do_post_move_processing (); -} - -bool -Key_engraver::key_changed_b () const -{ - return keyreq_l_ ; } void @@ -44,7 +63,7 @@ Key_engraver::create_key (bool def) // todo: put this in basic props. item_p_->set_elt_property ("old-accidentals", old_accs_); - item_p_->set_elt_property ("new-accidentals", new_accs_); + item_p_->set_elt_property ("new-accidentals", get_property ("keySignature")); Staff_symbol_referencer_interface st (item_p_); st.set_interface (); @@ -82,17 +101,16 @@ Key_engraver::do_try_music (Music * req_l) void Key_engraver::acknowledge_element (Score_element_info info) { - if (dynamic_cast (info.req_l_)) + if (dynamic_cast (info.elem_l_)) { SCM c = get_property ("createKeyOnClefChange"); if (to_boolean (c)) { create_key (false); - } } else if (dynamic_cast (info.elem_l_) - && gh_pair_p (new_accs_)) + && gh_pair_p (get_property ("keySignature"))) { create_key (true); } @@ -102,7 +120,7 @@ Key_engraver::acknowledge_element (Score_element_info info) void Key_engraver::do_process_music () { - if (keyreq_l_) + if (keyreq_l_ || old_accs_ != get_property ("keySignature")) { create_key (false); } @@ -118,94 +136,45 @@ Key_engraver::do_pre_move_processing () } } - -/* - TODO. Use properties; and this is too hairy. - */ void Key_engraver::read_req (Key_change_req const * r) { if (!r->key_) return; - - key_.clear (); - SCM prop = get_property ("keyOctaviation"); - bool multi = to_boolean (prop); - - SCM n = SCM_EOL; - - if (r->key_->ordinary_key_b_) - { - int no_of_acc = r->key_->ordinary_accidentals_i (); - // Hmm, can't these be handled/constructed by Key_change_req? - if (no_of_acc < 0) - { - int accidental = 6 ; // First accidental: bes - for ( ; no_of_acc < 0 ; no_of_acc++ ) - { - Musical_pitch m; - m.accidental_i_ = -1; - m.notename_i_ = accidental; - if (multi) - key_.set (m.octave_i_, m.notename_i_, m.accidental_i_); - else - key_.set (m.notename_i_, m.accidental_i_); - - SCM pair = gh_cons (gh_int2scm (m.notename_i_), - gh_int2scm (m.accidental_i_)); - n = gh_cons (pair, n) ; - accidental = (accidental + 3) % 7 ; - } - } - else - { - int accidental = 3 ; // First accidental: fis - for ( ; no_of_acc > 0 ; no_of_acc-- ) - { - Musical_pitch m; - m.accidental_i_ = 1; - m.notename_i_ = accidental; - if (multi) - key_.set (m.octave_i_, m.notename_i_, m.accidental_i_); - else - key_.set (m.notename_i_, m.accidental_i_); - - SCM pair = gh_cons (gh_int2scm (m.notename_i_), - gh_int2scm (m.accidental_i_)); - n = gh_cons (pair, n); - - accidental = (accidental + 4) % 7 ; - } - } - } - else // Special key + SCM n = scm_list_copy (r->key_->pitch_alist_); + SCM accs = SCM_EOL; + for (SCM s = get_property ("keyAccidentalOrder"); + gh_pair_p (s); s = gh_cdr (s)) { - for (int i = 0; i < r->key_->pitch_arr_.size (); i ++) + if (gh_pair_p (scm_member (gh_car (s), n))) { - Musical_pitch m_l =r->key_->pitch_arr_[i]; - if (multi) - key_.set (m_l.octave_i_, m_l.notename_i_, m_l.accidental_i_); - else - key_.set (m_l.notename_i_, m_l.accidental_i_); - - SCM pair = gh_cons (gh_int2scm (m_l.notename_i_), - gh_int2scm (m_l.accidental_i_)); - n = gh_cons (pair, n); + accs = gh_cons (gh_car (s), accs); + n = scm_delete_x (gh_car (s), n); } } + for (SCM s = n ; gh_pair_p (s); s = gh_cdr (s)) + if (gh_scm2int (gh_cdar (s))) + accs = gh_cons (gh_car (s), accs); - old_accs_ = new_accs_; - new_accs_ = n; - + old_accs_ = get_property ("keySignature"); + daddy_trans_l_->set_property ("keySignature", accs); } void Key_engraver::do_post_move_processing () { keyreq_l_ = 0; + old_accs_ = get_property ("keySignature"); +} + +void +Key_engraver::do_creation_processing () +{ + daddy_trans_l_->set_property ("keySignature", SCM_EOL); old_accs_ = SCM_EOL; } + ADD_THIS_TRANSLATOR (Key_engraver);