]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-number-engraver.cc
release: 1.3.73
[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 "protected-scm.hh"
19
20 class Bar_number_engraver : public Engraver
21 {
22 protected:
23   Item* text_p_;
24
25   Protected_scm staffs_;
26
27 protected:
28   virtual void do_pre_move_processing ();
29   virtual void acknowledge_element (Score_element_info);
30   void create_items();
31   void do_process_music ();
32 public:
33   VIRTUAL_COPY_CONS(Translator);
34   Bar_number_engraver();
35 };
36
37 void
38 Bar_number_engraver::do_process_music ()
39 {
40   // todo include (&&!time->cadenza_b_ )
41   SCM bn = get_property("currentBarNumber");
42   SCM smp = get_property ("measurePosition");
43   Moment mp =  (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
44   
45   if (gh_number_p (bn) &&
46       !mp && now_mom () > Moment (0))
47     {
48       create_items ();
49
50       // guh.
51       text_p_->set_elt_property ("text",
52                                  ly_str02scm (to_str (gh_scm2int (bn)).ch_C()));
53     }
54 }
55
56 ADD_THIS_TRANSLATOR(Bar_number_engraver);
57
58 Bar_number_engraver::Bar_number_engraver ()
59 {
60   text_p_ =0;
61   staffs_ = SCM_EOL;
62 }
63
64
65
66                                                
67 void
68 Bar_number_engraver::acknowledge_element (Score_element_info inf)
69 {
70   Score_element * s = inf.elem_l_;
71   if (Staff_symbol::has_interface (s))
72     {
73       staffs_ = gh_cons (inf.elem_l_->self_scm_, staffs_);
74     }
75   else if (text_p_
76            && dynamic_cast<Item*> (s)
77            && s->get_elt_property ("break-align-symbol") == ly_symbol2scm ("Left_edge_item"))
78     {
79       /*
80         By default this would land on the Paper_column -- so why
81         doesn't it work when you leave this out?  */
82       text_p_->set_parent (s, X_AXIS);
83     }
84 }
85
86 void 
87 Bar_number_engraver::do_pre_move_processing ()
88 {
89   if (text_p_)
90     {
91       text_p_->set_elt_property ("side-support-elements", staffs_);
92       typeset_element (text_p_);
93       text_p_ =0;
94     }
95 }
96
97
98 void
99 Bar_number_engraver::create_items ()
100 {
101   if (text_p_)
102     return;
103
104   SCM b = get_property ("basicBarNumberProperties");
105   text_p_ = new Item (b);
106   Side_position::set_axis(text_p_,Y_AXIS);
107
108   SCM prop = get_property ("barNumberDirection");
109   if (!isdir_b (prop))
110     {
111       prop = gh_int2scm (UP);
112     }
113   text_p_->set_elt_property ("direction", prop);
114
115   SCM padding = get_property ("barNumberScriptPadding");
116   if (gh_number_p(padding))
117     {
118       text_p_->set_elt_property ("padding", padding);
119     }
120   else
121     {
122       text_p_
123         ->set_elt_property ("padding",
124                             gh_double2scm(paper_l ()->get_var ("interline")));
125     }
126
127
128   announce_element (text_p_, 0);
129 }
130