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