lilypond-1.3.124
[lilypond.git] / lily / bar-number-engraver.cc
blobce129ffd9b18e525fe368d29ae4bfffc5a426eaa
1 /*
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>
7 */
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 "item.hh"
16 #include "moment.hh"
17 #include "engraver.hh"
18 #include "translator-group.hh"
21 class Bar_number_engraver : public Engraver
23 protected:
24 Item* text_p_;
26 protected:
27 virtual void stop_translation_timestep ();
28 virtual void acknowledge_grob (Grob_info);
29 virtual void initialize ();
30 virtual void create_grobs ();
31 void create_items();
33 public:
34 VIRTUAL_COPY_CONS(Translator);
35 Bar_number_engraver();
38 void
39 Bar_number_engraver::create_grobs ()
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))
49 create_items ();
51 // guh.
52 text_p_->set_grob_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 ()
61 text_p_ =0;
64 void
65 Bar_number_engraver::initialize ()
68 ugh: need to share code with mark_engraver
70 daddy_trans_l_->set_property ("staffsFound", SCM_EOL);
75 void
76 Bar_number_engraver::acknowledge_grob (Grob_info inf)
78 Grob * s = inf.elem_l_;
79 if (Staff_symbol::has_interface (s))
81 SCM sts = get_property ("staffsFound");
82 SCM thisstaff = inf.elem_l_->self_scm ();
83 if (scm_memq (thisstaff, sts) == SCM_BOOL_F)
84 daddy_trans_l_->set_property ("staffsFound", gh_cons (thisstaff, sts));
86 else if (text_p_
87 && dynamic_cast<Item*> (s)
88 && s->get_grob_property ("break-align-symbol") == ly_symbol2scm ("Left_edge_item"))
91 By default this would land on the Paper_column -- so why
92 doesn't it work when you leave this out? */
93 text_p_->set_parent (s, X_AXIS);
97 void
98 Bar_number_engraver::stop_translation_timestep ()
100 if (text_p_)
102 text_p_->set_grob_property ("side-support-elements", get_property ("staffsFound"));
103 typeset_grob (text_p_);
104 text_p_ =0;
109 void
110 Bar_number_engraver::create_items ()
112 if (text_p_)
113 return;
115 SCM b = get_property ("BarNumber");
116 text_p_ = new Item (b);
117 Side_position::set_axis(text_p_,Y_AXIS);
119 announce_grob (text_p_, 0);