* lily/music-iterator.cc (quit, do_quit): new function: break link
[lilypond.git] / lily / chord-name-engraver.cc
blobbbccd04afee50aed36bd4055f133b46077bdfac9
1 /*
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>
7 */
9 #include "engraver.hh"
10 #include "chord-name.hh"
11 #include "chord.hh"
12 #include "musical-request.hh"
13 #include "paper-def.hh"
14 #include "font-interface.hh"
15 #include "paper-def.hh"
16 #include "main.hh"
17 #include "dimensions.hh"
18 #include "item.hh"
19 #include "pitch.hh"
20 #include "protected-scm.hh"
22 class Chord_name_engraver : public Engraver
24 TRANSLATOR_DECLARATIONS( Chord_name_engraver);
25 protected:
26 virtual void stop_translation_timestep ();
27 virtual void process_music ();
28 virtual bool try_music (Music *);
30 private:
31 void add_note (Note_req *);
33 Item* chord_name_;
35 Protected_scm chord_;
36 Protected_scm last_chord_;
41 Chord_name_engraver::Chord_name_engraver ()
43 chord_name_ = 0;
44 chord_ = gh_cons (SCM_EOL, gh_cons (SCM_EOL, SCM_EOL));
45 last_chord_ = chord_;
48 void
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");
60 else
61 pitches = scm_sort_list (gh_cons (n->get_mus_property ("pitch"), pitches),
62 Pitch::less_p_proc);
63 chord_ = gh_cons (pitches, gh_cons (inversion, bass));
66 bool
67 Chord_name_engraver::try_music (Music* m)
69 if (Note_req* n = dynamic_cast<Note_req*> (m))
71 add_note (n);
72 return true;
74 return false;
77 void
78 Chord_name_engraver::process_music ()
80 if (ly_car (chord_) != SCM_EOL)
82 chord_name_ = new Item (get_property ("ChordName"));
83 chord_name_->set_grob_property ("chord", chord_);
84 announce_grob(chord_name_, 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_->set_grob_property ("begin-of-line-visible", SCM_BOOL_T);
92 void
93 Chord_name_engraver::stop_translation_timestep ()
95 if (chord_name_)
97 typeset_grob (chord_name_);
99 chord_name_ = 0;
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",
110 /* acks */ "",
111 /* reads */ "chordChanges",
112 /* write */ "");