2 chord-name-engraver.cc -- implement Chord_name_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2009 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "chord-name.hh"
11 #include "dimensions.hh"
12 #include "engraver.hh"
13 #include "font-interface.hh"
15 #include "output-def.hh"
17 #include "protected-scm.hh"
18 #include "stream-event.hh"
21 #include "translator.icc"
23 class Chord_name_engraver
: public Engraver
25 TRANSLATOR_DECLARATIONS (Chord_name_engraver
);
27 void stop_translation_timestep ();
28 void process_music ();
29 virtual void finalize ();
30 virtual void derived_mark () const;
31 DECLARE_TRANSLATOR_LISTENER (note
);
34 vector
<Stream_event
*> notes_
;
40 Chord_name_engraver::finalize ()
45 Chord_name_engraver::derived_mark () const
47 scm_gc_mark (last_chord_
);
50 Chord_name_engraver::Chord_name_engraver ()
53 last_chord_
= SCM_EOL
;
57 Chord_name_engraver::process_music ()
63 SCM inversion
= SCM_EOL
;
64 SCM pitches
= SCM_EOL
;
66 Stream_event
*inversion_event
= 0;
67 for (vsize i
= 0; i
< notes_
.size (); i
++)
69 Stream_event
*n
= notes_
[i
];
70 SCM p
= n
->get_property ("pitch");
71 if (!unsmob_pitch (p
))
74 if (n
->get_property ("inversion") == SCM_BOOL_T
)
79 else if (n
->get_property ("bass") == SCM_BOOL_T
)
82 pitches
= scm_cons (p
, pitches
);
87 SCM oct
= inversion_event
->get_property ("octavation");
88 if (scm_is_number (oct
))
90 Pitch
*p
= unsmob_pitch (inversion_event
->get_property ("pitch"));
91 int octavation
= scm_to_int (oct
);
92 Pitch orig
= p
->transposed (Pitch (-octavation
, 0, 0));
94 pitches
= scm_cons (orig
.smobbed_copy (), pitches
);
97 programming_error ("inversion does not have original pitch");
100 pitches
= scm_sort_list (pitches
, Pitch::less_p_proc
);
102 SCM name_proc
= get_property ("chordNameFunction");
103 SCM markup
= scm_call_4 (name_proc
, pitches
, bass
, inversion
,
104 context ()->self_scm ());
109 SCM chord_as_scm
= scm_cons (pitches
, scm_cons (bass
, inversion
));
111 chord_name_
= make_item ("ChordName", notes_
[0]->self_scm ());
112 chord_name_
->set_property ("text", markup
);
114 SCM s
= get_property ("chordChanges");
115 if (to_boolean (s
) && scm_is_pair (last_chord_
)
116 && ly_is_equal (chord_as_scm
, last_chord_
))
117 chord_name_
->set_property ("begin-of-line-visible", SCM_BOOL_T
);
119 last_chord_
= chord_as_scm
;
122 IMPLEMENT_TRANSLATOR_LISTENER (Chord_name_engraver
, note
);
124 Chord_name_engraver::listen_note (Stream_event
*ev
)
126 notes_
.push_back (ev
);
130 Chord_name_engraver::stop_translation_timestep ()
137 The READs description is not strictly accurate:
138 which properties are read depend on the chord naming function active.
140 ADD_TRANSLATOR (Chord_name_engraver
,
142 "Catch note events and generate the appropriate chordname.",
149 "chordNameExceptions "
153 "chordNameExceptions "