]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-number-engraver.cc
Remove redundant acknowledger in Bar_number_engraver.
[lilypond.git] / lily / bar-number-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
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.
10
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.
15
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/>.
18 */
19
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"
26
27 #include "translator.icc"
28
29 /*
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.
33 */
34 class Bar_number_engraver : public Engraver
35 {
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);
44 };
45
46 void
47 Bar_number_engraver::process_music ()
48 {
49   SCM wb = get_property ("whichBar");
50
51   if (scm_is_string (wb))
52     {
53       Moment mp (robust_scm2moment (get_property ("measurePosition"), Moment (0)));
54       if (mp.main_part_ == Rational (0))
55         {
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)))
60             {
61               create_items ();
62               // guh.
63               text_->set_property
64                 ("text", scm_number_to_string (bn, scm_from_int (10)));
65             }
66         }
67     }
68 }
69
70 Bar_number_engraver::Bar_number_engraver ()
71 {
72   text_ = 0;
73 }
74
75 void
76 Bar_number_engraver::acknowledge_break_alignment (Grob_info inf)
77 {
78   Grob *s = inf.grob ();
79   if (text_
80       && dynamic_cast<Item *> (s))
81     {
82       text_->set_parent (s, X_AXIS);
83     }
84 }
85
86 void
87 Bar_number_engraver::stop_translation_timestep ()
88 {
89   if (text_)
90     {
91       text_->set_object ("side-support-elements",
92                          grob_list_to_grob_array (get_property ("stavesFound")));
93       text_ = 0;
94     }
95 }
96
97 void
98 Bar_number_engraver::create_items ()
99 {
100   if (text_)
101     return;
102
103   text_ = make_item ("BarNumber", SCM_EOL);
104 }
105
106
107 ADD_ACKNOWLEDGER (Bar_number_engraver, break_alignment);
108
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}.",
117
118                 /* create */
119                 "BarNumber ",
120
121                 /* read */
122                 "currentBarNumber "
123                 "whichBar "
124                 "stavesFound "
125                 "barNumberVisibility ",
126
127                 /* write */
128                 ""
129                 );