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> script_p_arr_;
18 Link_array<Articulation_req> script_req_l_arr_;
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_req_l_arr_.clear ();
38 Script_engraver::try_music (Music *r_l)
40 if (Articulation_req *mr = dynamic_cast <Articulation_req *> (r_l))
42 for (int i=0; i < script_req_l_arr_.size (); i++)
44 if (script_req_l_arr_[i]->equal_b (mr))
47 script_req_l_arr_.push (mr);
54 Script_engraver::process_music ()
56 for (int i=0; i < script_req_l_arr_.size (); i++)
58 Articulation_req* l=script_req_l_arr_[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.ch_C ()));
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 priority += i * (to_dir (force_dir) ? to_dir (force_dir) : 1);
95 if (ly_dir_p (force_dir) && to_dir (force_dir))
96 p->set_grob_property ("direction", force_dir);
97 else if (to_dir (relative_stem_dir))
98 p->set_grob_property ("side-relative-direction", relative_stem_dir);
102 FIXME: should figure this out in relation with basic props!
104 SCM axisprop = get_property ("scriptHorizontal");
105 bool xaxis = to_boolean (axisprop);
106 Side_position_interface::set_axis (p, xaxis ? X_AXIS : Y_AXIS);
108 if (!follow_staff && ! xaxis)
109 p->set_grob_property ("staff-support", SCM_BOOL_T);
111 if (!xaxis && follow_staff)
112 p->add_offset_callback (Side_position_interface::quantised_position_proc, Y_AXIS);
115 p->set_grob_property ("script-priority", gh_int2scm (priority));
117 script_p_arr_.push (p);
119 announce_grob (p, l->self_scm());
124 Script_engraver::acknowledge_grob (Grob_info inf)
126 if (Stem::has_interface (inf.grob_l_))
128 for (int i=0; i < script_p_arr_.size (); i++)
130 Grob*e = script_p_arr_[i];
132 e->set_grob_property ("direction-source", inf.grob_l_->self_scm ());
133 e->add_dependency (inf.grob_l_);
134 Side_position_interface::add_support (e, inf.grob_l_);
137 else if (Rhythmic_head::has_interface (inf.grob_l_))
139 for (int i=0; i < script_p_arr_.size (); i++)
141 Grob *e = script_p_arr_[i];
143 if (Side_position_interface::get_axis (e) == X_AXIS
144 && !e->get_parent (Y_AXIS))
146 e->set_parent (inf.grob_l_, Y_AXIS);
147 e->add_dependency (inf.grob_l_); // ??
149 Side_position_interface::add_support (e,inf.grob_l_);
152 else if (Note_column::has_interface (inf.grob_l_))
156 We make note column the parent of the script. That's not
157 correct, but due to seconds in a chord, noteheads may be
158 swapped around horizontally. We don't know which note head to
159 put it on, so we postpone this decision to
160 Script_interface::before_line_breaking ().
163 for (int i=0; i < script_p_arr_.size (); i++)
165 Grob *e = script_p_arr_[i];
167 if (!e->get_parent (X_AXIS) &&
168 Side_position_interface::get_axis (e) == Y_AXIS)
170 e->set_parent (inf.grob_l_, X_AXIS);
177 Script_engraver::stop_translation_timestep ()
179 for (int i=0; i < script_p_arr_.size (); i++)
183 TODO: junk staff-support.
185 Grob * sc = script_p_arr_[i];
186 if (to_boolean (sc->get_grob_property ("staff-support")))
188 Side_position_interface::add_staff_support (sc);
192 script_p_arr_.clear ();
196 Script_engraver::start_translation_timestep ()
198 script_req_l_arr_.clear ();
203 Script_engraver::Script_engraver(){}
205 ENTER_DESCRIPTION(Script_engraver,
206 /* descr */ " Handles note ornaments generated by @code{\\script}.
208 /* creats*/ "Script",
209 /* acks */ "stem-interface rhythmic-head-interface note-column-interface",
210 /* reads */ "scriptDefinitions scriptHorizontal",