2 spacing-engraver.cc -- implement Spacing_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "musical-request.hh"
11 #include "paper-column.hh"
12 #include "spacing-engraver.hh"
13 #include "spacing-spanner.hh"
16 compare (Rhythmic_tuple const &a, Rhythmic_tuple const &b)
18 return Rhythmic_tuple::time_compare (a,b);
22 Rhythmic_tuple::time_compare (Rhythmic_tuple const &h1,
23 Rhythmic_tuple const &h2)
25 return (h1.end_ - h2.end_ ).sign ();
28 Spacing_engraver::Spacing_engraver()
34 Spacing_engraver::do_creation_processing ()
36 spacing_p_ =new Spacing_spanner (SCM_EOL);
37 spacing_p_->set_bound (LEFT, unsmob_element (get_property ("currentCommandColumn")));
38 announce_element (Score_element_info (spacing_p_, 0));
42 Spacing_engraver::do_removal_processing ()
44 Score_element * p = unsmob_element (get_property ("currentCommandColumn"));
45 spacing_p_->set_bound (RIGHT, p);
46 typeset_element (spacing_p_);
51 Spacing_engraver::acknowledge_element (Score_element_info i)
53 if (to_boolean (i.elem_l_->get_elt_property ("grace")))
56 if (to_boolean (i.elem_l_->get_elt_property ("non-rhythmic")))
59 if (Rhythmic_req * r = dynamic_cast<Rhythmic_req*>(i.req_l_))
61 Rhythmic_tuple t(i, now_mom () + r->length_mom ());
62 now_durations_.push (t);
67 Spacing_engraver::do_pre_move_processing ()
69 Moment shortest_playing;
70 shortest_playing.set_infinite (1);
71 for (int i=0; i < playing_durations_.size (); i++)
73 Moment m = (playing_durations_[i].info_.req_l_)->length_mom ();
76 shortest_playing = shortest_playing <? m;
83 for (int i=0; i < now_durations_.size (); i++)
85 Moment m = now_durations_[i].info_.req_l_->length_mom ();
87 starter = starter <? m;
89 playing_durations_.insert (now_durations_[i]);
91 now_durations_.clear ();
93 shortest_playing = shortest_playing <? starter;
96 = dynamic_cast<Paper_column*> (unsmob_element (get_property ("currentMusicalColumn")));
98 SCM sh = smobify (new Moment (shortest_playing));
99 SCM st = smobify (new Moment (starter));
101 sc->set_elt_property ("shortest-playing-duration", sh);
102 sc->set_elt_property ("shortest-starter-duration", st);
106 Spacing_engraver::do_post_move_processing ()
108 Moment now = now_mom ();
109 stopped_durations_.clear ();
110 while (playing_durations_.size () && playing_durations_.front ().end_ < now)
111 playing_durations_.delmin ();
112 while (playing_durations_.size () && playing_durations_.front ().end_ == now)
113 stopped_durations_.push (playing_durations_.get ());
116 ADD_THIS_TRANSLATOR(Spacing_engraver);