2 chord-name-engraver.cc -- implement Chord_name_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2009 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "chord-name.hh"
11 #include "dimensions.hh"
12 #include "engraver.hh"
13 #include "font-interface.hh"
15 #include "output-def.hh"
17 #include "protected-scm.hh"
18 #include "stream-event.hh"
19 #include "text-interface.hh"
22 #include "translator.icc"
24 class Chord_name_engraver : public Engraver
26 TRANSLATOR_DECLARATIONS (Chord_name_engraver);
28 void stop_translation_timestep ();
29 void process_music ();
30 virtual void finalize ();
31 virtual void derived_mark () const;
32 DECLARE_TRANSLATOR_LISTENER (note);
33 DECLARE_TRANSLATOR_LISTENER (rest);
36 vector<Stream_event*> notes_;
39 Stream_event *rest_event_;
43 Chord_name_engraver::finalize ()
48 Chord_name_engraver::derived_mark () const
50 scm_gc_mark (last_chord_);
53 Chord_name_engraver::Chord_name_engraver ()
56 last_chord_ = SCM_EOL;
61 Chord_name_engraver::process_music ()
65 SCM inversion = SCM_EOL;
66 SCM pitches = SCM_EOL;
70 SCM no_chord_markup = get_property ("noChordSymbol");
71 if (!Text_interface::is_markup (no_chord_markup))
73 markup = no_chord_markup;
80 Stream_event *inversion_event = 0;
81 for (vsize i = 0; i < notes_.size (); i++)
83 Stream_event *n = notes_[i];
84 SCM p = n->get_property ("pitch");
85 if (!unsmob_pitch (p))
88 if (n->get_property ("inversion") == SCM_BOOL_T)
93 else if (n->get_property ("bass") == SCM_BOOL_T)
96 pitches = scm_cons (p, pitches);
101 SCM oct = inversion_event->get_property ("octavation");
102 if (scm_is_number (oct))
104 Pitch *p = unsmob_pitch (inversion_event->get_property ("pitch"));
105 int octavation = scm_to_int (oct);
106 Pitch orig = p->transposed (Pitch (-octavation, 0, 0));
108 pitches = scm_cons (orig.smobbed_copy (), pitches);
111 programming_error ("inversion does not have original pitch");
114 pitches = scm_sort_list (pitches, Pitch::less_p_proc);
116 SCM name_proc = get_property ("chordNameFunction");
117 markup = scm_call_4 (name_proc, pitches, bass, inversion,
118 context ()->self_scm ());
123 SCM chord_as_scm = scm_cons (pitches, scm_cons (bass, inversion));
125 chord_name_ = make_item ("ChordName",
126 rest_event_ ? rest_event_->self_scm () : notes_[0]->self_scm ());
127 chord_name_->set_property ("text", markup);
129 SCM chord_changes = get_property("chordChanges");
130 if (to_boolean (chord_changes) && scm_is_pair (last_chord_)
131 && ly_is_equal (chord_as_scm, last_chord_))
132 chord_name_->set_property ("begin-of-line-visible", SCM_BOOL_T);
134 last_chord_ = chord_as_scm;
137 IMPLEMENT_TRANSLATOR_LISTENER (Chord_name_engraver, note);
139 Chord_name_engraver::listen_note (Stream_event *ev)
141 notes_.push_back (ev);
144 IMPLEMENT_TRANSLATOR_LISTENER (Chord_name_engraver, rest);
146 Chord_name_engraver::listen_rest (Stream_event *ev)
148 ASSIGN_EVENT_ONCE(rest_event_, ev);
152 Chord_name_engraver::stop_translation_timestep ()
160 The READs description is not strictly accurate:
161 which properties are read depend on the chord naming function active.
163 ADD_TRANSLATOR (Chord_name_engraver,
165 "Catch note and rest events and generate the appropriate chordname.",
172 "chordNameExceptions "
176 "chordNameExceptions "