2 grob-pq-engraver.cc -- implement Grob_pq_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2001--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "translator-group.hh"
10 #include "engraver.hh"
15 TODO: should junk this engraver.
23 Grob_mom (Grob*gr, Moment e)
30 int compare (Grob_mom const &a, Grob_mom const &b)
32 return Moment::compare (a.end_, b.end_);
37 class Grob_pq_engraver: public Engraver
40 TRANSLATOR_DECLARATIONS(Grob_pq_engraver);
42 Array<Grob_mom> current_grobs_;
44 virtual void initialize ();
45 virtual void acknowledge_grob (Grob_info);
46 virtual void start_translation_timestep ();
47 virtual void stop_translation_timestep ();
51 Grob_pq_engraver::Grob_pq_engraver()
57 Grob_pq_engraver::initialize ()
59 daddy_trans_->set_property ("busyGrobs", SCM_EOL);
63 Grob_pq_engraver::acknowledge_grob (Grob_info gi)
65 Music * m = gi.music_cause ();
68 && !gi.grob_->internal_has_interface (ly_symbol2scm ("multi-measure-interface")))
70 Moment n = now_mom ();
71 Moment l = m->get_length ();
78 l.grace_part_ = l.main_part_;
82 current_grobs_.push (Grob_mom (gi.grob_, n + l));
86 LY_DEFINE(ly_grob_pq_less_p,
87 "ly:grob-pq-less?", 2 , 0 ,0, (SCM a, SCM b),
88 "Compare 2 Grob PQ entries. Internal")
90 if ( Moment::compare (*unsmob_moment (gh_car (a)),
91 *unsmob_moment (gh_car (b))) < 0)
99 Grob_pq_engraver::stop_translation_timestep ()
101 Moment now = now_mom();
103 current_grobs_.sort (&compare);
104 SCM current_list = SCM_EOL;
105 for (int i = current_grobs_.size(); i--;)
106 current_list = scm_cons (scm_cons (current_grobs_[i].end_.smobbed_copy(),
107 current_grobs_[i].grob_->self_scm ()), current_list);
110 We generate some garbage here.
112 SCM busy = get_property ("busyGrobs");
113 while (gh_pair_p (busy) && *unsmob_moment (gh_caar (busy)) == now)
115 busy = gh_cdr (busy);
118 busy = scm_merge_x (current_list, busy, ly_grob_pq_less_p_proc);
119 current_grobs_.clear ();
120 daddy_trans_->set_property ("busyGrobs", busy);
124 Grob_pq_engraver::start_translation_timestep ()
126 Moment now = now_mom();
128 SCM start_busy = get_property ("busyGrobs");
129 SCM busy = start_busy;
130 while (gh_pair_p (busy) && *unsmob_moment (gh_caar (busy)) < now)
133 Todo: do something sensible. The grob-pq-engraver is not water
134 tight, and stuff like tupletSpannerDuration confuses it.
136 programming_error (_f("Skipped something?\nGrob %s ended before I expected it to end.", unsmob_grob (gh_cdar (busy))->name().to_str0()));
138 busy = gh_cdr (busy);
141 if (start_busy != busy)
142 daddy_trans_->set_property ("busyGrobs", busy);
147 ENTER_DESCRIPTION(Grob_pq_engraver,
149 /* descr */ "Administrate when certain grobs (eg. note heads) stop playing; this \
150 engraver is a sort-of a failure, since it doesn't handle all sorts of \
151 borderline cases very well. \
156 /* acks */ "grob-interface", \
157 /* reads */ "busyGrobs", \
158 /* write */ "busyGrobs");