]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-walker.cc
6d6aed474320491515c0db2e13e5628b894b31ed
[lilypond.git] / lily / score-walker.cc
1 /*
2   score-walker.cc -- implement Score_walker
3
4   source file of the LilyPond music typesetter
5
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"
16
17 Score_walker::Score_walker(Score *s)
18     :PCursor<Score_column *> (s->cols_)
19 {
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);
25     }
26
27     if(ok()) {
28         s->find_col(0, false)->set_breakable();
29         s->find_col(s->last(), false)->set_breakable();
30     }
31     reinit();
32     breaks_i_=0;
33 }
34
35
36 void
37 Score_walker::reinit()
38 {
39     disallow_break_walk_l_arr = walker_p_arr_;
40     disallow_break_count_ = disallow_break_walk_l_arr.size();
41 }
42
43
44 /** Advance the cursor, and all Staff_walkers contained in this. Reset
45   runtime fields */
46 void 
47 Score_walker::operator ++(int )
48 {
49     Moment last = ptr()->when();
50     
51     PCursor<Score_column *>::operator++(0);
52     if (ok() && ptr()->when() == last)
53         PCursor<Score_column *>::operator++(0);
54     reinit();
55     bool last_b =  (!ok());     // urgh
56     for (int i=0; i< walker_p_arr_.size(); i++) {
57         if (walker_p_arr_[i]->ok() &&
58             (last_b || walker_p_arr_[i]->when() < when())) {
59
60             walker_p_arr_[i]->operator++(0);
61         }
62     }
63 }
64
65 /** Allow the command_column to be breakable for one staff. If all
66   staffs allow, then allow a break here.  */
67 void
68 Score_walker::allow_break(Staff_walker*w)
69 {
70     for (int i=0; i < disallow_break_walk_l_arr.size(); i++) {
71         if (w == disallow_break_walk_l_arr[i]) {
72             disallow_break_count_ --;
73             disallow_break_walk_l_arr[i] =0;
74
75             if (!disallow_break_count_) {
76                 PCursor<Score_column*> col_cursor = *this;
77                 if (ptr()->musical_b())
78                     col_cursor --;
79                 col_cursor->set_breakable();
80             }
81         }
82     }
83 }
84
85 bool
86 Score_walker::break_allowed_b()
87 {
88     return !disallow_break_count_;
89 }
90
91 Moment
92 Score_walker::when()
93 {
94     return ptr()->when();
95 }
96
97 void
98 Score_walker::process()
99 {
100     for (int i=0; i < walker_p_arr_.size(); i++) {
101         Staff_walker *w = walker_p_arr_[i];
102         if ( w->ok() && w->when() == when() ) {
103             walker_p_arr_[i]->process();
104         }
105     }
106     if (break_allowed_b()){
107         breaks_i_ ++;
108         if (! (breaks_i_ % 8)) 
109             *mlog << "[" <<breaks_i_<<"]"<<flush;
110     }
111 }
112
113 Score_walker::~Score_walker()
114 {
115     *mlog << "[" <<breaks_i_<<"]"<<flush;
116     for (int i=0; i < walker_p_arr_.size(); i++) 
117         delete walker_p_arr_[i];
118     assert( !score_l_->find_col(score_l_->last(), true)->used_b());
119 }
120
121