2 bar-number-grav.cc -- implement Bar_number_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "lily-guile.hh"
11 #include "paper-column.hh"
12 #include "paper-def.hh"
13 #include "side-position-interface.hh"
14 #include "staff-symbol.hh"
15 #include "text-item.hh"
17 #include "engraver.hh"
18 #include "protected-scm.hh"
20 class Bar_number_engraver : public Engraver
24 Protected_scm visibility_lambda_;
25 Protected_scm staffs_;
28 virtual void do_creation_processing ();
29 virtual void do_pre_move_processing ();
30 virtual void acknowledge_element (Score_element_info);
32 void do_process_music ();
34 VIRTUAL_COPY_CONS(Translator);
35 Bar_number_engraver();
39 Bar_number_engraver::do_process_music ()
41 // todo include (&&!time->cadenza_b_ )
42 SCM bn = get_property("currentBarNumber");
43 SCM smp = get_property ("measurePosition");
44 Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
46 if (gh_number_p (bn) &&
47 !mp && now_mom () > Moment (0))
52 text_p_->set_elt_property ("text",
53 ly_str02scm (to_str (gh_scm2int (bn)).ch_C()));
57 ADD_THIS_TRANSLATOR(Bar_number_engraver);
59 Bar_number_engraver::Bar_number_engraver ()
66 Bar_number_engraver::do_creation_processing ()
68 String t = "barNumberVisibilityFunction";
69 SCM proc = get_property (t);
71 if (gh_procedure_p (proc))
72 visibility_lambda_ = proc;
78 Bar_number_engraver::acknowledge_element (Score_element_info inf)
80 Score_element * s = inf.elem_l_;
81 if (dynamic_cast<Staff_symbol*> (s))
83 staffs_ = gh_cons (inf.elem_l_->self_scm_, staffs_);
86 && dynamic_cast<Item*> (s)
87 && s->get_elt_property ("break-align-symbol") == ly_symbol2scm ("Left_edge_item"))
90 By default this would land on the Paper_column -- so why
91 doesn't it work when you leave this out? */
92 text_p_->set_parent (s, X_AXIS);
97 Bar_number_engraver::do_pre_move_processing ()
101 text_p_->set_elt_pointer ("side-support-elements", staffs_);
102 typeset_element (text_p_);
109 Bar_number_engraver::create_items ()
114 text_p_ = new Text_item;
115 text_p_->set_elt_property ("breakable", SCM_BOOL_T); // ugh
116 Side_position_interface staffside(text_p_);
117 staffside.set_axis (Y_AXIS);
119 SCM prop = get_property ("barNumberDirection");
122 prop = gh_int2scm (UP);
124 text_p_->set_elt_property ("direction", prop);
126 SCM padding = get_property ("barNumberScriptPadding");
127 if (gh_number_p(padding))
129 text_p_->set_elt_property ("padding", padding);
134 ->set_elt_property ("padding",
135 gh_double2scm(paper_l ()->get_var ("interline")));
138 if (gh_procedure_p (visibility_lambda_))
139 text_p_->set_elt_property ("visibility-lambda",
142 announce_element (Score_element_info (text_p_, 0));