]> git.donarmstrong.com Git - lilypond.git/blob - lily/pulk-voices.cc
release: 0.0.64
[lilypond.git] / lily / pulk-voices.cc
1 /*
2   pulk-voices.cc -- implement Pulk_voices
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "pulk-voice.hh"
10 #include "pulk-voices.hh"
11 #include "staff.hh"
12 #include "voice.hh"
13 #include "request-column.hh"
14 #include "debug.hh"
15
16 Pulk_voices::Pulk_voices(Link_list<Staff*> const& l)
17     : staff_l_list_(l)
18 {
19     int staff_i = 0;
20     last_= 0;
21     Moment min_staff_last_mom=1e8; // ugh
22     for (iter_top(l, i); i.ok(); i++,   staff_i++) {
23         Moment staff_last=0;
24         for (iter_top(i->voice_list_,j); j.ok(); j++) {
25             if (j->elts_.size()) {
26                 staff_last = staff_last >? j->last();
27                 voice_pq_.insert(Voice_l(j, staff_i));
28             }
29         }
30         min_staff_last_mom = min_staff_last_mom <? staff_last;
31         last_ = last_ >? staff_last;
32     }
33     next_mom_ = voice_pq_.front().l_->start_;
34     time_arr_.set_size(staff_i);
35
36     if (last_ != min_staff_last_mom)
37         warning("Not all staffs end simultaneously");
38
39 }
40
41 void
42 Pulk_voices::get_aligned_request(Request_column* col_l)
43 {
44     while (voice_pq_.size() && voice_pq_.front().l_->start_ == next_mom_) {
45         Voice_l v = voice_pq_.get();
46         pulk_p_list_.bottom().add( new Pulk_voice ( v.l_, v.staff_idx_ ));
47     }
48
49     /* hairy. #i# is a cursor which points to Pulk_voice (which a
50        cursor, essentially) 
51        
52        
53        At the same time bookkeeping of measures is done.
54        */
55     
56     Moment new_next_mom = last_;
57     iter(pulk_p_list_.top() , i);
58     while  ( i.ok() ) {
59         mtor << "considering staff"<< i->staff_idx_ << "at " << i->when() << "\n";
60         assert (i->when() >= next_mom_);
61         if (i->when() == next_mom_) {
62             col_l->add_reqs(i->staff_idx_, i->get_req_l_arr() );
63             Time_description &t_r  = time_arr_[i->staff_idx_]; 
64             col_l->update_time(i->staff_idx_, t_r);
65             
66             if (! t_r.cadenza_b_ && t_r.next_bar_moment() > next_mom_) {
67                 mtor << "next bar at: " << t_r.next_bar_moment();
68                 new_next_mom = new_next_mom <? t_r.next_bar_moment();
69             }
70
71             if (!i->ok()) {
72                 i.del();
73                 continue;
74             }
75         }
76         assert( i->when()  > next_mom_);
77         /* no need to call i->next(), since this is done automatically */
78         new_next_mom = new_next_mom <? i->when();
79
80         i++;
81
82     }
83     
84     if (voice_pq_.size() )
85         new_next_mom = new_next_mom <? voice_pq_.front().l_->start_;
86
87     for (int j=0; j < time_arr_.size(); j++)
88         time_arr_[j].add( new_next_mom - next_mom_  );
89
90     if (pulk_p_list_.size())
91         assert( new_next_mom > next_mom_);
92     next_mom_ = new_next_mom;
93 }
94
95
96 bool
97 Pulk_voices::ok() const
98 {
99     return pulk_p_list_.size() || voice_pq_.size();
100 }
101
102 int
103 compare(Voice_l const& v1, Voice_l const& v2)
104 {
105     return sign(v1.l_->start_ - v2.l_->start_);
106 }
107             
108 Moment
109 Pulk_voices::next_mom()const
110 {
111     return next_mom_;
112 }
113
114 bool
115 Pulk_voices::time_checks_failed_b()const
116 {
117     bool b = false;
118     for (int i=0; !b && i < time_arr_.size(); i++)
119         b|=time_arr_[i].error_b_;
120     return b;
121 }