]> git.donarmstrong.com Git - lilypond.git/blob - lily/spacing-engraver.cc
release: 1.3.66
[lilypond.git] / lily / spacing-engraver.cc
1 /*   
2   spacing-engraver.cc --  implement Spacing_engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "musical-request.hh"
11 #include "paper-column.hh"
12 #include "spacing-engraver.hh"
13 #include "spacing-spanner.hh"
14
15 inline int
16 compare (Rhythmic_tuple const &a, Rhythmic_tuple const &b)
17 {
18   return Rhythmic_tuple::time_compare (a,b);
19 }
20
21 int
22 Rhythmic_tuple::time_compare (Rhythmic_tuple const &h1,
23                               Rhythmic_tuple const &h2)
24 {
25   return (h1.end_ - h2.end_ ).sign ();
26 }
27
28 Spacing_engraver::Spacing_engraver()
29 {
30   spacing_p_ = 0;
31 }
32
33 void
34 Spacing_engraver::do_creation_processing ()
35 {
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));
39 }
40
41 void
42 Spacing_engraver::do_removal_processing ()
43 {
44   Score_element * p = unsmob_element (get_property ("currentCommandColumn"));
45   spacing_p_->set_bound (RIGHT, p);
46   typeset_element (spacing_p_);
47   spacing_p_ =0;
48 }
49
50 void
51 Spacing_engraver::acknowledge_element (Score_element_info i)
52 {
53   if (to_boolean (i.elem_l_->get_elt_property ("grace")))
54     return;
55
56   if (to_boolean (i.elem_l_->get_elt_property ("non-rhythmic")))
57     return;
58   
59   if (Rhythmic_req * r = dynamic_cast<Rhythmic_req*>(i.req_l_))
60     {
61       Rhythmic_tuple t(i, now_mom () + r->length_mom ());
62       now_durations_.push (t);
63     }
64 }
65
66 void
67 Spacing_engraver::do_pre_move_processing ()
68 {
69   Moment shortest_playing;
70   shortest_playing.set_infinite (1);
71   for (int i=0; i < playing_durations_.size (); i++)
72     {
73       Moment m = (playing_durations_[i].info_.req_l_)->length_mom ();
74       if (m)
75         {
76           shortest_playing = shortest_playing <? m;
77         }
78     }
79   
80   Moment starter, inf;
81   inf.set_infinite (1);
82   starter=inf;
83   for (int i=0; i < now_durations_.size (); i++)
84     {
85       Moment m = now_durations_[i].info_.req_l_->length_mom ();
86       if (m)
87         starter = starter <? m;
88
89       playing_durations_.insert (now_durations_[i]);
90     }
91   now_durations_.clear ();
92   
93   shortest_playing = shortest_playing <? starter;
94   
95   Paper_column * sc
96     = dynamic_cast<Paper_column*> (unsmob_element (get_property ("currentMusicalColumn")));
97
98   SCM sh = smobify (new Moment (shortest_playing));
99   SCM st = smobify (new Moment (starter));
100
101   sc->set_elt_property ("shortest-playing-duration", sh);  
102   sc->set_elt_property ("shortest-starter-duration", st);
103 }
104
105 void
106 Spacing_engraver::do_post_move_processing ()
107 {
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 ());
114 }
115
116 ADD_THIS_TRANSLATOR(Spacing_engraver);
117
118