2 spacing-engraver.cc -- implement Spacing_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2005 Han-Wen Nienhuys <hanwen@xs4all.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"
17 #include "translator.icc"
27 Rhythmic_tuple (Grob_info i, Moment m)
32 static int time_compare (Rhythmic_tuple const &, Rhythmic_tuple const &);
36 TODO: allow starting & stopping of spacing regions.
39 Acknowledge rhythmic elements, for initializing spacing fields in
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);
53 DECLARE_ACKNOWLEDGER (staff_spacing);
54 DECLARE_ACKNOWLEDGER (note_spacing);
55 DECLARE_ACKNOWLEDGER (rhythmic_head);
57 void start_translation_timestep ();
58 void stop_translation_timestep ();
59 void process_music ();
60 virtual void finalize ();
64 compare (Rhythmic_tuple const &a, Rhythmic_tuple const &b)
66 return Rhythmic_tuple::time_compare (a, b);
70 Rhythmic_tuple::time_compare (Rhythmic_tuple const &h1,
71 Rhythmic_tuple const &h2)
73 return (h1.end_ - h2.end_).main_part_.sign ();
76 Spacing_engraver::Spacing_engraver ()
82 Spacing_engraver::process_music ()
86 spacing_ = make_spanner ("SpacingSpanner", SCM_EOL);
87 spacing_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn")));
92 Spacing_engraver::finalize ()
96 Grob *p = unsmob_grob (get_property ("currentCommandColumn"));
98 spacing_->set_bound (RIGHT, p);
104 Spacing_engraver::acknowledge_note_spacing (Grob_info i)
106 Pointer_group_interface::add_grob (spacing_, ly_symbol2scm ("wishes"), i.grob ());
110 Spacing_engraver::acknowledge_staff_spacing (Grob_info i)
112 Pointer_group_interface::add_grob (spacing_, ly_symbol2scm ("wishes"), i.grob ());
116 Spacing_engraver::acknowledge_rhythmic_head (Grob_info i)
118 if (i.grob ()->internal_has_interface (ly_symbol2scm ("lyric-syllable-interface"))
119 || i.grob ()->internal_has_interface (ly_symbol2scm ("multi-measure-interface")))
123 only pay attention to durations that are not grace notes.
125 if (!now_.grace_part_)
127 Music *r = i.music_cause ();
128 if (r && r->is_mus_type ("rhythmic-event"))
130 Moment len = r->get_length ();
131 Rhythmic_tuple t (i, now_mom () + len);
132 now_durations_.push (t);
138 Spacing_engraver::stop_translation_timestep ()
140 Paper_column *musical_column
141 = dynamic_cast<Paper_column *> (unsmob_grob (get_property ("currentMusicalColumn")));
143 SCM proportional = get_property ("proportionalNotationDuration");
144 if (unsmob_moment (proportional))
146 musical_column->set_property ("shortest-playing-duration", proportional);
147 musical_column->set_property ("shortest-starter-duration", proportional);
151 Moment shortest_playing;
152 shortest_playing.set_infinite (1);
153 for (int i = 0; i < playing_durations_.size (); i++)
155 Music *mus = playing_durations_[i].info_.music_cause ();
158 Moment m = mus->get_length ();
159 shortest_playing = min (shortest_playing, m);
163 starter.set_infinite (1);
165 for (int i = 0; i < now_durations_.size (); i++)
167 Moment m = now_durations_[i].info_.music_cause ()->get_length ();
170 starter = min (starter, m);
171 playing_durations_.insert (now_durations_[i]);
174 now_durations_.clear ();
176 shortest_playing = min (shortest_playing, starter);
178 assert (starter.to_bool ());
179 SCM sh = shortest_playing.smobbed_copy ();
180 SCM st = starter.smobbed_copy ();
182 musical_column->set_property ("shortest-playing-duration", sh);
183 musical_column->set_property ("shortest-starter-duration", st);
187 Spacing_engraver::start_translation_timestep ()
190 stopped_durations_.clear ();
191 while (playing_durations_.size () && playing_durations_.front ().end_ < now_)
192 playing_durations_.delmin ();
193 while (playing_durations_.size () && playing_durations_.front ().end_ == now_)
194 stopped_durations_.push (playing_durations_.get ());
197 ADD_ACKNOWLEDGER (Spacing_engraver, staff_spacing);
198 ADD_ACKNOWLEDGER (Spacing_engraver, note_spacing);
199 ADD_ACKNOWLEDGER (Spacing_engraver, rhythmic_head);
201 ADD_TRANSLATOR (Spacing_engraver,
202 "make a SpacingSpanner and do "
203 "bookkeeping of shortest starting and playing notes ",
205 /* create */ "SpacingSpanner",
208 "currentMusicalColumn "
209 "currentCommandColumn "
210 "proportionalNotationDuration",