2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "engraver.hh"
23 #include "directional-element-interface.hh"
24 #include "international.hh"
25 #include "note-column.hh"
26 #include "paper-column.hh"
27 #include "rhythmic-head.hh"
28 #include "script-interface.hh"
29 #include "side-position-interface.hh"
31 #include "staff-symbol-referencer.hh"
33 #include "stream-event.hh"
36 #include "translator.icc"
49 class Script_engraver : public Engraver
51 vector<Script_tuple> scripts_;
54 void stop_translation_timestep ();
55 void process_music ();
57 DECLARE_TRANSLATOR_LISTENER (articulation);
58 DECLARE_ACKNOWLEDGER (rhythmic_head);
59 DECLARE_ACKNOWLEDGER (stem);
60 DECLARE_ACKNOWLEDGER (stem_tremolo);
61 DECLARE_ACKNOWLEDGER (tie);
62 DECLARE_END_ACKNOWLEDGER (tie);
63 DECLARE_ACKNOWLEDGER (note_column);
64 DECLARE_ACKNOWLEDGER (inline_accidental);
67 TRANSLATOR_DECLARATIONS (Script_engraver);
70 Script_engraver::Script_engraver ()
74 IMPLEMENT_TRANSLATOR_LISTENER (Script_engraver, articulation);
76 Script_engraver::listen_articulation (Stream_event *ev)
78 /* Discard double articulations for part-combining. */
79 for (vsize i = 0; i < scripts_.size (); i++)
80 if (ly_is_equal (scripts_[i].event_
81 ->get_property ("articulation-type"),
82 ev->get_property ("articulation-type")))
87 scripts_.push_back (t);
91 copy_property (Grob *g, SCM sym, SCM alist)
93 if (g->internal_get_property (sym) == SCM_EOL)
95 SCM entry = scm_assoc (sym, alist);
96 if (scm_is_pair (entry))
97 g->set_property (sym, scm_cdr (entry));
101 /* Add the properties, one by one for each Script. A little memory
102 could be saved by tacking the props onto the Script grob (i.e. make
103 ScriptStaccato , ScriptMarcato, etc. ).
106 make_script_from_event (Grob *p, Context *tg,
107 SCM art_type, int index)
109 SCM alist = tg->get_property ("scriptDefinitions");
110 SCM art = scm_assoc (art_type, alist);
112 if (art == SCM_BOOL_F)
115 warning (_ ("do not know how to interpret articulation:"));
116 warning (_ (" scheme encoding: "));
117 scm_write (art_type, scm_current_error_port ());
124 bool priority_found = false;
126 for (SCM s = art; scm_is_pair (s); s = scm_cdr (s))
128 SCM sym = scm_caar (s);
129 SCM type = scm_object_property (sym, ly_symbol2scm ("backend-type?"));
130 if (!ly_is_procedure (type))
133 SCM val = scm_cdar (s);
135 if (sym == ly_symbol2scm ("script-priority"))
137 priority_found = true;
138 /* Make sure they're in order of user input by adding index i.
139 Don't use the direction in this priority. Smaller means closer
141 int prio = scm_to_int (val) + index;
143 val = scm_from_int (prio);
146 SCM preset = p->get_property_data (sym);
148 || scm_call_1 (type, preset) == SCM_BOOL_F)
149 p->set_property (sym, val);
154 p->set_property ("script-priority",
155 scm_from_int (index));
160 Script_engraver::process_music ()
162 for (vsize i = 0; i < scripts_.size (); i++)
164 Stream_event *ev = scripts_[i].event_;
166 Grob *p = make_item ("Script", ev->self_scm ());
168 make_script_from_event (p, context (),
169 ev->get_property ("articulation-type"),
172 scripts_[i].script_ = p;
174 SCM force_dir = ev->get_property ("direction");
175 if (is_direction (force_dir) && to_dir (force_dir))
176 p->set_property ("direction", force_dir);
181 Script_engraver::acknowledge_stem (Grob_info info)
183 for (vsize i = 0; i < scripts_.size (); i++)
185 Grob *e = scripts_[i].script_;
187 if (to_dir (e->get_property ("side-relative-direction")))
188 e->set_object ("direction-source", info.grob ()->self_scm ());
190 Side_position_interface::add_support (e, info.grob ());
195 Script_engraver::acknowledge_stem_tremolo (Grob_info info)
197 for (vsize i = 0; i < scripts_.size (); i++)
199 Grob *e = scripts_[i].script_;
200 Side_position_interface::add_support (e, info.grob ());
205 Script_engraver::acknowledge_tie (Grob_info info)
207 for (vsize i = 0; i < scripts_.size (); i++)
209 Grob *e = scripts_[i].script_;
210 Side_position_interface::add_support (e, info.grob ());
215 Script_engraver::acknowledge_end_tie (Grob_info info)
217 for (vsize i = 0; i < scripts_.size (); i++)
219 Grob *e = scripts_[i].script_;
220 Side_position_interface::add_support (e, info.grob ());
225 Script_engraver::acknowledge_inline_accidental (Grob_info info)
227 for (vsize i = 0; i < scripts_.size (); i++)
229 Grob *e = scripts_[i].script_;
230 Side_position_interface::add_support (e, info.grob ());
235 Script_engraver::acknowledge_rhythmic_head (Grob_info info)
237 if (info.event_cause ())
239 for (vsize i = 0; i < scripts_.size (); i++)
241 Grob *e = scripts_[i].script_;
243 if (Side_position_interface::get_axis (e) == X_AXIS
244 && !e->get_parent (Y_AXIS))
246 e->set_parent (info.grob (), Y_AXIS);
248 Side_position_interface::add_support (e, info.grob ());
254 Script_engraver::acknowledge_note_column (Grob_info info)
256 /* Make note column the parent of the script. That is not
257 correct, but due to seconds in a chord, noteheads may be
258 swapped around horizontally.
260 As the note head to put it on is not known now, postpone this
261 decision to Script_interface::calc_direction (). */
262 for (vsize i = 0; i < scripts_.size (); i++)
264 Grob *e = scripts_[i].script_;
266 if (!e->get_parent (X_AXIS)
267 && Side_position_interface::get_axis (e) == Y_AXIS)
268 e->set_parent (info.grob (), X_AXIS);
273 Script_engraver::stop_translation_timestep ()
278 ADD_ACKNOWLEDGER (Script_engraver, rhythmic_head);
279 ADD_ACKNOWLEDGER (Script_engraver, stem);
280 ADD_ACKNOWLEDGER (Script_engraver, tie);
281 ADD_END_ACKNOWLEDGER (Script_engraver, tie);
282 ADD_ACKNOWLEDGER (Script_engraver, note_column);
283 ADD_ACKNOWLEDGER (Script_engraver, stem_tremolo);
284 ADD_ACKNOWLEDGER (Script_engraver, inline_accidental);
286 ADD_TRANSLATOR (Script_engraver,
288 "Handle note scripted articulations.",
294 "scriptDefinitions ",