Nitpick: ly:spanner-bound grob name slur -> spanner.
[lilypond.git] / lily / bar-number-engraver.cc
blob61242297cde75b2d082373060a27a16a21150d4c
1 /*
2 bar-number-engraver.cc -- implement Bar_number_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "paper-column.hh"
10 #include "output-def.hh"
11 #include "side-position-interface.hh"
12 #include "engraver.hh"
13 #include "context.hh"
14 #include "grob-array.hh"
16 #include "translator.icc"
19 TODO: detect the top staff (stavesFound), and acknowledge staff-group
20 system-start-delims. If we find these, and the top staff is in the
21 staff-group, add padding to the bar number.
23 class Bar_number_engraver : public Engraver
25 protected:
26 Item *text_;
27 protected:
28 void stop_translation_timestep ();
29 DECLARE_ACKNOWLEDGER (break_aligned);
30 DECLARE_ACKNOWLEDGER (break_alignment);
31 void process_music ();
32 void create_items ();
33 TRANSLATOR_DECLARATIONS (Bar_number_engraver);
36 void
37 Bar_number_engraver::process_music ()
39 SCM wb = get_property ("whichBar");
41 if (scm_is_string (wb))
43 Moment mp (robust_scm2moment (get_property ("measurePosition"), Moment (0)));
44 if (mp.main_part_ == Rational (0))
46 SCM bn = get_property ("currentBarNumber");
47 SCM proc = get_property ("barNumberVisibility");
48 if (scm_is_number (bn) && ly_is_procedure (proc)
49 && to_boolean (scm_call_1 (proc, bn)))
51 create_items ();
52 // guh.
53 text_->set_property
54 ("text", scm_number_to_string (bn, scm_from_int (10)));
60 Bar_number_engraver::Bar_number_engraver ()
62 text_ = 0;
67 see rehearsal mark comments.
69 void
70 Bar_number_engraver::acknowledge_break_aligned (Grob_info inf)
72 Grob *s = inf.grob ();
73 if (text_
74 && !text_->get_parent (X_AXIS)
75 && dynamic_cast<Item *> (s)
76 && (s->get_property_data ("break-align-symbol")
77 == text_->get_property_data ("break-align-symbol")))
80 By default this would land on the Paper_column -- so why
81 doesn't it work when you leave this out? */
82 text_->set_parent (s, X_AXIS);
87 void
88 Bar_number_engraver::acknowledge_break_alignment (Grob_info inf)
90 Grob *s = inf.grob ();
91 if (text_
92 && dynamic_cast<Item *> (s))
94 text_->set_parent (s, X_AXIS);
98 void
99 Bar_number_engraver::stop_translation_timestep ()
101 if (text_)
103 text_->set_object ("side-support-elements",
104 grob_list_to_grob_array (get_property ("stavesFound")));
105 text_ = 0;
109 void
110 Bar_number_engraver::create_items ()
112 if (text_)
113 return;
115 text_ = make_item ("BarNumber", SCM_EOL);
119 ADD_ACKNOWLEDGER (Bar_number_engraver, break_aligned);
120 ADD_ACKNOWLEDGER (Bar_number_engraver, break_alignment);
122 ADD_TRANSLATOR (Bar_number_engraver,
123 /* doc */
124 "A bar number is created whenever @code{measurePosition} is"
125 " zero and when there is a bar line (i.e., when"
126 " @code{whichBar} is set). It is put on top of all staves,"
127 " and appears only at the left side of the staff. The staves"
128 " are taken from @code{stavesFound}, which is maintained by"
129 " @ref{Staff_collecting_engraver}.",
131 /* create */
132 "BarNumber ",
134 /* read */
135 "currentBarNumber "
136 "whichBar "
137 "stavesFound "
138 "barNumberVisibility ",
140 /* write */