]> git.donarmstrong.com Git - lilypond.git/blob - src/staff-walker.cc
release: 0.0.38
[lilypond.git] / src / 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 "grouping.hh"
10 #include "staff.hh"
11 #include "musicalrequest.hh"
12 #include "staff-walker.hh"
13 #include "staff-column.hh"
14 #include "score-column.hh"
15 #include "debug.hh"
16 #include "time-description.hh"
17 #include "commandrequest.hh"
18 #include "grouping.hh"
19 #include "score-walker.hh"
20
21 Staff_walker::~Staff_walker()
22 {
23     do_pre_move();
24 }
25
26 Staff_walker::Staff_walker(Staff_walker const &s)
27     :PCursor<Staff_column*> (s)
28 {
29     assert(false);
30 }
31
32 Staff_walker::Staff_walker(Staff * s, PScore*ps )
33     : PCursor<Staff_column*> (s->cols_)
34 {
35     staff_l_ = s;
36     pscore_l_ = ps;
37     
38     // should be in tdes. TODO
39     default_grouping = new Rhythmic_grouping(MInterval(0, 1), 4); 
40     score_walk_l_ = 0;
41 }
42
43 Moment
44 Staff_walker::when() const
45 {
46     return ptr()->when();
47 }
48
49
50 void
51 Staff_walker::process_timing_reqs()
52 {
53     for (int i=0; i < ptr()->timing_req_l_arr_.size(); i++) {
54         Timing_req * tr_l = ptr()->timing_req_l_arr_[i];
55         if (tr_l->meterchange()) {
56             int b_i=tr_l->meterchange()->beats_i_;
57             int o_i = tr_l->meterchange()->one_beat_i_;
58             time_.set_meter(b_i, o_i);
59                         
60             *default_grouping = Rhythmic_grouping(
61                 MInterval(0,Moment(b_i, o_i)), b_i);
62         } 
63     }
64     
65     for (int i=0; i < ptr()->timing_req_l_arr_.size(); i++) {
66         Timing_req * tr_l = ptr()->timing_req_l_arr_[i];
67         if (tr_l->partial()) {
68             time_.setpartial(tr_l->partial()->duration_);
69         } else if (tr_l->barcheck() && time_.whole_in_measure_) {
70             warning( "Barcheck failed", tr_l->defined_ch_c_l_ );
71         } else if (tr_l->cadenza()) {
72             time_.set_cadenza(tr_l->cadenza()->on_b_);
73         } else if (tr_l->measuregrouping()) {
74             *default_grouping = parse_grouping(
75                 tr_l->measuregrouping()->beat_i_arr_,
76                 tr_l->measuregrouping()->elt_length_arr_);
77         }
78     }
79     time_.OK();
80 }
81
82 void
83 Staff_walker::operator++(int i)
84 {
85     Moment last = when();
86
87     do_pre_move();
88     PCursor<Staff_column*>::operator++(i);
89     if (ok() ) {
90         Moment delta_t = when() - last;
91         assert(delta_t >0);
92         time_.add( delta_t );
93     }
94     do_post_move();
95 }
96
97 void
98 Staff_walker::process()
99 {
100     process_timing_reqs();    
101     process_requests();
102 }
103
104 void 
105 Staff_walker::allow_break()
106 {
107     score_walk_l_->allow_break(this);
108 }
109