2 chord-name-engraver.cc -- implement Chord_name_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2005 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "chord-name.hh"
11 #include "output-def.hh"
12 #include "font-interface.hh"
13 #include "output-def.hh"
14 #include "dimensions.hh"
16 #include "protected-scm.hh"
20 class Chord_name_engraver : public Engraver
22 TRANSLATOR_DECLARATIONS ( Chord_name_engraver);
24 virtual void stop_translation_timestep ();
25 virtual void process_music ();
26 virtual bool try_music (Music *);
27 virtual void finalize ();
28 virtual void derived_mark () const;
30 void add_note (Music *);
33 Link_array<Music> notes_;
41 Chord_name_engraver::finalize ()
46 Chord_name_engraver::derived_mark() const
48 scm_gc_mark (last_chord_);
51 Chord_name_engraver::Chord_name_engraver ()
54 last_chord_ = SCM_EOL;
58 Chord_name_engraver::add_note (Music * n)
64 Chord_name_engraver::process_music ()
70 SCM inversion = SCM_EOL;
71 SCM pitches = SCM_EOL;
73 Music* inversion_event = 0;
74 for (int i = 0 ; i < notes_.size (); i++)
77 SCM p = n->get_property ("pitch");
78 if (!unsmob_pitch (p))
81 if (n->get_property ("inversion") == SCM_BOOL_T)
86 else if (n->get_property ("bass") == SCM_BOOL_T)
89 pitches = scm_cons (p, pitches);
94 SCM oct = inversion_event->get_property ("octavation");
95 if (scm_is_number (oct))
97 Pitch *p = unsmob_pitch (inversion_event->get_property ("pitch"));
98 int octavation = scm_to_int (oct);
99 Pitch orig = p->transposed (Pitch (-octavation, 0, 0));
101 pitches = scm_cons (orig.smobbed_copy (), pitches);
104 programming_error ("Inversion does not have original pitch.");
107 pitches = scm_sort_list (pitches, Pitch::less_p_proc);
109 SCM name_proc = get_property ("chordNameFunction");
110 SCM markup = scm_call_4 (name_proc, pitches, bass, inversion,
111 context ()->self_scm ());
116 SCM chord_as_scm = scm_cons (pitches, scm_cons (bass, inversion));
118 chord_name_ = make_item ("ChordName", notes_[0]->self_scm ());
119 chord_name_->set_property ("text", markup);
121 SCM s = get_property ("chordChanges");
122 if (to_boolean (s) && scm_is_pair (last_chord_)
123 && ly_c_equal_p (chord_as_scm, last_chord_))
124 chord_name_->set_property ("begin-of-line-visible", SCM_BOOL_T);
126 last_chord_ = chord_as_scm;
130 Chord_name_engraver::try_music (Music* m)
135 if (m->is_mus_type ("note-event"))
144 Chord_name_engraver::stop_translation_timestep ()
151 The READs description is not strictly accurate:
152 which properties are read depend on the chord naming function active.
154 ADD_TRANSLATOR (Chord_name_engraver,
155 /* descr */ "Catch note-events "
156 "and generate the appropriate chordname.",
157 /* creats*/ "ChordName",
158 /* accepts */ "note-event",
160 /* reads */ "chordChanges chordNameExceptions chordNameFunction "
161 "chordNoteNamer chordRootNamer chordNameExceptions majorSevenSymbol",