]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-number-engraver.cc
* lily/include/grob-info.hh (class Grob_info): make data member
[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--2005 Han-Wen Nienhuys <hanwen@cs.uu.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
15 /*
16   TODO: detect the top staff (stavesFound), and acknowledge staff-group
17   system-start-delims. If we find these, and the top staff is in the
18   staff-group, add padding to the bar number.
19 */
20
21 class Bar_number_engraver : public Engraver
22 {
23 protected:
24   Item *text_;
25 protected:
26   virtual void stop_translation_timestep ();
27   virtual void acknowledge_grob (Grob_info);
28   virtual void process_music ();
29   void create_items ();
30   TRANSLATOR_DECLARATIONS (Bar_number_engraver);
31 };
32
33 void
34 Bar_number_engraver::process_music ()
35 {
36   // todo include (&&!time->cadenza_b_)
37
38   SCM wb = get_property ("whichBar");
39
40   if (scm_is_string (wb))
41     {
42       Moment mp (robust_scm2moment (get_property ("measurePosition"), Moment (0)));
43       if (mp.main_part_ == Rational (0))
44         {
45           SCM bn = get_property ("currentBarNumber");
46           SCM proc = get_property ("barNumberVisibility");
47           if (scm_is_number (bn) && ly_c_procedure_p (proc)
48               && to_boolean (scm_call_1 (proc, bn)))
49             {
50               create_items ();
51               // guh.
52               text_->set_property
53                 ("text", scm_makfrom0str (to_string (scm_to_int (bn)).to_str0 ()));
54             }
55         }
56     }
57 }
58
59 Bar_number_engraver::Bar_number_engraver ()
60 {
61   text_ = 0;
62 }
63
64 void
65 Bar_number_engraver::acknowledge_grob (Grob_info inf)
66 {
67   Grob *s = inf.grob ();
68   if (text_
69       && dynamic_cast<Item *> (s)
70       && s->get_property ("break-align-symbol") == ly_symbol2scm ("left-edge"))
71     {
72       /*
73         By default this would land on the Paper_column -- so why
74         doesn't it work when you leave this out?  */
75       text_->set_parent (s, X_AXIS);
76     }
77 }
78
79 void
80 Bar_number_engraver::stop_translation_timestep ()
81 {
82   if (text_)
83     {
84       text_->set_property ("side-support-elements", get_property ("stavesFound"));
85
86       text_ = 0;
87     }
88 }
89
90 void
91 Bar_number_engraver::create_items ()
92 {
93   if (text_)
94     return;
95
96   text_ = make_item ("BarNumber", SCM_EOL);
97   Side_position_interface::set_axis (text_, Y_AXIS);
98 }
99
100 ADD_TRANSLATOR (Bar_number_engraver,
101                 /* descr */ "A bar number is created whenever measurePosition is zero. It is\n"
102                 "put on top of all staves, and appears only at  left side of the staff. "
103                 "The staves are taken from @code{stavesFound}, which is maintained by "
104                 "@code{@ref{Staff_collecting_engraver}}. ",
105
106                 /* creats*/ "BarNumber",
107                 /* accepts */ "",
108                 /* acks  */ "break-aligned-interface",
109                 /* reads */ "currentBarNumber stavesFound barNumberVisibility",
110                 /* write */ "");