]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-script-engraver.cc
release: 1.1.24
[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 "g-staff-side.hh"
13 #include "g-text-item.hh"
14 #include "lily-guile.hh"
15
16 Bar_script_engraver::Bar_script_engraver ()
17 {
18   axis_ = Y_AXIS;
19   staff_side_p_ = 0;
20   text_p_ =0;
21   visibility_lambda_ 
22     = gh_eval_str ("(lambda (d) (if (= d -1) '(#t . #t) '(#f . #f)))");
23 }
24
25 void
26 Bar_script_engraver::acknowledge_element (Score_element_info i)
27 {
28   Axis other_axis = Axis((axis_ + 1)%2);
29   
30   if (staff_side_p_ && !staff_side_p_->dim_cache_[other_axis].parent_l_) 
31     {
32       Bar * bar_l = dynamic_cast<Bar*> (i.elem_l_);
33       if (!bar_l)
34         return;
35       
36       /* Only put numbers on bars that are at our own level (don't put
37          numbers over the staffs of a GrandStaff, only over the GrandStaff
38          itself */
39       if (i.origin_grav_l_arr_.size () == 1)
40         {
41           staff_side_p_->dim_cache_[other_axis].parent_l_ =  &bar_l->dim_cache_[other_axis];
42           staff_side_p_->add_support (i.elem_l_);
43         }
44     }
45 }
46
47 void 
48 Bar_script_engraver::do_pre_move_processing ()
49 {
50   if (text_p_)
51     {
52       text_p_->breakable_b_ = true; // ugh
53       typeset_element (text_p_);
54       text_p_ =0;
55     }
56   
57   if (staff_side_p_) 
58     {
59       staff_side_p_->breakable_b_ = true; // ugh
60       typeset_element (staff_side_p_);
61       staff_side_p_ = 0;
62     }
63 }
64
65
66 void
67 Bar_script_engraver::create_items (Request *rq)
68 {
69   if (staff_side_p_ || text_p_)
70     return;
71   
72   staff_side_p_ = new G_staff_side_item;
73   staff_side_p_->axis_ = axis_;
74   
75   text_p_ = new G_text_item;
76
77   Scalar prop = get_property (type_ + "Direction", 0);
78   if (prop.isnum_b ())
79     {
80       staff_side_p_->dir_ = (Direction) (int) prop;
81     }
82   else 
83     {
84       staff_side_p_->dir_ = UP;
85     }
86
87   staff_side_p_->set_victim(text_p_);
88   
89   Scalar padding = get_property (type_ + "ScriptPadding", 0);
90   if (padding.length_i() && padding.isnum_b ())
91     {
92       staff_side_p_->padding_f_ = Real(padding);
93     }
94
95   staff_side_p_->visibility_lambda_  = visibility_lambda_;
96   text_p_->visibility_lambda_ = visibility_lambda_;  
97   
98   announce_element (Score_element_info (text_p_, rq));
99   announce_element (Score_element_info (staff_side_p_, rq));
100 }