]> git.donarmstrong.com Git - lilypond.git/blob - lily/spacing-engraver.cc
patch::: 1.3.18.jcn1
[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 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 ADD_THIS_TRANSLATOR (Spacing_engraver);
16
17 inline int
18 compare (Rhythmic_tuple const &a, Rhythmic_tuple const &b)
19 {
20   return Rhythmic_tuple::time_compare (a,b);
21 }
22
23 int
24 Rhythmic_tuple::time_compare (Rhythmic_tuple const &h1,
25                               Rhythmic_tuple const &h2)
26 {
27   
28   return (h1.end_ - h2.end_ ).sign ();
29 }
30
31 Spacing_engraver::Spacing_engraver()
32 {
33   spacing_p_ = 0;
34 }
35
36 void
37 Spacing_engraver::do_creation_processing ()
38 {
39   spacing_p_  =new Spacing_spanner;
40   spacing_p_->set_bounds (LEFT, get_staff_info ().command_pcol_l ());  
41   announce_element (Score_element_info (spacing_p_, 0));
42 }
43
44 void
45 Spacing_engraver::do_removal_processing ()
46 {
47   Paper_column * p = get_staff_info ().command_pcol_l ();
48
49   spacing_p_->set_bounds (RIGHT, p);
50   typeset_element (spacing_p_);
51   spacing_p_ =0;
52 }
53
54 void
55 Spacing_engraver::acknowledge_element (Score_element_info i)
56 {
57   if (to_boolean (i.elem_l_->get_elt_property ("grace")))
58     return;
59
60   if (to_boolean (i.elem_l_->get_elt_property ("non-rhythmic")))
61     return;
62   
63   if (Rhythmic_req * r = dynamic_cast<Rhythmic_req*>(i.req_l_))
64     {
65       Rhythmic_tuple t(i, now_mom () + r->length_mom ());
66       now_durations_.push (t);
67     }
68 }
69
70 void
71 Spacing_engraver::do_pre_move_processing ()
72 {
73   Moment shortest_playing;
74   shortest_playing.set_infinite (1);
75   for (int i=0; i < playing_durations_.size (); i++)
76     {
77       Moment m = (playing_durations_[i].info_.req_l_)->length_mom ();
78       if (m)
79         shortest_playing = shortest_playing <? m;
80     }
81
82   Moment starter, inf;
83   inf.set_infinite (1);
84   starter=inf;
85   for (int i=0; i < now_durations_.size (); i++)
86     {
87       Moment m = now_durations_[i].info_.req_l_->length_mom ();
88       if (m)
89         starter = starter <? m;
90
91       playing_durations_.insert (now_durations_[i]);
92     }
93   now_durations_.clear ();
94   
95   shortest_playing = shortest_playing <? starter;
96   
97   Paper_column * sc
98     = dynamic_cast<Paper_column*> (get_staff_info ().musical_pcol_l ());
99
100   sc->set_elt_property ("shortest-playing",  (new Moment (shortest_playing))->smobify_self ());
101   
102   sc->set_elt_property ("shortest-starter", (new Moment (starter))->smobify_self ());
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