]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-script-engraver.cc
release: 1.1.32
[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       i = dynamic_cast<Clef_item*> (e);
61     }
62   else
63     {
64       i = dynamic_cast<Bar*> (e);
65     }
66   return i;
67 }
68                                                
69 void
70 Bar_script_engraver::acknowledge_element (Score_element_info inf)
71 {
72   if (inf.origin_grav_l_arr_.size () == 1)
73     {
74       Item *i=cast_to_interesting_item (inf.elem_l_);
75       if (!i)
76         return;
77
78       /* Only put numbers on bars that are at our own level (don't put
79          numbers over the staffs of a GrandStaff, only over the GrandStaff
80          itself */
81       if (inf.origin_grav_l_arr_.size () != 1)
82         return;
83
84       do_acknowledge_element (i);
85     }
86 }
87
88 void 
89 Bar_script_engraver::do_pre_move_processing ()
90 {
91   if (text_p_)
92     {
93       typeset_element (text_p_);
94       text_p_ =0;
95     }
96   
97   if (staff_side_p_) 
98     {
99       typeset_element (staff_side_p_);
100       staff_side_p_ = 0;
101     }
102 }
103
104
105 void
106 Bar_script_engraver::create_items (Request *rq)
107 {
108   if (staff_side_p_ || text_p_)
109     return;
110   
111   staff_side_p_ = new G_staff_side_item;
112   staff_side_p_->axis_ = axis_;
113   staff_side_p_->breakable_b_ = true; // ugh
114
115   
116   text_p_ = new G_text_item;
117   text_p_->breakable_b_ = true; // ugh
118
119   Scalar prop = get_property (type_ + "Direction", 0);
120   if (prop.isnum_b ())
121     {
122       staff_side_p_->dir_ = (Direction) (int) prop;
123     }
124   else 
125     {
126       staff_side_p_->dir_ = UP;
127     }
128
129   staff_side_p_->set_victim(text_p_);
130   
131   Scalar padding = get_property (type_ + "ScriptPadding", 0);
132   if (padding.length_i() && padding.isnum_b ())
133     {
134       staff_side_p_->padding_f_ = Real(padding);
135     }
136
137   staff_side_p_->visibility_lambda_  = visibility_lambda_;
138   text_p_->visibility_lambda_ = visibility_lambda_;  
139   
140   announce_element (Score_element_info (text_p_, rq));
141   announce_element (Score_element_info (staff_side_p_, rq));
142 }