]> git.donarmstrong.com Git - lilypond.git/blob - lily/pulk-voices.cc
release: 0.0.63
[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
35
36     if (last_ != min_staff_last_mom)
37         warning("Not all staffs end simultaneously");
38 }
39
40 void
41 Pulk_voices::get_aligned_request(Request_column* col_l)
42 {
43     while (voice_pq_.size() && voice_pq_.front().l_->start_ == next_mom_) {
44         Voice_l v = voice_pq_.get();
45         pulk_p_list_.bottom().add( new Pulk_voice ( v.l_, v.staff_idx_ ));
46     }
47
48     /* hairy. #i# is a cursor which points to Pulk_voice (which a
49        cursor, essentially) */
50     
51     Moment new_next_mom = last_;
52     iter(pulk_p_list_.top() , i);
53     while  ( i.ok() ) {
54         mtor << "considering staff"<< i->staff_idx_ << "at " << i->when() << "\n";
55         assert (i->when() >= next_mom_);
56         if (i->when() == next_mom_) {
57             col_l->add_reqs(i->staff_idx_, i->get_req_l_arr() );
58
59             if (!i->ok()) {
60                 i.del();
61                 continue;
62             }
63         }
64         new_next_mom = new_next_mom <? i->when();
65         i++; 
66     }
67     
68     if (voice_pq_.size() )
69         new_next_mom = new_next_mom <? voice_pq_.front().l_->start_;
70     next_mom_ = new_next_mom;
71 }
72
73
74 bool
75 Pulk_voices::ok() const
76 {
77     return pulk_p_list_.size() || voice_pq_.size();
78 }
79
80 int compare(Voice_l const& v1, Voice_l const& v2)
81 {
82     return sign(v1.l_->start_ - v2.l_->start_);
83 }
84