2 dynamic-engraver.cc -- implement Dynamic_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "dimensions.hh"
10 #include "crescendo.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
31 print text & hairpin dynamics.
33 class Dynamic_engraver : public Engraver
36 Spanner * finished_cresc_p_;
39 Text_script_req* script_req_l_;
41 Span_req * current_cresc_req_;
42 Drul_array<Span_req*> accepted_spanreqs_drul_;
44 Spanner* line_spanner_;
45 Spanner* finished_line_spanner_;
47 Link_array<Note_column> pending_column_arr_;
48 Link_array<Grob> pending_element_arr_;
53 VIRTUAL_COPY_CONS(Translator);
57 virtual void finalize ();
58 virtual void acknowledge_grob (Grob_info);
59 virtual bool try_music (Music *req_l);
60 virtual void stop_translation_timestep ();
61 virtual void create_grobs ();
62 virtual void start_translation_timestep ();
65 ADD_THIS_TRANSLATOR (Dynamic_engraver);
68 Dynamic_engraver::Dynamic_engraver ()
71 finished_cresc_p_ = 0;
73 finished_line_spanner_ = 0;
74 current_cresc_req_ = 0;
78 accepted_spanreqs_drul_[START] = 0;
79 accepted_spanreqs_drul_[STOP] = 0;
83 Dynamic_engraver::start_translation_timestep ()
86 accepted_spanreqs_drul_[START] = 0;
87 accepted_spanreqs_drul_[STOP] = 0;
91 Dynamic_engraver::try_music (Music * m)
93 if (dynamic_cast <Text_script_req*> (m)
94 && m->get_mus_property ("text-type") == ly_symbol2scm ("dynamic"))
96 script_req_l_ = dynamic_cast<Text_script_req*> (m);
99 else if (Span_req* s = dynamic_cast <Span_req*> (m))
101 String t = ly_scm2string (s->get_mus_property ("span-type"));
104 accepted_spanreqs_drul_[LEFT] = 0;
105 accepted_spanreqs_drul_[RIGHT] = 0;
107 line_spanner_->suicide ();
110 cresc_p_->suicide ();
113 else if (t == "crescendo"
114 || t == "decrescendo")
116 accepted_spanreqs_drul_[s->get_span_dir()] = s;
124 Dynamic_engraver::create_grobs ()
126 if (accepted_spanreqs_drul_[START] || accepted_spanreqs_drul_[STOP] || script_req_l_)
131 line_spanner_ = new Spanner (get_property ("DynamicLineSpanner"));
133 Side_position::set_axis (line_spanner_, Y_AXIS);
134 Axis_group_interface::set_interface (line_spanner_);
135 Axis_group_interface::set_axes (line_spanner_, Y_AXIS, Y_AXIS);
137 Music * rq = accepted_spanreqs_drul_[START];
140 announce_grob (line_spanner_, rq);
147 finish side position alignment if the (de)cresc ends here, and
148 there are no new dynamics.
151 else if (accepted_spanreqs_drul_[STOP]
152 && !accepted_spanreqs_drul_[START] && !script_req_l_)
154 finished_line_spanner_ = line_spanner_;
159 todo: resurrect dynamic{direction, padding,minimumspace}
162 During a (de)crescendo, pending request will not be cleared,
163 and a line-spanner will always be created, as \< \! are already
166 Maybe always creating a line-spanner for a (de)crescendo (see
167 below) is not a good idea:
171 the \p will be centred on the line-spanner, and thus clash
172 with the hairpin. When axis-group code is in place, the \p
173 should move below the hairpin, which is probably better?
175 Urg, but line-spanner must always have at least same duration
176 as (de)crecsendo, b.o. line-breaking.
182 maybe we should leave dynamic texts to the text-engraver and
183 simply acknowledge them?
187 script_p_ = new Item (get_property ("DynamicText"));
188 script_p_->set_grob_property ("text",
189 script_req_l_->get_mus_property ("text"));
190 if (Direction d = script_req_l_->get_direction ())
191 Directional_element_interface::set (line_spanner_, d);
193 Axis_group_interface::add_element (line_spanner_, script_p_);
195 announce_grob (script_p_, script_req_l_);
198 if (accepted_spanreqs_drul_[STOP])
202 accepted_spanreqs_drul_[STOP]->origin ()->warning
203 (_ ("can't find start of (de)crescendo"));
207 assert (!finished_cresc_p_);
208 Grob* cc = unsmob_grob (get_property ("currentMusicalColumn"));
210 cresc_p_->set_bound (RIGHT, cc);
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_string_p (s) || ly_scm2string (s) == "hairpin")
243 cresc_p_ = new Spanner (get_property ("Crescendo"));
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);
258 daddy_trans_l_->set_property (start_type
259 + "Spanner", SCM_UNDEFINED);
260 s = get_property ((start_type + "Text").ch_C());
263 cresc_p_->set_grob_property ("edge-text",
264 gh_cons (s, ly_str02scm ("")));
265 daddy_trans_l_->set_property (start_type + "Text",
269 cresc_p_->set_bound (LEFT, script_p_
271 : unsmob_grob (get_property ("currentMusicalColumn")));
273 Axis_group_interface::add_element (line_spanner_, cresc_p_);
274 announce_grob (cresc_p_, accepted_spanreqs_drul_[START]);
278 accepted_spanreqs_drul_[START] = 0;
279 accepted_spanreqs_drul_[STOP] = 0;
283 Dynamic_engraver::stop_translation_timestep ()
289 Dynamic_engraver::finalize ()
294 finished_line_spanner_ = line_spanner_;
300 current_cresc_req_->origin ()->warning (_ ("unterminated (de)crescendo"));
301 cresc_p_->suicide ();
307 Dynamic_engraver::typeset_all ()
309 if (finished_cresc_p_)
311 finished_cresc_p_->set_bound (RIGHT, script_p_
313 : unsmob_grob (get_property ("currentMusicalColumn")));
315 typeset_grob (finished_cresc_p_);
316 finished_cresc_p_ =0;
321 typeset_grob (script_p_);
324 if (finished_line_spanner_)
326 Side_position::add_staff_support (finished_line_spanner_);
327 extend_spanner_over_elements (finished_line_spanner_);
328 typeset_grob (finished_line_spanner_);
329 finished_line_spanner_ = 0;
334 Dynamic_engraver::acknowledge_grob (Grob_info i)
336 if (Note_column::has_interface (i.elem_l_))
340 Side_position::add_support (line_spanner_,i.elem_l_);
341 add_bound_item (line_spanner_,dynamic_cast<Item*>(i.elem_l_));