2 beam-grav.cc -- implement Beam_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 #include "duration-convert.hh"
9 #include "time-description.hh"
10 #include "beam-engraver.hh"
13 #include "musical-request.hh"
14 #include "grouping.hh"
18 Beam_engraver::Beam_engraver()
20 span_reqs_drul_
[LEFT
] = span_reqs_drul_
[RIGHT
] =0;
22 current_grouping_p_
=0;
26 Beam_engraver::do_try_music (Music
*r
)
28 Beam_req
* b
= dynamic_cast <Beam_req
*> (r
);
32 if (bool (beam_p_
) == bool (b
->spantype_
== START
))
35 Direction d
= (!beam_p_
) ? LEFT
: RIGHT
;
36 if (span_reqs_drul_
[d
] && !span_reqs_drul_
[d
]->equal_b (b
))
39 span_reqs_drul_
[d
] = b
;
44 Beam_engraver::do_process_requests()
46 if (beam_p_
|| !span_reqs_drul_
[LEFT
])
49 current_grouping_p_
= new Rhythmic_grouping
;
52 Scalar prop
= get_property ("beamslopedamping");
54 beam_p_
->damping_i_
= prop
;
56 prop
= get_property ("beamquantisation");
58 beam_p_
->quantisation_
= (Beam::Quantisation
)(int)prop
;
60 announce_element (Score_element_info (beam_p_
, span_reqs_drul_
[LEFT
]));
64 Beam_engraver::do_pre_move_processing()
66 if (!beam_p_
|| !span_reqs_drul_
[RIGHT
])
69 Rhythmic_grouping
const * rg_C
= get_staff_info().rhythmic_C_
;
70 rg_C
->extend (current_grouping_p_
->interval());
71 beam_p_
->set_grouping (*rg_C
, *current_grouping_p_
);
72 typeset_element (beam_p_
);
75 delete current_grouping_p_
;
76 current_grouping_p_
= 0;
78 span_reqs_drul_
[RIGHT
] = span_reqs_drul_
[LEFT
] = 0;
82 Beam_engraver::do_removal_processing()
86 span_reqs_drul_
[LEFT
]->warning (_("unterminated beam"));
87 typeset_element (beam_p_
);
94 Beam_engraver::acknowledge_element (Score_element_info i
)
96 Stem
* s
= dynamic_cast<Stem
*> (i
.elem_l_
);
100 if (!dynamic_cast <Rhythmic_req
*> (i
.req_l_
))
102 ::warning ( _("Stem must have Rhythmic structure."));
106 Rhythmic_req
*rhythmic_req
= dynamic_cast <Rhythmic_req
*> (i
.req_l_
);
107 if (rhythmic_req
->duration_
.durlog_i_
<= 2)
109 rhythmic_req
->warning (_ ("stem doesn't fit in beam"));
114 TODO: do something sensible if it doesn't fit in the beam.
116 Moment start
= get_staff_info().time_C_
->whole_in_measure_
;
118 if (!current_grouping_p_
->child_fit_b (start
))
120 String
s (_("please fix me") + ": "
121 + _f ("stem at %s doesn't fit in beam", now_moment ().str ()));
123 i
.req_l_
->warning(s
);
129 current_grouping_p_
->add_child (start
, rhythmic_req
->duration ());
130 s
->flag_i_
= rhythmic_req
->duration_
.durlog_i_
;
131 beam_p_
->add_stem (s
);
135 ADD_THIS_TRANSLATOR(Beam_engraver
);