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"
17 #include "translator.icc"
27 Rhythmic_tuple (Grob_info i, Moment m)
32 static int time_compare (Rhythmic_tuple const &, Rhythmic_tuple const &);
37 TODO: allow starting & stopping of spacing regions.
40 Acknowledge rhythmic elements, for initializing spacing fields in
43 class Spacing_engraver : public Engraver
45 PQueue<Rhythmic_tuple> playing_durations_;
46 Array<Rhythmic_tuple> now_durations_;
47 Array<Rhythmic_tuple> stopped_durations_;
51 TRANSLATOR_DECLARATIONS (Spacing_engraver);
54 DECLARE_ACKNOWLEDGER (staff_spacing);
55 DECLARE_ACKNOWLEDGER (note_spacing);
56 DECLARE_ACKNOWLEDGER (rhythmic_head);
58 void start_translation_timestep ();
59 void stop_translation_timestep ();
60 void process_music ();
61 virtual void finalize ();
65 compare (Rhythmic_tuple const &a, Rhythmic_tuple const &b)
67 return Rhythmic_tuple::time_compare (a, b);
71 Rhythmic_tuple::time_compare (Rhythmic_tuple const &h1,
72 Rhythmic_tuple const &h2)
74 return (h1.end_ - h2.end_).main_part_.sign ();
77 Spacing_engraver::Spacing_engraver ()
83 Spacing_engraver::process_music ()
87 spacing_ = make_spanner ("SpacingSpanner", SCM_EOL);
88 spacing_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn")));
93 Spacing_engraver::finalize ()
97 Grob *p = unsmob_grob (get_property ("currentCommandColumn"));
99 spacing_->set_bound (RIGHT, p);
105 Spacing_engraver::acknowledge_note_spacing (Grob_info i)
107 Pointer_group_interface::add_grob (spacing_, ly_symbol2scm ("wishes"), i.grob ());
111 Spacing_engraver::acknowledge_staff_spacing (Grob_info i)
113 Pointer_group_interface::add_grob (spacing_, ly_symbol2scm ("wishes"), i.grob ());
117 Spacing_engraver::acknowledge_rhythmic_head (Grob_info i)
119 if (i.grob ()->internal_has_interface (ly_symbol2scm ("lyric-syllable-interface"))
120 || i.grob ()->internal_has_interface (ly_symbol2scm ("multi-measure-interface")))
124 only pay attention to durations that are not grace notes.
126 if (!now_.grace_part_)
128 Music *r = i.music_cause ();
129 if (r && r->is_mus_type ("rhythmic-event"))
131 Moment len = r->get_length ();
132 Rhythmic_tuple t (i, now_mom () + len);
133 now_durations_.push (t);
139 Spacing_engraver::stop_translation_timestep ()
141 Paper_column *musical_column
142 = dynamic_cast<Paper_column *> (unsmob_grob (get_property ("currentMusicalColumn")));
144 SCM proportional = get_property ("proportionalNotationDuration");
145 if (unsmob_moment (proportional))
147 musical_column->set_property ("shortest-playing-duration", proportional);
148 musical_column->set_property ("shortest-starter-duration", proportional);
152 Moment shortest_playing;
153 shortest_playing.set_infinite (1);
154 for (int i = 0; i < playing_durations_.size (); i++)
156 Music *mus = playing_durations_[i].info_.music_cause ();
159 Moment m = mus->get_length ();
160 shortest_playing = min (shortest_playing, m);
164 starter.set_infinite (1);
166 for (int i = 0; i < now_durations_.size (); i++)
168 Moment m = now_durations_[i].info_.music_cause ()->get_length ();
171 starter = min (starter, m);
172 playing_durations_.insert (now_durations_[i]);
175 now_durations_.clear ();
177 shortest_playing = min (shortest_playing, starter);
180 assert (starter.to_bool ());
181 SCM sh = shortest_playing.smobbed_copy ();
182 SCM st = starter.smobbed_copy ();
184 musical_column->set_property ("shortest-playing-duration", sh);
185 musical_column->set_property ("shortest-starter-duration", st);
189 Spacing_engraver::start_translation_timestep ()
192 stopped_durations_.clear ();
193 while (playing_durations_.size () && playing_durations_.front ().end_ < now_)
194 playing_durations_.delmin ();
195 while (playing_durations_.size () && playing_durations_.front ().end_ == now_)
196 stopped_durations_.push (playing_durations_.get ());
199 ADD_ACKNOWLEDGER (Spacing_engraver, staff_spacing);
200 ADD_ACKNOWLEDGER (Spacing_engraver, note_spacing);
201 ADD_ACKNOWLEDGER (Spacing_engraver, rhythmic_head);
203 ADD_TRANSLATOR (Spacing_engraver,
204 "make a SpacingSpanner and do "
205 "bookkeeping of shortest starting and playing notes ",
207 /* create */ "SpacingSpanner",
209 /* read */ "currentMusicalColumn currentCommandColumn proportionalNotationDuration",