lilypond-1.1.40
[lilypond.git] / src / staff.cc
blob4f72617f5e2bd8badb53ee49793e27e6548d126f
1 #include "staff.hh"
2 #include "score.hh"
3 #include "voice.hh"
4 #include "staff-walker.hh"
5 #include "staff-column.hh"
6 #include "score-column.hh"
7 #include "voice-element.hh"
8 #include "debug.hh"
9 #include "musicalrequest.hh"
10 #include "commandrequest.hh" // todo
11 #include "midi-stream.hh"
13 void
14 Staff::add(PointerList<Voice*> const &l)
16 for (iter_top(l,i); i.ok(); i++)
17 voice_list_.bottom().add(i);
20 Paper_def *
21 Staff::paper() const
23 return score_l_->paper_p_;
26 void
27 Staff::clean_cols()
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;
36 if (!i->command_column_l_&& !i->musical_column_l_)
37 delete i.get_p();
38 else
39 i++;
43 Staff_column *
44 Staff::get_col(Moment w, PCursor<Staff_column*> *last)
46 iter_top(cols_,i);
47 if (last && last->ok() && (*last)->when() <= w)
48 i = *last;
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;
60 PCursor<Score_column*> scorecolumns(score_l_->find_col(w, false));
61 Staff_column* staffcolumn_p = new Staff_column;
62 staffcolumn_p->staff_l_ = this;
63 Score_column* comcol_l = scorecolumns++;
64 staffcolumn_p->set_cols(comcol_l, scorecolumns);
66 if (!i.ok()) {
67 cols_.bottom().add( staffcolumn_p);
68 i = cols_.bottom();
69 } else {
70 i.insert(staffcolumn_p);
71 i--;
73 if (last)
74 *last = i;
75 return i;
78 /**
79 put all stuff grouped vertically in the Staff_cols.
80 Do the preprarations for walking the cols. not virtual
82 void
83 Staff::setup_staffcols()
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++) {
90 Staff_column *s_l= get_col(now, &last);
91 assert(now == s_l->when());
92 s_l->add(j);
93 now += j->duration;
97 OK();
100 void
101 Staff::OK() const
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() );
112 assert(score_l_);
113 #endif
117 Moment
118 Staff::last() const
120 Moment l = 0;
121 for (iter_top(voice_list_,i); i.ok(); i++) {
122 l = l >? i->last();
124 return l;
127 void
128 Staff::print() const
130 #ifndef NPRINT
131 mtor << "Staff {\n";
132 for (iter_top(voice_list_,i); i.ok(); i++) {
133 i->print();
135 mtor <<"}\n";
136 #endif
139 Staff::Staff()
141 score_l_ =0;
142 pscore_l_ =0;
143 pstaff_l_ =0;