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 "staff-symbol.hh"
13 #include "rhythmic-head.hh"
14 #include "dimension-cache.hh"
16 #include "engraver.hh"
18 class Script_engraver
: public Engraver
{
19 Link_array
<Script
> script_p_arr_
;
20 Link_array
<Articulation_req
> script_req_l_arr_
;
23 VIRTUAL_COPY_CONS(Translator
);
27 virtual bool do_try_music (Music
*);
28 virtual void do_process_requests ();
29 virtual void do_pre_move_processing ();
30 virtual void do_post_move_processing ();
31 virtual void acknowledge_element (Score_element_info
);
35 Script_engraver::Script_engraver()
37 do_post_move_processing();
41 Script_engraver::do_try_music (Music
*r_l
)
43 if (Articulation_req
*mr
= dynamic_cast <Articulation_req
*> (r_l
))
45 for (int i
=0; i
< script_req_l_arr_
.size(); i
++)
47 if (script_req_l_arr_
[i
]->equal_b (mr
))
50 script_req_l_arr_
.push (mr
);
57 Script_engraver::do_process_requests()
59 for (int i
=0; i
< script_req_l_arr_
.size(); i
++)
61 Articulation_req
* l
=script_req_l_arr_
[i
];
63 SCM list
= ly_eval_str (("(articulation-to-scriptdef \"" + l
->articulation_str_
+ "\")").ch_C());
65 if (list
== SCM_BOOL_F
)
67 l
->warning (_f ("Don't know how to interpret articulation `%s'",
68 l
->articulation_str_
.ch_C ()));
71 Script
*p
=new Script
;
72 Side_position_interface
stafy (p
);
76 p
->set_elt_property ("molecule",
80 bool follow_staff
= gh_scm2bool (gh_car (list
));
82 int relative_stem_dir
= gh_scm2int (gh_car (list
));
84 int force_dir
=gh_scm2int (gh_car (list
));
86 SCM priority
= gh_car (list
);
89 if (relative_stem_dir
)
90 p
->set_elt_property ("side-relative-direction", gh_int2scm (relative_stem_dir
));
92 stafy
.set_direction ((Direction
)force_dir
);
94 if (l
->get_direction ())
95 stafy
.set_direction (l
->get_direction ());
97 SCM axisprop
= get_property ("scriptHorizontal",0);
98 bool xaxis
= to_boolean (axisprop
);
100 stafy
.set_axis (X_AXIS
);
102 stafy
.set_axis (Y_AXIS
);
104 if (!follow_staff
&& ! xaxis
)
105 p
->set_elt_property ("staff-support", SCM_BOOL_T
);
107 if (!xaxis
&& follow_staff
)
108 stafy
.set_quantised (Y_AXIS
);
110 p
->set_elt_property ("script-priority", priority
);
112 script_p_arr_
.push (p
);
114 announce_element (Score_element_info (p
, l
));
119 Script_engraver::acknowledge_element (Score_element_info inf
)
121 bool them_grace
= to_boolean (inf
.elem_l_
->get_elt_property ("grace"));
122 bool us_grace
= to_boolean (get_property ("weAreGraceContext",0));
124 if (us_grace
!= them_grace
)
127 if (Stem
*s
= dynamic_cast<Stem
*>(inf
.elem_l_
))
129 for (int i
=0; i
< script_p_arr_
.size(); i
++)
131 Side_position_interface
stafy (script_p_arr_
[i
]);
132 stafy
.elt_l_
->set_elt_property ("direction-source", s
->self_scm_
);
133 stafy
.add_support (s
);
136 else if (Rhythmic_head
* rh
= dynamic_cast<Rhythmic_head
*>(inf
.elem_l_
))
138 for (int i
=0; i
< script_p_arr_
.size(); i
++)
140 Side_position_interface
stafy(script_p_arr_
[i
]);
142 if (!stafy
.elt_l_
->parent_l (X_AXIS
))
144 stafy
.elt_l_
->set_parent (inf
.elem_l_
, X_AXIS
);
146 if (stafy
.get_axis () == X_AXIS
147 && !stafy
.elt_l_
->parent_l (Y_AXIS
))
148 stafy
.elt_l_
->set_parent (rh
, Y_AXIS
);
150 stafy
.add_support (rh
);
156 Script_engraver::do_pre_move_processing()
158 for (int i
=0; i
< script_p_arr_
.size(); i
++)
160 if (to_boolean (script_p_arr_
[i
]->remove_elt_property ("staff-support")))
161 side_position (script_p_arr_
[i
]).add_staff_support ();
162 typeset_element (script_p_arr_
[i
]);
164 script_p_arr_
.clear();
168 Script_engraver::do_post_move_processing()
170 script_req_l_arr_
.clear();
173 ADD_THIS_TRANSLATOR(Script_engraver
);