]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-number-engraver.cc
47bceef5bb1f57cfccc6da4a87b00a685bce8e40
[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--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   
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 /*
42   TODO: more advanced formatting via SCM function, perhaps barnumbers
43   every 5 measures?  */
44
45 void
46 Bar_number_engraver::process_music ()
47 {
48   // todo include (&&!time->cadenza_b_)
49
50   SCM wb = get_property ("whichBar");
51   
52   if (gh_string_p (wb))
53     {
54       SCM bn = get_property ("currentBarNumber");
55       SCM smp = get_property ("measurePosition");
56       int ibn = gh_number_p (bn) ? gh_scm2int(bn) : 1;
57       
58       Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
59       if (mp.main_part_ == Rational (0)
60           && ibn != 1)
61         {
62           create_items ();
63           
64           // guh.
65           text_->set_grob_property ("text",
66                                       scm_makfrom0str (to_string (gh_scm2int (bn)).to_str0 ()));
67         }
68     }
69
70 }
71
72
73
74 Bar_number_engraver::Bar_number_engraver ()
75 {
76   text_ =0;
77 }
78
79                                                
80 void
81 Bar_number_engraver::acknowledge_grob (Grob_info inf)
82 {
83   Grob * s = inf.grob_;
84   if (text_
85       && dynamic_cast<Item*> (s)
86       && s->get_grob_property ("break-align-symbol") == ly_symbol2scm ("left-edge"))
87     {
88       /*
89         By default this would land on the Paper_column -- so why
90         doesn't it work when you leave this out?  */
91       text_->set_parent (s, X_AXIS);
92     }
93 }
94
95 void 
96 Bar_number_engraver::stop_translation_timestep ()
97 {
98   if (text_)
99     {
100       text_->set_grob_property ("side-support-elements", get_property ("stavesFound"));
101       typeset_grob (text_);
102       text_ =0;
103     }
104 }
105
106
107 void
108 Bar_number_engraver::create_items ()
109 {
110   if (text_)
111     return;
112
113   SCM b = get_property ("BarNumber");
114   text_ = new Item (b);
115   Side_position_interface::set_axis (text_,Y_AXIS);
116
117   announce_grob(text_, SCM_EOL);
118 }
119
120 ENTER_DESCRIPTION(Bar_number_engraver,
121 /* descr */       "A bar number is created whenever measurePosition is zero. It is
122 put on top of all staves, and appears only at  left side of the staff.",
123 /* creats*/       "BarNumber",
124 /* acks  */       "break-aligned-interface",
125 /* reads */       "currentBarNumber stavesFound" ,
126 /* write */       "");