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_;
39 Chord_name_engraver::finalize ()
44 Chord_name_engraver::derived_mark () const
46 scm_gc_mark (last_chord_);
49 Chord_name_engraver::Chord_name_engraver ()
52 last_chord_ = SCM_EOL;
56 Chord_name_engraver::add_note (Music *n)
62 Chord_name_engraver::process_music ()
68 SCM inversion = SCM_EOL;
69 SCM pitches = SCM_EOL;
71 Music *inversion_event = 0;
72 for (int i = 0; i < notes_.size (); i++)
75 SCM p = n->get_property ("pitch");
76 if (!unsmob_pitch (p))
79 if (n->get_property ("inversion") == SCM_BOOL_T)
84 else if (n->get_property ("bass") == SCM_BOOL_T)
87 pitches = scm_cons (p, pitches);
92 SCM oct = inversion_event->get_property ("octavation");
93 if (scm_is_number (oct))
95 Pitch *p = unsmob_pitch (inversion_event->get_property ("pitch"));
96 int octavation = scm_to_int (oct);
97 Pitch orig = p->transposed (Pitch (-octavation, 0, 0));
99 pitches = scm_cons (orig.smobbed_copy (), pitches);
102 programming_error ("Inversion does not have original pitch.");
105 pitches = scm_sort_list (pitches, Pitch::less_p_proc);
107 SCM name_proc = get_property ("chordNameFunction");
108 SCM markup = scm_call_4 (name_proc, pitches, bass, inversion,
109 context ()->self_scm ());
114 SCM chord_as_scm = scm_cons (pitches, scm_cons (bass, inversion));
116 chord_name_ = make_item ("ChordName", notes_[0]->self_scm ());
117 chord_name_->set_property ("text", markup);
119 SCM s = get_property ("chordChanges");
120 if (to_boolean (s) && scm_is_pair (last_chord_)
121 && ly_c_equal_p (chord_as_scm, last_chord_))
122 chord_name_->set_property ("begin-of-line-visible", SCM_BOOL_T);
124 last_chord_ = chord_as_scm;
128 Chord_name_engraver::try_music (Music *m)
133 if (m->is_mus_type ("note-event"))
142 Chord_name_engraver::stop_translation_timestep ()
149 The READs description is not strictly accurate:
150 which properties are read depend on the chord naming function active.
152 ADD_TRANSLATOR (Chord_name_engraver,
153 /* descr */ "Catch note-events "
154 "and generate the appropriate chordname.",
155 /* creats*/ "ChordName",
156 /* accepts */ "note-event",
158 /* reads */ "chordChanges chordNameExceptions chordNameFunction "
159 "chordNoteNamer chordRootNamer chordNameExceptions majorSevenSymbol",