2 script-engraver.cc -- engrave Scripts: Articulations.
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 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_;
43 void stop_translation_timestep ();
44 void process_music ();
46 DECLARE_TRANSLATOR_LISTENER (articulation);
47 DECLARE_ACKNOWLEDGER (rhythmic_head);
48 DECLARE_ACKNOWLEDGER (stem);
49 DECLARE_ACKNOWLEDGER (stem_tremolo);
50 DECLARE_ACKNOWLEDGER (note_column);
53 TRANSLATOR_DECLARATIONS (Script_engraver);
56 Script_engraver::Script_engraver ()
60 IMPLEMENT_TRANSLATOR_LISTENER (Script_engraver, articulation);
62 Script_engraver::listen_articulation (Stream_event *ev)
64 /* Discard double articulations for part-combining. */
65 int script_count = scripts_.size ();
66 for (int i = 0; i < script_count; i++)
67 if (ly_is_equal (scripts_[i].event_
68 ->get_property ("articulation-type"),
69 ev->get_property ("articulation-type")))
74 scripts_.push_back (t);
78 copy_property (Grob *g, SCM sym, SCM alist)
80 if (g->internal_get_property (sym) == SCM_EOL)
82 SCM entry = scm_assoc (sym, alist);
83 if (scm_is_pair (entry))
84 g->set_property (sym, scm_cdr (entry));
88 /* Add the properties, one by one for each Script. A little memory
89 could be saved by tacking the props onto the Script grob (i.e. make
90 ScriptStaccato , ScriptMarcato, etc. ).
93 make_script_from_event (Grob *p, Context *tg,
94 SCM art_type, int index)
96 SCM alist = tg->get_property ("scriptDefinitions");
97 SCM art = scm_assoc (art_type, alist);
99 if (art == SCM_BOOL_F)
102 warning (_ ("do not know how to interpret articulation: "));
103 warning (_ ("scheme encoding: "));
104 scm_write (art_type, scm_current_error_port ());
111 bool priority_found = false;
113 for (SCM s = art; scm_is_pair (s); s = scm_cdr (s))
115 SCM sym = scm_caar (s);
116 SCM type = scm_object_property (sym, ly_symbol2scm ("backend-type?"));
117 if (!ly_is_procedure (type))
120 SCM val = scm_cdar (s);
122 if (sym == ly_symbol2scm ("script-priority"))
124 priority_found = true;
125 /* Make sure they're in order of user input by adding index i.
126 Don't use the direction in this priority. Smaller means closer
128 int prio = scm_to_int (val) + index;
130 val = scm_from_int (prio);
133 SCM preset = p->get_property_data (sym);
135 || scm_call_1 (type, preset) == SCM_BOOL_F)
136 p->set_property (sym, val);
141 p->set_property ("script-priority",
142 scm_from_int (index));
147 Script_engraver::process_music ()
149 for (vsize i = 0; i < scripts_.size (); i++)
151 Stream_event *ev = scripts_[i].event_;
153 Grob *p = make_item ("Script", ev->self_scm ());
155 make_script_from_event (p, context (),
156 ev->get_property ("articulation-type"),
159 scripts_[i].script_ = p;
161 SCM force_dir = ev->get_property ("direction");
162 if (is_direction (force_dir) && to_dir (force_dir))
163 p->set_property ("direction", force_dir);
168 Script_engraver::acknowledge_stem (Grob_info info)
170 int script_count = scripts_.size ();
171 for (int i = 0; i < script_count; i++)
173 Grob *e = scripts_[i].script_;
175 if (to_dir (e->get_property ("side-relative-direction")))
176 e->set_object ("direction-source", info.grob ()->self_scm ());
178 Side_position_interface::add_support (e, info.grob ());
183 Script_engraver::acknowledge_stem_tremolo (Grob_info info)
185 int script_count = scripts_.size ();
186 for (int i = 0; i < script_count; i++)
188 Grob *e = scripts_[i].script_;
189 Side_position_interface::add_support (e, info.grob ());
195 Script_engraver::acknowledge_rhythmic_head (Grob_info info)
197 if (info.event_cause ())
199 for (vsize i = 0; i < scripts_.size (); i++)
201 Grob *e = scripts_[i].script_;
203 if (Side_position_interface::get_axis (e) == X_AXIS
204 && !e->get_parent (Y_AXIS))
206 e->set_parent (info.grob (), Y_AXIS);
208 Side_position_interface::add_support (e, info.grob ());
214 Script_engraver::acknowledge_note_column (Grob_info info)
216 /* Make note column the parent of the script. That is not
217 correct, but due to seconds in a chord, noteheads may be
218 swapped around horizontally.
220 As the note head to put it on is not known now, postpone this
221 decision to Script_interface::calc_direction (). */
222 for (vsize i = 0; i < scripts_.size (); i++)
224 Grob *e = scripts_[i].script_;
226 if (!e->get_parent (X_AXIS)
227 && Side_position_interface::get_axis (e) == Y_AXIS)
228 e->set_parent (info.grob (), X_AXIS);
233 Script_engraver::stop_translation_timestep ()
238 ADD_ACKNOWLEDGER (Script_engraver, rhythmic_head);
239 ADD_ACKNOWLEDGER (Script_engraver, stem);
240 ADD_ACKNOWLEDGER (Script_engraver, note_column);
241 ADD_ACKNOWLEDGER (Script_engraver, stem_tremolo);
243 ADD_TRANSLATOR (Script_engraver,
245 "Handle note scripted articulations.",
251 "scriptDefinitions ",