2 dynamic-engraver.cc -- implement Dynamic_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 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_;
59 TRANSLATOR_DECLARATIONS(Dynamic_engraver );
62 virtual void finalize ();
63 virtual void acknowledge_grob (Grob_info);
64 virtual bool try_music (Music *req_l);
65 virtual void stop_translation_timestep ();
66 virtual void process_music ();
67 virtual void start_translation_timestep ();
73 Dynamic_engraver::Dynamic_engraver ()
76 finished_cresc_p_ = 0;
78 finished_line_spanner_ = 0;
79 current_cresc_req_ = 0;
83 accepted_spanreqs_drul_[START] = 0;
84 accepted_spanreqs_drul_[STOP] = 0;
88 Dynamic_engraver::start_translation_timestep ()
91 accepted_spanreqs_drul_[START] = 0;
92 accepted_spanreqs_drul_[STOP] = 0;
96 Dynamic_engraver::try_music (Music * m)
98 if (dynamic_cast <Text_script_req*> (m)
99 && m->get_mus_property ("text-type") == ly_symbol2scm ("dynamic"))
101 script_req_l_ = dynamic_cast<Text_script_req*> (m);
104 else if (Span_req* s = dynamic_cast <Span_req*> (m))
106 String t = ly_scm2string (s->get_mus_property ("span-type"));
109 accepted_spanreqs_drul_[LEFT] = 0;
110 accepted_spanreqs_drul_[RIGHT] = 0;
112 Let's not kill the line spanner, since that would fuck up
113 earlier, not-to-be-terminated stuff.
115 It will disappear by itself when stop_translation_timestep
116 () finds that there is nothing to support anymore. */
119 cresc_p_->suicide ();
122 else if (t == "crescendo"
123 || t == "decrescendo")
125 accepted_spanreqs_drul_[s->get_span_dir ()] = s;
133 Dynamic_engraver::process_music ()
135 if (accepted_spanreqs_drul_[START] || accepted_spanreqs_drul_[STOP] || script_req_l_)
139 line_spanner_ = new Spanner (get_property ("DynamicLineSpanner"));
141 Side_position_interface::set_axis (line_spanner_, Y_AXIS);
143 Music * rq = accepted_spanreqs_drul_[START];
146 announce_grob(line_spanner_, rq ? rq->self_scm(): SCM_EOL);
153 During a (de)crescendo, pending request will not be cleared,
154 and a line-spanner will always be created, as \< \! are already
157 Note: line-spanner must always have at least same duration
158 as (de)crecsendo, b.o. line-breaking.
164 maybe we should leave dynamic texts to the text-engraver and
165 simply acknowledge them?
169 script_p_ = new Item (get_property ("DynamicText"));
170 script_p_->set_grob_property ("text",
171 script_req_l_->get_mus_property ("text"));
173 if (Direction d = script_req_l_->get_direction ())
174 Directional_element_interface::set (line_spanner_, d);
176 Axis_group_interface::add_element (line_spanner_, script_p_);
178 announce_grob(script_p_, script_req_l_->self_scm());
181 if (accepted_spanreqs_drul_[STOP])
184 finish side position alignment if the (de)cresc ends here, and
185 there are no new dynamics.
190 accepted_spanreqs_drul_[STOP]->origin ()->warning
191 (_ ("can't find start of (de)crescendo"));
192 accepted_spanreqs_drul_[STOP] = 0;
196 assert (!finished_cresc_p_ && cresc_p_);
198 cresc_p_->set_bound (RIGHT, script_p_
200 : unsmob_grob (get_property ("currentMusicalColumn")));
201 add_bound_item (line_spanner_, cresc_p_->get_bound (RIGHT));
204 finished_cresc_p_ = cresc_p_;
206 current_cresc_req_ = 0;
210 if (accepted_spanreqs_drul_[START])
212 if (current_cresc_req_)
214 accepted_spanreqs_drul_[START]->origin ()->warning
215 (current_cresc_req_->get_span_dir () == 1
216 ? _ ("already have a crescendo")
217 : _ ("already have a decrescendo"));
221 current_cresc_req_ = accepted_spanreqs_drul_[START];
227 String start_type = ly_scm2string (accepted_spanreqs_drul_[START]->get_mus_property ("span-type"));
232 SCM s = get_property ((start_type + "Spanner").ch_C ());
233 if (!gh_symbol_p (s) || s == ly_symbol2scm ("hairpin"))
235 cresc_p_ = new Spanner (get_property ("Hairpin"));
236 cresc_p_->set_grob_property ("grow-direction",
237 gh_int2scm ((start_type == "crescendo")
238 ? BIGGER : SMALLER));
242 This is a convenient (and legacy) interface to TextSpanners
243 for use in (de)crescendi.
248 cresc_p_ = new Spanner (get_property ("TextSpanner"));
249 cresc_p_->set_grob_property ("type", s);
250 daddy_trans_l_->set_property ((start_type
251 + "Spanner").ch_C(), SCM_UNDEFINED);
252 s = get_property ((start_type + "Text").ch_C ());
254 FIXME: use markup_p () to check type.
256 if (gh_string_p (s) || gh_pair_p (s))
258 cresc_p_->set_grob_property ("edge-text",
259 gh_cons (s, ly_str02scm ("")));
260 daddy_trans_l_->set_property ((start_type + "Text").ch_C(),
265 cresc_p_->set_bound (LEFT, script_p_
267 : unsmob_grob (get_property ("currentMusicalColumn")));
269 Axis_group_interface::add_element (line_spanner_, cresc_p_);
271 add_bound_item (line_spanner_, cresc_p_->get_bound (LEFT));
273 announce_grob(cresc_p_, accepted_spanreqs_drul_[START]->self_scm());
279 Dynamic_engraver::stop_translation_timestep ()
282 if (script_req_l_ && !current_cresc_req_)
284 finished_line_spanner_ = line_spanner_;
291 Dynamic_engraver::finalize ()
296 && line_spanner_->immutable_property_alist_ == SCM_EOL)
300 finished_line_spanner_ = line_spanner_;
305 && cresc_p_->immutable_property_alist_ == SCM_EOL)
309 current_cresc_req_->origin ()->warning (_ ("unterminated (de)crescendo"));
310 cresc_p_->suicide ();
316 Dynamic_engraver::typeset_all ()
319 remove suicided spanners,
320 ugh: we'll need this for every spanner, beam, slur
321 Hmm, how to do this, cleanly?
322 Maybe just check at typeset_grob ()?
324 if (finished_cresc_p_
325 && finished_cresc_p_->immutable_property_alist_ == SCM_EOL)
326 finished_cresc_p_ = 0;
327 if (finished_line_spanner_
328 && finished_line_spanner_->immutable_property_alist_ == SCM_EOL)
329 finished_line_spanner_ = 0;
331 if (finished_cresc_p_)
333 if (!finished_cresc_p_->get_bound (RIGHT))
335 finished_cresc_p_->set_bound (RIGHT, script_p_
337 : unsmob_grob (get_property ("currentMusicalColumn")));
339 if (finished_line_spanner_)
340 add_bound_item (finished_line_spanner_,
341 finished_cresc_p_->get_bound (RIGHT));
343 typeset_grob (finished_cresc_p_);
344 finished_cresc_p_ =0;
349 typeset_grob (script_p_);
352 if (finished_line_spanner_)
354 /* To make sure that this works */
355 Side_position_interface::add_staff_support (finished_line_spanner_);
360 extend_spanner_over_elements (finished_line_spanner_);
362 but this is rather kludgy, since finished_line_spanner_
363 typically has a staff-symbol field set , extending it over the
368 Grob * l = finished_line_spanner_->get_bound (LEFT );
369 Grob * r = finished_line_spanner_->get_bound (RIGHT);
371 finished_line_spanner_->set_bound (RIGHT, l);
373 finished_line_spanner_->set_bound (LEFT, r);
377 This is a isolated dynamic apparently, and does not even have
378 any interesting support item.
380 Grob * cc = unsmob_grob (get_property ("currentMusicalColumn"));
381 Item * ci = dynamic_cast<Item*>(cc);
382 finished_line_spanner_->set_bound (RIGHT, ci);
383 finished_line_spanner_->set_bound (LEFT, ci);
386 typeset_grob (finished_line_spanner_);
387 finished_line_spanner_ = 0;
392 Dynamic_engraver::acknowledge_grob (Grob_info i)
394 if (Note_column::has_interface (i.grob_l_))
397 /* Don't refill killed spanner */
398 && line_spanner_->immutable_property_alist_ != SCM_EOL)
400 Side_position_interface::add_support (line_spanner_,i.grob_l_);
401 add_bound_item (line_spanner_,dynamic_cast<Item*> (i.grob_l_));
405 ENTER_DESCRIPTION(Dynamic_engraver,
407 This engraver creates hairpins, dynamic texts, and their vertical
408 alignments. The symbols are collected onto a DynamicLineSpanner grob
409 which takes care of vertical positioning.
412 /* creats*/ "DynamicLineSpanner DynamicText Hairpin TextSpanner",
413 /* acks */ "note-column-interface",