]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-number-engraver.cc
Update source file headers. Fixes using standard GNU package conventions.
[lilypond.git] / lily / bar-number-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2009 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_aligned);
41   DECLARE_ACKNOWLEDGER (break_alignment);
42   void process_music ();
43   void create_items ();
44   TRANSLATOR_DECLARATIONS (Bar_number_engraver);
45 };
46
47 void
48 Bar_number_engraver::process_music ()
49 {
50   SCM wb = get_property ("whichBar");
51
52   if (scm_is_string (wb))
53     {
54       Moment mp (robust_scm2moment (get_property ("measurePosition"), Moment (0)));
55       if (mp.main_part_ == Rational (0))
56         {
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)))
61             {
62               create_items ();
63               // guh.
64               text_->set_property
65                 ("text", scm_number_to_string (bn, scm_from_int (10)));
66             }
67         }
68     }
69 }
70
71 Bar_number_engraver::Bar_number_engraver ()
72 {
73   text_ = 0;
74 }
75
76
77 /*
78   see rehearsal mark comments.
79  */
80 void
81 Bar_number_engraver::acknowledge_break_aligned (Grob_info inf)
82 {
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")))
89     {
90       /*
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);
94     }
95 }
96
97
98 void
99 Bar_number_engraver::acknowledge_break_alignment (Grob_info inf)
100 {
101   Grob *s = inf.grob ();
102   if (text_
103       && dynamic_cast<Item *> (s))
104     {
105       text_->set_parent (s, X_AXIS);
106     }
107 }
108
109 void
110 Bar_number_engraver::stop_translation_timestep ()
111 {
112   if (text_)
113     {
114       text_->set_object ("side-support-elements",
115                          grob_list_to_grob_array (get_property ("stavesFound")));
116       text_ = 0;
117     }
118 }
119
120 void
121 Bar_number_engraver::create_items ()
122 {
123   if (text_)
124     return;
125
126   text_ = make_item ("BarNumber", SCM_EOL);
127 }
128
129
130 ADD_ACKNOWLEDGER (Bar_number_engraver, break_aligned);
131 ADD_ACKNOWLEDGER (Bar_number_engraver, break_alignment);
132
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}.",
141
142                 /* create */
143                 "BarNumber ",
144
145                 /* read */
146                 "currentBarNumber "
147                 "whichBar "
148                 "stavesFound "
149                 "barNumberVisibility ",
150
151                 /* write */
152                 ""
153                 );