]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-number-engraver.cc
* lily/break-align-interface.cc (self_align_callback): new
[lilypond.git] / lily / bar-number-engraver.cc
1 /*
2   bar-number-engraver.cc -- implement Bar_number_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
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"
15
16 #include "translator.icc"
17
18 /*
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.
22 */
23
24 class Bar_number_engraver : public Engraver
25 {
26 protected:
27   Item *text_;
28 protected:
29   void stop_translation_timestep ();
30   DECLARE_ACKNOWLEDGER (break_aligned);
31   DECLARE_ACKNOWLEDGER (break_alignment);
32   void process_music ();
33   void create_items ();
34   TRANSLATOR_DECLARATIONS (Bar_number_engraver);
35 };
36
37 void
38 Bar_number_engraver::process_music ()
39 {
40   // todo include (&&!time->cadenza_b_)
41
42   SCM wb = get_property ("whichBar");
43
44   if (scm_is_string (wb))
45     {
46       Moment mp (robust_scm2moment (get_property ("measurePosition"), Moment (0)));
47       if (mp.main_part_ == Rational (0))
48         {
49           SCM bn = get_property ("currentBarNumber");
50           SCM proc = get_property ("barNumberVisibility");
51           if (scm_is_number (bn) && ly_is_procedure (proc)
52               && to_boolean (scm_call_1 (proc, bn)))
53             {
54               create_items ();
55               // guh.
56               text_->set_property
57                 ("text", scm_number_to_string (bn, scm_from_int (10)));
58             }
59         }
60     }
61 }
62
63 Bar_number_engraver::Bar_number_engraver ()
64 {
65   text_ = 0;
66 }
67
68
69 /*
70   see rehearsal mark comments.
71  */
72 void
73 Bar_number_engraver::acknowledge_break_aligned (Grob_info inf)
74 {
75   Grob *s = inf.grob ();
76   if (text_
77       && !text_->get_parent (X_AXIS)
78       && dynamic_cast<Item *> (s)
79       && (s->get_property_data (ly_symbol2scm ("break-align-symbol"))
80           == text_->get_property_data (ly_symbol2scm ("break-align-symbol"))))
81     {
82       /*
83         By default this would land on the Paper_column -- so why
84         doesn't it work when you leave this out?  */
85       text_->set_parent (s, X_AXIS);
86     }
87 }
88
89
90 void
91 Bar_number_engraver::acknowledge_break_alignment (Grob_info inf)
92 {
93   Grob *s = inf.grob ();
94   if (text_
95       && dynamic_cast<Item *> (s))
96     {
97       text_->set_parent (s, X_AXIS);
98     }
99 }
100
101 void
102 Bar_number_engraver::stop_translation_timestep ()
103 {
104   if (text_)
105     {
106       text_->set_object ("side-support-elements",
107                          grob_list_to_grob_array (get_property ("stavesFound")));
108       text_ = 0;
109     }
110 }
111
112 void
113 Bar_number_engraver::create_items ()
114 {
115   if (text_)
116     return;
117
118   text_ = make_item ("BarNumber", SCM_EOL);
119 }
120
121
122 ADD_ACKNOWLEDGER(Bar_number_engraver,break_aligned);
123 ADD_ACKNOWLEDGER(Bar_number_engraver,break_alignment);
124
125 ADD_TRANSLATOR (Bar_number_engraver,
126                 /* doc */ "A bar number is created whenever measurePosition "
127                 "is zero and when there is a bar line (ie. when @code{whichBar} is set. "
128                 "It is \n"
129                 "put on top of all staves, and appears only at  left side of the staff. "
130                 "The staves are taken from @code{stavesFound}, which is maintained by "
131                 "@code{@ref{Staff_collecting_engraver}}. ",
132
133                 /* create */ "BarNumber",
134                 /* accept */ "",
135                 /* read */
136                 "currentBarNumber "
137                 "whichBar "
138                 "stavesFound "
139                 "barNumberVisibility ",
140                 /* write */ "");