lilypond-1.3.65
[lilypond.git] / lily / score-walker.cc
blob78041613f02908c924ae3804598bab46cb8389c9
1 /*
2 score-walker.cc -- implement Score_walker
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8 #include "proto.hh"
9 #include "plist.hh"
10 #include "debug.hh"
11 #include "score-walker.hh"
12 #include "score.hh"
13 #include "staff-walker.hh"
14 #include "staff.hh"
15 #include "score-column.hh"
17 Score_walker::Score_walker(Score *s)
18 :PCursor<Score_column *> (s->cols_)
20 score_l_ = s;
21 for (iter_top(s->staffs_,i); i.ok(); i++) {
22 Staff_walker* w_p=i->get_walker_p();
23 w_p->score_walk_l_ =this;
24 walker_p_arr_.push(w_p);
27 reinit();
28 breaks_i_=0;
32 void
33 Score_walker::reinit()
35 disallow_break_walk_l_arr = walker_p_arr_;
36 disallow_break_count_ = disallow_break_walk_l_arr.size();
40 /** Advance the cursor, and all Staff_walkers contained in this. Reset
41 runtime fields */
42 void
43 Score_walker::operator ++(int )
45 Moment last = ptr()->when();
47 PCursor<Score_column *>::operator++(0);
48 if (ok() && ptr()->when() == last)
49 PCursor<Score_column *>::operator++(0);
50 reinit();
51 bool last_b = (!ok()); // ughh
52 for (int i=0; i< walker_p_arr_.size(); i++) {
53 if (walker_p_arr_[i]->ok() &&
54 (last_b || walker_p_arr_[i]->when() < when())) {
56 walker_p_arr_[i]->operator++(0);
61 /** Allow the command_column to be breakable for one staff. If all
62 staffs allow, then allow a break here. */
63 void
64 Score_walker::allow_break(Staff_walker*w)
66 for (int i=0; i < disallow_break_walk_l_arr.size(); i++) {
67 if (w == disallow_break_walk_l_arr[i]) {
68 disallow_break_count_ --;
69 disallow_break_walk_l_arr[i] =0;
71 if (!disallow_break_count_) {
72 PCursor<Score_column*> col_cursor = *this;
73 if (ptr()->musical_b())
74 col_cursor --;
75 col_cursor->set_breakable();
81 bool
82 Score_walker::break_allowed_b()
84 return !disallow_break_count_;
87 Moment
88 Score_walker::when()
90 return ptr()->when();
93 void
94 Score_walker::process()
96 for (int i=0; i < walker_p_arr_.size(); i++) {
97 Staff_walker *w = walker_p_arr_[i];
98 if ( w->ok() && w->when() == when() ) {
99 walker_p_arr_[i]->process();
102 if (break_allowed_b()){
103 breaks_i_ ++;
104 if (! (breaks_i_ % 8))
105 *mlog << "[" <<breaks_i_<<"]"<<flush;
109 Score_walker::~Score_walker()
111 *mlog << "[" <<breaks_i_<<"]"<<flush;
112 for (int i=0; i < walker_p_arr_.size(); i++)
113 delete walker_p_arr_[i];