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)
26 return (h1.end_ - h2.end_ ).sign ();
29 Spacing_engraver::Spacing_engraver()
35 Spacing_engraver::do_creation_processing ()
37 spacing_p_ =new Spacing_spanner (SCM_EOL);
38 spacing_p_->set_bound (LEFT, unsmob_element (get_property ("currentCommandColumn")));
39 announce_element (Score_element_info (spacing_p_, 0));
43 Spacing_engraver::do_removal_processing ()
45 Score_element * p = unsmob_element (get_property ("currentCommandColumn"));
46 spacing_p_->set_bound (RIGHT, p);
47 typeset_element (spacing_p_);
52 Spacing_engraver::acknowledge_element (Score_element_info i)
54 if (to_boolean (i.elem_l_->get_elt_property ("grace")))
57 if (to_boolean (i.elem_l_->get_elt_property ("non-rhythmic")))
60 if (Rhythmic_req * r = dynamic_cast<Rhythmic_req*>(i.req_l_))
62 Rhythmic_tuple t(i, now_mom () + r->length_mom ());
63 now_durations_.push (t);
68 Spacing_engraver::do_pre_move_processing ()
70 Moment shortest_playing;
71 shortest_playing.set_infinite (1);
72 for (int i=0; i < playing_durations_.size (); i++)
74 Moment m = (playing_durations_[i].info_.req_l_)->length_mom ();
77 shortest_playing = shortest_playing <? m;
84 for (int i=0; i < now_durations_.size (); i++)
86 Moment m = now_durations_[i].info_.req_l_->length_mom ();
88 starter = starter <? m;
90 playing_durations_.insert (now_durations_[i]);
92 now_durations_.clear ();
94 shortest_playing = shortest_playing <? starter;
97 = dynamic_cast<Paper_column*> (unsmob_element (get_property ("currentMusicalColumn")));
99 SCM sh = smobify (new Moment (shortest_playing));
100 SCM st = smobify (new Moment (starter));
102 sc->set_elt_property ("shortest-playing-duration", sh);
103 sc->set_elt_property ("shortest-starter-duration", st);
107 Spacing_engraver::do_post_move_processing ()
109 Moment now = now_mom ();
110 stopped_durations_.clear ();
111 while (playing_durations_.size () && playing_durations_.front ().end_ < now)
112 playing_durations_.delmin ();
113 while (playing_durations_.size () && playing_durations_.front ().end_ == now)
114 stopped_durations_.push (playing_durations_.get ());
117 ADD_THIS_TRANSLATOR(Spacing_engraver);