]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-script-engraver.cc
b319bdc4bcb8ea05af4187d9725fc266f129d9b9
[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 "p-col.hh"
17 #include "paper-def.hh"
18
19 Bar_script_engraver::Bar_script_engraver ()
20 {
21   axis_ = Y_AXIS;
22   staff_side_p_ = 0;
23   text_p_ =0;
24   hang_on_clef_b_ = false;
25   visibility_lambda_ 
26     = gh_eval_str ("non_postbreak_visibility");
27 }
28
29 void
30 Bar_script_engraver::do_creation_processing ()
31 {
32   Scalar prop = get_property (type_ + "HangOnClef", 0);
33   if (prop.to_bool ())
34     {
35       hang_on_clef_b_ = true;
36     }
37 }
38
39 /*
40   Some interesting item came across.  Lets attach the text and the
41   positioner to the item.
42
43 */
44  
45 void
46 Bar_script_engraver::do_acknowledge_element (Item *i)
47 {
48   Axis other_axis = Axis((axis_ + 1)%2);
49   if (staff_side_p_ && !staff_side_p_->dim_cache_[other_axis]->parent_l_) 
50     {
51       staff_side_p_->dim_cache_[other_axis]->parent_l_
52         = i->dim_cache_[other_axis];
53       staff_side_p_->dim_cache_[axis_]->parent_l_
54         =  i->dim_cache_[axis_];          
55
56       if (!text_p_->dim_cache_[other_axis]->parent_l_)
57         text_p_->dim_cache_[other_axis]->parent_l_ = i->dim_cache_[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       get_staff_info ().command_pcol_l ()->add_dependency (staff_side_p_);
65     }
66 }
67
68 /*
69   URG.
70  */
71 Item*
72 Bar_script_engraver::cast_to_interesting_item (Score_element *e)
73 {
74   Item * i =0;
75   if (hang_on_clef_b_)
76     {
77       Clef_item * c = dynamic_cast<Clef_item*> (e);
78
79
80       // urg.
81       if (c) //  && c->default_b_)
82         {
83           i = c;
84         }
85     }
86   else
87     {
88       i = dynamic_cast<Bar*> (e);
89     }
90   return i;
91 }
92                                                
93 void
94 Bar_script_engraver::acknowledge_element (Score_element_info inf)
95 {
96   if (inf.origin_trans_l_arr_.size () == 1)
97     {
98       Item *i=cast_to_interesting_item (inf.elem_l_);
99       if (!i)
100         return;
101
102       /* Only put numbers on bars that are at our own level (don't put
103          numbers over the staffs of a GrandStaff, only over the GrandStaff
104          itself */
105       if (inf.origin_trans_l_arr_.size () != 1)
106         return;
107
108       do_acknowledge_element (i);
109     }
110 }
111
112 void 
113 Bar_script_engraver::do_pre_move_processing ()
114 {
115   if (text_p_)
116     {
117       typeset_element (text_p_);
118       text_p_ =0;
119     }
120   
121   if (staff_side_p_) 
122     {
123       typeset_element (staff_side_p_);
124       staff_side_p_ = 0;
125     }
126 }
127
128
129 void
130 Bar_script_engraver::create_items (Request *rq)
131 {
132   if (staff_side_p_ || text_p_)
133     return;
134   
135   staff_side_p_ = new Staff_side_item;
136   staff_side_p_->axis_ = axis_;
137   staff_side_p_->set_elt_property (breakable_scm_sym, SCM_BOOL_T); // ugh
138
139   
140   text_p_ = new Text_item;
141   text_p_->set_elt_property (breakable_scm_sym, SCM_BOOL_T); // ugh
142
143   Scalar prop = get_property (type_ + "Direction", 0);
144   if (prop.isnum_b ())
145     {
146       staff_side_p_->dir_ = (Direction) (int) prop;
147     }
148   else 
149     {
150       staff_side_p_->dir_ = UP;
151     }
152
153   staff_side_p_->set_victim(text_p_);
154   
155   Scalar padding = get_property (type_ + "ScriptPadding", 0);
156   if (padding.length_i() && padding.isnum_b ())
157     {
158       staff_side_p_->set_elt_property (padding_scm_sym, gh_double2scm(Real(padding)));
159     }
160   else
161     {
162       staff_side_p_
163         ->set_elt_property (padding_scm_sym,
164                             gh_double2scm(paper_l ()->get_realvar (interline_scm_sym)));
165     }
166   
167   staff_side_p_->set_elt_property (visibility_lambda_scm_sym,
168                                    visibility_lambda_);
169   text_p_->set_elt_property (visibility_lambda_scm_sym,
170                              visibility_lambda_);
171   
172   announce_element (Score_element_info (text_p_, rq));
173   announce_element (Score_element_info (staff_side_p_, rq));
174 }