lilypond-1.3.80
[lilypond.git] / lily / pulk-voices.cc
blob6a480fab6a339e848ab62c987b46792ea6fcc07c
1 /*
2 pulk-voices.cc -- implement Pulk_voices
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
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"
16 Pulk_voices::Pulk_voices(Link_list<Staff*> const& l)
17 : staff_l_list_(l)
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));
30 min_staff_last_mom = min_staff_last_mom <? staff_last;
31 last_ = last_ >? staff_last;
33 next_mom_ = voice_pq_.front().l_->start_;
34 time_arr_.set_size(staff_i);
36 if (last_ != min_staff_last_mom)
37 warning("Not all staffs end simultaneously");
41 void
42 Pulk_voices::get_aligned_request(Request_column* col_l)
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_ ));
49 /* hairy. #i# is a cursor which points to Pulk_voice (which a
50 cursor, essentially)
53 At the same time bookkeeping of measures is done.
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);
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();
71 if (!i->ok()) {
72 i.del();
73 continue;
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();
80 i++;
84 if (voice_pq_.size() )
85 new_next_mom = new_next_mom <? voice_pq_.front().l_->start_;
87 for (int j=0; j < time_arr_.size(); j++)
88 time_arr_[j].add( new_next_mom - next_mom_ );
90 if (pulk_p_list_.size())
91 assert( new_next_mom > next_mom_);
92 next_mom_ = new_next_mom;
96 bool
97 Pulk_voices::ok() const
99 return pulk_p_list_.size() || voice_pq_.size();
103 compare(Voice_l const& v1, Voice_l const& v2)
105 return sign(v1.l_->start_ - v2.l_->start_);
108 Moment
109 Pulk_voices::next_mom()const
111 return next_mom_;
114 bool
115 Pulk_voices::time_checks_failed_b()const
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;