2 dynamic-engraver.cc -- implement Dynamic_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "dimensions.hh"
11 #include "musical-request.hh"
12 #include "paper-column.hh"
13 #include "note-column.hh"
15 #include "side-position-interface.hh"
16 #include "engraver.hh"
17 #include "group-interface.hh"
18 #include "directional-element-interface.hh"
19 #include "translator-group.hh"
20 #include "axis-group-interface.hh"
26 * direction of text-dynamic-request if not equal to direction of
29 - TODO: this engraver is too complicated. We should split it into
30 the handling of the basic grobs and the linespanner
32 - TODO: the line-spanner is not killed after the (de)crescs are
38 print text & hairpin dynamics.
40 class Dynamic_engraver : public Engraver
43 Spanner * finished_cresc_p_;
46 Text_script_req* script_req_l_;
48 Span_req * current_cresc_req_;
49 Drul_array<Span_req*> accepted_spanreqs_drul_;
51 Spanner* line_spanner_;
52 Spanner* finished_line_spanner_;
54 Link_array<Note_column> pending_column_arr_;
55 Link_array<Grob> pending_element_arr_;
60 VIRTUAL_COPY_CONS(Translator);
64 virtual void finalize ();
65 virtual void acknowledge_grob (Grob_info);
66 virtual bool try_music (Music *req_l);
67 virtual void stop_translation_timestep ();
68 virtual void process_music ();
69 virtual void start_translation_timestep ();
72 ADD_THIS_TRANSLATOR (Dynamic_engraver);
75 Dynamic_engraver::Dynamic_engraver ()
78 finished_cresc_p_ = 0;
80 finished_line_spanner_ = 0;
81 current_cresc_req_ = 0;
85 accepted_spanreqs_drul_[START] = 0;
86 accepted_spanreqs_drul_[STOP] = 0;
90 Dynamic_engraver::start_translation_timestep ()
93 accepted_spanreqs_drul_[START] = 0;
94 accepted_spanreqs_drul_[STOP] = 0;
98 Dynamic_engraver::try_music (Music * m)
100 if (dynamic_cast <Text_script_req*> (m)
101 && m->get_mus_property ("text-type") == ly_symbol2scm ("dynamic"))
103 script_req_l_ = dynamic_cast<Text_script_req*> (m);
106 else if (Span_req* s = dynamic_cast <Span_req*> (m))
108 String t = ly_scm2string (s->get_mus_property ("span-type"));
111 accepted_spanreqs_drul_[LEFT] = 0;
112 accepted_spanreqs_drul_[RIGHT] = 0;
114 Let's not kill the line spanner, since that would fuck up
115 earlier, not-to-be-terminated stuff.
117 It will disappear by itself when stop_translation_timestep
118 () finds that there is nothing to support anymore. */
122 cresc_p_->suicide ();
125 else if (t == "crescendo"
126 || t == "decrescendo")
128 accepted_spanreqs_drul_[s->get_span_dir()] = s;
136 Dynamic_engraver::process_music ()
138 if (accepted_spanreqs_drul_[START] || accepted_spanreqs_drul_[STOP] || script_req_l_)
142 line_spanner_ = new Spanner (get_property ("DynamicLineSpanner"));
144 Side_position::set_axis (line_spanner_, Y_AXIS);
145 Axis_group_interface::set_interface (line_spanner_);
146 Axis_group_interface::set_axes (line_spanner_, Y_AXIS, Y_AXIS);
148 Music * rq = accepted_spanreqs_drul_[START];
151 announce_grob (line_spanner_, rq);
158 During a (de)crescendo, pending request will not be cleared,
159 and a line-spanner will always be created, as \< \! are already
162 Note: line-spanner must always have at least same duration
163 as (de)crecsendo, b.o. line-breaking.
169 maybe we should leave dynamic texts to the text-engraver and
170 simply acknowledge them?
174 script_p_ = new Item (get_property ("DynamicText"));
175 script_p_->set_grob_property ("text",
176 script_req_l_->get_mus_property ("text"));
178 Side_position::set_direction (script_p_, LEFT);
179 Side_position::set_axis (script_p_, X_AXIS);
181 if (Direction d = script_req_l_->get_direction ())
182 Directional_element_interface::set (line_spanner_, d);
184 Axis_group_interface::add_element (line_spanner_, script_p_);
186 announce_grob (script_p_, script_req_l_);
189 if (accepted_spanreqs_drul_[STOP])
192 finish side position alignment if the (de)cresc ends here, and
193 there are no new dynamics.
198 accepted_spanreqs_drul_[STOP]->origin ()->warning
199 (_ ("can't find start of (de)crescendo"));
200 accepted_spanreqs_drul_[STOP] = 0;
204 assert (!finished_cresc_p_ && cresc_p_);
206 cresc_p_->set_bound (RIGHT, script_p_
208 : unsmob_grob (get_property ("currentMusicalColumn")));
209 add_bound_item (line_spanner_, cresc_p_->get_bound (RIGHT));
212 finished_cresc_p_ = cresc_p_;
214 current_cresc_req_ = 0;
218 if (accepted_spanreqs_drul_[START])
220 if (current_cresc_req_)
222 accepted_spanreqs_drul_[START]->origin ()->warning
223 (current_cresc_req_->get_span_dir() == 1
224 ? _ ("already have a crescendo")
225 : _ ("already have a decrescendo"));
229 current_cresc_req_ = accepted_spanreqs_drul_[START];
235 String start_type = ly_scm2string (accepted_spanreqs_drul_[START]->get_mus_property ("span-type"));
240 SCM s = get_property ((start_type + "Spanner").ch_C());
241 if (!gh_symbol_p (s) || s == ly_symbol2scm ("hairpin"))
243 cresc_p_ = new Spanner (get_property ("Hairpin"));
244 cresc_p_->set_grob_property ("grow-direction",
245 gh_int2scm ((start_type == "crescendo")
246 ? BIGGER : SMALLER));
250 This is a convenient (and legacy) interface to TextSpanners
251 for use in (de)crescendi.
256 cresc_p_ = new Spanner (get_property ("TextSpanner"));
257 cresc_p_->set_grob_property ("type", s);
259 daddy_trans_l_->set_property (start_type
260 + "Spanner", SCM_UNDEFINED);
261 s = get_property ((start_type + "Text").ch_C());
264 cresc_p_->set_grob_property ("edge-text",
265 gh_cons (s, ly_str02scm ("")));
266 daddy_trans_l_->set_property (start_type + "Text",
271 cresc_p_->set_bound (LEFT, script_p_
273 : unsmob_grob (get_property ("currentMusicalColumn")));
275 Axis_group_interface::add_element (line_spanner_, cresc_p_);
277 add_bound_item (line_spanner_, cresc_p_->get_bound (LEFT));
279 announce_grob (cresc_p_, accepted_spanreqs_drul_[START]);
285 Dynamic_engraver::stop_translation_timestep ()
288 if (script_req_l_ && !current_cresc_req_)
290 finished_line_spanner_ = line_spanner_;
297 Dynamic_engraver::finalize ()
302 finished_line_spanner_ = line_spanner_;
308 current_cresc_req_->origin ()->warning (_ ("unterminated (de)crescendo"));
309 cresc_p_->suicide ();
315 Dynamic_engraver::typeset_all ()
317 if (finished_cresc_p_)
319 if (!finished_cresc_p_->get_bound (RIGHT))
321 finished_cresc_p_->set_bound (RIGHT, script_p_
323 : unsmob_grob (get_property ("currentMusicalColumn")));
325 if (finished_line_spanner_)
326 add_bound_item (finished_line_spanner_,
327 finished_cresc_p_->get_bound (RIGHT));
329 typeset_grob (finished_cresc_p_);
330 finished_cresc_p_ =0;
335 typeset_grob (script_p_);
338 if (finished_line_spanner_)
341 To make sure that this works
343 Side_position::add_staff_support (finished_line_spanner_);
347 extend_spanner_over_elements (finished_line_spanner_);
349 but this is rather kludgy, since finished_line_spanner_
350 typically has a staff-symbol field set , extending it over the
355 if (!finished_line_spanner_->get_bound (RIGHT))
356 finished_line_spanner_->set_bound (RIGHT, finished_line_spanner_->get_bound (LEFT));
358 typeset_grob (finished_line_spanner_);
359 finished_line_spanner_ = 0;
364 Dynamic_engraver::acknowledge_grob (Grob_info i)
366 if (Note_column::has_interface (i.elem_l_))
370 Side_position::add_support (line_spanner_,i.elem_l_);
371 add_bound_item (line_spanner_,dynamic_cast<Item*>(i.elem_l_));