2 chord-name-engraver.cc -- implement Chord_name_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "chord-name.hh"
12 #include "output-def.hh"
13 #include "font-interface.hh"
14 #include "output-def.hh"
15 #include "dimensions.hh"
18 #include "protected-scm.hh"
22 class Chord_name_engraver : public Engraver
24 TRANSLATOR_DECLARATIONS ( Chord_name_engraver);
26 virtual void stop_translation_timestep ();
27 virtual void process_music ();
28 virtual bool try_music (Music *);
29 virtual void finalize ();
30 virtual void derived_mark () const;
32 void add_note (Music *);
35 Link_array<Music> notes_;
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;
60 Chord_name_engraver::add_note (Music * n)
66 Chord_name_engraver::process_music ()
72 SCM inversion = SCM_EOL;
73 SCM pitches = SCM_EOL;
75 Music* inversion_event = 0;
76 for (int i =0 ; i < notes_.size (); i++)
79 SCM p = n->get_property ("pitch");
80 if (!unsmob_pitch (p))
83 if (n->get_property ("inversion") == SCM_BOOL_T)
88 else if (n->get_property ("bass") == SCM_BOOL_T)
91 pitches = scm_cons (p, pitches);
96 SCM oct = inversion_event->get_property ("octavation");
97 if (scm_is_number (oct))
99 Pitch *p = unsmob_pitch (inversion_event->get_property ("pitch"));
100 int octavation = scm_to_int (oct);
101 Pitch orig = p->transposed (Pitch (-octavation, 0,0));
103 pitches= scm_cons (orig.smobbed_copy (), pitches);
106 programming_error ("Inversion does not have original pitch.");
109 pitches = scm_sort_list (pitches, Pitch::less_p_proc);
111 SCM name_proc = get_property ("chordNameFunction");
112 SCM markup = scm_call_4 (name_proc, pitches, bass, inversion,
113 context ()->self_scm ());
118 SCM chord_as_scm = scm_cons (pitches, scm_cons (bass, inversion));
120 chord_name_ = make_item ("ChordName",notes_[0]->self_scm ());
121 chord_name_->set_property ("text", markup);
123 SCM s = get_property ("chordChanges");
124 if (to_boolean (s) && scm_is_pair (last_chord_)
125 && ly_c_equal_p (chord_as_scm, last_chord_))
126 chord_name_->set_property ("begin-of-line-visible", SCM_BOOL_T);
128 last_chord_ = chord_as_scm;
132 Chord_name_engraver::try_music (Music* m)
137 if (m->is_mus_type ("note-event"))
146 Chord_name_engraver::stop_translation_timestep ()
153 The READs description is not strictly accurate:
154 which properties are read depend on the chord naming function active.
156 ENTER_DESCRIPTION (Chord_name_engraver,
157 /* descr */ "Catch note-events "
158 "and generate the appropriate chordname.",
159 /* creats*/ "ChordName",
160 /* accepts */ "note-event",
162 /* reads */ "chordChanges chordNameExceptions chordNameFunction "
163 "chordNoteNamer chordRootNamer chordNameExceptions majorSevenSymbol",