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"
25 description_ = SCM_EOL;
29 class Script_engraver : public Engraver
31 Array<Script_tuple> scripts_;
33 TRANSLATOR_DECLARATIONS(Script_engraver);
35 virtual bool try_music (Music*);
36 virtual void initialize ();
37 virtual void stop_translation_timestep ();
38 virtual void start_translation_timestep ();
39 virtual void process_music ();
40 virtual void acknowledge_grob (Grob_info);
44 Script_engraver::initialize ()
50 Script_engraver::try_music (Music *r)
52 if (r->is_mus_type ("articulation-event"))
63 copy_property (Grob * g , SCM sym, SCM alist)
65 if (g->internal_get_grob_property (sym) == SCM_EOL)
67 SCM entry = scm_assoc (sym,alist);
68 if (gh_pair_p (entry))
70 g->internal_set_grob_property (sym, gh_cdr (entry));
77 We add the properties, one by one for each Script. We could save a
78 little space by tacking the props onto the Script grob (i.e. make
79 ScriptStaccato , ScriptMarcato, etc. )
81 Grob *make_script_from_event (SCM * descr, Translator_group*tg, Music * event,
84 SCM alist = tg->get_property ("scriptDefinitions");
85 SCM art = scm_assoc (event->get_mus_property ("articulation-type"), alist);
87 if (art == SCM_BOOL_F)
89 String a = ly_scm2string (event->get_mus_property ("articulation-type"));
90 event->origin ()->warning (_f ("Don't know how to interpret articulation `%s'", a.to_str0 ()));
96 Grob *p =new Item (tg->get_property ("Script"));
99 SCM force_dir = event->get_mus_property ("direction");
100 if (ly_dir_p (force_dir) && to_dir (force_dir))
101 p->set_grob_property ("direction", force_dir);
103 copy_property (p, ly_symbol2scm ("script-molecule"), 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 (gh_pair_p (sprio))
110 prio = gh_scm2int (gh_cdr (sprio));
114 Make sure they're in order of user input by adding index i.
115 Don't use the direction in this priority. Smaller means closer
120 Side_position_interface::set_axis (p, Y_AXIS);
121 p->set_grob_property ("script-priority", gh_int2scm (prio));
126 Script_engraver::process_music ()
128 for (int i=0; i < scripts_.size (); i++)
130 Music* l=scripts_[i].event_;
132 Grob * p = make_script_from_event (&scripts_[i].description_, daddy_trans_, l, i);
134 scripts_[i].script_ = p;
136 announce_grob (p, l->self_scm());
141 Script_engraver::acknowledge_grob (Grob_info inf)
143 if (Stem::has_interface (inf.grob_))
145 for (int i=0; i < scripts_.size (); i++)
147 Grob*e = scripts_[i].script_;
149 if (to_dir (e->get_grob_property ("side-relative-direction")))
150 e->set_grob_property ("direction-source", inf.grob_->self_scm ());
155 e->add_dependency (inf.grob_);
156 Side_position_interface::add_support (e, inf.grob_);
159 else if (Rhythmic_head::has_interface (inf.grob_))
161 for (int i=0; i < scripts_.size (); i++)
163 Grob *e = scripts_[i].script_;
165 if (Side_position_interface::get_axis (e) == X_AXIS
166 && !e->get_parent (Y_AXIS))
168 e->set_parent (inf.grob_, Y_AXIS);
169 e->add_dependency (inf.grob_); // ??
171 Side_position_interface::add_support (e,inf.grob_);
174 else if (Note_column::has_interface (inf.grob_))
178 We make note column the parent of the script. That's not
179 correct, but due to seconds in a chord, noteheads may be
180 swapped around horizontally. We don't know which note head to
181 put it on, so we postpone this decision to
182 Script_interface::before_line_breaking ().
185 for (int i=0; i < scripts_.size (); i++)
187 Grob *e = scripts_[i].script_;
189 if (!e->get_parent (X_AXIS) &&
190 Side_position_interface::get_axis (e) == Y_AXIS)
192 e->set_parent (inf.grob_, X_AXIS);
199 Script_engraver::stop_translation_timestep ()
201 for (int i=0; i < scripts_.size (); i++)
203 if (!scripts_[i].script_)
206 Grob * sc = scripts_[i].script_;
208 SCM follow = scm_assoc (ly_symbol2scm ("follow-into-staff"), scripts_[i].description_);
209 if (gh_pair_p (follow) && to_boolean (gh_cdr (follow)))
210 sc->add_offset_callback (Side_position_interface::quantised_position_proc, Y_AXIS);
212 Side_position_interface::add_staff_support (sc);
219 Script_engraver::start_translation_timestep ()
226 Script_engraver::Script_engraver(){}
228 ENTER_DESCRIPTION(Script_engraver,
229 /* descr */ "Handles note scripted articulations.",
230 /* creats*/ "Script",
231 /* accepts */ "script-event articulation-event",
232 /* acks */ "stem-interface rhythmic-head-interface note-column-interface",
233 /* reads */ "scriptDefinitions",