2 spacing-engraver.cc -- implement Spacing_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "paper-column.hh"
10 #include "engraver.hh"
12 #include "note-spacing.hh"
13 #include "staff-spacing.hh"
14 #include "group-interface.hh"
25 Rhythmic_tuple (Grob_info i, Moment m)
30 static int time_compare (Rhythmic_tuple const &, Rhythmic_tuple const &);
34 Acknowledge rhythmic elements, for initializing spacing fields in
37 should be the last one of the toplevel context
39 class Spacing_engraver : public Engraver
41 PQueue<Rhythmic_tuple> playing_durations_;
42 Array<Rhythmic_tuple> now_durations_;
43 Array<Rhythmic_tuple> stopped_durations_;
47 TRANSLATOR_DECLARATIONS (Spacing_engraver);
49 virtual void acknowledge_grob (Grob_info);
50 virtual void start_translation_timestep ();
51 virtual void stop_translation_timestep ();
52 virtual void process_music ();
53 virtual void finalize ();
57 compare (Rhythmic_tuple const &a, Rhythmic_tuple const &b)
59 return Rhythmic_tuple::time_compare (a, b);
63 Rhythmic_tuple::time_compare (Rhythmic_tuple const &h1,
64 Rhythmic_tuple const &h2)
66 return (h1.end_ - h2.end_).main_part_.sign ();
69 Spacing_engraver::Spacing_engraver ()
75 Spacing_engraver::process_music ()
79 spacing_ = make_spanner ("SpacingSpanner", SCM_EOL);
80 spacing_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn")));
85 Spacing_engraver::finalize ()
89 Grob *p = unsmob_grob (get_property ("currentCommandColumn"));
91 spacing_->set_bound (RIGHT, p);
97 Spacing_engraver::acknowledge_grob (Grob_info i)
99 if (Note_spacing::has_interface (i.grob ()) || Staff_spacing::has_interface (i.grob ()))
101 Pointer_group_interface::add_grob (spacing_, ly_symbol2scm ("wishes"), i.grob ());
104 if (i.grob ()->internal_has_interface (ly_symbol2scm ("lyric-syllable-interface"))
105 || i.grob ()->internal_has_interface (ly_symbol2scm ("multi-measure-event")))
109 only pay attention to durations that are not grace notes.
111 if (!now_.grace_part_)
113 Music *r = i.music_cause ();
114 if (r && r->is_mus_type ("rhythmic-event"))
116 Moment len = r->get_length ();
117 Rhythmic_tuple t (i, now_mom () + len);
118 now_durations_.push (t);
124 Spacing_engraver::stop_translation_timestep ()
126 Moment shortest_playing;
127 shortest_playing.set_infinite (1);
128 for (int i = 0; i < playing_durations_.size (); i++)
130 Music *mus = playing_durations_[i].info_.music_cause ();
133 Moment m = mus->get_length ();
134 shortest_playing = min (shortest_playing, m);
138 starter.set_infinite (1);
140 for (int i = 0; i < now_durations_.size (); i++)
142 Moment m = now_durations_[i].info_.music_cause ()->get_length ();
145 starter = min (starter, m);
146 playing_durations_.insert (now_durations_[i]);
149 now_durations_.clear ();
151 shortest_playing = min (shortest_playing, starter);
154 = dynamic_cast<Paper_column *> (unsmob_grob (get_property ("currentMusicalColumn")));
156 assert (starter.to_bool ());
157 SCM sh = shortest_playing.smobbed_copy ();
158 SCM st = starter.smobbed_copy ();
160 sc->set_property ("shortest-playing-duration", sh);
161 sc->set_property ("shortest-starter-duration", st);
165 Spacing_engraver::start_translation_timestep ()
168 stopped_durations_.clear ();
169 while (playing_durations_.size () && playing_durations_.front ().end_ < now_)
170 playing_durations_.delmin ();
171 while (playing_durations_.size () && playing_durations_.front ().end_ == now_)
172 stopped_durations_.push (playing_durations_.get ());
175 ADD_TRANSLATOR (Spacing_engraver,
176 /* descr */ "make a SpacingSpanner and do bookkeeping of shortest starting and playing notes ",
177 /* creats*/ "SpacingSpanner",
179 /* acks */ "grob-interface",