lilypond-0.1.57
[lilypond.git] / lily / stem-beam-reg.cc
blob1630f4b79dd6685f06b09b8267fa9bd75f537c8a
1 /*
2 stem-beam-reg.cc -- part of GNU LilyPond
4 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
5 */
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 "debug.hh"
14 #include "grouping.hh"
15 #include "note-head.hh"
16 #include "time-description.hh"
18 Stem_beam_register::Stem_beam_register()
20 do_post_move_processing();
22 current_grouping = 0;
23 beam_p_ = 0;
24 default_dir_i_ =0;
25 start_req_l_ = 0;
28 bool
29 Stem_beam_register::do_try_request(Request*req_l)
32 Musical_req* mus_l = req_l->musical();
33 /* Debiele puntkomma's. Laat je er eentje per ongeluk achter een
34 if(..) staan, lijkt het net op een luis in gcc.
36 (ofwel Python rules)
38 if (!mus_l)
39 return false;
42 if ( mus_l->beam() ) {
43 if (bool(beam_p_ ) == bool(mus_l->beam()->spantype == Span_req::START))
44 return false;
46 if (beam_req_l_ && Beam_req::compare(*beam_req_l_ , *mus_l->beam()))
47 return false;
49 beam_req_l_ = mus_l->beam();
50 return true;
53 if ( mus_l->stem() ) {
54 if (current_grouping && !current_grouping->child_fit_b(
55 get_staff_info().time_C_->whole_in_measure_))
56 return false;
58 if (stem_req_l_ && Stem_req::compare(*stem_req_l_, *mus_l->stem()))
59 return false;
61 stem_req_l_ = mus_l->stem();
62 return true;
64 return false;
67 void
68 Stem_beam_register::do_process_requests()
70 if (beam_req_l_) {
71 if (beam_req_l_->spantype == Span_req::STOP) {
72 end_beam_b_ = true;
73 start_req_l_ = 0;
74 } else {
75 beam_p_ = new Beam;
76 start_req_l_ = beam_req_l_;
77 beam_p_->left_col_l_ = get_staff_info().musical_pcol_l();
78 current_grouping = new Rhythmic_grouping;
79 if (beam_req_l_->nplet) {
80 Text_spanner* t = new Text_spanner();
81 Text_def *defp = new Text_def;
82 t->set_support(beam_p_);
83 defp->align_i_ = 0;
84 defp->text_str_ = beam_req_l_->nplet;
85 defp->style_str_="italic";
86 t->spec_p_ = defp;
87 typeset_element(t);
93 if (stem_req_l_) {
94 stem_p_ = new Stem(8);
95 if (current_grouping)
96 current_grouping->add_child(
97 get_staff_info().time_C_->whole_in_measure_,
98 stem_req_l_->duration());
100 stem_p_->flag_i_ = stem_req_l_->duration_.type_i_;
102 if (beam_p_) {
103 if (stem_req_l_->duration_.type_i_<= 4)
104 stem_req_l_->warning( "stem doesn't fit in Beam");
105 else
106 beam_p_->add(stem_p_);
107 stem_p_->print_flag_b_ = false;
108 } else {
109 stem_p_->print_flag_b_ = true;
112 announce_element(Score_elem_info(stem_p_, stem_req_l_));
116 void
117 Stem_beam_register::acknowledge_element(Score_elem_info info)
119 if (!stem_p_)
120 return;
122 if (info.elem_l_->name() == Note_head::static_name() &&
123 stem_req_l_->duration()
124 == info.req_l_->musical()->rhythmic()->duration()){
125 Note_head * n_l= (Note_head*)info.elem_l_->item();
126 stem_p_->add(n_l);
129 void
130 Stem_beam_register::do_pre_move_processing()
132 if (stem_p_) {
133 if (default_dir_i_)
134 stem_p_->dir_i_ = default_dir_i_;
136 typeset_element(stem_p_);
137 stem_p_ = 0;
139 if (beam_p_ && end_beam_b_) {
140 Rhythmic_grouping const * rg_C = get_staff_info().rhythmic_C_;
141 rg_C->extend(current_grouping->interval());
142 beam_p_->set_grouping(*rg_C, *current_grouping);
143 beam_p_->right_col_l_ = get_staff_info().musical_pcol_l();
144 typeset_element(beam_p_);
145 delete current_grouping;
146 current_grouping = 0;
147 beam_p_ = 0;
149 end_beam_b_ = false;
151 void
152 Stem_beam_register::do_post_move_processing()
154 stem_p_ = 0;
155 beam_req_l_ = 0;
156 stem_req_l_ = 0;
157 end_beam_b_ = false;
160 Stem_beam_register::~Stem_beam_register()
162 if (beam_p_)
163 start_req_l_->warning("unterminated beam");
166 void
167 Stem_beam_register::set_feature(Feature i)
169 if (i.type_ == "vdir")
170 default_dir_i_ = i.value_;
173 IMPLEMENT_STATIC_NAME(Stem_beam_register);
174 IMPLEMENT_IS_TYPE_B1(Stem_beam_register,Request_register);
175 ADD_THIS_REGISTER(Stem_beam_register);