]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-script-engraver.cc
release: 1.2.4
[lilypond.git] / lily / bar-script-engraver.cc
1 /*   
2   bar-script-engraver.cc --  implement Bar_script_engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "bar-script-engraver.hh"
11 #include "bar.hh"
12 #include "clef-item.hh"
13 #include "staff-side.hh"
14 #include "text-item.hh"
15 #include "lily-guile.hh"
16 #include "paper-column.hh"
17 #include "paper-def.hh"
18 #include "dimension-cache.hh"
19
20
21 Bar_script_engraver::Bar_script_engraver ()
22 {
23   axis_ = Y_AXIS;
24   staff_side_p_ = 0;
25   text_p_ =0;
26   hang_on_clef_b_ = false;
27   visibility_lambda_ 
28     = ly_ch_C_eval_scm ("non_postbreak_visibility");
29 }
30
31 void
32 Bar_script_engraver::do_creation_processing ()
33 {
34   Scalar prop = get_property (type_ + "HangOnClef", 0);
35   if (prop.to_bool ())
36     {
37       hang_on_clef_b_ = true;
38     }
39 }
40
41 /*
42   Some interesting item came across.  Lets attach the text and the
43   positioner to the item.
44
45 */
46  
47 void
48 Bar_script_engraver::do_acknowledge_element (Item *i)
49 {
50   Axis other_axis = Axis((axis_ + 1)%2);
51   if (staff_side_p_ && !staff_side_p_->parent_l(other_axis)) 
52     {
53       staff_side_p_->set_parent (i,other_axis);
54       staff_side_p_->set_parent (i,axis_);
55
56       if (!text_p_->parent_l(other_axis))
57         text_p_->set_parent (i,other_axis);
58       staff_side_p_->add_support (i);
59
60       /*
61         How do we make sure that staff_side_p_ has a dependency from
62         someone else? We can't use i for that,  so we use some other element.
63        */
64       // staff_side_p_->set_elt_property (dangling_scm_sym, SCM_BOOL_T)
65       get_staff_info ().command_pcol_l ()->add_dependency (staff_side_p_);
66     }
67 }
68
69 /*
70   URG.
71  */
72 Item*
73 Bar_script_engraver::cast_to_interesting_item (Score_element *e)
74 {
75   Item * i =0;
76   if (hang_on_clef_b_)
77     {
78       Clef_item * c = dynamic_cast<Clef_item*> (e);
79
80
81       // urg.
82       if (c) //  && c->default_b_)
83         {
84           i = c;
85         }
86     }
87   else
88     {
89       i = dynamic_cast<Bar*> (e);
90     }
91   return i;
92 }
93                                                
94 void
95 Bar_script_engraver::acknowledge_element (Score_element_info inf)
96 {
97   if (inf.origin_trans_l_arr_.size () == 1)
98     {
99       Item *i=cast_to_interesting_item (inf.elem_l_);
100       if (!i)
101         return;
102
103       /* Only put numbers on bars that are at our own level (don't put
104          numbers over the staffs of a GrandStaff, only over the GrandStaff
105          itself */
106       if (inf.origin_trans_l_arr_.size () != 1)
107         return;
108
109       do_acknowledge_element (i);
110     }
111 }
112
113 void 
114 Bar_script_engraver::do_pre_move_processing ()
115 {
116   if (text_p_)
117     {
118       typeset_element (text_p_);
119       text_p_ =0;
120     }
121   
122   if (staff_side_p_) 
123     {
124       typeset_element (staff_side_p_);
125       staff_side_p_ = 0;
126     }
127 }
128
129
130 void
131 Bar_script_engraver::create_items (Request *rq)
132 {
133   if (staff_side_p_ || text_p_)
134     return;
135   
136   staff_side_p_ = new Staff_side_item;
137   staff_side_p_->axis_ = axis_;
138   staff_side_p_->set_elt_property (breakable_scm_sym, SCM_BOOL_T); // ugh
139
140   
141   text_p_ = new Text_item;
142   text_p_->set_elt_property (breakable_scm_sym, SCM_BOOL_T); // ugh
143
144   Scalar prop = get_property (type_ + "Direction", 0);
145   if (prop.isnum_b ())
146     {
147       staff_side_p_->dir_ = (Direction) (int) prop;
148     }
149   else 
150     {
151       staff_side_p_->dir_ = UP;
152     }
153
154   staff_side_p_->set_victim(text_p_);
155   
156   Scalar padding = get_property (type_ + "ScriptPadding", 0);
157   if (padding.length_i() && padding.isnum_b ())
158     {
159       staff_side_p_->set_elt_property (padding_scm_sym, gh_double2scm(Real(padding)));
160     }
161   else
162     {
163       staff_side_p_
164         ->set_elt_property (padding_scm_sym,
165                             gh_double2scm(paper_l ()->get_realvar (interline_scm_sym)));
166     }
167   
168   staff_side_p_->set_elt_property (visibility_lambda_scm_sym,
169                                    visibility_lambda_);
170   text_p_->set_elt_property (visibility_lambda_scm_sym,
171                              visibility_lambda_);
172   
173   announce_element (Score_element_info (text_p_, rq));
174   announce_element (Score_element_info (staff_side_p_, rq));
175 }