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