Fix type predicates/docstrings for two music properties.
[lilypond/mpolesky.git] / lily / bar-number-engraver.cc
bloba5d5023b9bea55d0dfde5ec51deb0a6d1f2add24
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "paper-column.hh"
21 #include "output-def.hh"
22 #include "side-position-interface.hh"
23 #include "engraver.hh"
24 #include "context.hh"
25 #include "grob-array.hh"
27 #include "translator.icc"
30 TODO: detect the top staff (stavesFound), and acknowledge staff-group
31 system-start-delims. If we find these, and the top staff is in the
32 staff-group, add padding to the bar number.
34 class Bar_number_engraver : public Engraver
36 protected:
37 Item *text_;
38 protected:
39 void stop_translation_timestep ();
40 DECLARE_ACKNOWLEDGER (break_aligned);
41 DECLARE_ACKNOWLEDGER (break_alignment);
42 void process_music ();
43 void create_items ();
44 TRANSLATOR_DECLARATIONS (Bar_number_engraver);
47 void
48 Bar_number_engraver::process_music ()
50 SCM wb = get_property ("whichBar");
52 if (scm_is_string (wb))
54 Moment mp (robust_scm2moment (get_property ("measurePosition"), Moment (0)));
55 if (mp.main_part_ == Rational (0))
57 SCM bn = get_property ("currentBarNumber");
58 SCM proc = get_property ("barNumberVisibility");
59 if (scm_is_number (bn) && ly_is_procedure (proc)
60 && to_boolean (scm_call_1 (proc, bn)))
62 create_items ();
63 // guh.
64 text_->set_property
65 ("text", scm_number_to_string (bn, scm_from_int (10)));
71 Bar_number_engraver::Bar_number_engraver ()
73 text_ = 0;
78 see rehearsal mark comments.
80 void
81 Bar_number_engraver::acknowledge_break_aligned (Grob_info inf)
83 Grob *s = inf.grob ();
84 if (text_
85 && !text_->get_parent (X_AXIS)
86 && dynamic_cast<Item *> (s)
87 && (s->get_property_data ("break-align-symbol")
88 == text_->get_property_data ("break-align-symbol")))
91 By default this would land on the Paper_column -- so why
92 doesn't it work when you leave this out? */
93 text_->set_parent (s, X_AXIS);
98 void
99 Bar_number_engraver::acknowledge_break_alignment (Grob_info inf)
101 Grob *s = inf.grob ();
102 if (text_
103 && dynamic_cast<Item *> (s))
105 text_->set_parent (s, X_AXIS);
109 void
110 Bar_number_engraver::stop_translation_timestep ()
112 if (text_)
114 text_->set_object ("side-support-elements",
115 grob_list_to_grob_array (get_property ("stavesFound")));
116 text_ = 0;
120 void
121 Bar_number_engraver::create_items ()
123 if (text_)
124 return;
126 text_ = make_item ("BarNumber", SCM_EOL);
130 ADD_ACKNOWLEDGER (Bar_number_engraver, break_aligned);
131 ADD_ACKNOWLEDGER (Bar_number_engraver, break_alignment);
133 ADD_TRANSLATOR (Bar_number_engraver,
134 /* doc */
135 "A bar number is created whenever @code{measurePosition} is"
136 " zero and when there is a bar line (i.e., when"
137 " @code{whichBar} is set). It is put on top of all staves,"
138 " and appears only at the left side of the staff. The staves"
139 " are taken from @code{stavesFound}, which is maintained by"
140 " @ref{Staff_collecting_engraver}.",
142 /* create */
143 "BarNumber ",
145 /* read */
146 "currentBarNumber "
147 "whichBar "
148 "stavesFound "
149 "barNumberVisibility ",
151 /* write */