lilypond-0.0.4
[lilypond.git] / staff.cc
blob12bf074d04bb837e762212dcc3b93cdd549ec572
1 #include "staff.hh"
2 #include "debug.hh"
3 #include "pscore.hh"
5 void
6 Staff::clean_cols()
8 PCursor<Staff_column *> stc(cols);
9 for(; stc.ok(); ){
10 if (!stc->score_column->used())
11 stc.del();
12 else
13 stc++;
18 maak een staff column, met specs in args.
20 (sorry wat is het vroeg vandaag..)
22 Staff_column *
23 Staff::get_col(Mtime w, bool mus)
25 Score_column* sc = score_->find_col(w,mus);
26 assert(sc->when == w);
27 PCursor<Staff_column *> stc(cols);
28 for (; stc.ok(); stc++) {
29 if (*sc < *stc->score_column)
30 break;
31 if (sc == stc->score_column)
32 return stc;
34 Staff_column* newst = create_col(sc);
36 if (!stc.ok()) {
37 cols.bottom().add(newst);
38 return cols.bottom();
41 if (mus) {
42 stc.insert(newst);
43 return newst;
46 if ((stc-1)->when() == newst->when()) {
47 stc--;
50 stc.insert(newst);
52 return newst;
56 void
57 Staff::add_voice(Voice *v)
59 voices.bottom().add(v);
63 put all stuff grouped vertically in the Staff_cols
65 void
66 Staff::setup_staffcols()
69 for (PCursor<Voice*> vc(voices); vc.ok(); vc++) {
71 Mtime now = vc->start;
72 for (PCursor<Voice_element *> ve(vc->elts); ve.ok(); ve++) {
74 Staff_column *sc=get_col(now,true);
75 sc->add(ve);
76 now += ve->duration;
80 for (PCursor<Command*> cc(commands); cc.ok(); cc++) {
81 Staff_column *sc=get_col(cc->when,false);
82 sc->s_commands.add(cc);
86 /// merge commands from score
87 void
88 Staff::add_commands(PointerList<Command*> const &cl)
90 PCursor<Command*> score_c(cl);
91 PCursor<Command*> cc(commands);
93 while (score_c.ok()) {
94 while (cc.ok() && cc->when <= score_c->when)
95 cc++;
97 Command*nc = new Command (*(* score_c));
98 if (cc.ok()) {
99 // cc->when > score_c->when
100 cc.insert( nc );
101 } else {
102 commands.bottom().add( nc);
103 cc = commands.bottom();
105 score_c++;
108 // now integrate break commands with other commands.
109 // may be do this in derived functions.
112 void
113 Staff::process()
115 setup_staffcols();
116 OK();
117 for (PCursor<Staff_column*> sc(cols); sc.ok(); sc++) {
118 sc->process_commands();
119 sc->process_requests();
121 grant_requests();
124 void
125 Staff::OK() const
127 #ifndef NDEBUG
128 cols.OK();
129 commands.OK();
130 voices.OK();
131 assert(score_);
132 #endif
136 Mtime
137 Staff::last() const {
138 Mtime l = 0.0;
139 for (PCursor<Voice*> vc(voices); vc.ok(); vc++) {
140 l = MAX(l, vc->last());
142 return l;
146 void
147 Staff::print() const
149 mtor << "Staff {\n";
150 for (PCursor<Voice*> vc(voices); vc.ok(); vc++) {
151 vc->print();
154 mtor <<"}\n";
157 /****************************************************************/
159 bool
160 Staff_column::mus() const
162 return score_column->musical;
165 Mtime
166 Staff_column::when() const
168 return score_column->when;
171 void
172 Staff_column::add(Voice_element*ve)
174 Mtime d= ve->duration;
175 if (d){
176 score_column->durations.add(d);
179 v_elts.add(ve);
182 Staff_column::Staff_column(Score_column*s) {
183 score_column = s;