2 chord-name-engraver.cc -- implement Chord_name_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2000 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "chord-name.hh"
12 #include "musical-request.hh"
13 #include "paper-def.hh"
14 #include "font-interface.hh"
15 #include "paper-def.hh"
17 #include "dimensions.hh"
20 #include "protected-scm.hh"
22 class Chord_name_engraver : public Engraver
25 Chord_name_engraver ();
26 VIRTUAL_COPY_CONS (Translator);
29 virtual void do_pre_move_processing ();
30 virtual void acknowledge_element (Score_element_info i);
31 virtual void do_process_music ();
32 virtual bool do_try_music (Music* m);
35 void create_chord_name ();
38 Protected_scm pitches_;
41 Protected_scm last_chord_;
43 Protected_scm tonic_req_;
44 Protected_scm inversion_req_;
45 Protected_scm bass_req_;
48 ADD_THIS_TRANSLATOR (Chord_name_engraver);
50 Chord_name_engraver::Chord_name_engraver ()
55 inversion_req_ = SCM_EOL;
58 last_chord_ = SCM_EOL;
62 Chord_name_engraver::acknowledge_element (Score_element_info i)
64 if (Note_req* n = dynamic_cast<Note_req*> (i.req_l_))
65 pitches_ = gh_cons (n->get_mus_property ("pitch"), pitches_);
69 Chord_name_engraver::do_try_music (Music* m)
71 if (Note_req* n = dynamic_cast<Note_req*> (m))
73 pitches_ = gh_cons (n->get_mus_property ("pitch"), pitches_);
76 if (Tonic_req* t = dynamic_cast<Tonic_req*> (m))
78 tonic_req_ = t->get_mus_property ("pitch");
81 if (Inversion_req* i = dynamic_cast<Inversion_req*> (m))
83 inversion_req_ = i->get_mus_property ("pitch");
86 if (Bass_req* b = dynamic_cast<Bass_req*> (m))
88 bass_req_ = b->get_mus_property ("pitch");
95 Chord_name_engraver::do_process_music ()
97 if (!chord_name_p_ && pitches_ != SCM_EOL)
99 bool find_inversion_b = false;
100 SCM chord_inversion = get_property ("chordInversion");
101 if (gh_boolean_p (chord_inversion))
102 find_inversion_b = gh_scm2bool (chord_inversion);
104 chord_ = Chord::pitches_and_requests_to_chord (pitches_,
110 create_chord_name ();
111 announce_element (chord_name_p_, 0);
112 SCM s = get_property ("drarnChords"); //FIXME!
113 if (to_boolean (s) && last_chord_ != SCM_EOL &&
114 gh_equal_p (chord_, last_chord_))
115 chord_name_p_->set_elt_property ("begin-of-line-visible", SCM_BOOL_T);
120 Chord_name_engraver::create_chord_name ()
122 chord_name_p_ = new Item (get_property ("ChordName"));
124 SCM pitches = gh_car (chord_);
125 SCM modifiers = gh_cdr (chord_);
126 SCM inversion = gh_car (modifiers);
127 SCM bass = gh_cdr (modifiers);
128 /* Hmm, maybe chord-name should use (pitches (inversion . base)) too? */
129 chord_name_p_->set_elt_property ("pitches", pitches);
130 chord_name_p_->set_elt_property ("inversion", inversion);
131 chord_name_p_->set_elt_property ("inversion", bass);
135 Chord_name_engraver::do_pre_move_processing ()
139 typeset_element (chord_name_p_);
144 tonic_req_ = SCM_EOL;
145 inversion_req_ = SCM_EOL;
147 last_chord_ = chord_;