]> git.donarmstrong.com Git - lilypond.git/blob - src/staff.cc
cbe0e59bbb77130da3d916c76c82ce6776488d78
[lilypond.git] / src / staff.cc
1 #include "staff.hh"
2 #include "score.hh"
3 #include "voice.hh"
4 #include "swalker.hh"
5 #include "stcol.hh"
6 #include "sccol.hh"
7 #include "staffcommands.hh"
8 #include "debug.hh"
9
10 void
11 Staff::add(PointerList<Voice*> &l)
12 {
13     for (PCursor<Voice*> i(l); i.ok(); i++)
14         voices.bottom().add(i);
15 }
16
17 void
18 Staff::process_commands(Real l)
19 {
20     if (staff_commands_)
21         staff_commands_->clean(l);
22 }
23
24 Paperdef*
25 Staff::paper() const
26 {
27     return score_->paper_;
28 }
29
30 void
31 Staff::clean_cols()
32 {
33     PCursor<Staff_column *> i(cols);
34     for(; i.ok(); ){
35         if (!i->score_column->used())
36             i.del();
37         else
38             i++;
39     }
40 }
41
42 Staff_column *
43 Staff::get_col(Real w, bool mus)
44 {
45     Score_column* sc = score_->find_col(w,mus);
46     assert(sc->when == w);
47     
48     PCursor<Staff_column *> i(cols);
49     for (; i.ok(); i++) {
50         if (*i->score_column > *sc) // too far
51             break;
52         if (sc == i->score_column)
53             return i;
54     }
55
56     /* post: *sc > *->score_column || !i.ok() */
57     Staff_column* newst = create_col(sc);
58
59     if (!i.ok()) {
60         cols.bottom().add(newst);
61         return cols.bottom();
62     }
63     
64     if (mus) {
65         i.insert(newst);
66         return newst;
67     }
68
69 //  ;  assert((i-1).ok())
70     // todo!
71     
72     // making a fix at 2:30 am, with several beers drunk.
73     // but it works :-)
74     if ((i-1).ok()&& (i-1)->when() == newst->when()) {
75         i--;
76     }
77
78     i.insert(newst);
79     
80     return newst;
81 }
82
83
84
85 /*
86     put all stuff grouped vertically in the Staff_cols
87     */
88 void
89 Staff::setup_staffcols()
90 {    
91     for (PCursor<Voice*> i(voices); i.ok(); i++) {
92         Real now = i->start;
93         for (PCursor<Voice_element *> ve(i->elts); ve.ok(); ve++) {
94
95             Staff_column *sc=get_col(now,true);
96             sc->add(ve);
97             now += ve->duration;            
98         }       
99     }
100
101     for (PCursor<Command*> cc(*staff_commands_); cc.ok(); cc++) {
102         Staff_column *sc=get_col(cc->when,false);
103         sc->s_commands.add(cc);
104     }
105 }
106
107 void
108 Staff::process()
109 {
110     setup_staffcols();
111     OK();
112     walk();
113 }
114
115 void
116 Staff::OK() const
117 {
118 #ifndef NDEBUG
119     cols.OK();
120     voices.OK();
121     assert(score_);    
122 #endif    
123 }
124
125
126 Real
127 Staff::last() const
128 {
129     Real l = 0.0;
130     for (PCursor<Voice*> i(voices); i.ok(); i++) {
131         l = MAX(l, i->last());
132     }
133     return l;
134 }
135
136
137 void
138 Staff::print() const
139 {
140 #ifndef NPRINT
141     mtor << "Staff {\n";
142     for (PCursor<Voice*> i(voices); i.ok(); i++) {
143         i->print();     
144     }
145     if (staff_commands_)
146         staff_commands_->print();
147     mtor <<"}\n";
148 #endif
149 }
150
151 Staff::Staff()
152 {
153     staff_commands_ = 0;
154     score_ =0;
155     pscore_=0;    
156 }