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"
19 #include "translator-group.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 *);
31 void add_note (Music *);
34 Link_array<Music> notes_;
36 Protected_scm last_chord_;
39 Chord_name_engraver::Chord_name_engraver ()
42 last_chord_ = SCM_EOL;
46 Chord_name_engraver::add_note (Music * n)
52 Chord_name_engraver::process_music ()
58 SCM inversion = SCM_EOL;
59 SCM pitches = SCM_EOL;
61 Music* inversion_event = 0;
62 for (int i =0 ; i < notes_.size (); i++)
65 SCM p = n->get_mus_property ("pitch");
66 if (!unsmob_pitch (p))
69 if (n->get_mus_property ("inversion") == SCM_BOOL_T)
74 else if (n->get_mus_property ("bass") == SCM_BOOL_T)
77 pitches = gh_cons (p, pitches);
82 SCM oct = inversion_event->get_mus_property ("octavation");
83 if (gh_number_p (oct))
85 Pitch *p = unsmob_pitch (inversion_event->get_mus_property ("pitch"));
86 int octavation = gh_scm2int (oct);
87 Pitch orig = p->transposed (Pitch (-octavation, 0,0));
89 pitches= gh_cons (orig.smobbed_copy (), pitches);
92 programming_error ("Inversion does not have original pitch.");
95 pitches = scm_sort_list (pitches, Pitch::less_p_proc);
97 SCM name_proc = get_property ("chordNameFunction");
98 SCM markup = scm_call_4 (name_proc, pitches, bass, inversion,
99 daddy_trans_->self_scm());
104 SCM chord_as_scm = gh_cons (pitches, gh_cons (bass, inversion));
106 chord_name_ = make_item ("ChordName");
107 chord_name_->set_grob_property("text", markup);
108 announce_grob(chord_name_, notes_[0]->self_scm ());
109 SCM s = get_property ("chordChanges");
110 if (to_boolean (s) && gh_pair_p (last_chord_)
111 && gh_equal_p (chord_as_scm, last_chord_))
112 chord_name_->set_grob_property ("begin-of-line-visible", SCM_BOOL_T);
114 last_chord_ = chord_as_scm;
118 Chord_name_engraver::try_music (Music* m)
123 if (m->is_mus_type ("note-event"))
132 Chord_name_engraver::stop_translation_timestep ()
136 typeset_grob (chord_name_);
143 The READs description is not strictly accurate:
144 which properties are read depend on the chord naming function active.
146 ENTER_DESCRIPTION(Chord_name_engraver,
147 /* descr */ "Catch note-events "
148 "and generate the appropriate chordname.",
149 /* creats*/ "ChordName",
150 /* accepts */ "note-event",
152 /* reads */ "chordChanges chordNameExceptions chordNameFunction "
153 "chordNoteNamer chordRootNamer chordNameExceptions majorSevenSymbol",