lilypond-0.0.2
[lilypond.git] / staff.cc
blob61699dccb20d6506a6c337d79ddcc37c1cf1ca1c
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(); stc++){
10 if (!stc->score_column->used())
11 stc.remove();
16 maak een staff column, met specs in args.
18 (sorry wat is het vroeg vandaag..)
20 Staff_column *
21 Staff::get_col(Mtime w, bool mus)
23 Score_column* sc = score_->find_col(w,mus);
24 assert(sc->when == w);
25 PCursor<Staff_column *> stc(cols);
26 for (; stc.ok(); stc++) {
27 if (*sc < *stc->score_column)
28 break;
29 if (sc == stc->score_column)
30 return stc;
32 Staff_column* newst = create_col(sc);
34 if (!stc.ok()) {
35 cols.bottom().add(newst);
36 return cols.bottom();
39 if (mus) {
40 stc.insert(newst);
41 return newst;
44 if ((stc-1)->when() == newst->when()) {
45 stc--;
48 stc.insert(newst);
50 return newst;
54 void
55 Staff::add_voice(Voice *v)
57 voices.bottom().add(v);
61 put all stuff grouped vertically in the Staff_cols
63 void
64 Staff::setup_staffcols()
67 for (PCursor<Voice*> vc(voices); vc.ok(); vc++) {
69 Mtime now = vc->start;
70 for (PCursor<Voice_element *> ve(vc->elts); ve.ok(); ve++) {
72 Staff_column *sc=get_col(now,true);
73 sc->add(ve);
74 now += ve->duration;
78 for (PCursor<Command*> cc(commands); cc.ok(); cc++) {
79 Staff_column *sc=get_col(cc->when,false);
80 sc->s_commands.add(cc);
84 /// merge commands from score
85 void
86 Staff::add_commands(PointerList<Command*> const &cl)
88 PCursor<Command*> score_c(cl);
89 PCursor<Command*> cc(commands);
91 while (score_c.ok()) {
92 while (cc.ok() && cc->when <= score_c->when)
93 cc++;
95 Command*nc = new Command (*(* score_c));
96 if (cc.ok()) {
97 // cc->when > score_c->when
98 cc.insert( nc );
99 } else {
100 commands.bottom().add( nc);
101 cc = commands.bottom();
103 score_c++;
106 // now integrate break commands with other commands.
107 // may be do this in derived functions.
110 void
111 Staff::process()
113 setup_staffcols();
114 OK();
115 for (PCursor<Staff_column*> sc(cols); sc.ok(); sc++) {
116 sc->process_commands();
117 sc->process_requests();
119 grant_requests();
122 void
123 Staff::OK() const
125 cols.OK();
126 commands.OK();
127 voices.OK();
128 assert(score_);
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 mtor << "Staff {\n";
147 for (PCursor<Voice*> vc(voices); vc.ok(); vc++) {
148 vc->print();
151 mtor <<"}\n";
154 /****************************************************************/
156 bool
157 Staff_column::mus() const
159 return score_column->musical;
162 Mtime
163 Staff_column::when() const
165 return score_column->when;
167 void
168 Staff_column::add(Voice_element*ve)
170 Mtime d= ve->duration;
171 if (d){
172 score_column->durations.add(d);
175 v_elts.add(ve);
177 Staff_column::Staff_column(Score_column*s) {
178 score_column = s;