]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-script-engraver.cc
patch::: 1.1.31.mb1: Re: Spacing problem
[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
17 Bar_script_engraver::Bar_script_engraver ()
18 {
19   axis_ = Y_AXIS;
20   staff_side_p_ = 0;
21   text_p_ =0;
22   hang_on_clef_b_ = false;
23   visibility_lambda_ 
24     = gh_eval_str ("non_postbreak_visibility");
25 }
26
27 void
28 Bar_script_engraver::do_creation_processing ()
29 {
30   Scalar prop = get_property (type_ + "HangOnClef", 0);
31   if (prop.to_bool ())
32     {
33       hang_on_clef_b_ = true;
34     }
35 }
36
37 void
38 Bar_script_engraver::do_acknowledge_element (Item *i)
39 {
40   Axis other_axis = Axis((axis_ + 1)%2);
41   if (staff_side_p_ && !staff_side_p_->dim_cache_[other_axis].parent_l_) 
42     {
43       staff_side_p_->dim_cache_[other_axis].parent_l_
44         = &i->dim_cache_[other_axis];
45       staff_side_p_->dim_cache_[axis_].parent_l_
46         =  &i->dim_cache_[axis_];         
47
48       staff_side_p_->add_support (i);
49       i->add_dependency (staff_side_p_); // UGH. 
50     }
51 }
52
53
54 Item*
55 Bar_script_engraver::cast_to_interesting_item (Score_element *e)
56 {
57   Item * i =0;
58   if (hang_on_clef_b_)
59     {
60       Clef_item * c = dynamic_cast<Clef_item*> (e);
61       if (c && c->default_b_)
62         {
63           i = c;
64         }
65     }
66   else
67     {
68       i = dynamic_cast<Bar*> (e);
69     }
70   return i;
71 }
72                                                
73 void
74 Bar_script_engraver::acknowledge_element (Score_element_info inf)
75 {
76   if (inf.origin_grav_l_arr_.size () == 1)
77     {
78       Item *i=cast_to_interesting_item (inf.elem_l_);
79       if (!i)
80         return;
81
82       /* Only put numbers on bars that are at our own level (don't put
83          numbers over the staffs of a GrandStaff, only over the GrandStaff
84          itself */
85       if (inf.origin_grav_l_arr_.size () != 1)
86         return;
87
88       do_acknowledge_element (i);
89     }
90 }
91
92 void 
93 Bar_script_engraver::do_pre_move_processing ()
94 {
95   if (text_p_)
96     {
97       text_p_->breakable_b_ = true; // ugh
98       typeset_element (text_p_);
99       text_p_ =0;
100     }
101   
102   if (staff_side_p_) 
103     {
104       staff_side_p_->breakable_b_ = true; // ugh
105       typeset_element (staff_side_p_);
106       staff_side_p_ = 0;
107     }
108 }
109
110
111 void
112 Bar_script_engraver::create_items (Request *rq)
113 {
114   if (staff_side_p_ || text_p_)
115     return;
116   
117   staff_side_p_ = new G_staff_side_item;
118   staff_side_p_->axis_ = axis_;
119   
120   text_p_ = new G_text_item;
121
122   Scalar prop = get_property (type_ + "Direction", 0);
123   if (prop.isnum_b ())
124     {
125       staff_side_p_->dir_ = (Direction) (int) prop;
126     }
127   else 
128     {
129       staff_side_p_->dir_ = UP;
130     }
131
132   staff_side_p_->set_victim(text_p_);
133   
134   Scalar padding = get_property (type_ + "ScriptPadding", 0);
135   if (padding.length_i() && padding.isnum_b ())
136     {
137       staff_side_p_->padding_f_ = Real(padding);
138     }
139
140   staff_side_p_->visibility_lambda_  = visibility_lambda_;
141   text_p_->visibility_lambda_ = visibility_lambda_;  
142   
143   announce_element (Score_element_info (text_p_, rq));
144   announce_element (Score_element_info (staff_side_p_, rq));
145 }