]> git.donarmstrong.com Git - lilypond.git/blob - src/staff.cc
release: 0.0.34
[lilypond.git] / src / staff.cc
1 #include "staff.hh"
2 #include "score.hh"
3 #include "voice.hh"
4 #include "staffwalker.hh"
5 #include "stcol.hh"
6 #include "sccol.hh"
7
8 #include "debug.hh"
9 #include "musicalrequest.hh"
10 #include "commandrequest.hh" // todo
11 #include "midistream.hh"
12
13 void
14 Staff::add(PointerList<Voice*> const &l)
15 {
16     for (iter_top(l,i); i.ok(); i++)
17         voice_list_.bottom().add(i);
18 }
19
20 Paperdef *
21 Staff::paper() const
22 {
23     return score_l_->paper_p_;
24 }
25
26 void
27 Staff::clean_cols()
28 {
29     iter_top(cols_,i);
30     for(; i.ok(); ){
31         if (!i->musical_column_l_->used_b())
32             i->musical_column_l_ = 0;
33         if (!i->command_column_l_->used_b())
34             i->command_column_l_ =0;
35         
36         if (!i->command_column_l_&& !i->musical_column_l_)
37             delete i.get();
38         else
39             i++;
40     }
41 }
42
43 Staff_column *
44 Staff::get_col(Moment w, PCursor<Staff_column*> *last)
45 {    
46     iter_top(cols_,i);
47     if (last && last->ok() && (*last)->when() <= w)
48         i = *last;
49     
50     for (; i.ok(); i++) {
51         if (i->when() == w) {
52             if (last)
53                 *last = i;
54             return i;
55         } else if (i->when() > w)
56             break;
57     }
58
59
60     PCursor<Score_column*> sccols(score_l_->find_col(w, false));
61     Staff_column* stcol_p = new Staff_column;
62     stcol_p->staff_l_ = this;
63     Score_column* comcol_l  = sccols++;
64     stcol_p->set_cols(comcol_l, sccols);
65     
66     if (!i.ok()) {
67         cols_.bottom().add(    stcol_p);
68         i = cols_.bottom();
69     } else {
70         i.insert(stcol_p);
71         i--;
72     }
73     if (last)
74         *last = i;
75     return i;
76 }
77
78 /**
79   put all stuff grouped vertically in the Staff_cols.
80   Do the preprarations for walking the cols. not virtual
81     */
82 void
83 Staff::setup_staffcols()
84 {    
85     for (iter_top(voice_list_,i); i.ok(); i++) {
86         PCursor<Staff_column*> last(cols_);
87         Moment now = i->start;
88         for (iter_top(i->elts,j); j.ok(); j++) {
89             
90             Staff_column *s_l= get_col(now, &last);
91             assert(now == s_l->when());
92             s_l->add(j);
93             now += j->duration;     
94         }
95
96     }
97     OK();
98 }
99
100 void
101 Staff::OK() const
102 {
103 #ifndef NDEBUG
104     cols_.OK();
105     voice_list_.OK();
106     iter_top(cols_, i);
107     iter_top(cols_, j);
108     i++;
109     for (; i.ok(); j++,i++) {
110         assert(j->when () < i->when() );
111     }
112     assert(score_l_);
113 #endif    
114 }
115
116
117 Moment
118 Staff::last() const
119 {
120     Moment l = 0.0;
121     for (iter_top(voice_list_,i); i.ok(); i++) {
122         l = l >? i->last();
123     }
124     return l;
125 }
126
127 void
128 Staff::print() const
129 {
130 #ifndef NPRINT
131     mtor << "Staff {\n";
132     for (iter_top(voice_list_,i); i.ok(); i++) {
133         i->print();     
134     }
135     mtor <<"}\n";
136 #endif
137 }
138
139 Staff::Staff()
140 {    
141     score_l_ =0;
142     pscore_l_ =0;
143     pstaff_l_ =0;
144 }