]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-beam-reg.cc
release: 0.0.46.jcn1
[lilypond.git] / lily / stem-beam-reg.cc
1 /*
2   stem-beam-reg.cc -- part of LilyPond
3
4   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
5 */
6
7 #include "musical-request.hh"
8 #include "stem-beam-reg.hh"
9 #include "beam.hh"
10 #include "stem.hh"
11 #include "grouping.hh"
12 #include "text-spanner.hh"
13 #include "complex-walker.hh"
14 #include "complex-staff.hh"
15 #include "debug.hh"
16 #include "grouping.hh"
17 #include "notehead.hh"
18
19 Stem_beam_register::Stem_beam_register()
20 {
21     post_move_processing();
22     current_grouping = 0;
23     beam_p_ = 0;
24     set_feature(Features::dir(0));
25     start_req_l_ = 0;
26 }
27
28 bool
29 Stem_beam_register::try_request(Request*req_l)
30 {
31     if ( req_l->beam() ) {
32         if (bool(beam_p_ ) == bool(req_l->beam()->spantype == Span_req::START))
33             return false;
34         
35         if (beam_req_l_ && Beam_req::compare(*beam_req_l_ , *req_l->beam()))
36             return false;
37         
38         beam_req_l_ = req_l->beam();
39         return true;
40     }
41     
42     if ( req_l->stem() ) {
43         if (current_grouping && !current_grouping->child_fit_query(
44             get_staff_info().time_C_->whole_in_measure_))
45             return false;
46
47         if (stem_req_l_ && Stem_req::compare(*stem_req_l_, *req_l->stem()))
48             return false;
49
50         stem_req_l_ = req_l->stem();
51         return true;
52     }
53     return false;
54 }
55
56 void
57 Stem_beam_register::process_requests()
58 {
59     if (beam_req_l_) {
60         if (beam_req_l_->spantype == Span_req::STOP) {
61             end_beam_b_ = true;
62             start_req_l_ = 0;
63         } else {
64             beam_p_ = new Beam;
65             start_req_l_ = beam_req_l_;
66
67             current_grouping = new Rhythmic_grouping;
68             if (beam_req_l_->nplet) {
69                 Text_spanner* t = new Text_spanner();
70                 t->set_support(beam_p_);
71                 t->spec.align_i_ = 0;
72                 t->spec.text_str_ = beam_req_l_->nplet;
73                 t->spec.style_str_="italic";
74                 typeset_element(t);
75             }
76              
77         }
78     }
79
80     if (stem_req_l_) {
81         stem_p_ = new Stem(4);
82         if (current_grouping)
83             current_grouping->add_child(
84                 get_staff_info().time_C_->whole_in_measure_,
85                 stem_req_l_->duration());
86
87         stem_p_->flag = stem_req_l_->duration_.type_i_;
88
89         if (beam_p_) {
90             if (stem_req_l_->duration_.type_i_<= 4)
91                 
92                          stem_req_l_->warning( "stem doesn't fit in Beam");
93             else
94                 beam_p_->add(stem_p_);
95             stem_p_->print_flag = false;
96         } else {
97             stem_p_->print_flag = true;
98         }
99         
100         announce_element(Staff_elem_info(stem_p_, stem_req_l_));
101     }
102 }
103
104 void
105 Stem_beam_register::acknowledge_element(Staff_elem_info info)
106 {
107     if (!stem_p_)
108         return;
109
110     if (info.elem_p_->name() == Notehead::static_name() &&
111         stem_req_l_->duration() == info.req_l_->rhythmic()->duration())
112         
113         stem_p_->add((Notehead*)info.elem_p_);
114 }
115
116 void
117 Stem_beam_register::pre_move_processing()
118 {
119     if (stem_p_) {
120         if (default_dir_i_)
121             stem_p_->dir = default_dir_i_;
122         
123         typeset_element(stem_p_);
124         stem_p_ = 0;
125     }
126     if (beam_p_ && end_beam_b_) {
127         Rhythmic_grouping const * rg_C = get_staff_info().rhythmic_C_;
128         rg_C->extend(current_grouping->interval());
129         beam_p_->set_grouping(*rg_C, *current_grouping);
130         typeset_element(beam_p_);
131         delete current_grouping;
132         current_grouping = 0;
133         beam_p_ = 0;
134     }
135     end_beam_b_ = false;
136 }
137 void
138 Stem_beam_register::post_move_processing()
139 {
140     stem_p_ = 0;
141     beam_req_l_ = 0;
142     stem_req_l_ = 0;
143     end_beam_b_ = false;
144 }
145
146 Stem_beam_register::~Stem_beam_register()
147 {
148     if (beam_p_)
149         start_req_l_->warning("unterminated beam");
150 }
151
152 void
153 Stem_beam_register::set_feature(Features i)
154 {
155     default_dir_i_ = i.direction_i_;
156 }
157
158 IMPLEMENT_STATIC_NAME(Stem_beam_register);
159 ADD_THIS_REGISTER(Stem_beam_register);