2 script-engraver.cc -- engrave Scripts: Articulations.
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "directional-element-interface.hh"
11 #include "engraver.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"
19 #include "staff-symbol-referencer.hh"
27 bool follow_into_staff_;
30 follow_into_staff_ = false;
36 class Script_engraver : public Engraver
38 Array<Script_tuple> scripts_;
42 virtual bool try_music (Music*);
43 virtual void stop_translation_timestep ();
44 virtual void process_music ();
45 virtual void acknowledge_grob (Grob_info);
48 TRANSLATOR_DECLARATIONS (Script_engraver);
51 Script_engraver::Script_engraver ()
57 Script_engraver::try_music (Music *m)
59 if (m->is_mus_type ("articulation-event"))
61 /* Discard double articulations for part-combining. */
62 int script_count = scripts_.size ();
63 for (int i = 0; i < script_count; i++)
64 if (ly_c_equal_p (scripts_[i].event_
65 ->get_property ("articulation-type"),
66 m->get_property ("articulation-type")))
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 (ly_c_pair_p (entry))
84 g->internal_set_property (sym, ly_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 void make_script_from_event (Grob *p, bool * follow, 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 ());
110 SCM follow_scm = scm_assoc (ly_symbol2scm ("follow-into-staff"),
113 *follow = ly_c_pair_p (follow_scm) && to_boolean (ly_cdr (follow_scm));
114 bool priority_found = false ;
116 for (SCM s = art ; ly_c_pair_p (s); s = ly_cdr (s))
118 SCM sym = ly_caar (s);
119 SCM type = scm_object_property (sym, ly_symbol2scm ("backend-type?"));
120 if (!ly_c_procedure_p (type))
123 SCM val = ly_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;
134 val = scm_int2num (prio);
136 if (p->internal_get_property (sym) == SCM_EOL)
137 p->internal_set_property (sym, val);
142 p->set_property ("script-priority",
143 scm_int2num (index));
146 Side_position_interface::set_axis (p, Y_AXIS);
151 Script_engraver::process_music ()
153 int script_count = scripts_.size ();
154 for (int i = 0; i < script_count; i++)
156 Music *m = scripts_[i].event_;
158 Grob *p = make_item ("Script", m->self_scm ());
160 make_script_from_event (p, &scripts_[i].follow_into_staff_, context (),
161 m->get_property ("articulation-type"),
164 scripts_[i].script_ = p;
166 SCM force_dir = m->get_property ("direction");
167 if (is_direction (force_dir) && to_dir (force_dir))
168 p->set_property ("direction", force_dir);
173 Script_engraver::acknowledge_grob (Grob_info info)
175 int script_count = scripts_.size ();
176 if (Stem::has_interface (info.grob_))
178 for (int i = 0; i < script_count; i++)
180 Grob *e = scripts_[i].script_;
182 if (to_dir (e->get_property ("side-relative-direction")))
183 e->set_property ("direction-source", info.grob_->self_scm ());
185 /* FIXME: add dependency */
186 e->add_dependency (info.grob_);
187 Side_position_interface::add_support (e, info.grob_);
190 else if (Rhythmic_head::has_interface (info.grob_)
191 && info.music_cause ())
193 for (int i = 0; i < script_count; i++)
195 Grob *e = scripts_[i].script_;
197 if (Side_position_interface::get_axis (e) == X_AXIS
198 && !e->get_parent (Y_AXIS))
200 e->set_parent (info.grob_, Y_AXIS);
201 e->add_dependency (info.grob_);
203 Side_position_interface::add_support (e,info.grob_);
206 else if (Note_column::has_interface (info.grob_))
208 /* Make note column the parent of the script. That is not
209 correct, but due to seconds in a chord, noteheads may be
210 swapped around horizontally.
212 As the note head to put it on is not known now, postpone this
213 decision to Script_interface::before_line_breaking (). */
214 for (int i = 0; i < script_count; i++)
216 Grob *e = scripts_[i].script_;
218 if (!e->get_parent (X_AXIS)
219 && Side_position_interface::get_axis (e) == Y_AXIS)
220 e->set_parent (info.grob_, X_AXIS);
223 else if (Slur::has_interface (info.grob_))
224 slur_ = dynamic_cast<Spanner*> (info.grob_);
228 Script_engraver::stop_translation_timestep ()
230 int script_count = scripts_.size ();
231 for (int i = 0; i < script_count; i++)
232 if (scripts_[i].follow_into_staff_)
234 Grob *sc = scripts_[i].script_;
235 sc->add_offset_callback (Side_position_interface
236 ::quantised_position_proc, Y_AXIS);
237 sc->set_property ("staff-padding", SCM_EOL);
243 ENTER_DESCRIPTION (Script_engraver,
244 /* descr */ "Handles note scripted articulations.",
245 /* creats*/ "Script",
246 /* accepts */ "script-event articulation-event",
247 /* acks */ "stem-interface rhythmic-head-interface "
248 "slur-interface note-column-interface",
249 /* reads */ "scriptDefinitions",