2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1998--2011 Jan Nieuwenhuizen <janneke@gnu.org>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "chord-name.hh"
22 #include "dimensions.hh"
23 #include "engraver.hh"
24 #include "font-interface.hh"
26 #include "output-def.hh"
28 #include "protected-scm.hh"
29 #include "stream-event.hh"
30 #include "text-interface.hh"
33 #include "translator.icc"
35 class Chord_name_engraver
: public Engraver
37 TRANSLATOR_DECLARATIONS (Chord_name_engraver
);
39 void stop_translation_timestep ();
40 void process_music ();
41 virtual void finalize ();
42 virtual void derived_mark () const;
43 DECLARE_TRANSLATOR_LISTENER (note
);
44 DECLARE_TRANSLATOR_LISTENER (rest
);
47 vector
<Stream_event
*> notes_
;
50 Stream_event
*rest_event_
;
54 Chord_name_engraver::finalize ()
59 Chord_name_engraver::derived_mark () const
61 scm_gc_mark (last_chord_
);
64 Chord_name_engraver::Chord_name_engraver ()
67 last_chord_
= SCM_EOL
;
72 Chord_name_engraver::process_music ()
76 SCM inversion
= SCM_EOL
;
77 SCM pitches
= SCM_EOL
;
81 SCM no_chord_markup
= get_property ("noChordSymbol");
82 if (!Text_interface::is_markup (no_chord_markup
))
84 markup
= no_chord_markup
;
91 Stream_event
*inversion_event
= 0;
92 for (vsize i
= 0; i
< notes_
.size (); i
++)
94 Stream_event
*n
= notes_
[i
];
95 SCM p
= n
->get_property ("pitch");
96 if (!unsmob_pitch (p
))
99 if (n
->get_property ("inversion") == SCM_BOOL_T
)
104 else if (n
->get_property ("bass") == SCM_BOOL_T
)
107 pitches
= scm_cons (p
, pitches
);
112 SCM oct
= inversion_event
->get_property ("octavation");
113 if (scm_is_number (oct
))
115 Pitch
*p
= unsmob_pitch (inversion_event
->get_property ("pitch"));
116 int octavation
= scm_to_int (oct
);
117 Pitch orig
= p
->transposed (Pitch (-octavation
, 0, 0));
119 pitches
= scm_cons (orig
.smobbed_copy (), pitches
);
122 programming_error ("inversion does not have original pitch");
125 pitches
= scm_sort_list (pitches
, Pitch::less_p_proc
);
127 SCM name_proc
= get_property ("chordNameFunction");
128 markup
= scm_call_4 (name_proc
, pitches
, bass
, inversion
,
129 context ()->self_scm ());
134 SCM chord_as_scm
= scm_cons (pitches
, scm_cons (bass
, inversion
));
136 chord_name_
= make_item ("ChordName",
137 rest_event_
? rest_event_
->self_scm () : notes_
[0]->self_scm ());
138 chord_name_
->set_property ("text", markup
);
140 SCM chord_changes
= get_property("chordChanges");
141 if (to_boolean (chord_changes
) && scm_is_pair (last_chord_
)
142 && ly_is_equal (chord_as_scm
, last_chord_
))
143 chord_name_
->set_property ("begin-of-line-visible", SCM_BOOL_T
);
145 last_chord_
= chord_as_scm
;
148 IMPLEMENT_TRANSLATOR_LISTENER (Chord_name_engraver
, note
);
150 Chord_name_engraver::listen_note (Stream_event
*ev
)
152 notes_
.push_back (ev
);
155 IMPLEMENT_TRANSLATOR_LISTENER (Chord_name_engraver
, rest
);
157 Chord_name_engraver::listen_rest (Stream_event
*ev
)
159 ASSIGN_EVENT_ONCE(rest_event_
, ev
);
163 Chord_name_engraver::stop_translation_timestep ()
171 The READs description is not strictly accurate:
172 which properties are read depend on the chord naming function active.
174 ADD_TRANSLATOR (Chord_name_engraver
,
176 "Catch note and rest events and generate the appropriate chordname.",
183 "chordNameExceptions "
187 "chordNameExceptions "