2 spacing-engraver.cc -- implement Spacing_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "musical-request.hh"
11 #include "paper-column.hh"
13 #include "spacing-spanner.hh"
14 #include "engraver.hh"
16 #include "note-spacing.hh"
17 #include "staff-spacing.hh"
18 #include "group-interface.hh"
28 Rhythmic_tuple (Grob_info i
, Moment m
)
33 static int time_compare (Rhythmic_tuple
const &, Rhythmic_tuple
const &);
37 Acknowledge rhythmic elements, for initializing spacing fields in
40 should be the last one of the toplevel context
42 class Spacing_engraver
: public Engraver
44 PQueue
<Rhythmic_tuple
> playing_durations_
;
45 Array
<Rhythmic_tuple
> now_durations_
;
46 Array
<Rhythmic_tuple
> stopped_durations_
;
50 TRANSLATOR_DECLARATIONS(Spacing_engraver
);
52 virtual void acknowledge_grob (Grob_info
);
53 virtual void start_translation_timestep ();
54 virtual void stop_translation_timestep ();
55 virtual void initialize ();
56 virtual void finalize ();
60 compare (Rhythmic_tuple
const &a
, Rhythmic_tuple
const &b
)
62 return Rhythmic_tuple::time_compare (a
,b
);
66 Rhythmic_tuple::time_compare (Rhythmic_tuple
const &h1
,
67 Rhythmic_tuple
const &h2
)
69 return (h1
.end_
- h2
.end_
).main_part_
.sign ();
72 Spacing_engraver::Spacing_engraver ()
78 Spacing_engraver::initialize ()
80 spacing_p_
=new Spanner (get_property ("SpacingSpanner"));
81 spacing_p_
->set_bound (LEFT
, unsmob_grob (get_property ("currentCommandColumn")));
82 announce_grob(spacing_p_
, SCM_EOL
);
86 Spacing_engraver::finalize ()
88 Grob
* p
= unsmob_grob (get_property ("currentCommandColumn"));
89 spacing_p_
->set_bound (RIGHT
, p
);
90 typeset_grob (spacing_p_
);
95 Spacing_engraver::acknowledge_grob (Grob_info i
)
97 if (Note_spacing::has_interface (i
.grob_l_
) || Staff_spacing::has_interface (i
.grob_l_
))
99 Pointer_group_interface::add_grob (spacing_p_
, ly_symbol2scm ("wishes"), i
.grob_l_
);
102 if (to_boolean (i
.grob_l_
->get_grob_property ("non-rhythmic")))
105 if (Rhythmic_req
* r
= dynamic_cast<Rhythmic_req
*> (i
.music_cause ()))
107 Rhythmic_tuple
t (i
, now_mom () + r
->length_mom ());
108 now_durations_
.push (t
);
113 Spacing_engraver::stop_translation_timestep ()
115 Moment shortest_playing
;
116 shortest_playing
.set_infinite (1);
117 for (int i
=0; i
< playing_durations_
.size (); i
++)
119 Moment m
= (playing_durations_
[i
].info_
.music_cause ())->length_mom ();
122 shortest_playing
= shortest_playing
<? m
;
127 inf
.set_infinite (1);
129 for (int i
=0; i
< now_durations_
.size (); i
++)
131 Moment m
= now_durations_
[i
].info_
.music_cause ()->length_mom ();
133 starter
= starter
<? m
;
135 playing_durations_
.insert (now_durations_
[i
]);
137 now_durations_
.clear ();
139 shortest_playing
= shortest_playing
<? starter
;
142 = dynamic_cast<Paper_column
*> (unsmob_grob (get_property ("currentMusicalColumn")));
144 SCM sh
= shortest_playing
.smobbed_copy ();
145 SCM st
= starter
.smobbed_copy ();
147 sc
->set_grob_property ("shortest-playing-duration", sh
);
148 sc
->set_grob_property ("shortest-starter-duration", st
);
152 Spacing_engraver::start_translation_timestep ()
154 Moment now
= now_mom ();
155 stopped_durations_
.clear ();
156 while (playing_durations_
.size () && playing_durations_
.front ().end_
< now
)
157 playing_durations_
.delmin ();
158 while (playing_durations_
.size () && playing_durations_
.front ().end_
== now
)
159 stopped_durations_
.push (playing_durations_
.get ());
165 ENTER_DESCRIPTION(Spacing_engraver
,
166 /* descr */ "make a SpacingSpanner and do bookkeeping of shortest starting and playing notes ",
167 /* creats*/ "SpacingSpanner",
168 /* acks */ "grob-interface",