lilypond-1.3.16
[lilypond.git] / lily / bar-script-engraver.cc
blobc51d6611753c929ab97aba58d4223080adeb8a4e
1 /*
2 bar-script-engraver.cc -- implement Bar_script_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
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"
21 Bar_script_engraver::Bar_script_engraver ()
23 axis_ = Y_AXIS;
24 text_p_ =0;
25 hang_on_clef_b_ = false;
26 visibility_lambda_
27 = ly_eval_str ("non-postbreak-visibility");
30 void
31 Bar_script_engraver::do_creation_processing ()
33 SCM prop = get_property (type_ + "HangOnClef", 0);
34 if (to_boolean (prop))
36 hang_on_clef_b_ = true;
41 Some interesting item came across. Lets attach the text and the
42 positioner to the item.
46 void
47 Bar_script_engraver::attach_script_to_item (Item *i)
49 Axis other_axis = Axis((axis_ + 1)%2);
50 if (text_p_ && !text_p_->parent_l(other_axis))
52 text_p_->set_parent (i,other_axis);
53 text_p_->set_parent (i,axis_);
55 if (!text_p_->parent_l(other_axis))
56 text_p_->set_parent (i,other_axis);
58 Side_position_interface (text_p_).add_support (i);
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.
64 // text_p_->set_elt_property ("dangling", SCM_BOOL_T)
65 get_staff_info ().command_pcol_l ()->add_dependency (text_p_);
70 URG.
72 Item*
73 Bar_script_engraver::cast_to_interesting_item (Score_element *e)
75 Item * i =0;
76 if (hang_on_clef_b_)
78 Clef_item * c = dynamic_cast<Clef_item*> (e);
81 // urg.
82 if (c) // && c->default_b_)
84 i = c;
87 else
89 i = dynamic_cast<Bar*> (e);
91 return i;
94 void
95 Bar_script_engraver::acknowledge_element (Score_element_info inf)
97 if (inf.origin_trans_l_arr_.size () == 1)
99 Item *i=cast_to_interesting_item (inf.elem_l_);
100 if (!i)
101 return;
103 /* Only put numbers on bars that are at our own level (don't put
104 numbers over the staffs of a GrandStaff, only over the GrandStaff
105 itself */
106 if (inf.origin_trans_l_arr_.size () != 1)
107 return;
109 attach_script_to_item (i);
113 void
114 Bar_script_engraver::do_pre_move_processing ()
116 if (text_p_)
118 typeset_element (text_p_);
119 text_p_ =0;
124 void
125 Bar_script_engraver::create_items (Request *rq)
127 if (text_p_)
128 return;
130 text_p_ = new Text_item;
131 text_p_->set_elt_property ("breakable", SCM_BOOL_T); // ugh
132 Side_position_interface staffside(text_p_);
133 staffside.set_axis (axis_);
135 SCM prop = get_property (type_ + "Direction", 0);
136 if (!isdir_b (prop))
138 prop = gh_int2scm (UP);
140 text_p_->set_elt_property ("direction", prop);
142 SCM padding = get_property (type_ + "ScriptPadding", 0);
143 if (gh_number_p(padding))
145 text_p_->set_elt_property ("padding", padding);
147 else
149 text_p_
150 ->set_elt_property ("padding",
151 gh_double2scm(paper_l ()->get_var ("interline")));
154 text_p_->set_elt_property ("visibility-lambda",
155 visibility_lambda_);
157 announce_element (Score_element_info (text_p_, rq));