lilypond-0.0.33
[lilypond.git] / src / staff.cc
blobc93ca997cc87b285de6fb4b11a366408abad7935
1 #include "staff.hh"
2 #include "score.hh"
3 #include "voice.hh"
4 #include "staffwalker.hh"
5 #include "stcol.hh"
6 #include "sccol.hh"
8 #include "debug.hh"
9 #include "musicalrequest.hh"
10 #include "commandrequest.hh" // todo
11 #include "midistream.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 Paperdef *
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())
32 i->musical_column_l_ = 0;
33 if (!i->command_column_l_->used())
34 i->command_column_l_ =0;
36 if (!i->command_column_l_&& !i->musical_column_l_)
37 delete i.get();
38 else
39 i++;
43 // Midi_track*
44 // Staff::midi_track_p()
45 // {
46 // Midi_track_p midi_track_p = new Midi_track;
47 // Midi_walker( *this );
48 // }
50 Staff_column *
51 Staff::get_col(Moment w, PCursor<Staff_column*> *last)
53 iter_top(cols,i);
54 if (last && last->ok() && (*last)->when() <= w)
55 i = *last;
57 for (; i.ok(); i++) {
58 if (i->when() == w) {
59 if (last)
60 *last = i;
61 return i;
62 } else if (i->when() > w)
63 break;
67 PCursor<Score_column*> sccols(score_l_->find_col(w, false));
68 Staff_column* stcol_p = create_col();
70 Score_column* comcol_l = sccols++;
71 stcol_p->set_cols(comcol_l, sccols);
73 if (!i.ok()) {
74 cols.bottom().add( stcol_p);
75 i = cols.bottom();
76 } else {
77 i.insert(stcol_p);
78 i--;
80 if (last)
81 *last = i;
82 return i;
85 /**
86 put all stuff grouped vertically in the Staff_cols.
87 Do the preprarations for walking the cols. not virtual
89 void
90 Staff::setup_staffcols()
92 for (iter_top(voice_list_,i); i.ok(); i++) {
93 PCursor<Staff_column*> last(cols);
94 Moment now = i->start;
95 for (iter_top(i->elts,j); j.ok(); j++) {
97 Staff_column *s_l= get_col(now, &last);
98 assert(now == s_l->when());
99 s_l->add(j);
100 now += j->duration;
102 // get_col(now,last);
104 OK();
107 void
108 Staff::OK() const
110 #ifndef NDEBUG
111 cols.OK();
112 voice_list_.OK();
113 iter_top(cols, i);
114 iter_top(cols, j);
115 i++;
116 for (; i.ok(); j++,i++) {
117 assert(j->when () < i->when() );
119 assert(score_l_);
120 #endif
124 Moment
125 Staff::last() const
127 Moment l = 0.0;
128 for (iter_top(voice_list_,i); i.ok(); i++) {
129 l = l >? i->last();
131 return l;
134 void
135 Staff::print() const
137 #ifndef NPRINT
138 mtor << "Staff {\n";
139 for (iter_top(voice_list_,i); i.ok(); i++) {
140 i->print();
142 mtor <<"}\n";
143 #endif
146 Staff::Staff()
148 score_l_ =0;
149 pscore_l_ =0;