]> git.donarmstrong.com Git - lilypond.git/blob - src/staff.cc
c93ca997cc87b285de6fb4b11a366408abad7935
[lilypond.git] / src / staff.cc
1 #include "staff.hh"
2 #include "score.hh"
3 #include "voice.hh"
4 #include "staffwalker.hh"
5 #include "stcol.hh"
6 #include "sccol.hh"
7
8 #include "debug.hh"
9 #include "musicalrequest.hh"
10 #include "commandrequest.hh" // todo
11 #include "midistream.hh"
12
13 void
14 Staff::add(PointerList<Voice*> const &l)
15 {
16     for (iter_top(l,i); i.ok(); i++)
17         voice_list_.bottom().add(i);
18 }
19
20 Paperdef *
21 Staff::paper() const
22 {
23     return score_l_->paper_p_;
24 }
25
26 void
27 Staff::clean_cols()
28 {
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;
35         
36         if (!i->command_column_l_&& !i->musical_column_l_)
37             delete i.get();
38         else
39             i++;
40     }
41 }
42
43 // Midi_track*
44 // Staff::midi_track_p()
45 // {
46 //     Midi_track_p midi_track_p = new Midi_track;
47 //    Midi_walker( *this );
48 // }
49
50 Staff_column *
51 Staff::get_col(Moment w, PCursor<Staff_column*> *last)
52 {    
53     iter_top(cols,i);
54     if (last && last->ok() && (*last)->when() <= w)
55         i = *last;
56     
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;
64     }
65
66
67     PCursor<Score_column*> sccols(score_l_->find_col(w, false));
68     Staff_column* stcol_p = create_col();
69
70     Score_column* comcol_l  = sccols++;
71     stcol_p->set_cols(comcol_l, sccols);
72     
73     if (!i.ok()) {
74         cols.bottom().add(    stcol_p);
75         i = cols.bottom();
76     } else {
77         i.insert(stcol_p);
78         i--;
79     }
80     if (last)
81         *last = i;
82     return i;
83 }
84
85 /**
86   put all stuff grouped vertically in the Staff_cols.
87   Do the preprarations for walking the cols. not virtual
88     */
89 void
90 Staff::setup_staffcols()
91 {    
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++) {
96             
97             Staff_column *s_l= get_col(now, &last);
98             assert(now == s_l->when());
99             s_l->add(j);
100             now += j->duration;     
101         }
102 //      get_col(now,last);
103     }
104     OK();
105 }
106
107 void
108 Staff::OK() const
109 {
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() );
118     }
119     assert(score_l_);
120 #endif    
121 }
122
123
124 Moment
125 Staff::last() const
126 {
127     Moment l = 0.0;
128     for (iter_top(voice_list_,i); i.ok(); i++) {
129         l = l >? i->last();
130     }
131     return l;
132 }
133
134 void
135 Staff::print() const
136 {
137 #ifndef NPRINT
138     mtor << "Staff {\n";
139     for (iter_top(voice_list_,i); i.ok(); i++) {
140         i->print();     
141     }
142     mtor <<"}\n";
143 #endif
144 }
145
146 Staff::Staff()
147 {    
148     score_l_ =0;
149     pscore_l_ =0;    
150 }