lilypond-0.0.40
[lilypond.git] / lily / staff.cc
bloba3ad17d07665d803d1ef76bb1fe647045f512693
1 #include "proto.hh"
2 #include "plist.hh"
3 #include "staff.hh"
4 #include "score.hh"
5 #include "voice.hh"
6 #include "staff-walker.hh"
7 #include "staff-column.hh"
8 #include "score-column.hh"
9 #include "voice-element.hh"
10 #include "debug.hh"
11 #include "musicalrequest.hh"
12 #include "commandrequest.hh" // todo
13 #include "midi-stream.hh"
15 void
16 Staff::add(PointerList<Voice*> const &l)
18 for (iter_top(l,i); i.ok(); i++)
19 voice_list_.bottom().add(i);
22 Paper_def *
23 Staff::paper() const
25 return score_l_->paper_p_;
28 void
29 Staff::clean_cols()
31 iter_top(cols_,i);
32 for(; i.ok(); ){
33 if (!i->musical_column_l_->used_b())
34 i->musical_column_l_ = 0;
35 if (!i->command_column_l_->used_b())
36 i->command_column_l_ =0;
38 if (!i->command_column_l_&& !i->musical_column_l_)
39 delete i.remove_p();
40 else
41 i++;
45 Staff_column *
46 Staff::get_col(Moment w, PCursor<Staff_column*> *last)
48 iter_top(cols_,i);
49 if (last && last->ok() && (*last)->when() <= w)
50 i = *last;
52 for (; i.ok(); i++) {
53 if (i->when() == w) {
54 if (last)
55 *last = i;
56 return i;
57 } else if (i->when() > w)
58 break;
62 PCursor<Score_column*> scorecolumns(score_l_->find_col(w, false));
63 Staff_column* staffcolumn_p = new Staff_column;
64 staffcolumn_p->staff_l_ = this;
65 Score_column* comcol_l = scorecolumns++;
66 staffcolumn_p->set_cols(comcol_l, scorecolumns);
68 if (!i.ok()) {
69 cols_.bottom().add( staffcolumn_p);
70 i = cols_.bottom();
71 } else {
72 i.insert(staffcolumn_p);
73 i--;
75 if (last)
76 *last = i;
77 return i;
80 /**
81 put all stuff grouped vertically in the Staff_cols.
82 Do the preprarations for walking the cols. not virtual
84 void
85 Staff::setup_staffcols()
87 for (iter_top(voice_list_,i); i.ok(); i++) {
88 PCursor<Staff_column*> last(cols_);
89 Moment now = i->start;
90 for (iter_top(i->elts,j); j.ok(); j++) {
92 Staff_column *s_l= get_col(now, &last);
93 assert(now == s_l->when());
94 s_l->add(j);
95 now += j->duration;
99 OK();
102 void
103 Staff::OK() const
105 #ifndef NDEBUG
106 cols_.OK();
107 voice_list_.OK();
108 iter_top(cols_, i);
109 iter_top(cols_, j);
110 i++;
111 for (; i.ok(); j++,i++) {
112 assert(j->when () < i->when() );
114 assert(score_l_);
115 #endif
119 Moment
120 Staff::last() const
122 Moment l = 0;
123 for (iter_top(voice_list_,i); i.ok(); i++) {
124 l = l >? i->last();
126 return l;
129 void
130 Staff::print() const
132 #ifndef NPRINT
133 mtor << "Staff {\n";
134 for (iter_top(voice_list_,i); i.ok(); i++) {
135 i->print();
137 mtor <<"}\n";
138 #endif
141 Staff::Staff()
143 score_l_ =0;
144 pscore_l_ =0;
145 pstaff_l_ =0;