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 ();
31 void add_note (Music *);
34 Link_array<Music> notes_;
36 Protected_scm last_chord_;
40 Chord_name_engraver::finalize ()
42 last_chord_ = SCM_EOL;
45 Chord_name_engraver::Chord_name_engraver ()
48 last_chord_ = SCM_EOL;
52 Chord_name_engraver::add_note (Music * n)
58 Chord_name_engraver::process_music ()
64 SCM inversion = SCM_EOL;
65 SCM pitches = SCM_EOL;
67 Music* inversion_event = 0;
68 for (int i =0 ; i < notes_.size (); i++)
71 SCM p = n->get_property ("pitch");
72 if (!unsmob_pitch (p))
75 if (n->get_property ("inversion") == SCM_BOOL_T)
80 else if (n->get_property ("bass") == SCM_BOOL_T)
83 pitches = scm_cons (p, pitches);
88 SCM oct = inversion_event->get_property ("octavation");
89 if (ly_c_number_p (oct))
91 Pitch *p = unsmob_pitch (inversion_event->get_property ("pitch"));
92 int octavation = ly_scm2int (oct);
93 Pitch orig = p->transposed (Pitch (-octavation, 0,0));
95 pitches= scm_cons (orig.smobbed_copy (), pitches);
98 programming_error ("Inversion does not have original pitch.");
101 pitches = scm_sort_list (pitches, Pitch::less_p_proc);
103 SCM name_proc = get_property ("chordNameFunction");
104 SCM markup = scm_call_4 (name_proc, pitches, bass, inversion,
105 context ()->self_scm ());
110 SCM chord_as_scm = scm_cons (pitches, scm_cons (bass, inversion));
112 chord_name_ = make_item ("ChordName",notes_[0]->self_scm ());
113 chord_name_->set_property ("text", markup);
115 SCM s = get_property ("chordChanges");
116 if (to_boolean (s) && ly_c_pair_p (last_chord_)
117 && ly_c_equal_p (chord_as_scm, last_chord_))
118 chord_name_->set_property ("begin-of-line-visible", SCM_BOOL_T);
120 last_chord_ = chord_as_scm;
124 Chord_name_engraver::try_music (Music* m)
129 if (m->is_mus_type ("note-event"))
138 Chord_name_engraver::stop_translation_timestep ()
145 The READs description is not strictly accurate:
146 which properties are read depend on the chord naming function active.
148 ENTER_DESCRIPTION (Chord_name_engraver,
149 /* descr */ "Catch note-events "
150 "and generate the appropriate chordname.",
151 /* creats*/ "ChordName",
152 /* accepts */ "note-event",
154 /* reads */ "chordChanges chordNameExceptions chordNameFunction "
155 "chordNoteNamer chordRootNamer chordNameExceptions majorSevenSymbol",