lilypond-0.0.77.jcn1
[lilypond.git] / src / stembeamreg.cc
blob504ba6854f00895d4e47d08fb392486201ad0b03
1 /*
2 stembeamreg.cc -- part of LilyPond
4 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
5 */
7 #include "musicalrequest.hh"
8 #include "stembeamreg.hh"
9 #include "beam.hh"
10 #include "stem.hh"
11 #include "grouping.hh"
12 #include "textspanner.hh"
13 #include "complexwalker.hh"
14 #include "complexstaff.hh"
15 #include "debug.hh"
16 #include "grouping.hh"
17 Stem_beam_register::Stem_beam_register(Complex_walker*w)
18 :Request_register(w)
20 do_post_move_process();
21 current_grouping = 0;
22 beam_p_ = 0;
23 set_dir(0);
24 start_req_l_ = 0;
27 bool
28 Stem_beam_register::try_request(Request*req_l)
30 if ( req_l->beam() ) {
31 if (bool(beam_p_ ) == bool(req_l->beam()->spantype == Span_req::START))
32 return false;
34 if (beam_req_l_ && Beam_req::compare(*beam_req_l_ , *req_l->beam()))
35 return false;
37 beam_req_l_ = req_l->beam();
38 return true;
41 if ( req_l->stem() ) {
42 if (current_grouping && !current_grouping->child_fit_query(
43 walk_l_->time_.whole_in_measure_))
44 return false;
46 if (stem_req_l_ && Stem_req::compare(*stem_req_l_, *req_l->stem()))
47 return false;
49 stem_req_l_ = req_l->stem();
50 return true;
52 return false;
55 void
56 Stem_beam_register::process_request()
58 if (beam_req_l_) {
59 if (beam_req_l_->spantype == Span_req::STOP) {
60 end_beam_b_ = true;
61 start_req_l_ = 0;
62 } else {
63 beam_p_ = new Beam;
64 start_req_l_ = beam_req_l_;
66 current_grouping = new Rhythmic_grouping;
67 if (beam_req_l_->nplet) {
68 Text_spanner* t = new Text_spanner();
69 t->set_support(beam_p_);
70 t->spec.align_i_ = 0;
71 t->spec.text_str_ = beam_req_l_->nplet;
72 t->spec.style_str_="italic";
73 typeset_element(t);
79 if (stem_req_l_) {
80 stem_p_ = new Stem(4);
81 if (current_grouping)
82 current_grouping->add_child(
83 walk_l_->time_.whole_in_measure_,
84 stem_req_l_->duration());
86 stem_p_->flag = stem_req_l_->balltype;
88 if (beam_p_) {
89 if (stem_req_l_->balltype<= 4)
90 warning( "stem doesn't fit in Beam",
91 stem_req_l_->defined_ch_c_l_);
92 else
93 beam_p_->add(stem_p_);
94 stem_p_->print_flag = false;
95 } else {
96 stem_p_->print_flag = true;
99 announce_element(Staff_elem_info(stem_p_,
100 stem_req_l_, this));
104 void
105 Stem_beam_register::acknowledge_element(Staff_elem_info info)
107 if (!stem_p_)
108 return;
110 if (info.elem_p_->name() == String("Notehead") &&
111 stem_req_l_->duration() == info.req_l_->rhythmic()->duration())
113 stem_p_->add((Notehead*)info.elem_p_);
116 void
117 Stem_beam_register::do_pre_move_process()
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 walk_l_->default_grouping->extend(current_grouping->interval());
128 beam_p_->set_grouping(*walk_l_->default_grouping, *current_grouping);
129 typeset_element(beam_p_);
130 delete current_grouping;
131 current_grouping = 0;
132 beam_p_ = 0;
134 end_beam_b_ = false;
136 void
137 Stem_beam_register::do_post_move_process()
139 stem_p_ = 0;
140 beam_req_l_ = 0;
141 stem_req_l_ = 0;
142 end_beam_b_ = false;
145 Stem_beam_register::~Stem_beam_register()
147 if (beam_p_)
148 warning("unterminated beam", start_req_l_->defined_ch_c_l_);
151 void
152 Stem_beam_register::set_dir(int i)
154 default_dir_i_ = i;