* lily/music-iterator.cc (quit, do_quit): new function: break link
[lilypond.git] / lily / custos-engraver.cc
blobb16c637029e006e293f29e2c72f5d5fdbbdaab58
1 /*
2 custos-engraver.cc -- implement Custos_engraver
4 source file of the GNU LilyPond music typesetter
6 (C) 2000 Juergen Reuter <reuterj@ira.uka.de>,
8 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 #include "engraver.hh"
13 #include "bar-line.hh"
14 #include "item.hh"
15 #include "note-head.hh"
16 #include "staff-symbol-referencer.hh"
17 #include "warn.hh"
18 #include "musical-request.hh"
21 This class implements an engraver for custos symbols.
23 class Custos_engraver : public Engraver
25 public:
26 TRANSLATOR_DECLARATIONS( Custos_engraver);
27 virtual void start_translation_timestep ();
28 virtual void acknowledge_grob (Grob_info);
29 virtual void process_acknowledged_grobs ();
30 virtual void stop_translation_timestep ();
31 virtual void finalize ();
34 private:
35 Item * create_custos ();
36 bool custos_permitted;
37 Link_array<Grob> custodes_;
38 Array<Pitch> pitches_;
41 Custos_engraver::Custos_engraver ()
43 custos_permitted = false;
47 void
48 Custos_engraver::stop_translation_timestep ()
51 delay typeset until we're at the next moment, so we can silence custodes at the end of the piece.
55 void
56 Custos_engraver::start_translation_timestep ()
58 for (int i = custodes_.size (); i--;)
60 typeset_grob (custodes_[i]);
62 custodes_.clear ();
63 pitches_.clear ();
65 custos_permitted = false;
69 void
70 Custos_engraver::acknowledge_grob (Grob_info info)
72 Item *item = dynamic_cast <Item *> (info.grob_);
73 if (item)
75 if (Bar_line::has_interface (info.grob_))
76 custos_permitted = true;
77 else if (Note_head::has_interface (info.grob_))
81 ideally, we'd do custos->set_parent (Y_AXIS, notehead),
82 but since the note head lives on the other system, we can't
84 So we copy the position from the note head pitch. We
85 don't look at the staff-position, since we can't be sure
86 whether Clef_engraver already applied a vertical shift.
88 Note_req * nr = dynamic_cast<Note_req*> (info.music_cause ());
89 if (nr)
90 pitches_.push (*unsmob_pitch (nr->get_mus_property ("pitch")));
95 void
96 Custos_engraver::process_acknowledged_grobs ()
98 if (gh_string_p (get_property ("whichBar")))
99 custos_permitted = true;
101 if (custos_permitted)
103 for (int i = pitches_.size (); i--;)
105 Item *c = create_custos ();
107 int p = pitches_[i].steps ();
108 SCM c0 = get_property ("centralCPosition");
109 if (gh_number_p (c0))
110 p += gh_scm2int (c0);
113 c->set_grob_property ("staff-position",
114 gh_int2scm (p));
118 pitches_.clear ();
122 Item*
123 Custos_engraver::create_custos ()
125 SCM basicProperties = get_property ("Custos");
126 Item* custos = new Item (basicProperties);
128 announce_grob(custos, SCM_EOL);
129 custodes_.push (custos);
131 return custos;
134 void
135 Custos_engraver::finalize ()
137 for (int i = custodes_.size (); i--;)
139 custodes_[i]->suicide ();
140 typeset_grob (custodes_[i]);
142 custodes_.clear ();
147 ENTER_DESCRIPTION(Custos_engraver,
148 /* descr */ "",
149 /* creats*/ "Custos",
150 /* acks */ "bar-line-interface note-head-interface",
151 /* reads */ "",
152 /* write */ "");