]> git.donarmstrong.com Git - lilypond.git/blob - lily/script-engraver.cc
patch::: 1.3.9.hwn2
[lilypond.git] / lily / script-engraver.cc
1 /*
2   script-engraver.cc -- implement Script_engraver
3
4   (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
5 */
6
7 #include "script-engraver.hh"
8 #include "script.hh"
9 #include "staff-side.hh"
10 #include "musical-request.hh"
11 #include "stem.hh"
12 #include "staff-symbol.hh"
13 #include "rhythmic-head.hh"
14 #include "dimension-cache.hh"
15
16 Script_engraver::Script_engraver()
17 {
18   do_post_move_processing();
19 }
20
21 bool
22 Script_engraver::do_try_music (Music *r_l)
23 {
24   if (Articulation_req *mr = dynamic_cast <Articulation_req *> (r_l))
25     {
26       for (int i=0; i < script_req_l_arr_.size(); i++) 
27         {
28           if (script_req_l_arr_[i]->equal_b (mr))
29             return true;
30         }
31       script_req_l_arr_.push (mr);
32       return true;
33     }
34   return false;
35 }
36
37 void
38 Script_engraver::do_process_requests()
39 {
40   for (int i=0; i < script_req_l_arr_.size(); i++)
41     {
42       Articulation_req* l=script_req_l_arr_[i];
43
44       SCM list = ly_eval_str (("(articulation-to-scriptdef \"" + l->articulation_str_ + "\")").ch_C());
45       
46       if (list == SCM_BOOL_F)
47         {
48           l->warning (_f ("Don't know how to interpret articulation `%s'",
49                         l->articulation_str_.ch_C ()));
50           continue;
51         }
52       Script *p =new Script;
53       Side_position_interface stafy (p); 
54       
55       list = gh_cdr (list);
56       p->set_elt_property ("molecule",
57                            SCM_CAR(list));
58
59       list = SCM_CDR(list);
60       bool follow_staff = gh_scm2bool (SCM_CAR(list));
61       list = SCM_CDR(list);
62       int relative_stem_dir = gh_scm2int (SCM_CAR(list));
63       list = SCM_CDR(list);
64       int force_dir =gh_scm2int (SCM_CAR(list));
65       list = SCM_CDR(list);
66       SCM priority = SCM_CAR(list);
67
68       
69       if (relative_stem_dir)
70           p->set_elt_property ("side-relative-direction", gh_int2scm (relative_stem_dir));
71       else
72           stafy.set_direction ((Direction)force_dir);
73
74       if (l->get_direction ())
75         stafy.set_direction (l->get_direction ());
76
77       SCM axisprop = get_property ("scriptHorizontal",0);
78       bool xaxis = gh_boolean_p (axisprop) && gh_scm2bool (axisprop);
79       if (xaxis)
80         stafy.set_axis (X_AXIS);
81       else
82         stafy.set_axis (Y_AXIS);
83       
84       if (!follow_staff && ! xaxis)
85         p->set_elt_property ("staff-support", SCM_BOOL_T);
86
87       if (!xaxis && follow_staff)
88         stafy.set_quantised (Y_AXIS);
89       
90       p->set_elt_property ("script-priority", priority);
91   
92       script_p_arr_.push (p);
93       
94       announce_element (Score_element_info (p, l));
95     }
96 }
97
98 void
99 Script_engraver::acknowledge_element (Score_element_info inf)
100 {
101   if (Stem *s = dynamic_cast<Stem*>(inf.elem_l_))
102     {
103       for (int i=0; i < script_p_arr_.size(); i++)
104         {
105           Side_position_interface stafy (script_p_arr_[i]);
106           stafy.elt_l_->set_elt_property ("direction-source", s->self_scm_);
107           stafy.add_support (s);
108         }
109     }
110   else if (Rhythmic_head * rh = dynamic_cast<Rhythmic_head*>(inf.elem_l_))
111     {
112       for (int i=0; i < script_p_arr_.size(); i++)
113         {
114           Side_position_interface stafy(script_p_arr_[i]);
115           
116           if (!stafy.elt_l_->parent_l (X_AXIS))
117             {
118               stafy.elt_l_->set_parent (inf.elem_l_, X_AXIS);
119             }
120           if (stafy.get_axis () == X_AXIS
121               && !stafy.elt_l_->parent_l (Y_AXIS))
122             stafy.elt_l_->set_parent (rh, Y_AXIS);
123           
124           stafy.add_support (rh);
125         }
126     }  
127 }
128
129 void
130 Script_engraver::do_pre_move_processing()
131 {
132   for (int i=0; i < script_p_arr_.size(); i++) 
133     {
134       typeset_element (script_p_arr_[i]);
135     }
136   script_p_arr_.clear();
137 }
138
139 void
140 Script_engraver::do_post_move_processing()
141 {
142   script_req_l_arr_.clear();
143 }
144
145 ADD_THIS_TRANSLATOR(Script_engraver);
146
147