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"
13 #include "spacing-spanner.hh"
14 #include "engraver.hh"
19 Score_element_info info_;
25 Rhythmic_tuple (Score_element_info i, Moment m )
30 static int time_compare (Rhythmic_tuple const &, Rhythmic_tuple const &);
34 Acknowledge rhythmic elements, for initializing spacing fields in
37 should be the last one of the toplevel context
39 class Spacing_engraver : public Engraver
41 PQueue<Rhythmic_tuple> playing_durations_;
42 Array<Rhythmic_tuple> now_durations_;
43 Array<Rhythmic_tuple> stopped_durations_;
47 VIRTUAL_COPY_CONS(Translator);
48 virtual void acknowledge_element (Score_element_info);
49 virtual void do_post_move_processing ();
50 virtual void do_pre_move_processing ();
51 virtual void do_creation_processing ();
52 virtual void do_removal_processing ();
58 compare (Rhythmic_tuple const &a, Rhythmic_tuple const &b)
60 return Rhythmic_tuple::time_compare (a,b);
64 Rhythmic_tuple::time_compare (Rhythmic_tuple const &h1,
65 Rhythmic_tuple const &h2)
67 return (h1.end_ - h2.end_ ).sign ();
70 Spacing_engraver::Spacing_engraver()
76 Spacing_engraver::do_creation_processing ()
78 spacing_p_ =new Spanner (get_property ("SpacingSpanner"));
79 Spacing_spanner::set_interface (spacing_p_);
80 spacing_p_->set_bound (LEFT, unsmob_element (get_property ("currentCommandColumn")));
81 announce_element (spacing_p_, 0);
85 Spacing_engraver::do_removal_processing ()
87 Score_element * p = unsmob_element (get_property ("currentCommandColumn"));
88 spacing_p_->set_bound (RIGHT, p);
89 typeset_element (spacing_p_);
94 Spacing_engraver::acknowledge_element (Score_element_info i)
96 if (to_boolean (i.elem_l_->get_elt_property ("grace")))
99 if (to_boolean (i.elem_l_->get_elt_property ("non-rhythmic")))
102 if (Rhythmic_req * r = dynamic_cast<Rhythmic_req*>(i.req_l_))
104 Rhythmic_tuple t(i, now_mom () + r->length_mom ());
105 now_durations_.push (t);
110 Spacing_engraver::do_pre_move_processing ()
112 Moment shortest_playing;
113 shortest_playing.set_infinite (1);
114 for (int i=0; i < playing_durations_.size (); i++)
116 Moment m = (playing_durations_[i].info_.req_l_)->length_mom ();
119 shortest_playing = shortest_playing <? m;
124 inf.set_infinite (1);
126 for (int i=0; i < now_durations_.size (); i++)
128 Moment m = now_durations_[i].info_.req_l_->length_mom ();
130 starter = starter <? m;
132 playing_durations_.insert (now_durations_[i]);
134 now_durations_.clear ();
136 shortest_playing = shortest_playing <? starter;
139 = dynamic_cast<Paper_column*> (unsmob_element (get_property ("currentMusicalColumn")));
141 SCM sh = shortest_playing.smobbed_copy( );
142 SCM st = starter.smobbed_copy();
144 sc->set_elt_property ("shortest-playing-duration", sh);
145 sc->set_elt_property ("shortest-starter-duration", st);
149 Spacing_engraver::do_post_move_processing ()
151 Moment now = now_mom ();
152 stopped_durations_.clear ();
153 while (playing_durations_.size () && playing_durations_.front ().end_ < now)
154 playing_durations_.delmin ();
155 while (playing_durations_.size () && playing_durations_.front ().end_ == now)
156 stopped_durations_.push (playing_durations_.get ());
159 ADD_THIS_TRANSLATOR(Spacing_engraver);