2 grob-pq-engraver.cc -- implement Grob_pq_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2001--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "translator-group.hh"
10 #include "engraver.hh"
19 Grob_mom (Grob
*gr
, Moment e
)
26 int compare (Grob_mom
const &a
, Grob_mom
const &b
)
28 return Moment::compare (a
.end_
, b
.end_
);
32 class Grob_pq_engraver
: public Engraver
35 TRANSLATOR_DECLARATIONS(Grob_pq_engraver
);
37 Array
<Grob_mom
> current_grobs_
;
39 virtual void initialize ();
40 virtual void acknowledge_grob (Grob_info
);
41 virtual void start_translation_timestep ();
42 virtual void stop_translation_timestep ();
46 Grob_pq_engraver::Grob_pq_engraver()
52 Grob_pq_engraver::initialize ()
54 daddy_trans_
->set_property ("busyGrobs", SCM_EOL
);
58 Grob_pq_engraver::acknowledge_grob (Grob_info gi
)
60 Music
* m
= gi
.music_cause ();
64 Moment n
= now_mom ();
65 Moment l
= m
->length_mom ();
72 l
.grace_part_
= l
.main_part_
;
76 current_grobs_
.push (Grob_mom (gi
.grob_
, n
+ l
));
80 LY_DEFINE(ly_grob_pq_less_p
,
81 "ly-grob-pq-less?", 2 , 0 ,0, (SCM a
, SCM b
),
82 "Compare 2 Grob PQ entries. Internal")
84 if ( Moment::compare (*unsmob_moment (gh_car (a
)),
85 *unsmob_moment (gh_car (b
))) < 0)
93 Grob_pq_engraver::stop_translation_timestep ()
95 Moment now
= now_mom();
97 current_grobs_
.sort (&compare
);
98 SCM current_list
= SCM_EOL
;
99 for (int i
= current_grobs_
.size(); i
--;)
100 current_list
= scm_cons (scm_cons (current_grobs_
[i
].end_
.smobbed_copy(),
101 current_grobs_
[i
].grob_
->self_scm ()), current_list
);
104 We generate some garbage here.
106 SCM busy
= get_property ("busyGrobs");
107 while (gh_pair_p (busy
) && *unsmob_moment (gh_caar (busy
)) == now
)
109 busy
= gh_cdr (busy
);
112 busy
= scm_merge_x (current_list
, busy
, ly_grob_pq_less_p_proc
);
113 current_grobs_
.clear ();
114 daddy_trans_
->set_property ("busyGrobs", 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 (gh_pair_p (busy
) && *unsmob_moment (gh_caar (busy
)) < now
)
127 Todo: do something sensible. The grob-pq-engraver is not water
128 tight, and stuff like tupletSpannerDuration confuses it.
130 programming_error (_f("Skipped something?\nGrob %s ended before I expected it to end.", unsmob_grob (gh_cdar (busy
))->name().to_str0()));
132 busy
= gh_cdr (busy
);
135 if (start_busy
!= busy
)
136 daddy_trans_
->set_property ("busyGrobs", busy
);
141 ENTER_DESCRIPTION(Grob_pq_engraver
,
142 /* descr */ "Administrate when certain grobs (eg. note heads) stop playing; this
143 engraver is a sort-of a failure, since it doesn't handle all sorts of borderline cases very well.
146 /* acks */ "grob-interface",
147 /* reads */ "busyGrobs",
148 /* write */ "busyGrobs");