]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-number-engraver.cc
* The grand 2005-2006 replace.
[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   void process_music ();
32   void create_items ();
33   TRANSLATOR_DECLARATIONS (Bar_number_engraver);
34 };
35
36 void
37 Bar_number_engraver::process_music ()
38 {
39   // todo include (&&!time->cadenza_b_)
40
41   SCM wb = get_property ("whichBar");
42
43   if (scm_is_string (wb))
44     {
45       Moment mp (robust_scm2moment (get_property ("measurePosition"), Moment (0)));
46       if (mp.main_part_ == Rational (0))
47         {
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)))
52             {
53               create_items ();
54               // guh.
55               text_->set_property
56                 ("text", scm_number_to_string (bn, scm_from_int (10)));
57             }
58         }
59     }
60 }
61
62 Bar_number_engraver::Bar_number_engraver ()
63 {
64   text_ = 0;
65 }
66
67 void
68 Bar_number_engraver::acknowledge_break_aligned (Grob_info inf)
69 {
70   Grob *s = inf.grob ();
71   if (text_
72       && dynamic_cast<Item *> (s)
73       && s->get_property ("break-align-symbol") == ly_symbol2scm ("left-edge"))
74     {
75       /*
76         By default this would land on the Paper_column -- so why
77         doesn't it work when you leave this out?  */
78       text_->set_parent (s, X_AXIS);
79     }
80 }
81
82 void
83 Bar_number_engraver::stop_translation_timestep ()
84 {
85   if (text_)
86     {
87       text_->set_object ("side-support-elements",
88                          grob_list_to_grob_array (get_property ("stavesFound")));
89       text_ = 0;
90     }
91 }
92
93 void
94 Bar_number_engraver::create_items ()
95 {
96   if (text_)
97     return;
98
99   text_ = make_item ("BarNumber", SCM_EOL);
100 }
101
102 ADD_TRANSLATOR (Bar_number_engraver,
103                 /* doc */ "A bar number is created whenever measurePosition "
104                 "is zero and there is a bar line. It is \n"
105                 "put on top of all staves, and appears only at  left side of the staff. "
106                 "The staves are taken from @code{stavesFound}, which is maintained by "
107                 "@code{@ref{Staff_collecting_engraver}}. ",
108
109                 /* create */ "BarNumber",
110                 /* accept */ "",
111                 /* read */
112                 "currentBarNumber "
113                 "whichBar "
114                 "stavesFound "
115                 "barNumberVisibility",
116                 /* write */ "");