2 new-dynamic-engraver.cc -- implement New_dynamic_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2008--2009 Han-Wen Nienhuys <hanwen@lilypond.org>
11 #include "engraver.hh"
14 #include "international.hh"
16 #include "note-column.hh"
17 #include "pointer-group-interface.hh"
18 #include "self-alignment-interface.hh"
20 #include "stream-event.hh"
21 #include "text-interface.hh"
23 #include "translator.icc"
25 class New_dynamic_engraver : public Engraver
27 TRANSLATOR_DECLARATIONS (New_dynamic_engraver);
28 DECLARE_ACKNOWLEDGER (note_column);
29 DECLARE_TRANSLATOR_LISTENER (absolute_dynamic);
30 DECLARE_TRANSLATOR_LISTENER (span_dynamic);
33 virtual void process_music ();
34 virtual void stop_translation_timestep ();
36 Drul_array<Stream_event *> accepted_spanevents_drul_;
37 Spanner *current_spanner_;
38 Spanner *finished_spanner_;
41 Stream_event *script_event_;
42 Stream_event *current_span_event_;
45 New_dynamic_engraver::New_dynamic_engraver ()
48 current_span_event_ = 0;
50 finished_spanner_ = 0;
52 accepted_spanevents_drul_.set (0, 0);
55 IMPLEMENT_TRANSLATOR_LISTENER (New_dynamic_engraver, absolute_dynamic);
57 New_dynamic_engraver::listen_absolute_dynamic (Stream_event *ev)
59 ASSIGN_EVENT_ONCE (script_event_, ev);
62 IMPLEMENT_TRANSLATOR_LISTENER (New_dynamic_engraver, span_dynamic);
64 New_dynamic_engraver::listen_span_dynamic (Stream_event *ev)
66 Direction d = to_dir (ev->get_property ("span-direction"));
68 ASSIGN_EVENT_ONCE (accepted_spanevents_drul_[d], ev);
73 New_dynamic_engraver::process_music ()
76 && (accepted_spanevents_drul_[STOP] || script_event_ || accepted_spanevents_drul_[START]))
78 Stream_event* ender = accepted_spanevents_drul_[STOP];
80 ender = script_event_;
83 ender = accepted_spanevents_drul_[START];
85 finished_spanner_ = current_spanner_;
86 announce_end_grob (finished_spanner_, ender->self_scm ());
88 current_span_event_ = 0;
91 if (accepted_spanevents_drul_[START])
93 current_span_event_ = accepted_spanevents_drul_[START];
95 SCM start_sym = current_span_event_->get_property ("class");
98 if (start_sym == ly_symbol2scm ("decrescendo-event"))
99 start_type = "decrescendo";
100 else if (start_sym == ly_symbol2scm ("crescendo-event"))
101 start_type = "crescendo";
104 programming_error ("unknown dynamic spanner type");
108 SCM cresc_type = get_property ((start_type + "Spanner").c_str ());
110 if (cresc_type == ly_symbol2scm ("text"))
113 = make_spanner ("DynamicTextSpanner",
114 accepted_spanevents_drul_[START]->self_scm ());
116 SCM text = get_property ((start_type + "Text").c_str ());
117 if (Text_interface::is_markup (text))
119 current_spanner_->set_property ("text", text);
124 if (cresc_type != ly_symbol2scm ("hairpin"))
126 // Fixme: should put value in error message.
127 string as_string = ly_scm_write_string (cresc_type);
129 ->origin()->warning (_f ("unknown crescendo style: %s\ndefaulting to hairpin.", as_string.c_str()));
131 current_spanner_ = make_spanner ("Hairpin",
132 current_span_event_->self_scm ());
133 if (finished_spanner_)
135 Pointer_group_interface::add_grob (finished_spanner_,
136 ly_symbol2scm ("adjacent-hairpins"),
139 Pointer_group_interface::add_grob (current_spanner_,
140 ly_symbol2scm ("adjacent-hairpins"),
148 script_ = make_item ("DynamicText", script_event_->self_scm ());
149 script_->set_property ("text",
150 script_event_->get_property ("text"));
152 if (finished_spanner_)
153 finished_spanner_->set_bound (RIGHT, script_);
154 if (current_spanner_)
156 current_spanner_->set_bound (LEFT, script_);
158 if (!Hairpin::has_interface (current_spanner_))
159 set_nested_property (current_spanner_,
160 scm_list_3 (ly_symbol2scm ("bound-details"),
161 ly_symbol2scm ("left"),
162 ly_symbol2scm ("attach-dir")
164 scm_from_int (RIGHT));
173 New_dynamic_engraver::stop_translation_timestep ()
175 if (finished_spanner_ && !finished_spanner_->get_bound (RIGHT))
176 finished_spanner_->set_bound (RIGHT,
177 unsmob_grob (get_property ("currentMusicalColumn")));
179 if (current_spanner_ && !current_spanner_->get_bound (LEFT))
180 current_spanner_->set_bound (LEFT,
181 unsmob_grob (get_property ("currentMusicalColumn")));
184 accepted_spanevents_drul_.set (0, 0);
185 finished_spanner_ = 0;
189 New_dynamic_engraver::acknowledge_note_column (Grob_info info)
191 if (script_ && !script_->get_parent (X_AXIS))
193 extract_grob_set (info.grob (), "note-heads", heads);
196 Grob *head = heads[0];
197 script_->set_parent (head, X_AXIS);
198 Self_alignment_interface::set_center_parent (script_, X_AXIS);
202 if (current_spanner_ && !current_spanner_->get_bound (LEFT))
203 current_spanner_->set_bound (LEFT, info.grob ());
204 if (finished_spanner_ && !finished_spanner_->get_bound (RIGHT))
205 finished_spanner_->set_bound (RIGHT, info.grob ());
208 ADD_ACKNOWLEDGER (New_dynamic_engraver, note_column);
209 ADD_TRANSLATOR (New_dynamic_engraver,
211 "Create hairpins, dynamic texts, and their vertical"
212 " alignments. The symbols are collected onto a"
213 " @code{DynamicLineSpanner} grob which takes care of vertical"
217 "DynamicTextSpanner "
224 "currentMusicalColumn "
225 "decrescendoSpanner "