]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-walker.cc
release: 0.0.53
[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     reinit();
28     breaks_i_=0;
29 }
30
31
32 void
33 Score_walker::reinit()
34 {
35     disallow_break_walk_l_arr = walker_p_arr_;
36     disallow_break_count_ = disallow_break_walk_l_arr.size();
37 }
38
39
40 /** Advance the cursor, and all Staff_walkers contained in this. Reset
41   runtime fields */
42 void 
43 Score_walker::operator ++(int )
44 {
45     Moment last = ptr()->when();
46     
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());     // urgh
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())) {
55
56             walker_p_arr_[i]->operator++(0);
57         }
58     }
59 }
60
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)
65 {
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;
70
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();
76             }
77         }
78     }
79 }
80
81 bool
82 Score_walker::break_allowed_b()
83 {
84     return !disallow_break_count_;
85 }
86
87 Moment
88 Score_walker::when()
89 {
90     return ptr()->when();
91 }
92
93 void
94 Score_walker::process()
95 {
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();
100         }
101     }
102     if (break_allowed_b()){
103         breaks_i_ ++;
104         if (! (breaks_i_ % 8)) 
105             *mlog << "[" <<breaks_i_<<"]"<<flush;
106     }
107 }
108
109 Score_walker::~Score_walker()
110 {
111     *mlog << "[" <<breaks_i_<<"]"<<flush;
112     for (int i=0; i < walker_p_arr_.size(); i++) 
113         delete walker_p_arr_[i];
114 }
115
116