lilypond-0.0.40
[lilypond.git] / lily / stem-beam-reg.cc
blob54579d337d4b7efae1e09095053537b54f4fbdab
1 /*
2 stem-beam-reg.cc -- part of LilyPond
4 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
5 */
7 #include "musicalrequest.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"
19 Stem_beam_register::Stem_beam_register()
21 post_move_processing();
22 current_grouping = 0;
23 beam_p_ = 0;
24 set_feature(Features::dir(0));
25 start_req_l_ = 0;
28 bool
29 Stem_beam_register::try_request(Request*req_l)
31 if ( req_l->beam() ) {
32 if (bool(beam_p_ ) == bool(req_l->beam()->spantype == Span_req::START))
33 return false;
35 if (beam_req_l_ && Beam_req::compare(*beam_req_l_ , *req_l->beam()))
36 return false;
38 beam_req_l_ = req_l->beam();
39 return true;
42 if ( req_l->stem() ) {
43 if (current_grouping && !current_grouping->child_fit_query(
44 get_staff_info().time_c_l_->whole_in_measure_))
45 return false;
47 if (stem_req_l_ && Stem_req::compare(*stem_req_l_, *req_l->stem()))
48 return false;
50 stem_req_l_ = req_l->stem();
51 return true;
53 return false;
56 void
57 Stem_beam_register::process_requests()
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_;
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);
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_l_->whole_in_measure_,
85 stem_req_l_->duration());
87 stem_p_->flag = stem_req_l_->balltype;
89 if (beam_p_) {
90 if (stem_req_l_->balltype<= 4)
91 warning( "stem doesn't fit in Beam",
92 stem_req_l_->defined_ch_c_l_);
93 else
94 beam_p_->add(stem_p_);
95 stem_p_->print_flag = false;
96 } else {
97 stem_p_->print_flag = true;
100 announce_element(Staff_elem_info(stem_p_, stem_req_l_));
104 void
105 Stem_beam_register::acknowledge_element(Staff_elem_info info)
107 if (!stem_p_)
108 return;
110 if (info.elem_p_->name() == Notehead::static_name() &&
111 stem_req_l_->duration() == info.req_l_->rhythmic()->duration())
113 stem_p_->add((Notehead*)info.elem_p_);
116 void
117 Stem_beam_register::pre_move_processing()
119 if (stem_p_) {
120 if (default_dir_i_)
121 stem_p_->dir = default_dir_i_;
123 typeset_element(stem_p_);
124 stem_p_ = 0;
126 if (beam_p_ && end_beam_b_) {
127 const Rhythmic_grouping * rg_c_l = get_staff_info().rhythmic_c_l_;
128 rg_c_l->extend(current_grouping->interval());
129 beam_p_->set_grouping(*rg_c_l, *current_grouping);
130 typeset_element(beam_p_);
131 delete current_grouping;
132 current_grouping = 0;
133 beam_p_ = 0;
135 end_beam_b_ = false;
137 void
138 Stem_beam_register::post_move_processing()
140 stem_p_ = 0;
141 beam_req_l_ = 0;
142 stem_req_l_ = 0;
143 end_beam_b_ = false;
146 Stem_beam_register::~Stem_beam_register()
148 if (beam_p_)
149 warning("unterminated beam", start_req_l_->defined_ch_c_l_);
152 void
153 Stem_beam_register::set_feature(Features i)
155 default_dir_i_ = i.direction_i_;