2 script-engraver.cc -- engrave Scripts: Articulations.
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
12 #include "directional-element-interface.hh"
13 #include "international.hh"
14 #include "note-column.hh"
15 #include "paper-column.hh"
16 #include "rhythmic-head.hh"
17 #include "script-interface.hh"
18 #include "side-position-interface.hh"
20 #include "staff-symbol-referencer.hh"
35 class Script_engraver : public Engraver
37 vector<Script_tuple> scripts_;
41 virtual bool try_music (Music *);
42 void stop_translation_timestep ();
43 void process_music ();
45 DECLARE_ACKNOWLEDGER (slur);
46 DECLARE_ACKNOWLEDGER (rhythmic_head);
47 DECLARE_ACKNOWLEDGER (stem);
48 DECLARE_ACKNOWLEDGER (stem_tremolo);
49 DECLARE_ACKNOWLEDGER (note_column);
52 TRANSLATOR_DECLARATIONS (Script_engraver);
55 Script_engraver::Script_engraver ()
61 Script_engraver::try_music (Music *m)
63 if (m->is_mus_type ("articulation-event"))
65 /* Discard double articulations for part-combining. */
66 int script_count = scripts_.size ();
67 for (int i = 0; i < script_count; i++)
68 if (ly_is_equal (scripts_[i].event_
69 ->get_property ("articulation-type"),
70 m->get_property ("articulation-type")))
75 scripts_.push_back (t);
82 copy_property (Grob *g, SCM sym, SCM alist)
84 if (g->internal_get_property (sym) == SCM_EOL)
86 SCM entry = scm_assoc (sym, alist);
87 if (scm_is_pair (entry))
88 g->internal_set_property (sym, scm_cdr (entry));
92 /* Add the properties, one by one for each Script. A little memory
93 could be saved by tacking the props onto the Script grob (i.e. make
94 ScriptStaccato , ScriptMarcato, etc. ).
96 void make_script_from_event (Grob *p, Context *tg,
97 SCM art_type, int index)
99 SCM alist = tg->get_property ("scriptDefinitions");
100 SCM art = scm_assoc (art_type, alist);
102 if (art == SCM_BOOL_F)
105 warning (_ ("don't know how to interpret articulation: "));
106 warning (_ ("scheme encoding: "));
107 scm_write (art_type, scm_current_error_port ());
114 bool priority_found = false;
116 for (SCM s = art; scm_is_pair (s); s = scm_cdr (s))
118 SCM sym = scm_caar (s);
119 SCM type = scm_object_property (sym, ly_symbol2scm ("backend-type?"));
120 if (!ly_is_procedure (type))
123 SCM val = scm_cdar (s);
125 if (sym == ly_symbol2scm ("script-priority"))
127 priority_found = true;
128 /* Make sure they're in order of user input by adding index i.
129 Don't use the direction in this priority. Smaller means closer
131 int prio = scm_to_int (val) + index;
133 val = scm_from_int (prio);
136 SCM preset = p->get_property_data (sym);
138 || scm_call_1 (type, preset) == SCM_BOOL_F)
139 p->internal_set_property (sym, val);
144 p->set_property ("script-priority",
145 scm_from_int (index));
148 Side_position_interface::set_axis (p, Y_AXIS);
152 Script_engraver::process_music ()
154 for (vsize i = 0; i < scripts_.size (); i++)
156 Music *music = scripts_[i].event_;
158 Grob *p = make_item ("Script", music->self_scm ());
160 make_script_from_event (p, context (),
161 music->get_property ("articulation-type"),
164 scripts_[i].script_ = p;
166 SCM force_dir = music->get_property ("direction");
167 if (is_direction (force_dir) && to_dir (force_dir))
168 p->set_property ("direction", force_dir);
173 Script_engraver::acknowledge_stem (Grob_info info)
175 int script_count = scripts_.size ();
176 for (int i = 0; i < script_count; i++)
178 Grob *e = scripts_[i].script_;
180 if (to_dir (e->get_property ("side-relative-direction")))
181 e->set_object ("direction-source", info.grob ()->self_scm ());
183 Side_position_interface::add_support (e, info.grob ());
188 Script_engraver::acknowledge_stem_tremolo (Grob_info info)
190 int script_count = scripts_.size ();
191 for (int i = 0; i < script_count; i++)
193 Grob *e = scripts_[i].script_;
194 Side_position_interface::add_support (e, info.grob ());
200 Script_engraver::acknowledge_rhythmic_head (Grob_info info)
202 if (info.music_cause ())
204 for (vsize i = 0; i < scripts_.size (); i++)
206 Grob *e = scripts_[i].script_;
208 if (Side_position_interface::get_axis (e) == X_AXIS
209 && !e->get_parent (Y_AXIS))
211 e->set_parent (info.grob (), Y_AXIS);
213 Side_position_interface::add_support (e, info.grob ());
219 Script_engraver::acknowledge_note_column (Grob_info info)
221 /* Make note column the parent of the script. That is not
222 correct, but due to seconds in a chord, noteheads may be
223 swapped around horizontally.
225 As the note head to put it on is not known now, postpone this
226 decision to Script_interface::calc_direction (). */
227 for (vsize i = 0; i < scripts_.size (); i++)
229 Grob *e = scripts_[i].script_;
231 if (!e->get_parent (X_AXIS)
232 && Side_position_interface::get_axis (e) == Y_AXIS)
233 e->set_parent (info.grob (), X_AXIS);
238 Script_engraver::acknowledge_slur (Grob_info info)
240 slur_ = info.spanner ();
244 Script_engraver::stop_translation_timestep ()
249 #include "translator.icc"
251 ADD_ACKNOWLEDGER (Script_engraver, slur);
252 ADD_ACKNOWLEDGER (Script_engraver, rhythmic_head);
253 ADD_ACKNOWLEDGER (Script_engraver, stem);
254 ADD_ACKNOWLEDGER (Script_engraver, note_column);
255 ADD_ACKNOWLEDGER (Script_engraver, stem_tremolo);
257 ADD_TRANSLATOR (Script_engraver,
258 /* doc */ "Handles note scripted articulations.",
259 /* create */ "Script",
260 /* accept */ "script-event articulation-event",
261 /* read */ "scriptDefinitions",