2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2001--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
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/>.
21 #include "engraver.hh"
25 #include "translator.icc"
34 operator < (Grob_pq_entry const &a, Grob_pq_entry const &b)
36 return a.end_ < b.end_;
39 class Grob_pq_engraver : public Engraver
42 TRANSLATOR_DECLARATIONS (Grob_pq_engraver);
44 virtual void initialize ();
45 void acknowledge_grob (Grob_info);
46 void start_translation_timestep ();
47 void stop_translation_timestep ();
48 void process_acknowledged ();
50 vector<Grob_pq_entry> started_now_;
53 Grob_pq_engraver::Grob_pq_engraver (Context *c)
59 Grob_pq_engraver::initialize ()
61 context ()->set_property ("busyGrobs", SCM_EOL);
64 LY_DEFINE (ly_grob_pq_less_p, "ly:grob-pq<?",
65 2, 0, 0, (SCM a, SCM b),
66 "Compare two grob priority queue entries."
67 " This is an internal function.")
69 if (Moment::compare (*unsmob<Moment> (scm_car (a)),
70 *unsmob<Moment> (scm_car (b))) < 0)
77 Grob_pq_engraver::acknowledge_grob (Grob_info gi)
79 Stream_event *ev = gi.event_cause ();
82 && !gi.grob ()->internal_has_interface (ly_symbol2scm ("multi-measure-interface")))
84 Moment n = now_mom ();
85 Moment l = get_event_length (ev, n);
96 started_now_.push_back (e);
101 Grob_pq_engraver::process_acknowledged ()
103 vector_sort (started_now_, less<Grob_pq_entry> ());
106 for (vsize i = 0; i < started_now_.size (); i++)
108 *tail = scm_acons (started_now_[i].end_.smobbed_copy (),
109 started_now_[i].grob_->self_scm (),
111 tail = SCM_CDRLOC (*tail);
114 SCM busy = get_property ("busyGrobs");
115 busy = scm_merge_x (lst, busy, ly_grob_pq_less_p_proc);
116 context ()->set_property ("busyGrobs", busy);
118 started_now_.clear ();
122 Grob_pq_engraver::stop_translation_timestep ()
124 Moment now = now_mom ();
125 SCM start_busy = get_property ("busyGrobs");
126 SCM busy = start_busy;
127 while (scm_is_pair (busy) && *unsmob<Moment> (scm_caar (busy)) == now)
128 busy = scm_cdr (busy);
133 Grob_pq_engraver::start_translation_timestep ()
135 Moment now = now_mom ();
137 SCM start_busy = get_property ("busyGrobs");
138 SCM busy = start_busy;
139 while (scm_is_pair (busy) && *unsmob<Moment> (scm_caar (busy)) < now)
142 The grob-pq-engraver is not water tight, and stuff like
143 tupletSpannerDuration confuses it.
145 busy = scm_cdr (busy);
148 if (start_busy != busy)
149 context ()->set_property ("busyGrobs", busy);
153 Grob_pq_engraver::boot ()
155 ADD_ACKNOWLEDGER (Grob_pq_engraver, grob);
158 ADD_TRANSLATOR (Grob_pq_engraver,
160 "Administrate when certain grobs (e.g., note heads) stop"