* lily/include/lily-guile.hh: many new ly_ functions. Thanks to
[lilypond.git] / lily / bar-number-engraver.cc
blob75a147f6bd9e7b930a11385aebddb448403e5786
1 /*
2 bar-number-engraver.cc -- implement Bar_number_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 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 "item.hh"
15 #include "moment.hh"
16 #include "engraver.hh"
17 #include "context.hh"
21 TODO: detect the top staff (stavesFound), and acknowledge staff-group
22 system-start-delims. If we find these, and the top staff is in the
23 staff-group, add padding to the bar number.
28 class Bar_number_engraver : public Engraver
30 protected:
31 Item* text_;
32 protected:
33 virtual void stop_translation_timestep ();
34 virtual void acknowledge_grob (Grob_info);
35 virtual void process_music ();
36 void create_items ();
37 TRANSLATOR_DECLARATIONS (Bar_number_engraver );
41 void
42 Bar_number_engraver::process_music ()
44 // todo include (&&!time->cadenza_b_)
46 SCM wb = get_property ("whichBar");
48 if (ly_string_p (wb))
50 SCM smp = get_property ("measurePosition");
52 Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
53 if (mp.main_part_ == Rational (0))
55 SCM bn = get_property ("currentBarNumber");
56 SCM proc = get_property ("barNumberVisibility");
57 if (ly_number_p (bn) && ly_procedure_p (proc)
58 && to_boolean (scm_call_1(proc, bn)))
60 create_items ();
61 // guh.
62 text_->set_property
63 ("text", scm_makfrom0str (to_string (ly_scm2int (bn)).to_str0 ()));
72 Bar_number_engraver::Bar_number_engraver ()
74 text_ =0;
78 void
79 Bar_number_engraver::acknowledge_grob (Grob_info inf)
81 Grob * s = inf.grob_;
82 if (text_
83 && dynamic_cast<Item*> (s)
84 && s->get_property ("break-align-symbol") == ly_symbol2scm ("left-edge"))
87 By default this would land on the Paper_column -- so why
88 doesn't it work when you leave this out? */
89 text_->set_parent (s, X_AXIS);
93 void
94 Bar_number_engraver::stop_translation_timestep ()
96 if (text_)
98 text_->set_property ("side-support-elements", get_property ("stavesFound"));
99 typeset_grob (text_);
100 text_ =0;
105 void
106 Bar_number_engraver::create_items ()
108 if (text_)
109 return;
111 text_ = make_item ("BarNumber");
112 Side_position_interface::set_axis (text_,Y_AXIS);
114 announce_grob (text_, SCM_EOL);
117 ENTER_DESCRIPTION (Bar_number_engraver,
118 /* descr */ "A bar number is created whenever measurePosition is zero. It is\n"
119 "put on top of all staves, and appears only at left side of the staff. "
120 "The staves are taken from @code{stavesFound}, which is maintained by "
121 "@code{@ref{Staff_collecting_engraver}}. "
124 /* creats*/ "BarNumber",
125 /* accepts */ "",
126 /* acks */ "break-aligned-interface",
127 /* reads */ "currentBarNumber stavesFound barNumberVisibility" ,
128 /* write */ "");