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"
22 #include "stream-event.hh"
25 #include "translator.icc"
38 class Script_engraver : public Engraver
40 vector<Script_tuple> scripts_;
44 void stop_translation_timestep ();
45 void process_music ();
47 DECLARE_TRANSLATOR_LISTENER (articulation);
48 DECLARE_ACKNOWLEDGER (slur);
49 DECLARE_ACKNOWLEDGER (rhythmic_head);
50 DECLARE_ACKNOWLEDGER (stem);
51 DECLARE_ACKNOWLEDGER (stem_tremolo);
52 DECLARE_ACKNOWLEDGER (note_column);
55 TRANSLATOR_DECLARATIONS (Script_engraver);
58 Script_engraver::Script_engraver ()
63 IMPLEMENT_TRANSLATOR_LISTENER (Script_engraver, articulation);
65 Script_engraver::listen_articulation (Stream_event *ev)
67 /* Discard double articulations for part-combining. */
68 int script_count = scripts_.size ();
69 for (int i = 0; i < script_count; i++)
70 if (ly_is_equal (scripts_[i].event_
71 ->get_property ("articulation-type"),
72 ev->get_property ("articulation-type")))
77 scripts_.push_back (t);
81 copy_property (Grob *g, SCM sym, SCM alist)
83 if (g->internal_get_property (sym) == SCM_EOL)
85 SCM entry = scm_assoc (sym, alist);
86 if (scm_is_pair (entry))
87 g->internal_set_property (sym, scm_cdr (entry));
91 /* Add the properties, one by one for each Script. A little memory
92 could be saved by tacking the props onto the Script grob (i.e. make
93 ScriptStaccato , ScriptMarcato, etc. ).
95 void make_script_from_event (Grob *p, Context *tg,
96 SCM art_type, int index)
98 SCM alist = tg->get_property ("scriptDefinitions");
99 SCM art = scm_assoc (art_type, alist);
101 if (art == SCM_BOOL_F)
104 warning (_ ("don't know how to interpret articulation: "));
105 warning (_ ("scheme encoding: "));
106 scm_write (art_type, scm_current_error_port ());
113 bool priority_found = false;
115 for (SCM s = art; scm_is_pair (s); s = scm_cdr (s))
117 SCM sym = scm_caar (s);
118 SCM type = scm_object_property (sym, ly_symbol2scm ("backend-type?"));
119 if (!ly_is_procedure (type))
122 SCM val = scm_cdar (s);
124 if (sym == ly_symbol2scm ("script-priority"))
126 priority_found = true;
127 /* Make sure they're in order of user input by adding index i.
128 Don't use the direction in this priority. Smaller means closer
130 int prio = scm_to_int (val) + index;
132 val = scm_from_int (prio);
135 SCM preset = p->get_property_data (sym);
137 || scm_call_1 (type, preset) == SCM_BOOL_F)
138 p->internal_set_property (sym, val);
143 p->set_property ("script-priority",
144 scm_from_int (index));
147 Side_position_interface::set_axis (p, Y_AXIS);
151 Script_engraver::process_music ()
153 for (vsize i = 0; i < scripts_.size (); i++)
155 Stream_event *ev = scripts_[i].event_;
157 Grob *p = make_item ("Script", ev->self_scm ());
159 make_script_from_event (p, context (),
160 ev->get_property ("articulation-type"),
163 scripts_[i].script_ = p;
165 SCM force_dir = ev->get_property ("direction");
166 if (is_direction (force_dir) && to_dir (force_dir))
167 p->set_property ("direction", force_dir);
172 Script_engraver::acknowledge_stem (Grob_info info)
174 int script_count = scripts_.size ();
175 for (int i = 0; i < script_count; i++)
177 Grob *e = scripts_[i].script_;
179 if (to_dir (e->get_property ("side-relative-direction")))
180 e->set_object ("direction-source", info.grob ()->self_scm ());
182 Side_position_interface::add_support (e, info.grob ());
187 Script_engraver::acknowledge_stem_tremolo (Grob_info info)
189 int script_count = scripts_.size ();
190 for (int i = 0; i < script_count; i++)
192 Grob *e = scripts_[i].script_;
193 Side_position_interface::add_support (e, info.grob ());
199 Script_engraver::acknowledge_rhythmic_head (Grob_info info)
201 if (info.event_cause ())
203 for (vsize i = 0; i < scripts_.size (); i++)
205 Grob *e = scripts_[i].script_;
207 if (Side_position_interface::get_axis (e) == X_AXIS
208 && !e->get_parent (Y_AXIS))
210 e->set_parent (info.grob (), Y_AXIS);
212 Side_position_interface::add_support (e, info.grob ());
218 Script_engraver::acknowledge_note_column (Grob_info info)
220 /* Make note column the parent of the script. That is not
221 correct, but due to seconds in a chord, noteheads may be
222 swapped around horizontally.
224 As the note head to put it on is not known now, postpone this
225 decision to Script_interface::calc_direction (). */
226 for (vsize i = 0; i < scripts_.size (); i++)
228 Grob *e = scripts_[i].script_;
230 if (!e->get_parent (X_AXIS)
231 && Side_position_interface::get_axis (e) == Y_AXIS)
232 e->set_parent (info.grob (), X_AXIS);
237 Script_engraver::acknowledge_slur (Grob_info info)
239 slur_ = info.spanner ();
243 Script_engraver::stop_translation_timestep ()
248 ADD_ACKNOWLEDGER (Script_engraver, slur);
249 ADD_ACKNOWLEDGER (Script_engraver, rhythmic_head);
250 ADD_ACKNOWLEDGER (Script_engraver, stem);
251 ADD_ACKNOWLEDGER (Script_engraver, note_column);
252 ADD_ACKNOWLEDGER (Script_engraver, stem_tremolo);
254 ADD_TRANSLATOR (Script_engraver,
255 /* doc */ "Handles note scripted articulations.",
256 /* create */ "Script",
257 /* accept */ "script-event articulation-event",
258 /* read */ "scriptDefinitions",