2 script-engraver.cc -- implement Script_engraver
4 (c) 1997--2001 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"
14 class Script_engraver : public Engraver
16 Link_array<Grob> script_p_arr_;
17 Link_array<Articulation_req> script_req_l_arr_;
20 TRANSLATOR_DECLARATIONS(Script_engraver);
22 virtual bool try_music (Music*);
23 virtual void initialize ();
24 virtual void stop_translation_timestep ();
25 virtual void start_translation_timestep ();
26 virtual void process_music ();
27 virtual void acknowledge_grob (Grob_info);
31 Script_engraver::initialize ()
33 script_req_l_arr_.clear ();
37 Script_engraver::try_music (Music *r_l)
39 if (Articulation_req *mr = dynamic_cast <Articulation_req *> (r_l))
41 for (int i=0; i < script_req_l_arr_.size (); i++)
43 if (script_req_l_arr_[i]->equal_b (mr))
46 script_req_l_arr_.push (mr);
53 Script_engraver::process_music ()
55 for (int i=0; i < script_req_l_arr_.size (); i++)
57 Articulation_req* l=script_req_l_arr_[i];
59 SCM alist = get_property ("scriptDefinitions");
60 SCM art = scm_assoc (l->get_mus_property ("articulation-type"), alist);
62 if (art == SCM_BOOL_F)
64 String a = ly_scm2string (l->get_mus_property ("articulation-type"));
65 l->origin ()->warning (_f ("Don't know how to interpret articulation `%s'", a.ch_C ()));
69 // todo -> use result of articulation-to-scriptdef directly as basic prop list.
70 Grob *p =new Item (get_property ("Script"));
72 p->set_grob_property ("molecule", ly_car (art));
75 bool follow_staff = gh_scm2bool (ly_car (art));
77 SCM relative_stem_dir = ly_car (art);
80 SCM force_dir = l->get_mus_property ("direction");
81 if (isdir_b (force_dir) && !to_dir (force_dir))
82 force_dir = ly_car (art);
85 SCM priority = ly_car (art);
87 if (isdir_b (force_dir) && to_dir (force_dir))
88 p->set_grob_property ("direction", force_dir);
89 else if (to_dir (relative_stem_dir))
90 p->set_grob_property ("side-relative-direction", relative_stem_dir);
94 FIXME: should figure this out in relation with basic props!
96 SCM axisprop = get_property ("scriptHorizontal");
97 bool xaxis = to_boolean (axisprop);
98 Side_position_interface::set_axis (p, xaxis ? X_AXIS : Y_AXIS);
100 if (!follow_staff && ! xaxis)
101 p->set_grob_property ("staff-support", SCM_BOOL_T);
103 if (!xaxis && follow_staff)
104 p->add_offset_callback (Side_position_interface::quantised_position_proc, Y_AXIS);
107 p->set_grob_property ("script-priority", priority);
109 script_p_arr_.push (p);
111 announce_grob (p, l);
116 Script_engraver::acknowledge_grob (Grob_info inf)
118 if (Stem::has_interface (inf.grob_l_))
120 for (int i=0; i < script_p_arr_.size (); i++)
122 Grob*e = script_p_arr_[i];
124 e->set_grob_property ("direction-source", inf.grob_l_->self_scm ());
125 e->add_dependency (inf.grob_l_);
126 Side_position_interface::add_support (e, inf.grob_l_);
129 else if (Rhythmic_head::has_interface (inf.grob_l_))
131 for (int i=0; i < script_p_arr_.size (); i++)
133 Grob *e = script_p_arr_[i];
135 if (!e->get_parent (X_AXIS))
137 e->set_parent (inf.grob_l_, X_AXIS);
139 if (Side_position_interface::get_axis (e) == X_AXIS
140 && !e->get_parent (Y_AXIS))
142 e->set_parent (inf.grob_l_, Y_AXIS);
143 e->add_dependency (inf.grob_l_); // ??
145 Side_position_interface::add_support (e,inf.grob_l_);
151 Script_engraver::stop_translation_timestep ()
153 for (int i=0; i < script_p_arr_.size (); i++)
155 Grob * sc = script_p_arr_[i];
156 if (to_boolean (sc->get_grob_property ("staff-support")))
158 Side_position_interface::add_staff_support (sc);
162 script_p_arr_.clear ();
166 Script_engraver::start_translation_timestep ()
168 script_req_l_arr_.clear ();
173 Script_engraver::Script_engraver(){}
175 ENTER_DESCRIPTION(Script_engraver,
176 /* descr */ " Handles note ornaments generated by @code{\\script}.
178 /* creats*/ "Script",
179 /* acks */ "stem-interface rhythmic-head-interface",
180 /* reads */ "scriptDefinitions scriptHorizontal",