2 script-engraver.cc -- implement Script_engraver
4 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "side-position-interface.hh"
10 #include "musical-request.hh"
12 #include "rhythmic-head.hh"
13 #include "engraver.hh"
15 class Script_engraver : public Engraver {
16 Link_array<Grob> script_p_arr_;
17 Link_array<Articulation_req> script_req_l_arr_;
20 VIRTUAL_COPY_CONS(Translator);
24 virtual bool try_music (Music*);
25 void deprecated_process_music ();
26 virtual void stop_translation_timestep ();
27 virtual void start_translation_timestep ();
28 virtual void create_grobs ();
29 virtual void acknowledge_grob (Grob_info);
33 Script_engraver::Script_engraver()
35 start_translation_timestep();
39 Script_engraver::try_music (Music *r_l)
41 if (Articulation_req *mr = dynamic_cast <Articulation_req *> (r_l))
43 for (int i=0; i < script_req_l_arr_.size(); i++)
45 if (script_req_l_arr_[i]->equal_b (mr))
48 script_req_l_arr_.push (mr);
55 Script_engraver::create_grobs ()
57 deprecated_process_music ();
61 Script_engraver::deprecated_process_music()
63 for (int i=0; i < script_req_l_arr_.size(); i++)
65 Articulation_req* l=script_req_l_arr_[i];
67 SCM alist = get_property ("scriptDefinitions");
68 SCM list = scm_assoc (l->get_mus_property ("articulation-type"), alist);
70 if (list == SCM_BOOL_F)
72 String a = ly_scm2string (l->get_mus_property ("articulation-type"));
73 l->origin ()->warning (_f ("Don't know how to interpret articulation `%s'", a.ch_C()));
77 // todo -> use result of articulation-to-scriptdef directly as basic prop list.
78 Grob *p =new Item (get_property ("Script"));
80 p->set_grob_property ("molecule",
84 bool follow_staff = gh_scm2bool (gh_car (list));
86 SCM relative_stem_dir = gh_car (list);
89 SCM force_dir = l->get_mus_property ("direction");
90 if (!isdir_b (force_dir))
91 force_dir = gh_car (list);
93 SCM priority = gh_car (list);
96 if (!isdir_b (force_dir)
97 && to_dir (relative_stem_dir))
98 p->set_grob_property ("side-relative-direction", relative_stem_dir);
100 p->set_grob_property ("direction", force_dir);
103 FIXME: should figure this out in relation with basic props!
105 SCM axisprop = get_property ("scriptHorizontal");
106 bool xaxis = to_boolean (axisprop);
107 Side_position::set_axis (p, xaxis ? X_AXIS : Y_AXIS);
109 if (!follow_staff && ! xaxis)
110 p->set_grob_property ("staff-support", SCM_BOOL_T);
112 if (!xaxis && follow_staff)
113 p->add_offset_callback (Side_position::quantised_position_proc, Y_AXIS);
116 p->set_grob_property ("script-priority", priority);
118 script_p_arr_.push (p);
120 announce_grob (p, l);
122 script_req_l_arr_.clear ();
126 Script_engraver::acknowledge_grob (Grob_info inf)
128 bool them_grace = to_boolean (inf.elem_l_->get_grob_property ("grace"));
129 bool us_grace = to_boolean (get_property ("weAreGraceContext"));
131 if (us_grace != them_grace)
134 if (Stem::has_interface (inf.elem_l_))
136 for (int i=0; i < script_p_arr_.size(); i++)
138 Grob*e = script_p_arr_[i];
140 e->set_grob_property ("direction-source", inf.elem_l_->self_scm ());
141 Side_position::add_support (e, inf.elem_l_);
144 else if (Rhythmic_head::has_interface (inf.elem_l_))
146 for (int i=0; i < script_p_arr_.size(); i++)
148 Grob *e = script_p_arr_[i];
150 if (!e->parent_l (X_AXIS))
152 e->set_parent (inf.elem_l_, X_AXIS);
154 if (Side_position::get_axis (e) == X_AXIS
155 && !e->parent_l (Y_AXIS))
156 e->set_parent (inf.elem_l_, Y_AXIS);
158 Side_position::add_support (e,inf.elem_l_);
164 Script_engraver::stop_translation_timestep()
166 for (int i=0; i < script_p_arr_.size(); i++)
168 Grob * sc = script_p_arr_[i];
169 if (to_boolean (sc->get_grob_property ("staff-support")))
171 Side_position::add_staff_support (sc);
175 script_p_arr_.clear();
179 Script_engraver::start_translation_timestep()
181 script_req_l_arr_.clear();
184 ADD_THIS_TRANSLATOR(Script_engraver);