]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-script-engraver.cc
release: 1.1.35
[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       typeset_element (text_p_);
98       text_p_ =0;
99     }
100   
101   if (staff_side_p_) 
102     {
103       typeset_element (staff_side_p_);
104       staff_side_p_ = 0;
105     }
106 }
107
108
109 void
110 Bar_script_engraver::create_items (Request *rq)
111 {
112   if (staff_side_p_ || text_p_)
113     return;
114   
115   staff_side_p_ = new G_staff_side_item;
116   staff_side_p_->axis_ = axis_;
117   staff_side_p_->set_elt_property (breakable_scm_sym, SCM_BOOL_T); // ugh
118
119   
120   text_p_ = new G_text_item;
121   text_p_->set_elt_property (breakable_scm_sym, SCM_BOOL_T); // ugh
122
123   Scalar prop = get_property (type_ + "Direction", 0);
124   if (prop.isnum_b ())
125     {
126       staff_side_p_->dir_ = (Direction) (int) prop;
127     }
128   else 
129     {
130       staff_side_p_->dir_ = UP;
131     }
132
133   staff_side_p_->set_victim(text_p_);
134   
135   Scalar padding = get_property (type_ + "ScriptPadding", 0);
136   if (padding.length_i() && padding.isnum_b ())
137     {
138       staff_side_p_->padding_f_ = Real(padding);
139     }
140
141   
142   staff_side_p_->set_elt_property (visibility_lambda_scm_sym,
143                                    visibility_lambda_);
144   text_p_->set_elt_property (visibility_lambda_scm_sym,
145                              visibility_lambda_);
146   
147   announce_element (Score_element_info (text_p_, rq));
148   announce_element (Score_element_info (staff_side_p_, rq));
149 }