]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-number-engraver.cc
patch::: 1.3.108.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--2000 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 do_pre_move_processing ();
28   virtual void acknowledge_element (Score_element_info);
29   virtual void do_creation_processing ();
30   virtual void process_acknowledged ();
31   void create_items();
32   void  deprecated_process_music ();
33 public:
34   VIRTUAL_COPY_CONS(Translator);
35   Bar_number_engraver();
36 };
37
38 void
39 Bar_number_engraver::deprecated_process_music ()
40 {
41   // todo include (&&!time->cadenza_b_ )
42   SCM bn = get_property("currentBarNumber");
43   SCM smp = get_property ("measurePosition");
44   Moment mp =  (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
45   
46   if (gh_number_p (bn) &&
47       !mp && now_mom () > Moment (0))
48     {
49       create_items ();
50
51       // guh.
52       text_p_->set_elt_property ("text",
53                                  ly_str02scm (to_str (gh_scm2int (bn)).ch_C()));
54     }
55 }
56
57 void
58 Bar_number_engraver::process_acknowledged ()
59 {
60   deprecated_process_music ();
61 }
62
63
64 ADD_THIS_TRANSLATOR(Bar_number_engraver);
65
66 Bar_number_engraver::Bar_number_engraver ()
67 {
68   text_p_ =0;
69 }
70
71 void
72 Bar_number_engraver::do_creation_processing ()
73 {
74   /*
75     ugh: need to share code with mark_engraver
76    */
77   daddy_trans_l_->set_property ("staffsFound", SCM_EOL); 
78 }
79
80
81                                                
82 void
83 Bar_number_engraver::acknowledge_element (Score_element_info inf)
84 {
85   Score_element * s = inf.elem_l_;
86   if (Staff_symbol::has_interface (s))
87     {
88       SCM sts = get_property ("staffsFound");
89       SCM thisstaff = inf.elem_l_->self_scm ();
90       if (scm_memq (thisstaff, sts) == SCM_BOOL_F)
91         daddy_trans_l_->set_property ("staffsFound", gh_cons (thisstaff, sts));
92     }
93   else if (text_p_
94            && dynamic_cast<Item*> (s)
95            && s->get_elt_property ("break-align-symbol") == ly_symbol2scm ("Left_edge_item"))
96     {
97       /*
98         By default this would land on the Paper_column -- so why
99         doesn't it work when you leave this out?  */
100       text_p_->set_parent (s, X_AXIS);
101     }
102 }
103
104 void 
105 Bar_number_engraver::do_pre_move_processing ()
106 {
107   if (text_p_)
108     {
109       text_p_->set_elt_property ("side-support-elements", get_property ("staffsFound"));
110       typeset_element (text_p_);
111       text_p_ =0;
112     }
113 }
114
115
116 void
117 Bar_number_engraver::create_items ()
118 {
119   if (text_p_)
120     return;
121
122   SCM b = get_property ("BarNumber");
123   text_p_ = new Item (b);
124   Side_position::set_axis(text_p_,Y_AXIS);
125
126   announce_element (text_p_, 0);
127 }
128