lilypond-0.1.37
[lilypond.git] / src / scorewalker.cc
blobc79031ab9a62219b7158d49fce5cc9a5567828e4
1 /*
2 scorewalker.cc -- implement Score_walker
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8 #include "debug.hh"
9 #include "plist.hh"
10 #include "scorewalker.hh"
11 #include "score.hh"
12 #include "staffwalker.hh"
13 #include "staff.hh"
14 #include "scorecolumn.hh"
16 Score_walker::Score_walker(Score *s)
17 :PCursor<Score_column *> (s->cols_)
19 score_l_ = s;
20 for (iter_top(s->staffs_,i); i.ok(); i++) {
21 Staff_walker* w_p=i->get_walker_p();
22 w_p->score_walk_l_ =this;
23 walker_p_arr_.push(w_p);
26 if(ok()) {
27 s->find_col(0, false)->set_breakable();
28 s->find_col(s->last(), false)->set_breakable();
30 reinit();
34 void
35 Score_walker::reinit()
37 disallow_break_walk_l_arr = walker_p_arr_;
38 disallow_break_count_ = disallow_break_walk_l_arr.size();
42 /** Advance the cursor, and all Staff_walkers contained in this. Reset
43 runtime fields */
44 void
45 Score_walker::operator ++(int )
47 Moment last = ptr()->when();
49 PCursor<Score_column *>::operator++(0);
50 if (ok() && ptr()->when() == last)
51 PCursor<Score_column *>::operator++(0);
52 reinit();
53 if (!ok())
54 return;
55 for (int i=0; i< walker_p_arr_.size(); i++) {
56 if (walker_p_arr_[i]->ok() &&
57 walker_p_arr_[i]->when() < when()) {
59 walker_p_arr_[i]->operator++(0);
64 /** Allow the command_column to be breakable for one staff. If all
65 staffs allow, then allow a break here. */
66 void
67 Score_walker::allow_break(Staff_walker*w)
69 for (int i=0; i < disallow_break_walk_l_arr.size(); i++) {
70 if (w == disallow_break_walk_l_arr[i]) {
71 disallow_break_count_ --;
72 disallow_break_walk_l_arr[i] =0;
74 if (!disallow_break_count_) {
75 PCursor<Score_column*> col_cursor = *this;
76 if (ptr()->musical_b())
77 col_cursor --;
78 col_cursor->set_breakable();
84 Moment
85 Score_walker::when()
87 return ptr()->when();
90 void
91 Score_walker::process()
93 for (int i=0; i < walker_p_arr_.size(); i++) {
94 Staff_walker *w = walker_p_arr_[i];
95 if ( w->ok() && w->when() == when() ) {
96 walker_p_arr_[i]->process();
99 if (when().denominator() == 1) {
100 *mlog << "." <<flush;
104 Score_walker::~Score_walker()
106 for (int i=0; i < walker_p_arr_.size(); i++)
107 delete walker_p_arr_[i];
108 assert( !score_l_->find_col(score_l_->last(), true)->used_b());