]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-number-engraver.cc
release: 1.3.46
[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 "text-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   Text_item* text_p_;
24   Protected_scm visibility_lambda_;
25   Protected_scm staffs_;
26
27 protected:
28   virtual void do_creation_processing ();
29   virtual void do_pre_move_processing ();
30   virtual void acknowledge_element (Score_element_info);
31   void create_items();
32   void do_process_music ();
33 public:
34   VIRTUAL_COPY_CONS(Translator);
35   Bar_number_engraver();
36 };
37
38 void
39 Bar_number_engraver::do_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 ADD_THIS_TRANSLATOR(Bar_number_engraver);
58
59 Bar_number_engraver::Bar_number_engraver ()
60 {
61   text_p_ =0;
62   staffs_ = SCM_EOL;
63 }
64
65 void
66 Bar_number_engraver::do_creation_processing ()
67 {
68   String t = "barNumberVisibilityFunction";
69   SCM proc = get_property (t);
70
71   if (gh_procedure_p (proc))
72     visibility_lambda_ = proc;
73 }
74
75
76                                                
77 void
78 Bar_number_engraver::acknowledge_element (Score_element_info inf)
79 {
80   Score_element * s = inf.elem_l_;
81   if (dynamic_cast<Staff_symbol*> (s))
82     {
83       staffs_ = gh_cons (inf.elem_l_->self_scm_, staffs_);
84     }
85   else if (text_p_
86            && dynamic_cast<Item*> (s)
87            && s->get_elt_property ("break-align-symbol") == ly_symbol2scm ("Left_edge_item"))
88     {
89       /*
90         By default this would land on the Paper_column -- so why
91         doesn't it work when you leave this out?  */
92       text_p_->set_parent (s, X_AXIS);
93     }
94 }
95
96 void 
97 Bar_number_engraver::do_pre_move_processing ()
98 {
99   if (text_p_)
100     {
101       text_p_->set_elt_property ("side-support", staffs_);
102       typeset_element (text_p_);
103       text_p_ =0;
104     }
105 }
106
107
108 void
109 Bar_number_engraver::create_items ()
110 {
111   if (text_p_)
112     return;
113   
114   text_p_ = new Text_item;
115   text_p_->set_elt_property ("breakable", SCM_BOOL_T); // ugh
116   Side_position_interface staffside(text_p_);
117   staffside.set_axis (Y_AXIS);
118
119   SCM prop = get_property ("barNumberDirection");
120   if (!isdir_b (prop))
121     {
122       prop = gh_int2scm (UP);
123     }
124   text_p_->set_elt_property ("direction", prop);
125
126   SCM padding = get_property ("barNumberScriptPadding");
127   if (gh_number_p(padding))
128     {
129       text_p_->set_elt_property ("padding", padding);
130     }
131   else
132     {
133       text_p_
134         ->set_elt_property ("padding",
135                             gh_double2scm(paper_l ()->get_var ("interline")));
136     }
137
138   if (gh_procedure_p (visibility_lambda_))
139       text_p_->set_elt_property ("visibility-lambda",
140                                  visibility_lambda_);
141
142   announce_element (Score_element_info (text_p_, 0));
143 }
144