]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-walker.cc
release: 0.0.63
[lilypond.git] / lily / staff-walker.cc
1 /*
2   staff-walker.cc -- implement Staff_walker
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "proto.hh"
10 #include "plist.hh"
11 #include "grouping.hh"
12 #include "staff.hh"
13 #include "musical-request.hh"
14 #include "staff-walker.hh"
15 #include "staff-column.hh"
16 #include "score-column.hh"
17 #include "debug.hh"
18 #include "time-description.hh"
19 #include "command-request.hh"
20 #include "grouping.hh"
21 #include "score-walker.hh"
22
23 Staff_walker::~Staff_walker()
24 {
25     do_pre_move();
26 }
27
28 Staff_walker::Staff_walker(Staff_walker const &s)
29     :PCursor<Staff_column*> (s)
30 {
31     assert(false);
32 }
33
34 Staff_walker::Staff_walker(Staff * s, PScore*ps )
35     : PCursor<Staff_column*> (s->cols_)
36 {
37     staff_l_ = s;
38     pscore_l_ = ps;
39     
40     // should be in tdes. TODO
41     default_grouping = new Rhythmic_grouping(MInterval(0, 1), 4); 
42     score_walk_l_ = 0;
43 }
44
45 Moment
46 Staff_walker::when() const
47 {
48     return ptr()->when();
49 }
50
51
52 void
53 Staff_walker::process_timing_reqs()
54 {
55     // first all meter changes
56     for (int i=0; i < ptr()->timing_req_l_arr_.size(); i++) {
57         Timing_req * tr_l = ptr()->timing_req_l_arr_[i];
58         if (tr_l->meterchange()) {
59             int b_i=tr_l->meterchange()->beats_i_;
60             int o_i = tr_l->meterchange()->one_beat_i_;
61             if (! time_.allow_meter_change_b() )
62                 
63                         tr_l->warning("Meterchange should be at start of measure");
64             else
65                 time_.set_meter(b_i, o_i);
66                         
67             *default_grouping = Rhythmic_grouping(
68                 MInterval(0,Moment(b_i, o_i)), b_i);
69         } 
70     }
71     
72     // then do the rest
73     for (int i=0; i < ptr()->timing_req_l_arr_.size(); i++) {
74         Timing_req * tr_l = ptr()->timing_req_l_arr_[i];
75         if (tr_l->partial()) {
76             Moment m = tr_l->partial()->duration_;
77             String error = time_.try_set_partial_str(m);
78             if (error != "") {
79                 tr_l->warning(error);
80             } else 
81                 time_.setpartial(m);
82         } else if (tr_l->barcheck() && time_.whole_in_measure_) {
83             tr_l ->warning( "Barcheck failed");
84         } else if (tr_l->cadenza()) {
85             time_.set_cadenza(tr_l->cadenza()->on_b_);
86         } else if (tr_l->measuregrouping()) {
87             *default_grouping = parse_grouping(
88                 tr_l->measuregrouping()->beat_i_arr_,
89                 tr_l->measuregrouping()->elt_length_arr_);
90         }
91     }
92     time_.OK();
93 }
94
95 void
96 Staff_walker::operator++(int i)
97 {
98     Moment last = when();
99
100     do_pre_move();
101     PCursor<Staff_column*>::operator++(i);
102     if (ok() ) {
103         Moment delta_t = when() - last;
104         assert(delta_t >Moment(0));
105         time_.add( delta_t );
106     }
107     do_post_move();
108 }
109
110 void
111 Staff_walker::process()
112 {
113     process_timing_reqs();    
114     process_requests();
115 }
116
117 void 
118 Staff_walker::allow_break()
119 {
120     score_walk_l_->allow_break(this);
121 }
122