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