Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / bar-number-engraver.cc
blob82bc09f0ed02160e009868013bb31fcb9299f517
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2011 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_alignment);
41 void process_music ();
42 void create_items ();
43 TRANSLATOR_DECLARATIONS (Bar_number_engraver);
46 void
47 Bar_number_engraver::process_music ()
49 SCM wb = get_property ("whichBar");
51 if (scm_is_string (wb))
53 Moment mp (robust_scm2moment (get_property ("measurePosition"), Moment (0)));
54 if (mp.main_part_ == Rational (0))
56 SCM bn = get_property ("currentBarNumber");
57 SCM proc = get_property ("barNumberVisibility");
58 if (scm_is_number (bn) && ly_is_procedure (proc)
59 && to_boolean (scm_call_1 (proc, bn)))
61 create_items ();
62 // guh.
63 text_->set_property
64 ("text", scm_number_to_string (bn, scm_from_int (10)));
70 Bar_number_engraver::Bar_number_engraver ()
72 text_ = 0;
75 void
76 Bar_number_engraver::acknowledge_break_alignment (Grob_info inf)
78 Grob *s = inf.grob ();
79 if (text_
80 && dynamic_cast<Item *> (s))
82 text_->set_parent (s, X_AXIS);
86 void
87 Bar_number_engraver::stop_translation_timestep ()
89 if (text_)
91 text_->set_object ("side-support-elements",
92 grob_list_to_grob_array (get_property ("stavesFound")));
93 text_ = 0;
97 void
98 Bar_number_engraver::create_items ()
100 if (text_)
101 return;
103 text_ = make_item ("BarNumber", SCM_EOL);
107 ADD_ACKNOWLEDGER (Bar_number_engraver, break_alignment);
109 ADD_TRANSLATOR (Bar_number_engraver,
110 /* doc */
111 "A bar number is created whenever @code{measurePosition} is"
112 " zero and when there is a bar line (i.e., when"
113 " @code{whichBar} is set). It is put on top of all staves,"
114 " and appears only at the left side of the staff. The staves"
115 " are taken from @code{stavesFound}, which is maintained by"
116 " @ref{Staff_collecting_engraver}.",
118 /* create */
119 "BarNumber ",
121 /* read */
122 "currentBarNumber "
123 "whichBar "
124 "stavesFound "
125 "barNumberVisibility ",
127 /* write */