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 "pointer-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 DECLARE_ACKNOWLEDGER(staff_spacing);
50 DECLARE_ACKNOWLEDGER(note_spacing);
51 DECLARE_ACKNOWLEDGER(rhythmic_head);
52 void start_translation_timestep ();
53 void stop_translation_timestep ();
54 void process_music ();
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::process_music ()
81 spacing_ = make_spanner ("SpacingSpanner", SCM_EOL);
82 spacing_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn")));
87 Spacing_engraver::finalize ()
91 Grob *p = unsmob_grob (get_property ("currentCommandColumn"));
93 spacing_->set_bound (RIGHT, p);
99 Spacing_engraver::acknowledge_note_spacing (Grob_info i)
101 Pointer_group_interface::add_grob (spacing_, ly_symbol2scm ("wishes"), i.grob ());
105 Spacing_engraver::acknowledge_staff_spacing (Grob_info i)
107 Pointer_group_interface::add_grob (spacing_, ly_symbol2scm ("wishes"), i.grob ());
111 Spacing_engraver::acknowledge_rhythmic_head (Grob_info i)
113 if (i.grob ()->internal_has_interface (ly_symbol2scm ("lyric-syllable-interface"))
114 || i.grob ()->internal_has_interface (ly_symbol2scm ("multi-measure-interface")))
118 only pay attention to durations that are not grace notes.
120 if (!now_.grace_part_)
122 Music *r = i.music_cause ();
123 if (r && r->is_mus_type ("rhythmic-event"))
125 Moment len = r->get_length ();
126 Rhythmic_tuple t (i, now_mom () + len);
127 now_durations_.push (t);
133 Spacing_engraver::stop_translation_timestep ()
135 Moment shortest_playing;
136 shortest_playing.set_infinite (1);
137 for (int i = 0; i < playing_durations_.size (); i++)
139 Music *mus = playing_durations_[i].info_.music_cause ();
142 Moment m = mus->get_length ();
143 shortest_playing = min (shortest_playing, m);
147 starter.set_infinite (1);
149 for (int i = 0; i < now_durations_.size (); i++)
151 Moment m = now_durations_[i].info_.music_cause ()->get_length ();
154 starter = min (starter, m);
155 playing_durations_.insert (now_durations_[i]);
158 now_durations_.clear ();
160 shortest_playing = min (shortest_playing, starter);
163 = dynamic_cast<Paper_column *> (unsmob_grob (get_property ("currentMusicalColumn")));
165 assert (starter.to_bool ());
166 SCM sh = shortest_playing.smobbed_copy ();
167 SCM st = starter.smobbed_copy ();
169 sc->set_property ("shortest-playing-duration", sh);
170 sc->set_property ("shortest-starter-duration", st);
174 Spacing_engraver::start_translation_timestep ()
177 stopped_durations_.clear ();
178 while (playing_durations_.size () && playing_durations_.front ().end_ < now_)
179 playing_durations_.delmin ();
180 while (playing_durations_.size () && playing_durations_.front ().end_ == now_)
181 stopped_durations_.push (playing_durations_.get ());
184 #include "translator.icc"
186 ADD_ACKNOWLEDGER(Spacing_engraver,staff_spacing);
187 ADD_ACKNOWLEDGER(Spacing_engraver,note_spacing);
188 ADD_ACKNOWLEDGER(Spacing_engraver,rhythmic_head);
190 ADD_TRANSLATOR (Spacing_engraver,
191 /* descr */ "make a SpacingSpanner and do bookkeeping of shortest starting and playing notes ",
192 /* creats*/ "SpacingSpanner",