]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-script-engraver.cc
release: 1.1.41
[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 "g-staff-side.hh"
14 #include "g-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 void
40 Bar_script_engraver::do_acknowledge_element (Item *i)
41 {
42   Axis other_axis = Axis((axis_ + 1)%2);
43   if (staff_side_p_ && !staff_side_p_->dim_cache_[other_axis].parent_l_) 
44     {
45       staff_side_p_->dim_cache_[other_axis].parent_l_
46         = &i->dim_cache_[other_axis];
47       staff_side_p_->dim_cache_[axis_].parent_l_
48         =  &i->dim_cache_[axis_];         
49
50       staff_side_p_->add_support (i);
51
52       /*
53         How do we make sure that staff_side_p_ has a dependency from
54         someone else? We can't use i for that,  so we use some other element.
55        */
56       get_staff_info ().command_pcol_l ()->add_dependency (staff_side_p_);
57     }
58 }
59
60 /*
61   URG.
62  */
63 Item*
64 Bar_script_engraver::cast_to_interesting_item (Score_element *e)
65 {
66   Item * i =0;
67   if (hang_on_clef_b_)
68     {
69       Clef_item * c = dynamic_cast<Clef_item*> (e);
70
71
72       // urg.
73       if (c) //  && c->default_b_)
74         {
75           i = c;
76         }
77     }
78   else
79     {
80       i = dynamic_cast<Bar*> (e);
81     }
82   return i;
83 }
84                                                
85 void
86 Bar_script_engraver::acknowledge_element (Score_element_info inf)
87 {
88   if (inf.origin_grav_l_arr_.size () == 1)
89     {
90       Item *i=cast_to_interesting_item (inf.elem_l_);
91       if (!i)
92         return;
93
94       /* Only put numbers on bars that are at our own level (don't put
95          numbers over the staffs of a GrandStaff, only over the GrandStaff
96          itself */
97       if (inf.origin_grav_l_arr_.size () != 1)
98         return;
99
100       do_acknowledge_element (i);
101     }
102 }
103
104 void 
105 Bar_script_engraver::do_pre_move_processing ()
106 {
107   if (text_p_)
108     {
109       typeset_element (text_p_);
110       text_p_ =0;
111     }
112   
113   if (staff_side_p_) 
114     {
115       typeset_element (staff_side_p_);
116       staff_side_p_ = 0;
117     }
118 }
119
120
121 void
122 Bar_script_engraver::create_items (Request *rq)
123 {
124   if (staff_side_p_ || text_p_)
125     return;
126   
127   staff_side_p_ = new G_staff_side_item;
128   staff_side_p_->axis_ = axis_;
129   staff_side_p_->set_elt_property (breakable_scm_sym, SCM_BOOL_T); // ugh
130
131   
132   text_p_ = new G_text_item;
133   text_p_->set_elt_property (breakable_scm_sym, SCM_BOOL_T); // ugh
134
135   Scalar prop = get_property (type_ + "Direction", 0);
136   if (prop.isnum_b ())
137     {
138       staff_side_p_->dir_ = (Direction) (int) prop;
139     }
140   else 
141     {
142       staff_side_p_->dir_ = UP;
143     }
144
145   staff_side_p_->set_victim(text_p_);
146   
147   Scalar padding = get_property (type_ + "ScriptPadding", 0);
148   if (padding.length_i() && padding.isnum_b ())
149     {
150       staff_side_p_->set_elt_property (padding_scm_sym, gh_double2scm(Real(padding)));
151     }
152   else
153     {
154       staff_side_p_
155         ->set_elt_property (padding_scm_sym,
156                             gh_double2scm(paper_l ()->get_realvar (interline_scm_sym)));
157     }
158   
159   staff_side_p_->set_elt_property (visibility_lambda_scm_sym,
160                                    visibility_lambda_);
161   text_p_->set_elt_property (visibility_lambda_scm_sym,
162                              visibility_lambda_);
163   
164   announce_element (Score_element_info (text_p_, rq));
165   announce_element (Score_element_info (staff_side_p_, rq));
166 }