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 "engraver.hh"
12 #include "note-column.hh"
13 #include "rhythmic-head.hh"
14 #include "script-interface.hh"
15 #include "side-position-interface.hh"
28 description_ = SCM_EOL;
32 class Script_engraver : public Engraver
34 Array<Script_tuple> scripts_;
37 virtual bool try_music (Music*);
38 virtual void stop_translation_timestep ();
39 virtual void process_music ();
40 virtual void acknowledge_grob (Grob_info);
43 TRANSLATOR_DECLARATIONS (Script_engraver);
46 Script_engraver::Script_engraver ()
51 Script_engraver::try_music (Music *r)
53 if (r->is_mus_type ("articulation-event"))
55 /* Discard double articulations for part-combining. */
56 int script_count = scripts_.size ();
57 for (int i = 0; i < script_count; i++)
58 if (ly_c_equal_p (scripts_[i].event_
59 ->get_property ("articulation-type"),
60 r->get_property ("articulation-type")))
72 copy_property (Grob *g, SCM sym, SCM alist)
74 if (g->internal_get_property (sym) == SCM_EOL)
76 SCM entry = scm_assoc (sym, alist);
77 if (ly_c_pair_p (entry))
78 g->internal_set_property (sym, ly_cdr (entry));
82 /* Add the properties, one by one for each Script. A little space
83 (memory? --jcn) could be saved by tacking the props onto the Script
84 grob (i.e. make ScriptStaccato , ScriptMarcato, etc. ). */
85 void make_script_from_event (Grob *p, SCM *descr, Context *tg,
86 SCM art_type, int index)
88 SCM alist = tg->get_property ("scriptDefinitions");
89 SCM art = scm_assoc (art_type, alist);
91 if (art == SCM_BOOL_F)
94 warning (_ ("Do not know how to interpret articulation: "));
95 warning (_ ("Scheme encoding: "));
96 scm_write (art_type, scm_current_error_port ());
103 copy_property (p, ly_symbol2scm ("script-stencil"), art);
104 copy_property (p, ly_symbol2scm ("direction"), art);
105 copy_property (p, ly_symbol2scm ("side-relative-direction"), art);
108 SCM sprio = scm_assoc (ly_symbol2scm ("script-priority"), art);
109 if (ly_c_pair_p (sprio))
110 prio = ly_scm2int (ly_cdr (sprio));
112 /* Make sure they're in order of user input by adding index i.
113 Don't use the direction in this priority. Smaller means closer
117 Side_position_interface::set_axis (p, Y_AXIS);
118 p->set_property ("script-priority", scm_int2num (prio));
122 Script_engraver::process_music ()
124 int script_count = scripts_.size ();
125 for (int i = 0; i < script_count; i++)
127 Music *m = scripts_[i].event_;
129 Grob *p = make_item ("Script", m->self_scm ());
131 make_script_from_event (p, &scripts_[i].description_, context (),
132 m->get_property ("articulation-type"),
135 scripts_[i].script_ = p;
137 SCM force_dir = m->get_property ("direction");
138 if (is_direction (force_dir) && to_dir (force_dir))
139 p->set_property ("direction", force_dir);
144 Script_engraver::acknowledge_grob (Grob_info inf)
146 int script_count = scripts_.size ();
147 if (Stem::has_interface (inf.grob_))
149 for (int i = 0; i < script_count; i++)
151 Grob *e = scripts_[i].script_;
153 if (to_dir (e->get_property ("side-relative-direction")))
154 e->set_property ("direction-source", inf.grob_->self_scm ());
156 /* FIXME: add dependency */
157 e->add_dependency (inf.grob_);
158 Side_position_interface::add_support (e, inf.grob_);
161 else if (Rhythmic_head::has_interface (inf.grob_))
163 for (int i = 0; i < script_count; i++)
165 Grob *e = scripts_[i].script_;
167 if (Side_position_interface::get_axis (e) == X_AXIS
168 && !e->get_parent (Y_AXIS))
170 e->set_parent (inf.grob_, Y_AXIS);
171 e->add_dependency (inf.grob_); // ??
173 Side_position_interface::add_support (e,inf.grob_);
176 else if (Note_column::has_interface (inf.grob_))
178 /* Make note column the parent of the script. That is not
179 correct, but due to seconds in a chord, noteheads may be
180 swapped around horizontally.
182 As the note head to put it on is not known now, postpone this
183 decision to Script_interface::before_line_breaking (). */
184 for (int i = 0; i < script_count; i++)
186 Grob *e = scripts_[i].script_;
188 if (!e->get_parent (X_AXIS)
189 && Side_position_interface::get_axis (e) == Y_AXIS)
190 e->set_parent (inf.grob_, X_AXIS);
196 Script_engraver::stop_translation_timestep ()
198 int script_count = scripts_.size ();
199 for (int i = 0; i < script_count; i++)
200 if (Grob *sc = scripts_[i].script_)
202 SCM follow = scm_assoc (ly_symbol2scm ("follow-into-staff"),
203 scripts_[i].description_);
204 if (ly_c_pair_p (follow) && to_boolean (ly_cdr (follow)))
206 sc->add_offset_callback (Side_position_interface
207 ::quantised_position_proc, Y_AXIS);
208 sc->set_property ("staff-padding", SCM_EOL);
214 ENTER_DESCRIPTION (Script_engraver,
215 /* descr */ "Handles note scripted articulations.",
216 /* creats*/ "Script",
217 /* accepts */ "script-event articulation-event",
218 /* acks */ "stem-interface rhythmic-head-interface note-column-interface",
219 /* reads */ "scriptDefinitions",