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_;
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 (_ ("don't 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));
145 Side_position_interface::set_axis (p, Y_AXIS);
149 Script_engraver::process_music ()
151 for (vsize i = 0; i < scripts_.size (); i++)
153 Stream_event *ev = scripts_[i].event_;
155 Grob *p = make_item ("Script", ev->self_scm ());
157 make_script_from_event (p, context (),
158 ev->get_property ("articulation-type"),
161 scripts_[i].script_ = p;
163 SCM force_dir = ev->get_property ("direction");
164 if (is_direction (force_dir) && to_dir (force_dir))
165 p->set_property ("direction", force_dir);
170 Script_engraver::acknowledge_stem (Grob_info info)
172 int script_count = scripts_.size ();
173 for (int i = 0; i < script_count; i++)
175 Grob *e = scripts_[i].script_;
177 if (to_dir (e->get_property ("side-relative-direction")))
178 e->set_object ("direction-source", info.grob ()->self_scm ());
180 Side_position_interface::add_support (e, info.grob ());
185 Script_engraver::acknowledge_stem_tremolo (Grob_info info)
187 int script_count = scripts_.size ();
188 for (int i = 0; i < script_count; i++)
190 Grob *e = scripts_[i].script_;
191 Side_position_interface::add_support (e, info.grob ());
197 Script_engraver::acknowledge_rhythmic_head (Grob_info info)
199 if (info.event_cause ())
201 for (vsize i = 0; i < scripts_.size (); i++)
203 Grob *e = scripts_[i].script_;
205 if (Side_position_interface::get_axis (e) == X_AXIS
206 && !e->get_parent (Y_AXIS))
208 e->set_parent (info.grob (), Y_AXIS);
210 Side_position_interface::add_support (e, info.grob ());
216 Script_engraver::acknowledge_note_column (Grob_info info)
218 /* Make note column the parent of the script. That is not
219 correct, but due to seconds in a chord, noteheads may be
220 swapped around horizontally.
222 As the note head to put it on is not known now, postpone this
223 decision to Script_interface::calc_direction (). */
224 for (vsize i = 0; i < scripts_.size (); i++)
226 Grob *e = scripts_[i].script_;
228 if (!e->get_parent (X_AXIS)
229 && Side_position_interface::get_axis (e) == Y_AXIS)
230 e->set_parent (info.grob (), X_AXIS);
235 Script_engraver::stop_translation_timestep ()
240 ADD_ACKNOWLEDGER (Script_engraver, rhythmic_head);
241 ADD_ACKNOWLEDGER (Script_engraver, stem);
242 ADD_ACKNOWLEDGER (Script_engraver, note_column);
243 ADD_ACKNOWLEDGER (Script_engraver, stem_tremolo);
245 ADD_TRANSLATOR (Script_engraver,
246 /* doc */ "Handles note scripted articulations.",
247 /* create */ "Script",
248 /* accept */ "script-event articulation-event",
249 /* read */ "scriptDefinitions",