]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-number-engraver.cc
patch::: 1.5.4.jcn3
[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--2001 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 "staff-symbol.hh"
15 #include "item.hh"
16 #include "moment.hh"
17 #include "engraver.hh"
18 #include "translator-group.hh"
19
20
21 class Bar_number_engraver : public Engraver
22 {
23 protected:
24   Item* text_p_;
25
26 protected:
27   virtual void stop_translation_timestep ();
28   virtual void acknowledge_grob (Grob_info);
29   virtual void initialize ();
30   virtual void create_grobs ();
31   void create_items ();
32
33 public:
34   VIRTUAL_COPY_CONS (Translator);
35   Bar_number_engraver ();
36 };
37
38
39 /*
40   TODO: more advanced formatting via SCM function, perhaps barnumbers
41   every 5 measures?  */
42
43 void
44 Bar_number_engraver::create_grobs ()
45 {
46   // todo include (&&!time->cadenza_b_)
47   SCM bn = get_property ("currentBarNumber");
48   SCM smp = get_property ("measurePosition");
49   Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
50   
51   if (gh_number_p (bn) &&
52       !mp && now_mom () > Moment (0))
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 ADD_THIS_TRANSLATOR (Bar_number_engraver);
63
64 Bar_number_engraver::Bar_number_engraver ()
65 {
66   text_p_ =0;
67 }
68
69 void
70 Bar_number_engraver::initialize ()
71 {
72   /*
73     ugh: need to share code with mark_engraver
74    */
75   daddy_trans_l_->set_property ("stavesFound", SCM_EOL); 
76 }
77
78
79                                                
80 void
81 Bar_number_engraver::acknowledge_grob (Grob_info inf)
82 {
83   Grob * s = inf.elem_l_;
84   if (Staff_symbol::has_interface (s))
85     {
86       SCM sts = get_property ("stavesFound");
87       SCM thisstaff = inf.elem_l_->self_scm ();
88       if (scm_memq (thisstaff, sts) == SCM_BOOL_F)
89         daddy_trans_l_->set_property ("stavesFound", gh_cons (thisstaff, sts));
90     }
91   else if (text_p_
92            && dynamic_cast<Item*> (s)
93            && s->get_grob_property ("break-align-symbol") == ly_symbol2scm ("Left_edge_item"))
94     {
95       /*
96         By default this would land on the Paper_column -- so why
97         doesn't it work when you leave this out?  */
98       text_p_->set_parent (s, X_AXIS);
99     }
100 }
101
102 void 
103 Bar_number_engraver::stop_translation_timestep ()
104 {
105   if (text_p_)
106     {
107       text_p_->set_grob_property ("side-support-elements", get_property ("stavesFound"));
108       typeset_grob (text_p_);
109       text_p_ =0;
110     }
111 }
112
113
114 void
115 Bar_number_engraver::create_items ()
116 {
117   if (text_p_)
118     return;
119
120   SCM b = get_property ("BarNumber");
121   text_p_ = new Item (b);
122   Side_position_interface::set_axis (text_p_,Y_AXIS);
123
124   announce_grob (text_p_, 0);
125 }
126