2 script-engraver.cc -- implement Script_engraver
4 (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 #include "side-position-interface.hh"
11 #include "rhythmic-head.hh"
12 #include "engraver.hh"
13 #include "note-column.hh"
14 #include "translator-group.hh"
26 description_ = SCM_EOL;
30 class Script_engraver : public Engraver
32 Array<Script_tuple> scripts_;
34 TRANSLATOR_DECLARATIONS(Script_engraver);
36 virtual bool try_music (Music*);
37 virtual void stop_translation_timestep ();
38 virtual void process_music ();
39 virtual void acknowledge_grob (Grob_info);
43 Script_engraver::try_music (Music *r)
45 if (r->is_mus_type ("articulation-event"))
48 Discard double articulations.
49 This is necessary for part-combining.
51 for (int j = 0; j < scripts_.size (); j++)
52 if (gh_equal_p (scripts_[j]. event_->get_mus_property ("articulation-type"),
53 r->get_mus_property ("articulation-type")
67 copy_property (Grob * g , SCM sym, SCM alist)
69 if (g->internal_get_grob_property (sym) == SCM_EOL)
71 SCM entry = scm_assoc (sym,alist);
72 if (gh_pair_p (entry))
74 g->internal_set_grob_property (sym, gh_cdr (entry));
81 We add the properties, one by one for each Script. We could save a
82 little space by tacking the props onto the Script grob (i.e. make
83 ScriptStaccato , ScriptMarcato, etc. )
85 void make_script_from_event (Grob *p,
86 SCM * descr, Translator_group*tg,
90 SCM alist = tg->get_property ("scriptDefinitions");
91 SCM art = scm_assoc (art_type, alist);
93 if (art == SCM_BOOL_F)
95 warning (_("Don't know how to interpret articulation:"));
96 warning (_("Scheme encoding: "));
97 scm_write (art_type, scm_current_error_port ());
106 copy_property (p, ly_symbol2scm ("script-molecule"), art);
107 copy_property (p, ly_symbol2scm ("direction"), art);
108 copy_property (p, ly_symbol2scm ("side-relative-direction"), art);
111 SCM sprio = scm_assoc (ly_symbol2scm ("script-priority"), art);
112 if (gh_pair_p (sprio))
113 prio = gh_scm2int (gh_cdr (sprio));
117 Make sure they're in order of user input by adding index i.
118 Don't use the direction in this priority. Smaller means closer
123 Side_position_interface::set_axis (p, Y_AXIS);
124 p->set_grob_property ("script-priority", gh_int2scm (prio));
128 Script_engraver::process_music ()
130 for (int i=0; i < scripts_.size (); i++)
132 Music* l=scripts_[i].event_;
134 Grob * p = make_item ("Script");
136 make_script_from_event (p, &scripts_[i].description_, daddy_trans_,
137 l->get_mus_property ("articulation-type"),
140 scripts_[i].script_ = p;
143 SCM force_dir = l->get_mus_property ("direction");
144 if (is_direction (force_dir) && to_dir (force_dir))
145 p->set_grob_property ("direction", force_dir);
148 announce_grob (p, l->self_scm());
153 Script_engraver::acknowledge_grob (Grob_info inf)
155 if (Stem::has_interface (inf.grob_))
157 for (int i=0; i < scripts_.size (); i++)
159 Grob*e = scripts_[i].script_;
161 if (to_dir (e->get_grob_property ("side-relative-direction")))
162 e->set_grob_property ("direction-source", inf.grob_->self_scm ());
167 e->add_dependency (inf.grob_);
168 Side_position_interface::add_support (e, inf.grob_);
171 else if (Rhythmic_head::has_interface (inf.grob_))
173 for (int i=0; i < scripts_.size (); i++)
175 Grob *e = scripts_[i].script_;
177 if (Side_position_interface::get_axis (e) == X_AXIS
178 && !e->get_parent (Y_AXIS))
180 e->set_parent (inf.grob_, Y_AXIS);
181 e->add_dependency (inf.grob_); // ??
183 Side_position_interface::add_support (e,inf.grob_);
186 else if (Note_column::has_interface (inf.grob_))
190 We make note column the parent of the script. That's not
191 correct, but due to seconds in a chord, noteheads may be
192 swapped around horizontally. We don't know which note head to
193 put it on, so we postpone this decision to
194 Script_interface::before_line_breaking ().
197 for (int i=0; i < scripts_.size (); i++)
199 Grob *e = scripts_[i].script_;
201 if (!e->get_parent (X_AXIS) &&
202 Side_position_interface::get_axis (e) == Y_AXIS)
204 e->set_parent (inf.grob_, X_AXIS);
211 Script_engraver::stop_translation_timestep ()
213 for (int i=0; i < scripts_.size (); i++)
215 if (!scripts_[i].script_)
218 Grob * sc = scripts_[i].script_;
220 SCM follow = scm_assoc (ly_symbol2scm ("follow-into-staff"), scripts_[i].description_);
221 if (gh_pair_p (follow) && to_boolean (gh_cdr (follow)))
223 sc->add_offset_callback (Side_position_interface::quantised_position_proc, Y_AXIS);
224 sc->set_grob_property ("staff-padding", SCM_EOL);
233 Script_engraver::Script_engraver(){}
235 ENTER_DESCRIPTION(Script_engraver,
236 /* descr */ "Handles note scripted articulations.",
237 /* creats*/ "Script",
238 /* accepts */ "script-event articulation-event",
239 /* acks */ "stem-interface rhythmic-head-interface note-column-interface",
240 /* reads */ "scriptDefinitions",