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"
12 #include "engraver.hh"
14 #include "note-spacing.hh"
15 #include "staff-spacing.hh"
16 #include "group-interface.hh"
27 Rhythmic_tuple (Grob_info i, Moment m)
32 static int time_compare (Rhythmic_tuple const &, Rhythmic_tuple const &);
36 Acknowledge rhythmic elements, for initializing spacing fields in
39 should be the last one of the toplevel context
41 class Spacing_engraver : public Engraver
43 PQueue<Rhythmic_tuple> playing_durations_;
44 Array<Rhythmic_tuple> now_durations_;
45 Array<Rhythmic_tuple> stopped_durations_;
49 TRANSLATOR_DECLARATIONS(Spacing_engraver);
51 virtual void acknowledge_grob (Grob_info);
52 virtual void start_translation_timestep ();
53 virtual void stop_translation_timestep ();
54 virtual void initialize ();
55 virtual void finalize ();
59 compare (Rhythmic_tuple const &a, Rhythmic_tuple const &b)
61 return Rhythmic_tuple::time_compare (a,b);
65 Rhythmic_tuple::time_compare (Rhythmic_tuple const &h1,
66 Rhythmic_tuple const &h2)
68 return (h1.end_ - h2.end_).main_part_.sign ();
71 Spacing_engraver::Spacing_engraver ()
77 Spacing_engraver::initialize ()
79 spacing_ =new Spanner (get_property ("SpacingSpanner"));
80 spacing_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn")));
81 announce_grob(spacing_, SCM_EOL);
85 Spacing_engraver::finalize ()
87 Grob * p = unsmob_grob (get_property ("currentCommandColumn"));
88 spacing_->set_bound (RIGHT, p);
89 typeset_grob (spacing_);
94 Spacing_engraver::acknowledge_grob (Grob_info i)
96 if (Note_spacing::has_interface (i.grob_) || Staff_spacing::has_interface (i.grob_))
98 Pointer_group_interface::add_grob (spacing_, ly_symbol2scm ("wishes"), i.grob_);
101 if (i.grob_->internal_has_interface (ly_symbol2scm ("lyric-syllable-interface")))
105 only pay attention to durations that are not grace notes.
107 if (!now_.grace_part_)
109 if (Rhythmic_req * r = dynamic_cast<Rhythmic_req*> (i.music_cause ()))
111 Moment len = r->length_mom ();
112 Rhythmic_tuple t (i, now_mom () + len);
113 now_durations_.push (t);
119 Spacing_engraver::stop_translation_timestep ()
121 Moment shortest_playing;
122 shortest_playing.set_infinite (1);
123 for (int i=0; i < playing_durations_.size (); i++)
125 Moment m = (playing_durations_[i].info_.music_cause ())->length_mom ();
126 shortest_playing = shortest_playing <? m;
130 starter.set_infinite (1);
132 for (int i=0; i < now_durations_.size (); i++)
134 Moment m = now_durations_[i].info_.music_cause ()->length_mom ();
137 starter = starter <? m;
138 playing_durations_.insert (now_durations_[i]);
142 now_durations_.clear ();
144 shortest_playing = shortest_playing <? starter;
147 = dynamic_cast<Paper_column*> (unsmob_grob (get_property ("currentMusicalColumn")));
149 assert (starter.to_bool ());
150 SCM sh = shortest_playing.smobbed_copy ();
151 SCM st = starter.smobbed_copy ();
153 sc->set_grob_property ("shortest-playing-duration", sh);
154 sc->set_grob_property ("shortest-starter-duration", st);
158 Spacing_engraver::start_translation_timestep ()
161 stopped_durations_.clear ();
162 while (playing_durations_.size () && playing_durations_.front ().end_ < now_)
163 playing_durations_.delmin ();
164 while (playing_durations_.size () && playing_durations_.front ().end_ == now_)
165 stopped_durations_.push (playing_durations_.get ());
171 ENTER_DESCRIPTION(Spacing_engraver,
172 /* descr */ "make a SpacingSpanner and do bookkeeping of shortest starting and playing notes ",
173 /* creats*/ "SpacingSpanner",
174 /* acks */ "grob-interface",