2 beam-grav.cc -- implement Beam_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
8 #include "duration-convert.hh"
9 #include "time-description.hh"
10 #include "beam-grav.hh"
13 #include "musical-request.hh"
14 #include "grouping.hh"
15 #include "text-spanner.hh"
16 #include "text-def.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_request(Request
*r
)
28 Musical_req
* mus_l
= r
->musical();
32 Beam_req
* b
= mus_l
->beam();
37 if (bool (beam_p_
) == bool (b
->spantype
== Span_req::START
))
40 Direction d
= (!beam_p_
) ? LEFT
: RIGHT
;
41 if (span_reqs_drul_
[d
] && !span_reqs_drul_
[d
]->equal_b (mus_l
))
44 span_reqs_drul_
[d
] = b
;
49 Beam_engraver::do_process_requests()
51 if ( !beam_p_
&& span_reqs_drul_
[LEFT
]) {
52 current_grouping_p_
= new Rhythmic_grouping
;
54 if (span_reqs_drul_
[LEFT
]->nplet
)
56 Text_spanner
* t
= new Text_spanner();
57 Text_def
*defp
= new Text_def
;
58 t
->set_support (beam_p_
);
60 defp
->text_str_
= span_reqs_drul_
[LEFT
]->nplet
;
61 defp
->style_str_
="italic";
63 announce_element (Score_elem_info (t
,0));
66 announce_element (Score_elem_info (beam_p_
, span_reqs_drul_
[LEFT
]));
71 Beam_engraver::do_pre_move_processing()
73 if (beam_p_
&& span_reqs_drul_
[RIGHT
]) {
74 Rhythmic_grouping
const * rg_C
= get_staff_info().rhythmic_C_
;
75 rg_C
->extend (current_grouping_p_
->interval());
76 beam_p_
->set_grouping (*rg_C
, *current_grouping_p_
);
77 typeset_element (beam_p_
);
80 delete current_grouping_p_
;
81 current_grouping_p_
= 0;
83 span_reqs_drul_
[RIGHT
] =
84 span_reqs_drul_
[LEFT
] = 0;
89 Beam_engraver::do_removal_processing()
93 span_reqs_drul_
[LEFT
]->warning (_("unterminated beam"));
94 typeset_element (beam_p_
);
101 Beam_engraver::acknowledge_element (Score_elem_info i
)
103 if (!beam_p_
|| !i
.elem_l_
->is_type_b (Stem::static_name ()))
106 Stem
* s
= (Stem
*)i
.elem_l_
->item();
107 Rhythmic_req
*rhythmic_req
= i
.req_l_
->musical ()->rhythmic ();
108 if (rhythmic_req
->duration_
.durlog_i_
<= 2)
110 rhythmic_req
->warning (_("Stem doesn't fit in Beam"));
115 TODO: do something sensible if it doesn't fit in the beam.
117 current_grouping_p_
->add_child (get_staff_info().time_C_
->whole_in_measure_
,
118 rhythmic_req
->duration ());
119 s
->flag_i_
= rhythmic_req
->duration_
.durlog_i_
;
123 IMPLEMENT_IS_TYPE_B1(Beam_engraver
, Engraver
);
124 ADD_THIS_TRANSLATOR(Beam_engraver
);