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