]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-number-engraver.cc
(Paper_column): copy rank_. This fixes
[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--2004 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   
17 TODO: detect the top staff (stavesFound), and acknowledge staff-group
18 system-start-delims. If we find these, and the top staff is in the
19 staff-group, add padding to the bar number.
20
21 */
22
23
24 class Bar_number_engraver : public Engraver
25 {
26 protected:
27   Item* text_;
28 protected:
29   virtual void stop_translation_timestep ();
30   virtual void acknowledge_grob (Grob_info);
31   virtual void process_music ();
32   void create_items ();
33   TRANSLATOR_DECLARATIONS (Bar_number_engraver );
34 };
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_c_procedure_p (proc)
52               && to_boolean (scm_call_1(proc, bn)))
53             {
54               create_items ();
55               // guh.
56               text_->set_property
57                 ("text", scm_makfrom0str (to_string (scm_to_int (bn)).to_str0 ()));
58             }
59         }
60     }
61
62 }
63
64
65
66 Bar_number_engraver::Bar_number_engraver ()
67 {
68   text_ = 0;
69 }
70
71                                                
72 void
73 Bar_number_engraver::acknowledge_grob (Grob_info inf)
74 {
75   Grob * s = inf.grob_;
76   if (text_
77       && dynamic_cast<Item*> (s)
78       && s->get_property ("break-align-symbol") == ly_symbol2scm ("left-edge"))
79     {
80       /*
81         By default this would land on the Paper_column -- so why
82         doesn't it work when you leave this out?  */
83       text_->set_parent (s, X_AXIS);
84     }
85 }
86
87 void 
88 Bar_number_engraver::stop_translation_timestep ()
89 {
90   if (text_)
91     {
92       text_->set_property ("side-support-elements", get_property ("stavesFound"));
93       
94       text_ = 0;
95     }
96 }
97
98
99 void
100 Bar_number_engraver::create_items ()
101 {
102   if (text_)
103     return;
104
105   text_ = make_item ("BarNumber", SCM_EOL);
106   Side_position_interface::set_axis (text_,Y_AXIS);
107 }
108
109 ENTER_DESCRIPTION (Bar_number_engraver,
110 /* descr */       "A bar number is created whenever measurePosition is zero. It is\n"
111                    "put on top of all staves, and appears only at  left side of the staff. "
112                    "The staves are taken from @code{stavesFound}, which is maintained by "
113                    "@code{@ref{Staff_collecting_engraver}}. "
114                    ,
115                    
116 /* creats*/       "BarNumber",
117 /* accepts */     "",
118 /* acks  */      "break-aligned-interface",
119 /* reads */       "currentBarNumber stavesFound barNumberVisibility" ,
120 /* write */       "");