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