]> git.donarmstrong.com Git - lilypond.git/blob - lily/spacing-engraver.cc
release: 1.1.58
[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 "score-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;
38   spacing_p_->set_bounds (LEFT, get_staff_info ().command_pcol_l ());  
39   announce_element (Score_element_info (spacing_p_, 0));
40 }
41
42 void
43 Spacing_engraver::do_removal_processing ()
44 {
45   Paper_column * p = get_staff_info ().command_pcol_l ();
46
47   spacing_p_->set_bounds (RIGHT, p);
48   typeset_element (spacing_p_);
49   spacing_p_ =0;
50 }
51
52 void
53 Spacing_engraver::acknowledge_element (Score_element_info i)
54 {
55   if (i.elem_l_->get_elt_property (grace_scm_sym) != SCM_BOOL_F)
56     return;
57
58   if (Rhythmic_req * r = dynamic_cast<Rhythmic_req*>(i.req_l_))
59     {
60       Rhythmic_tuple t(i, now_mom () + r->length_mom ());
61       now_durations_.push (t);
62     }
63 }
64
65 void
66 Spacing_engraver::do_pre_move_processing ()
67 {
68   Moment shortest_playing;
69   shortest_playing.set_infinite (1);
70   for (int i=0; i < playing_durations_.size (); i++)
71     {
72       Moment m = (playing_durations_[i].info_.req_l_)->length_mom ();
73       if (m)
74         shortest_playing = shortest_playing <? m;
75     }
76
77   Moment starter, inf;
78   inf.set_infinite (1);
79   starter=inf;
80   for (int i=0; i < now_durations_.size (); i++)
81     {
82       Moment m = now_durations_[i].info_.req_l_->length_mom ();
83       if (m)
84         starter = starter <? m;
85
86       playing_durations_.insert (now_durations_[i]);
87     }
88   now_durations_.clear ();
89   
90   shortest_playing = shortest_playing <? starter;
91   
92   Score_column * sc
93     = dynamic_cast<Score_column*> (get_staff_info ().musical_pcol_l ());
94
95   sc->shortest_playing_mom_ = shortest_playing;
96   sc->shortest_starter_mom_ = starter;
97 }
98
99 void
100 Spacing_engraver::do_post_move_processing ()
101 {
102   Moment now = now_mom ();
103   stopped_durations_.clear ();
104   while (playing_durations_.size () && playing_durations_.front ().end_ < now)
105     playing_durations_.delmin ();
106   while (playing_durations_.size () && playing_durations_.front ().end_ == now)
107     stopped_durations_.push (playing_durations_.get ());
108 }
109
110 ADD_THIS_TRANSLATOR(Spacing_engraver);
111