2 chord-name-engraver.cc -- implement Chord_name_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2001 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
25 Chord_name_engraver ();
26 VIRTUAL_COPY_CONS (Translator);
29 virtual void stop_translation_timestep ();
30 virtual void acknowledge_grob (Grob_info i);
31 virtual void create_grobs ();
32 virtual bool try_music (Music *);
35 void add_note (Note_req *);
40 Protected_scm last_chord_;
43 ADD_THIS_TRANSLATOR (Chord_name_engraver);
45 Chord_name_engraver::Chord_name_engraver ()
48 chord_ = gh_cons (SCM_EOL, gh_cons (SCM_EOL, SCM_EOL));
53 Chord_name_engraver::add_note (Note_req* n)
55 SCM pitches = gh_car (chord_);
56 SCM modifiers = gh_cdr (chord_);
57 SCM inversion = modifiers == SCM_EOL ? SCM_EOL : gh_car (modifiers);
58 SCM bass = modifiers == SCM_EOL ? SCM_EOL : gh_cdr (modifiers);
60 if (n->get_mus_property ("inversion") == SCM_BOOL_T)
61 inversion = n->get_mus_property ("pitch");
62 else if (n->get_mus_property ("bass") == SCM_BOOL_T)
63 bass = n->get_mus_property ("pitch");
65 pitches = scm_sort_list (gh_cons (n->get_mus_property ("pitch"), pitches),
67 chord_ = gh_cons (pitches, gh_cons (inversion, bass));
71 Chord_name_engraver::try_music (Music* m)
73 if (Note_req* n = dynamic_cast<Note_req*> (m))
82 Chord_name_engraver::acknowledge_grob (Grob_info i)
84 if (Note_req* n = dynamic_cast<Note_req*> (i.req_l_))
89 Chord_name_engraver::create_grobs ()
91 if (!chord_name_p_ && gh_car (chord_) != SCM_EOL)
93 chord_name_p_ = new Item (get_property ("ChordName"));
94 chord_name_p_->set_grob_property ("chord", chord_);
95 announce_grob (chord_name_p_, 0);
96 SCM s = get_property ("chordChanges");
97 if (to_boolean (s) && gh_car (last_chord_) != SCM_EOL
98 && gh_equal_p (chord_, last_chord_))
99 chord_name_p_->set_grob_property ("begin-of-line-visible", SCM_BOOL_T);
104 Chord_name_engraver::stop_translation_timestep ()
108 typeset_grob (chord_name_p_);
112 if (gh_car (chord_) != SCM_EOL)
113 last_chord_ = chord_;
114 chord_ = gh_cons (SCM_EOL, gh_cons (SCM_EOL, SCM_EOL));