]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-script-engraver.cc
patch::: 1.3.45.jcn2
[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--2000 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 "side-position-interface.hh"
14 #include "text-item.hh"
15 #include "lily-guile.hh"
16 #include "paper-column.hh"
17 #include "paper-def.hh"
18 #include "dimension-cache.hh"
19 #include "staff-symbol-referencer.hh"
20 #include "side-position-interface.hh"
21 #include "staff-symbol.hh"
22
23 Bar_script_engraver::Bar_script_engraver ()
24 {
25   axis_ = Y_AXIS;
26   text_p_ =0;
27 }
28
29 void
30 Bar_script_engraver::do_creation_processing ()
31 {
32   String t = type_  + "VisibilityFunction";
33   SCM proc = get_property (t);
34
35   if (gh_procedure_p (proc))
36       visibility_lambda_ = proc;
37 }
38
39
40 /*
41   Some interesting item came across.  Lets attach the text and the
42   positioner to the item.
43
44 */
45  
46 void
47 Bar_script_engraver::attach_script_to_item (Item *i)
48 {
49   Axis other_axis = Axis((axis_ + 1)%2);
50   if (text_p_ && !text_p_->parent_l(other_axis)) 
51     {
52       text_p_->set_parent (i,other_axis);
53       text_p_->set_parent (i,axis_);
54
55       if (!text_p_->parent_l(other_axis))
56         text_p_->set_parent (i,other_axis);
57
58       Side_position_interface (text_p_).add_support (i);
59
60       /*
61         How do we make sure that text_p_ has a dependency from
62         someone else? We can't use I for that,  so we use some other element.
63        */
64       // text_p_->set_elt_property ("dangling", SCM_BOOL_T)
65       get_staff_info ().command_pcol_l ()->add_dependency (text_p_);
66     }
67 }
68
69 /*
70   URG.
71  */
72 Item*
73 Bar_script_engraver::cast_to_interesting_item (Score_element *e)
74 {
75   Item * i =0;
76
77   /*
78     should do type lookup: if (e ->is_type (hang_on_type))
79    */
80   i = dynamic_cast<Bar*> (e);
81
82   return i;
83 }
84                                                
85 void
86 Bar_script_engraver::acknowledge_element (Score_element_info inf)
87 {
88   if (inf.origin_trans_l_arr (this).size () == 1)
89     {
90       Item *i=cast_to_interesting_item (inf.elem_l_);
91       if (!i)
92         return;
93
94       /* Only put numbers on bars that are at our own level (don't put
95          numbers over the staffs of a GrandStaff, only over the GrandStaff
96          itself */
97       if (inf.origin_trans_l_arr (this).size () != 1)
98         return;
99
100       attach_script_to_item (i);
101     }
102 }
103
104 void 
105 Bar_script_engraver::do_pre_move_processing ()
106 {
107   if (text_p_)
108     {
109       Staff_symbol * st = staff_symbol_referencer (text_p_).staff_symbol_l();
110       
111       if (st)
112         side_position (text_p_).add_support (st);
113       
114       typeset_element (text_p_);
115       text_p_ =0;
116     }
117 }
118
119
120 void
121 Bar_script_engraver::create_items (Request *rq)
122 {
123   if (text_p_)
124     return;
125   
126   text_p_ = new Text_item;
127   text_p_->set_elt_property ("breakable", SCM_BOOL_T); // ugh
128   Side_position_interface staffside(text_p_);
129   staffside.set_axis (axis_);
130
131   SCM prop = get_property (type_ + "Direction");
132   if (!isdir_b (prop))
133     {
134       prop = gh_int2scm (UP);
135     }
136   text_p_->set_elt_property ("direction", prop);
137
138   SCM padding = get_property (type_ + "ScriptPadding");
139   if (gh_number_p(padding))
140     {
141       text_p_->set_elt_property ("padding", padding);
142     }
143   else
144     {
145       text_p_
146         ->set_elt_property ("padding",
147                             gh_double2scm(paper_l ()->get_var ("interline")));
148     }
149
150   if (gh_procedure_p (visibility_lambda_))
151       text_p_->set_elt_property ("visibility-lambda",
152                                  visibility_lambda_);
153   
154   announce_element (Score_element_info (text_p_, rq));
155 }
156