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"
13 #include "note-column.hh"
14 #include "paper-column.hh"
15 #include "rhythmic-head.hh"
16 #include "script-interface.hh"
17 #include "side-position-interface.hh"
18 #include "staff-symbol-referencer.hh"
26 bool follow_into_staff_;
29 follow_into_staff_ = false;
35 class Script_engraver : public Engraver
37 Array<Script_tuple> scripts_;
41 virtual bool try_music (Music*);
42 virtual void stop_translation_timestep ();
43 virtual void process_music ();
44 virtual void acknowledge_grob (Grob_info);
47 TRANSLATOR_DECLARATIONS (Script_engraver);
50 Script_engraver::Script_engraver ()
56 Script_engraver::try_music (Music *m)
58 if (m->is_mus_type ("articulation-event"))
60 /* Discard double articulations for part-combining. */
61 int script_count = scripts_.size ();
62 for (int i = 0; i < script_count; i++)
63 if (ly_c_equal_p (scripts_[i].event_
64 ->get_property ("articulation-type"),
65 m->get_property ("articulation-type")))
77 copy_property (Grob *g, SCM sym, SCM alist)
79 if (g->internal_get_property (sym) == SCM_EOL)
81 SCM entry = scm_assoc (sym, alist);
82 if (scm_is_pair (entry))
83 g->internal_set_property (sym, scm_cdr (entry));
87 /* Add the properties, one by one for each Script. A little memory
88 could be saved by tacking the props onto the Script grob (i.e. make
89 ScriptStaccato , ScriptMarcato, etc. ).
92 void make_script_from_event (Grob *p, bool * follow, Context *tg,
93 SCM art_type, int index)
95 SCM alist = tg->get_property ("scriptDefinitions");
96 SCM art = scm_assoc (art_type, alist);
98 if (art == SCM_BOOL_F)
101 warning (_ ("Do not know how to interpret articulation: "));
102 warning (_ ("Scheme encoding: "));
103 scm_write (art_type, scm_current_error_port ());
109 SCM follow_scm = scm_assoc (ly_symbol2scm ("follow-into-staff"),
112 *follow = scm_is_pair (follow_scm) && to_boolean (scm_cdr (follow_scm));
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_c_procedure_p (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;
133 val = scm_int2num (prio);
135 if (p->internal_get_property (sym) == SCM_EOL)
136 p->internal_set_property (sym, val);
141 p->set_property ("script-priority",
142 scm_int2num (index));
145 Side_position_interface::set_axis (p, Y_AXIS);
150 Script_engraver::process_music ()
152 int script_count = scripts_.size ();
153 for (int i = 0; i < script_count; i++)
155 Music *m = scripts_[i].event_;
157 Grob *p = make_item ("Script", m->self_scm ());
159 make_script_from_event (p, &scripts_[i].follow_into_staff_, context (),
160 m->get_property ("articulation-type"),
163 scripts_[i].script_ = p;
165 SCM force_dir = m->get_property ("direction");
166 if (is_direction (force_dir) && to_dir (force_dir))
167 p->set_property ("direction", force_dir);
172 Script_engraver::acknowledge_grob (Grob_info info)
174 int script_count = scripts_.size ();
175 if (Stem::has_interface (info.grob_))
177 for (int i = 0; i < script_count; i++)
179 Grob *e = scripts_[i].script_;
181 if (to_dir (e->get_property ("side-relative-direction")))
182 e->set_property ("direction-source", info.grob_->self_scm ());
184 /* FIXME: add dependency */
185 e->add_dependency (info.grob_);
186 Side_position_interface::add_support (e, info.grob_);
189 else if (Rhythmic_head::has_interface (info.grob_)
190 && info.music_cause ())
192 for (int i = 0; i < script_count; i++)
194 Grob *e = scripts_[i].script_;
196 if (Side_position_interface::get_axis (e) == X_AXIS
197 && !e->get_parent (Y_AXIS))
199 e->set_parent (info.grob_, Y_AXIS);
200 e->add_dependency (info.grob_);
202 Side_position_interface::add_support (e,info.grob_);
205 else if (Note_column::has_interface (info.grob_))
207 /* Make note column the parent of the script. That is not
208 correct, but due to seconds in a chord, noteheads may be
209 swapped around horizontally.
211 As the note head to put it on is not known now, postpone this
212 decision to Script_interface::before_line_breaking (). */
213 for (int i = 0; i < script_count; i++)
215 Grob *e = scripts_[i].script_;
217 if (!e->get_parent (X_AXIS)
218 && Side_position_interface::get_axis (e) == Y_AXIS)
219 e->set_parent (info.grob_, X_AXIS);
222 else if (Slur::has_interface (info.grob_))
223 slur_ = dynamic_cast<Spanner*> (info.grob_);
227 Script_engraver::stop_translation_timestep ()
229 int script_count = scripts_.size ();
230 for (int i = 0; i < script_count; i++)
231 if (scripts_[i].follow_into_staff_)
233 Grob *sc = scripts_[i].script_;
234 sc->add_offset_callback (Side_position_interface
235 ::quantised_position_proc, Y_AXIS);
236 sc->set_property ("staff-padding", SCM_EOL);
242 ADD_TRANSLATOR (Script_engraver,
243 /* descr */ "Handles note scripted articulations.",
244 /* creats*/ "Script",
245 /* accepts */ "script-event articulation-event",
246 /* acks */ "stem-interface rhythmic-head-interface "
247 "slur-interface note-column-interface",
248 /* reads */ "scriptDefinitions",