2 script-engraver.cc -- engrave Scripts: Articulations.
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "directional-element-interface.hh"
11 #include "engraver.hh"
13 #include "note-column.hh"
14 #include "paper-column.hh"
15 #include "rhythmic-head.hh"
16 #include "script-interface.hh"
17 #include "side-position-interface.hh"
18 #include "staff-symbol-referencer.hh"
33 class Script_engraver : public Engraver
35 Array<Script_tuple> scripts_;
39 virtual bool try_music (Music *);
40 void stop_translation_timestep ();
41 void process_music ();
43 DECLARE_ACKNOWLEDGER (slur);
44 DECLARE_ACKNOWLEDGER (rhythmic_head);
45 DECLARE_ACKNOWLEDGER (stem);
46 DECLARE_ACKNOWLEDGER (stem_tremolo);
47 DECLARE_ACKNOWLEDGER (note_column);
50 TRANSLATOR_DECLARATIONS (Script_engraver);
53 Script_engraver::Script_engraver ()
59 Script_engraver::try_music (Music *m)
61 if (m->is_mus_type ("articulation-event"))
63 /* Discard double articulations for part-combining. */
64 int script_count = scripts_.size ();
65 for (int i = 0; i < script_count; i++)
66 if (ly_is_equal (scripts_[i].event_
67 ->get_property ("articulation-type"),
68 m->get_property ("articulation-type")))
80 copy_property (Grob *g, SCM sym, SCM alist)
82 if (g->internal_get_property (sym) == SCM_EOL)
84 SCM entry = scm_assoc (sym, alist);
85 if (scm_is_pair (entry))
86 g->internal_set_property (sym, scm_cdr (entry));
90 /* Add the properties, one by one for each Script. A little memory
91 could be saved by tacking the props onto the Script grob (i.e. make
92 ScriptStaccato , ScriptMarcato, etc. ).
94 void make_script_from_event (Grob *p, Context *tg,
95 SCM art_type, int index)
97 SCM alist = tg->get_property ("scriptDefinitions");
98 SCM art = scm_assoc (art_type, alist);
100 if (art == SCM_BOOL_F)
103 warning (_ ("don't know how to interpret articulation: "));
104 warning (_ ("scheme encoding: "));
105 scm_write (art_type, scm_current_error_port ());
112 bool priority_found = false;
114 for (SCM s = art; scm_is_pair (s); s = scm_cdr (s))
116 SCM sym = scm_caar (s);
117 SCM type = scm_object_property (sym, ly_symbol2scm ("backend-type?"));
118 if (!ly_is_procedure (type))
121 SCM val = scm_cdar (s);
123 if (sym == ly_symbol2scm ("script-priority"))
125 priority_found = true;
126 /* Make sure they're in order of user input by adding index i.
127 Don't use the direction in this priority. Smaller means closer
129 int prio = scm_to_int (val) + index;
131 val = scm_from_int (prio);
134 SCM preset = p->get_property_data (sym);
136 || scm_call_1 (type, preset) == SCM_BOOL_F)
137 p->internal_set_property (sym, val);
142 p->set_property ("script-priority",
143 scm_from_int (index));
146 Side_position_interface::set_axis (p, Y_AXIS);
150 Script_engraver::process_music ()
152 for (int i = 0; i < scripts_.size (); i++)
154 Music *music = scripts_[i].event_;
156 Grob *p = make_item ("Script", music->self_scm ());
158 make_script_from_event (p, context (),
159 music->get_property ("articulation-type"),
162 scripts_[i].script_ = p;
164 SCM force_dir = music->get_property ("direction");
165 if (is_direction (force_dir) && to_dir (force_dir))
166 p->set_property ("direction", force_dir);
171 Script_engraver::acknowledge_stem (Grob_info info)
173 int script_count = scripts_.size ();
174 for (int i = 0; i < script_count; i++)
176 Grob *e = scripts_[i].script_;
178 if (to_dir (e->get_property ("side-relative-direction")))
179 e->set_object ("direction-source", info.grob ()->self_scm ());
181 Side_position_interface::add_support (e, info.grob ());
186 Script_engraver::acknowledge_stem_tremolo (Grob_info info)
188 int script_count = scripts_.size ();
189 for (int i = 0; i < script_count; i++)
191 Grob *e = scripts_[i].script_;
192 Side_position_interface::add_support (e, info.grob ());
198 Script_engraver::acknowledge_rhythmic_head (Grob_info info)
200 if (info.music_cause ())
202 for (int i = 0; i < scripts_.size (); i++)
204 Grob *e = scripts_[i].script_;
206 if (Side_position_interface::get_axis (e) == X_AXIS
207 && !e->get_parent (Y_AXIS))
209 e->set_parent (info.grob (), Y_AXIS);
211 Side_position_interface::add_support (e, info.grob ());
217 Script_engraver::acknowledge_note_column (Grob_info info)
219 /* Make note column the parent of the script. That is not
220 correct, but due to seconds in a chord, noteheads may be
221 swapped around horizontally.
223 As the note head to put it on is not known now, postpone this
224 decision to Script_interface::calc_direction (). */
225 for (int i = 0; i < scripts_.size (); i++)
227 Grob *e = scripts_[i].script_;
229 if (!e->get_parent (X_AXIS)
230 && Side_position_interface::get_axis (e) == Y_AXIS)
231 e->set_parent (info.grob (), X_AXIS);
236 Script_engraver::acknowledge_slur (Grob_info info)
238 slur_ = info.spanner ();
242 Script_engraver::stop_translation_timestep ()
247 #include "translator.icc"
249 ADD_ACKNOWLEDGER (Script_engraver, slur);
250 ADD_ACKNOWLEDGER (Script_engraver, rhythmic_head);
251 ADD_ACKNOWLEDGER (Script_engraver, stem);
252 ADD_ACKNOWLEDGER (Script_engraver, note_column);
253 ADD_ACKNOWLEDGER (Script_engraver, stem_tremolo);
255 ADD_TRANSLATOR (Script_engraver,
256 /* doc */ "Handles note scripted articulations.",
257 /* create */ "Script",
258 /* accept */ "script-event articulation-event",
259 /* read */ "scriptDefinitions",