2 grob-pq-engraver.cc -- implement Grob_pq_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2001--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "engraver.hh"
21 operator< (Grob_pq_entry const &a, Grob_pq_entry const &b)
23 return a.end_ < b.end_;
26 class Grob_pq_engraver : public Engraver
29 TRANSLATOR_DECLARATIONS (Grob_pq_engraver);
31 virtual void initialize ();
32 DECLARE_ACKNOWLEDGER (grob);
33 void start_translation_timestep ();
34 void stop_translation_timestep ();
35 void process_acknowledged ();
37 vector<Grob_pq_entry> started_now_;
40 Grob_pq_engraver::Grob_pq_engraver ()
45 Grob_pq_engraver::initialize ()
47 context ()->set_property ("busyGrobs", SCM_EOL);
50 LY_DEFINE (ly_grob_pq_less_p, "ly:grob-pq<?",
51 2, 0, 0, (SCM a, SCM b),
52 "Compare 2 grob priority queue entries. Internal")
54 if (Moment::compare (*unsmob_moment (scm_car (a)),
55 *unsmob_moment (scm_car (b))) < 0)
62 Grob_pq_engraver::acknowledge_grob (Grob_info gi)
64 Stream_event *ev = gi.event_cause ();
67 && !gi.grob ()->internal_has_interface (ly_symbol2scm ("multi-measure-interface")))
69 Moment n = now_mom ();
70 Moment l = get_event_length (ev, n);
81 started_now_.push_back (e);
86 Grob_pq_engraver::process_acknowledged ()
88 vector_sort (started_now_, less<Grob_pq_entry> ());
91 for (vsize i = 0; i < started_now_.size (); i++)
93 *tail = scm_acons (started_now_[i].end_.smobbed_copy (),
94 started_now_[i].grob_->self_scm (),
96 tail = SCM_CDRLOC (*tail);
99 SCM busy = get_property ("busyGrobs");
100 busy = scm_merge_x (lst, busy, ly_grob_pq_less_p_proc);
101 context ()->set_property ("busyGrobs", busy);
103 started_now_.clear ();
107 Grob_pq_engraver::stop_translation_timestep ()
109 Moment now = now_mom ();
110 SCM start_busy = get_property ("busyGrobs");
111 SCM busy = start_busy;
112 while (scm_is_pair (busy) && *unsmob_moment (scm_caar (busy)) == now)
113 busy = scm_cdr (busy);
118 Grob_pq_engraver::start_translation_timestep ()
120 Moment now = now_mom ();
122 SCM start_busy = get_property ("busyGrobs");
123 SCM busy = start_busy;
124 while (scm_is_pair (busy) && *unsmob_moment (scm_caar (busy)) < now)
127 The grob-pq-engraver is not water tight, and stuff like
128 tupletSpannerDuration confuses it.
130 busy = scm_cdr (busy);
133 if (start_busy != busy)
134 context ()->set_property ("busyGrobs", busy);
137 #include "translator.icc"
138 ADD_ACKNOWLEDGER (Grob_pq_engraver, grob);
139 ADD_TRANSLATOR (Grob_pq_engraver,
141 /* doc */ "Administrate when certain grobs (eg. note heads) stop playing",
143 /* read */ "busyGrobs",
144 /* write */ "busyGrobs");