2 chord-name-engraver.cc -- implement Chord_name_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2006 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"
21 class Chord_name_engraver : public Engraver
23 TRANSLATOR_DECLARATIONS (Chord_name_engraver);
25 void stop_translation_timestep ();
26 void process_music ();
27 virtual bool try_music (Music *);
28 virtual void finalize ();
29 virtual void derived_mark () const;
31 void add_note (Music *);
34 vector<Music*> notes_;
40 Chord_name_engraver::finalize ()
45 Chord_name_engraver::derived_mark () const
47 scm_gc_mark (last_chord_);
50 Chord_name_engraver::Chord_name_engraver ()
53 last_chord_ = SCM_EOL;
57 Chord_name_engraver::add_note (Music *n)
63 Chord_name_engraver::process_music ()
69 SCM inversion = SCM_EOL;
70 SCM pitches = SCM_EOL;
72 Music *inversion_event = 0;
73 for (vsize i = 0; i < notes_.size (); i++)
76 SCM p = n->get_property ("pitch");
77 if (!unsmob_pitch (p))
80 if (n->get_property ("inversion") == SCM_BOOL_T)
85 else if (n->get_property ("bass") == SCM_BOOL_T)
88 pitches = scm_cons (p, pitches);
93 SCM oct = inversion_event->get_property ("octavation");
94 if (scm_is_number (oct))
96 Pitch *p = unsmob_pitch (inversion_event->get_property ("pitch"));
97 int octavation = scm_to_int (oct);
98 Pitch orig = p->transposed (Pitch (-octavation, 0, 0));
100 pitches = scm_cons (orig.smobbed_copy (), pitches);
103 programming_error ("inversion does not have original pitch");
106 pitches = scm_sort_list (pitches, Pitch::less_p_proc);
108 SCM name_proc = get_property ("chordNameFunction");
109 SCM markup = scm_call_4 (name_proc, pitches, bass, inversion,
110 context ()->self_scm ());
115 SCM chord_as_scm = scm_cons (pitches, scm_cons (bass, inversion));
117 chord_name_ = make_item ("ChordName", notes_[0]->self_scm ());
118 chord_name_->set_property ("text", markup);
120 SCM s = get_property ("chordChanges");
121 if (to_boolean (s) && scm_is_pair (last_chord_)
122 && ly_is_equal (chord_as_scm, last_chord_))
123 chord_name_->set_property ("begin-of-line-visible", SCM_BOOL_T);
125 last_chord_ = chord_as_scm;
129 Chord_name_engraver::try_music (Music *m)
134 if (m->is_mus_type ("note-event"))
143 Chord_name_engraver::stop_translation_timestep ()
150 The READs description is not strictly accurate:
151 which properties are read depend on the chord naming function active.
153 #include "translator.icc"
155 ADD_TRANSLATOR (Chord_name_engraver,
156 /* doc */ "Catch note-events "
157 "and generate the appropriate chordname.",
158 /* create */ "ChordName",
159 /* accept */ "note-event",
160 /* read */ "chordChanges chordNameExceptions chordNameFunction "
161 "chordNoteNamer chordRootNamer chordNameExceptions majorSevenSymbol",