]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-number-engraver.cc
release: 1.5.37
[lilypond.git] / lily / bar-number-engraver.cc
1 /*
2   bar-number-grav.cc -- implement Bar_number_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9
10 #include "lily-guile.hh"
11 #include "paper-column.hh"
12 #include "paper-def.hh"
13 #include "side-position-interface.hh"
14 #include "item.hh"
15 #include "moment.hh"
16 #include "engraver.hh"
17 #include "translator-group.hh"
18
19
20 class Bar_number_engraver : public Engraver
21 {
22 protected:
23   Item* text_p_;
24 protected:
25   virtual void stop_translation_timestep ();
26   virtual void acknowledge_grob (Grob_info);
27   virtual void process_music ();
28   void create_items ();
29   TRANSLATOR_DECLARATIONS(  Bar_number_engraver );
30 };
31
32
33 /*
34   TODO: more advanced formatting via SCM function, perhaps barnumbers
35   every 5 measures?  */
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 (gh_string_p (wb))
45     {
46       SCM bn = get_property ("currentBarNumber");
47       SCM smp = get_property ("measurePosition");
48       int ibn = gh_number_p (bn) ? gh_scm2int(bn) : 1;
49       
50       Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
51       if (mp.main_part_ == Rational (0)
52           && ibn != 1)
53         {
54           create_items ();
55           
56           // guh.
57           text_p_->set_grob_property ("text",
58                                       ly_str02scm (to_str (gh_scm2int (bn)).ch_C ()));
59         }
60     }
61
62 }
63
64
65
66 Bar_number_engraver::Bar_number_engraver ()
67 {
68   text_p_ =0;
69 }
70
71                                                
72 void
73 Bar_number_engraver::acknowledge_grob (Grob_info inf)
74 {
75   Grob * s = inf.grob_l_;
76   if (text_p_
77       && dynamic_cast<Item*> (s)
78       && s->get_grob_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_p_->set_parent (s, X_AXIS);
84     }
85 }
86
87 void 
88 Bar_number_engraver::stop_translation_timestep ()
89 {
90   if (text_p_)
91     {
92       text_p_->set_grob_property ("side-support-elements", get_property ("stavesFound"));
93       typeset_grob (text_p_);
94       text_p_ =0;
95     }
96 }
97
98
99 void
100 Bar_number_engraver::create_items ()
101 {
102   if (text_p_)
103     return;
104
105   SCM b = get_property ("BarNumber");
106   text_p_ = new Item (b);
107   Side_position_interface::set_axis (text_p_,Y_AXIS);
108
109   announce_grob(text_p_, SCM_EOL);
110 }
111
112 ENTER_DESCRIPTION(Bar_number_engraver,
113 /* descr */       "A bar number is created whenever measurePosition is zero. It is
114 put on top of all staves, and appears only at  left side of the staff.",
115 /* creats*/       "BarNumber",
116 /* acks  */       "break-aligned-interface",
117 /* reads */       "currentBarNumber stavesFound" ,
118 /* write */       "");