2 script-engraver.cc -- implement Script_engraver
4 (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 #include "side-position-interface.hh"
9 #include "musical-request.hh"
11 #include "rhythmic-head.hh"
12 #include "engraver.hh"
13 #include "note-column.hh"
15 class Script_engraver : public Engraver
17 Link_array<Grob> scripts_;
18 Link_array<Articulation_req> script_reqs_;
21 TRANSLATOR_DECLARATIONS(Script_engraver);
23 virtual bool try_music (Music*);
24 virtual void initialize ();
25 virtual void stop_translation_timestep ();
26 virtual void start_translation_timestep ();
27 virtual void process_music ();
28 virtual void acknowledge_grob (Grob_info);
32 Script_engraver::initialize ()
34 script_reqs_.clear ();
38 Script_engraver::try_music (Music *r)
40 if (Articulation_req *mr = dynamic_cast <Articulation_req *> (r))
42 for (int i=0; i < script_reqs_.size (); i++)
44 if (script_reqs_[i]->equal_b (mr))
47 script_reqs_.push (mr);
54 Script_engraver::process_music ()
56 for (int i=0; i < script_reqs_.size (); i++)
58 Articulation_req* l=script_reqs_[i];
60 SCM alist = get_property ("scriptDefinitions");
61 SCM art = scm_assoc (l->get_mus_property ("articulation-type"), alist);
63 if (art == SCM_BOOL_F)
65 String a = ly_scm2string (l->get_mus_property ("articulation-type"));
66 l->origin ()->warning (_f ("Don't know how to interpret articulation `%s'", a.to_str0 ()));
70 // todo -> use result of articulation-to-scriptdef directly as basic prop list.
71 Grob *p =new Item (get_property ("Script"));
73 p->set_grob_property ("script-molecule", ly_car (art));
76 bool follow_staff = gh_scm2bool (ly_car (art));
78 SCM relative_stem_dir = ly_car (art);
81 SCM force_dir = l->get_mus_property ("direction");
82 if (ly_dir_p (force_dir) && !to_dir (force_dir))
83 force_dir = ly_car (art);
86 int priority = gh_scm2int (ly_car (art));
88 SCM s = p->get_grob_property ("script-priority");
90 priority = gh_scm2int (s);
92 /* Make sure they're in order of user input by adding index i.
93 Don't use the direction in this priority. Smaller means closer
98 if (ly_dir_p (force_dir) && to_dir (force_dir))
99 p->set_grob_property ("direction", force_dir);
100 else if (to_dir (relative_stem_dir))
101 p->set_grob_property ("side-relative-direction", relative_stem_dir);
105 FIXME: should figure this out in relation with basic props!
107 SCM axisprop = get_property ("scriptHorizontal");
108 bool xaxis = to_boolean (axisprop);
109 Side_position_interface::set_axis (p, xaxis ? X_AXIS : Y_AXIS);
111 if (!follow_staff && ! xaxis)
112 p->set_grob_property ("staff-support", SCM_BOOL_T);
114 if (!xaxis && follow_staff)
115 p->add_offset_callback (Side_position_interface::quantised_position_proc, Y_AXIS);
118 p->set_grob_property ("script-priority", gh_int2scm (priority));
122 announce_grob (p, l->self_scm());
127 Script_engraver::acknowledge_grob (Grob_info inf)
129 if (Stem::has_interface (inf.grob_))
131 for (int i=0; i < scripts_.size (); i++)
133 Grob*e = scripts_[i];
135 e->set_grob_property ("direction-source", inf.grob_->self_scm ());
136 e->add_dependency (inf.grob_);
137 Side_position_interface::add_support (e, inf.grob_);
140 else if (Rhythmic_head::has_interface (inf.grob_))
142 for (int i=0; i < scripts_.size (); i++)
144 Grob *e = scripts_[i];
146 if (Side_position_interface::get_axis (e) == X_AXIS
147 && !e->get_parent (Y_AXIS))
149 e->set_parent (inf.grob_, Y_AXIS);
150 e->add_dependency (inf.grob_); // ??
152 Side_position_interface::add_support (e,inf.grob_);
155 else if (Note_column::has_interface (inf.grob_))
159 We make note column the parent of the script. That's not
160 correct, but due to seconds in a chord, noteheads may be
161 swapped around horizontally. We don't know which note head to
162 put it on, so we postpone this decision to
163 Script_interface::before_line_breaking ().
166 for (int i=0; i < scripts_.size (); i++)
168 Grob *e = scripts_[i];
170 if (!e->get_parent (X_AXIS) &&
171 Side_position_interface::get_axis (e) == Y_AXIS)
173 e->set_parent (inf.grob_, X_AXIS);
180 Script_engraver::stop_translation_timestep ()
182 for (int i=0; i < scripts_.size (); i++)
186 TODO: junk staff-support.
188 Grob * sc = scripts_[i];
189 if (to_boolean (sc->get_grob_property ("staff-support")))
191 Side_position_interface::add_staff_support (sc);
199 Script_engraver::start_translation_timestep ()
201 script_reqs_.clear ();
206 Script_engraver::Script_engraver(){}
208 ENTER_DESCRIPTION(Script_engraver,
209 /* descr */ " Handles note ornaments generated by @code{\\script}.
211 /* creats*/ "Script",
212 /* acks */ "stem-interface rhythmic-head-interface note-column-interface",
213 /* reads */ "scriptDefinitions scriptHorizontal",