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 "paper-def.hh"
13 #include "font-interface.hh"
14 #include "paper-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 = gh_cons (p, pitches);
88 SCM oct = inversion_event->get_property ("octavation");
89 if (gh_number_p (oct))
91 Pitch *p = unsmob_pitch (inversion_event->get_property ("pitch"));
92 int octavation = gh_scm2int (oct);
93 Pitch orig = p->transposed (Pitch (-octavation, 0,0));
95 pitches= gh_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 daddy_context_->self_scm ());
110 SCM chord_as_scm = gh_cons (pitches, gh_cons (bass, inversion));
112 chord_name_ = make_item ("ChordName");
113 chord_name_->set_property ("text", markup);
114 announce_grob (chord_name_, notes_[0]->self_scm ());
115 SCM s = get_property ("chordChanges");
116 if (to_boolean (s) && gh_pair_p (last_chord_)
117 && gh_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 ()
142 typeset_grob (chord_name_);
149 The READs description is not strictly accurate:
150 which properties are read depend on the chord naming function active.
152 ENTER_DESCRIPTION (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",