lilypond-1.3.28
[lilypond.git] / lily / spacing-engraver.cc
blob7f3ac132fce5c00f41ab4c8cda00e155f739f34a
1 /*
2 spacing-engraver.cc -- implement Spacing_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "musical-request.hh"
11 #include "paper-column.hh"
12 #include "spacing-engraver.hh"
13 #include "spacing-spanner.hh"
15 inline int
16 compare (Rhythmic_tuple const &a, Rhythmic_tuple const &b)
18 return Rhythmic_tuple::time_compare (a,b);
21 int
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()
31 spacing_p_ = 0;
34 void
35 Spacing_engraver::do_creation_processing ()
37 spacing_p_ =new Spacing_spanner;
38 spacing_p_->set_bounds (LEFT, get_staff_info ().command_pcol_l ());
39 announce_element (Score_element_info (spacing_p_, 0));
42 void
43 Spacing_engraver::do_removal_processing ()
45 Paper_column * p = get_staff_info ().command_pcol_l ();
47 spacing_p_->set_bounds (RIGHT, p);
48 typeset_element (spacing_p_);
49 spacing_p_ =0;
52 void
53 Spacing_engraver::acknowledge_element (Score_element_info i)
55 if (to_boolean (i.elem_l_->get_elt_property ("grace")))
56 return;
58 if (to_boolean (i.elem_l_->get_elt_property ("non-rhythmic")))
59 return;
61 if (Rhythmic_req * r = dynamic_cast<Rhythmic_req*>(i.req_l_))
63 Rhythmic_tuple t(i, now_mom () + r->length_mom ());
64 now_durations_.push (t);
68 void
69 Spacing_engraver::do_pre_move_processing ()
71 Moment shortest_playing;
72 shortest_playing.set_infinite (1);
73 for (int i=0; i < playing_durations_.size (); i++)
75 Moment m = (playing_durations_[i].info_.req_l_)->length_mom ();
76 if (m)
78 shortest_playing = shortest_playing <? m;
82 Moment starter, inf;
83 inf.set_infinite (1);
84 starter=inf;
85 for (int i=0; i < now_durations_.size (); i++)
87 Moment m = now_durations_[i].info_.req_l_->length_mom ();
88 if (m)
89 starter = starter <? m;
91 playing_durations_.insert (now_durations_[i]);
93 now_durations_.clear ();
95 shortest_playing = shortest_playing <? starter;
97 Paper_column * sc
98 = dynamic_cast<Paper_column*> (get_staff_info ().musical_pcol_l ());
100 SCM sh = (new Moment (shortest_playing))->smobify_self ();
101 SCM st = (new Moment (starter))->smobify_self ();
103 scm_unprotect_object (st);
104 scm_unprotect_object (sh);
106 sc->set_elt_property ("shortest-playing-duration", sh);
107 sc->set_elt_property ("shortest-starter-duration", st);
110 void
111 Spacing_engraver::do_post_move_processing ()
113 Moment now = now_mom ();
114 stopped_durations_.clear ();
115 while (playing_durations_.size () && playing_durations_.front ().end_ < now)
116 playing_durations_.delmin ();
117 while (playing_durations_.size () && playing_durations_.front ().end_ == now)
118 stopped_durations_.push (playing_durations_.get ());
121 ADD_THIS_TRANSLATOR(Spacing_engraver);