lilypond-0.0.5
[lilypond.git] / staff.cc
blob0827c953f015cc38bec5910e35c2abf0ef22beca
1 #include "staff.hh"
2 #include "stcol.hh"
3 #include "sccol.hh"
4 #include "debug.hh"
7 void
8 Staff::clean_cols()
10 PCursor<Staff_column *> stc(cols);
11 for(; stc.ok(); ){
12 if (!stc->score_column->used())
13 stc.del();
14 else
15 stc++;
19 Staff_column *
20 Staff::get_col(Mtime w, bool mus)
22 Score_column* sc = score_->find_col(w,mus);
23 assert(sc->when == w);
24 PCursor<Staff_column *> stc(cols);
25 for (; stc.ok(); stc++) {
26 if (*sc < *stc->score_column)
27 break;
28 if (sc == stc->score_column)
29 return stc;
31 Staff_column* newst = create_col(sc);
33 if (!stc.ok()) {
34 cols.bottom().add(newst);
35 return cols.bottom();
38 if (mus) {
39 stc.insert(newst);
40 return newst;
43 if ((stc-1)->when() == newst->when()) {
44 stc--;
47 stc.insert(newst);
49 return newst;
53 void
54 Staff::add_voice(Voice *v)
56 voices.bottom().add(v);
60 put all stuff grouped vertically in the Staff_cols
62 void
63 Staff::setup_staffcols()
66 for (PCursor<Voice*> vc(voices); vc.ok(); vc++) {
68 Mtime now = vc->start;
69 for (PCursor<Voice_element *> ve(vc->elts); ve.ok(); ve++) {
71 Staff_column *sc=get_col(now,true);
72 sc->add(ve);
73 now += ve->duration;
77 for (PCursor<Command*> cc(commands); cc.ok(); cc++) {
78 Staff_column *sc=get_col(cc->when,false);
79 sc->s_commands.add(cc);
83 /// merge commands from score
84 void
85 Staff::add_commands(PointerList<Command*> const &cl)
87 PCursor<Command*> score_c(cl);
88 PCursor<Command*> cc(commands);
90 while (score_c.ok()) {
91 while (cc.ok() && cc->when <= score_c->when)
92 cc++;
94 Command*nc = new Command (*(* score_c));
95 if (cc.ok()) {
96 // cc->when > score_c->when
97 cc.insert( nc );
98 } else {
99 commands.bottom().add( nc);
100 cc = commands.bottom();
102 score_c++;
105 // now integrate break commands with other commands.
106 // maybe do this in derived functions.
109 void
110 Staff::process()
112 setup_staffcols();
113 OK();
114 for (PCursor<Staff_column*> sc(cols); sc.ok(); sc++) {
115 sc->process_commands();
116 sc->process_requests();
118 grant_requests();
121 void
122 Staff::OK() const
124 #ifndef NDEBUG
125 cols.OK();
126 commands.OK();
127 voices.OK();
128 assert(score_);
129 #endif
133 Mtime
134 Staff::last() const {
135 Mtime l = 0.0;
136 for (PCursor<Voice*> vc(voices); vc.ok(); vc++) {
137 l = MAX(l, vc->last());
139 return l;
143 void
144 Staff::print() const
146 #ifndef NPRINT
148 mtor << "Staff {\n";
149 for (PCursor<Voice*> vc(voices); vc.ok(); vc++) {
150 vc->print();
153 mtor <<"}\n";
154 #endif