2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2000--2014 Juergen Reuter <reuter@ipd.uka.de>,
5 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 LilyPond is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 LilyPond is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
21 #include "engraver.hh"
23 #include "note-head.hh"
25 #include "staff-symbol-referencer.hh"
26 #include "stream-event.hh"
29 #include "translator.icc"
32 * This class implements an engraver for custos symbols.
34 * FIXME: note heads inside of ligatures (i.e. ligature heads) are
35 * sometimes not recognized by this engraver. --jr
37 class Custos_engraver : public Engraver
40 TRANSLATOR_DECLARATIONS (Custos_engraver);
41 void start_translation_timestep ();
42 DECLARE_ACKNOWLEDGER (bar);
43 DECLARE_ACKNOWLEDGER (note_head);
44 void process_acknowledged ();
45 void stop_translation_timestep ();
46 virtual void finalize ();
49 Item *create_custos ();
50 bool custos_permitted_;
51 vector<Grob *> custodes_;
52 vector<Pitch> pitches_;
55 Custos_engraver::Custos_engraver ()
57 custos_permitted_ = false;
61 Custos_engraver::stop_translation_timestep ()
64 delay typeset until we're at the next moment, so we can silence custodes at the end of the piece.
68 custos_permitted_ = false;
72 Custos_engraver::start_translation_timestep ()
78 Custos_engraver::acknowledge_bar (Grob_info /* info */)
80 custos_permitted_ = true;
84 Custos_engraver::acknowledge_note_head (Grob_info info)
86 Stream_event *ev = info.event_cause ();
87 if (ev && ev->in_event_class ("note-event"))
91 ideally, we'd do custos->set_parent (Y_AXIS, notehead),
92 but since the note head lives on the other system, we can't
94 So we copy the position from the note head pitch. We
95 don't look at the staff-position, since we can't be sure
96 whether Clef_engraver already applied a vertical shift.
98 pitches_.push_back (*Pitch::unsmob (ev->get_property ("pitch")));
103 Custos_engraver::process_acknowledged ()
105 if (scm_is_string (get_property ("whichBar")))
106 custos_permitted_ = true;
108 if (custos_permitted_)
110 for (vsize i = pitches_.size (); i--;)
112 Item *c = create_custos ();
114 int p = pitches_[i].steps ();
115 SCM c0 = get_property ("middleCPosition");
116 if (scm_is_number (c0))
117 p += scm_to_int (c0);
119 c->set_property ("staff-position",
128 Custos_engraver::create_custos ()
130 Item *custos = make_item ("Custos", SCM_EOL);
132 custodes_.push_back (custos);
138 Custos_engraver::finalize ()
140 for (vsize i = custodes_.size (); i--;)
141 custodes_[i]->suicide ();
145 ADD_ACKNOWLEDGER (Custos_engraver, bar);
146 ADD_ACKNOWLEDGER (Custos_engraver, note_head);
148 ADD_TRANSLATOR (Custos_engraver,