]> git.donarmstrong.com Git - lilypond.git/blob - lily/spacing-engraver.cc
release: 1.3.65
[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   
26   return (h1.end_ - h2.end_ ).sign ();
27 }
28
29 Spacing_engraver::Spacing_engraver()
30 {
31   spacing_p_ = 0;
32 }
33
34 void
35 Spacing_engraver::do_creation_processing ()
36 {
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));
40 }
41
42 void
43 Spacing_engraver::do_removal_processing ()
44 {
45   Score_element * p = unsmob_element (get_property ("currentCommandColumn"));
46   spacing_p_->set_bound (RIGHT, p);
47   typeset_element (spacing_p_);
48   spacing_p_ =0;
49 }
50
51 void
52 Spacing_engraver::acknowledge_element (Score_element_info i)
53 {
54   if (to_boolean (i.elem_l_->get_elt_property ("grace")))
55     return;
56
57   if (to_boolean (i.elem_l_->get_elt_property ("non-rhythmic")))
58     return;
59   
60   if (Rhythmic_req * r = dynamic_cast<Rhythmic_req*>(i.req_l_))
61     {
62       Rhythmic_tuple t(i, now_mom () + r->length_mom ());
63       now_durations_.push (t);
64     }
65 }
66
67 void
68 Spacing_engraver::do_pre_move_processing ()
69 {
70   Moment shortest_playing;
71   shortest_playing.set_infinite (1);
72   for (int i=0; i < playing_durations_.size (); i++)
73     {
74       Moment m = (playing_durations_[i].info_.req_l_)->length_mom ();
75       if (m)
76         {
77           shortest_playing = shortest_playing <? m;
78         }
79     }
80   
81   Moment starter, inf;
82   inf.set_infinite (1);
83   starter=inf;
84   for (int i=0; i < now_durations_.size (); i++)
85     {
86       Moment m = now_durations_[i].info_.req_l_->length_mom ();
87       if (m)
88         starter = starter <? m;
89
90       playing_durations_.insert (now_durations_[i]);
91     }
92   now_durations_.clear ();
93   
94   shortest_playing = shortest_playing <? starter;
95   
96   Paper_column * sc
97     = dynamic_cast<Paper_column*> (unsmob_element (get_property ("currentMusicalColumn")));
98
99   SCM sh = smobify (new Moment (shortest_playing));
100   SCM st = smobify (new Moment (starter));
101
102   sc->set_elt_property ("shortest-playing-duration", sh);  
103   sc->set_elt_property ("shortest-starter-duration", st);
104 }
105
106 void
107 Spacing_engraver::do_post_move_processing ()
108 {
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 ());
115 }
116
117 ADD_THIS_TRANSLATOR(Spacing_engraver);
118
119