2 chord-name-engraver.cc -- implement Chord_name_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2002 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "chord-name.hh"
12 #include "musical-request.hh"
13 #include "paper-def.hh"
14 #include "font-interface.hh"
15 #include "paper-def.hh"
17 #include "dimensions.hh"
20 #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 *);
31 void add_note (Note_req *);
36 Protected_scm last_chord_;
41 Chord_name_engraver::Chord_name_engraver ()
44 chord_ = gh_cons (SCM_EOL, gh_cons (SCM_EOL, SCM_EOL));
49 Chord_name_engraver::add_note (Note_req* n)
51 SCM pitches = ly_car (chord_);
52 SCM modifiers = ly_cdr (chord_);
53 SCM inversion = modifiers == SCM_EOL ? SCM_EOL : ly_car (modifiers);
54 SCM bass = modifiers == SCM_EOL ? SCM_EOL : ly_cdr (modifiers);
56 if (n->get_mus_property ("inversion") == SCM_BOOL_T)
57 inversion = n->get_mus_property ("pitch");
58 else if (n->get_mus_property ("bass") == SCM_BOOL_T)
59 bass = n->get_mus_property ("pitch");
61 pitches = scm_sort_list (gh_cons (n->get_mus_property ("pitch"), pitches),
63 chord_ = gh_cons (pitches, gh_cons (inversion, bass));
67 Chord_name_engraver::try_music (Music* m)
69 if (Note_req* n = dynamic_cast<Note_req*> (m))
78 Chord_name_engraver::process_music ()
80 if (ly_car (chord_) != SCM_EOL)
82 chord_name_p_ = new Item (get_property ("ChordName"));
83 chord_name_p_->set_grob_property ("chord", chord_);
84 announce_grob(chord_name_p_, SCM_EOL);
85 SCM s = get_property ("chordChanges");
86 if (to_boolean (s) && ly_car (last_chord_) != SCM_EOL
87 && gh_equal_p (chord_, last_chord_))
88 chord_name_p_->set_grob_property ("begin-of-line-visible", SCM_BOOL_T);
93 Chord_name_engraver::stop_translation_timestep ()
97 typeset_grob (chord_name_p_);
101 if (ly_car (chord_) != SCM_EOL)
102 last_chord_ = chord_;
103 chord_ = gh_cons (SCM_EOL, gh_cons (SCM_EOL, SCM_EOL));
106 ENTER_DESCRIPTION(Chord_name_engraver,
107 /* descr */ "Catch Note_req's, Tonic_reqs, Inversion_reqs, Bass_req
108 and generate the appropriate chordname.",
109 /* creats*/ "ChordName",
111 /* reads */ "chordChanges",