2 dynamic-reg.cc -- implement Dynamic_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "crescendo.hh"
10 #include "musical-request.hh"
12 #include "paper-def.hh"
13 #include "score-column.hh"
14 #include "staff-symbol.hh"
15 #include "note-column.hh"
16 #include "text-item.hh"
17 #include "side-position-interface.hh"
18 #include "engraver.hh"
20 #include "note-head.hh"
23 print text & hairpin dynamics.
25 class Dynamic_engraver
: public Engraver
28 Crescendo
* to_end_cresc_p_
;
31 Span_req
* cresc_req_l_
;
32 Array
<Request
*> dynamic_req_l_arr_
;
35 VIRTUAL_COPY_CONS(Translator
);
39 virtual void do_removal_processing ();
40 virtual void acknowledge_element (Score_element_info
);
41 virtual bool do_try_music (Music
*req_l
);
42 virtual void do_process_requests();
43 virtual void do_pre_move_processing();
44 virtual void do_post_move_processing();
49 Dynamic_engraver::Dynamic_engraver()
51 do_post_move_processing();
54 to_end_cresc_p_
= cresc_p_
= 0;
60 Dynamic_engraver::do_post_move_processing()
62 dynamic_req_l_arr_
.clear();
66 Dynamic_engraver::do_try_music (Music
* m
)
68 Request
* r
= dynamic_cast<Request
*> (m
);
70 if(Text_script_req
* d
= dynamic_cast <Text_script_req
*> (r
))
72 if (d
->style_str_
!= "dynamic")
75 else if (Span_req
* s
= dynamic_cast <Span_req
*> (r
))
77 if (s
-> span_type_str_
!= "crescendo"
78 && s
->span_type_str_
!= "decrescendo")
84 for (int i
=0; i
< dynamic_req_l_arr_
.size (); i
++)
85 if (r
->equal_b (dynamic_req_l_arr_
[i
]))
88 dynamic_req_l_arr_
.push (r
);
94 Dynamic_engraver::do_process_requests()
96 Crescendo
* new_cresc_p
=0;
98 for (int i
=0; i
< dynamic_req_l_arr_
.size(); i
++)
100 if (Text_script_req
*absd
=
101 dynamic_cast<Text_script_req
*> ( dynamic_req_l_arr_
[i
]))
105 dynamic_req_l_arr_
[i
]->warning (_("Got a dynamic already. Continuing dazed and confused."));
109 String loud
= absd
->text_str_
;
111 text_p_
= new Text_item
;
112 text_p_
->text_str_
= loud
; // ugh
113 text_p_
->set_elt_property ("style", gh_str02scm ("dynamic"));
114 text_p_
->set_elt_property ("script-priority",
116 text_p_
->set_elt_property ("staff-support", SCM_BOOL_T
);
118 Side_position_interface (text_p_
).set_axis (Y_AXIS
);
121 if (absd
->get_direction ())
123 text_p_
->set_elt_property ("direction", gh_int2scm (absd
->get_direction ()));
130 SCM prop
= get_property ("dynamicDirection", 0);
133 prop
= get_property ("verticalDirection", 0);
136 if (isdir_b (prop
) && to_dir (prop
))
137 text_p_
->set_elt_property ("direction", prop
);
139 prop
= get_property ("dynamicPadding", 0);
140 if (gh_number_p(prop
))
142 text_p_
->set_elt_property ("padding", prop
);
144 announce_element (Score_element_info (text_p_
, absd
));
146 else if (Span_req
*span_l
147 = dynamic_cast <Span_req
*> (dynamic_req_l_arr_
[i
]))
149 if (span_l
->span_dir_
== STOP
)
153 span_l
->warning (_ ("Can't find (de)crescendo to end"));
157 assert (!to_end_cresc_p_
);
158 to_end_cresc_p_
=cresc_p_
;
163 else if (span_l
->span_dir_
== START
)
165 cresc_req_l_
= span_l
;
166 assert (!new_cresc_p
);
167 new_cresc_p
= new Crescendo
;
168 new_cresc_p
->grow_dir_
= (span_l
->span_type_str_
== "crescendo") ? BIGGER
: SMALLER
;
169 new_cresc_p
->set_elt_property ("staff-support", SCM_BOOL_T
);
172 Side_position_interface (new_cresc_p
).set_axis (Y_AXIS
);
173 announce_element (Score_element_info (new_cresc_p
, span_l
));
182 ::warning (_ ("Too many crescendi here"));
185 typeset_element (cresc_p_
);
190 cresc_p_
= new_cresc_p
;
191 cresc_p_
->set_bounds(LEFT
,get_staff_info().musical_pcol_l ());
195 cresc_p_
->dyn_b_drul_
[LEFT
] = true;
197 to_end_cresc_p_
->dyn_b_drul_
[RIGHT
] = true;
203 Dynamic_engraver::do_pre_move_processing()
210 ADD_THIS_TRANSLATOR(Dynamic_engraver
);
213 Dynamic_engraver::do_removal_processing ()
217 typeset_element (cresc_p_
);
218 cresc_req_l_
->warning (_ ("unended crescendo"));
226 Dynamic_engraver::typeset_all ()
230 to_end_cresc_p_
->set_bounds(RIGHT
,get_staff_info().musical_pcol_l ());
231 typeset_element (to_end_cresc_p_
);
239 typeset_element (text_p_
);
246 Dynamic_engraver::acknowledge_element (Score_element_info i
)
248 if (dynamic_cast<Stem
*> (i
.elem_l_
)
249 || dynamic_cast<Note_head
*> (i
.elem_l_
)
253 Side_position_interface (text_p_
).add_support (i
.elem_l_
);
256 Side_position_interface (to_end_cresc_p_
).add_support (i
.elem_l_
);
259 Side_position_interface(cresc_p_
).add_support (i
.elem_l_
);