2 chord-name-engraver.cc -- implement Chord_name_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2003 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"
16 #include "dimensions.hh"
19 #include "protected-scm.hh"
21 class Chord_name_engraver : public Engraver
23 TRANSLATOR_DECLARATIONS( Chord_name_engraver);
25 virtual void stop_translation_timestep ();
26 virtual void process_music ();
27 virtual bool try_music (Music *);
30 void add_note (Music *);
35 Protected_scm last_chord_;
40 Chord_name_engraver::Chord_name_engraver ()
43 chord_ = gh_cons (SCM_EOL, gh_cons (SCM_EOL, SCM_EOL));
48 Chord_name_engraver::add_note (Music * n)
50 SCM pitches = ly_car (chord_);
51 SCM modifiers = ly_cdr (chord_);
52 SCM inversion = modifiers == SCM_EOL ? SCM_EOL : ly_car (modifiers);
53 SCM bass = modifiers == SCM_EOL ? SCM_EOL : ly_cdr (modifiers);
55 if (n->get_mus_property ("inversion") == SCM_BOOL_T)
56 inversion = n->get_mus_property ("pitch");
57 else if (n->get_mus_property ("bass") == SCM_BOOL_T)
58 bass = n->get_mus_property ("pitch");
60 pitches = scm_sort_list (gh_cons (n->get_mus_property ("pitch"), pitches),
62 chord_ = gh_cons (pitches, gh_cons (inversion, bass));
66 Chord_name_engraver::try_music (Music* m)
71 if (m->is_mus_type ("note-event"))
80 Chord_name_engraver::process_music ()
82 if (ly_car (chord_) != SCM_EOL)
84 chord_name_ = new Item (get_property ("ChordName"));
85 chord_name_->set_grob_property ("chord", chord_);
86 announce_grob(chord_name_, SCM_EOL);
87 SCM s = get_property ("chordChanges");
88 if (to_boolean (s) && ly_car (last_chord_) != SCM_EOL
89 && gh_equal_p (chord_, last_chord_))
90 chord_name_->set_grob_property ("begin-of-line-visible", SCM_BOOL_T);
95 Chord_name_engraver::stop_translation_timestep ()
99 typeset_grob (chord_name_);
103 if (ly_car (chord_) != SCM_EOL)
104 last_chord_ = chord_;
105 chord_ = gh_cons (SCM_EOL, gh_cons (SCM_EOL, SCM_EOL));
108 ENTER_DESCRIPTION(Chord_name_engraver,
109 /* descr */ "Catch note-events, Tonic_reqs, Inversion_reqs, Bass_req "
110 "and generate the appropriate chordname.",
111 /* creats*/ "ChordName",
112 /* accepts */ "note-event busy-playing-event",
114 /* reads */ "chordChanges",