]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-engraver.cc
release: 1.1.59
[lilypond.git] / lily / bar-engraver.cc
1 /*
2   bar-engraver.cc -- implement Bar_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997, 1998, 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9 #include "score-engraver.hh"
10 #include "bar-engraver.hh"
11 #include "staff-bar.hh"
12 #include "musical-request.hh"
13 #include "multi-measure-rest.hh"
14 #include "command-request.hh"
15 #include "time-description.hh"
16 #include "engraver-group-engraver.hh"
17 #include "warn.hh"
18
19 Bar_engraver::Bar_engraver()
20 {
21   bar_p_ =0;
22   do_post_move_processing();
23 }
24
25 bool
26 Bar_engraver::do_try_music (Music*r_l)
27 {
28   if (Bar_req  * b= dynamic_cast <Bar_req *> (r_l))
29     {
30       if (bar_req_l_ && bar_req_l_->equal_b (b)) // huh?
31         return false;
32       
33       bar_req_l_ = b;
34       return true;
35     }
36   
37   return false;
38 }
39
40
41
42 void
43 Bar_engraver::create_bar ()
44 {
45   if (!bar_p_)
46     {
47       bar_p_ = new Staff_bar;
48       bar_p_->set_elt_property (break_priority_scm_sym, gh_int2scm (0));
49
50       // urg: "" != empty...
51       String default_type = get_property ("defaultBarType", 0);
52       if (default_type.length_i ())
53         {
54           bar_p_->type_str_ = default_type;
55         }
56
57       /*
58         urg.  Why did I implement this?
59        */
60       Scalar prop = get_property ("barAtLineStart", 0);
61       if (prop.to_bool ())
62         {
63           bar_p_->set_elt_property (at_line_start_scm_sym, SCM_BOOL_T);
64         }
65       prop = get_property ("barSize", 0);
66       if (prop.isnum_b ())
67         {
68           bar_p_->set_elt_property (bar_size_scm_sym, 
69                                     gh_double2scm (Real(prop)));
70         }
71       announce_element (Score_element_info (bar_p_, bar_req_l_));
72     }
73 }
74
75 /**
76    Make a barline.  If there are both |: and :| requested, merge them
77    to :|:.
78
79 */
80 void
81 Bar_engraver::request_bar (String requested_type)
82 {
83   Scalar prop = get_property ("barAtLineStart", 0);
84   if (!now_mom ())
85     {
86       Scalar prop = get_property ("barAtLineStart", 0);
87       if (!prop.to_bool ())
88         return;
89     }
90   bool  bar_existed = bar_p_;
91   create_bar ();
92   if (bar_existed && requested_type == "")
93     {
94       return;
95     }
96   else if (((requested_type == "|:") && (bar_p_->type_str_ == ":|"))
97     || ((requested_type == ":|") && (bar_p_->type_str_ == "|:")))
98     bar_p_->type_str_ = ":|:";
99   else
100     bar_p_->type_str_ = requested_type;
101 }
102
103 void 
104 Bar_engraver::do_creation_processing ()
105 {
106   create_bar ();
107   bar_p_->type_str_ = "";
108 }
109
110 void
111 Bar_engraver::do_removal_processing ()
112 {
113   if (bar_p_) 
114     {
115       typeset_element (bar_p_);
116       bar_p_ =0;
117     }
118 }
119
120 void
121 Bar_engraver::do_process_requests()
122 {  
123   Time_description const *time = get_staff_info().time_C_;
124   if (bar_req_l_) 
125     {
126       create_bar ();    
127       bar_p_->type_str_ = bar_req_l_->type_str_;
128     }
129   else if (!now_mom ())
130     {
131       create_bar ();
132       bar_p_->type_str_ = "|";
133     }
134   else 
135     {
136       Scalar nonauto = get_property ("barNonAuto", 0);
137       if (!nonauto.to_bool ())
138         {
139           Scalar always = get_property ("barAlways", 0);
140           if ((time && !time->whole_in_measure_) || always.to_bool ())
141             create_bar ();
142         }
143     }
144   
145   if (!bar_p_)
146     {
147       Score_engraver * e = 0;
148       Translator * t  =  daddy_grav_l ();
149       for (; !e && t;  t = t->daddy_trans_l_)
150         {
151           e = dynamic_cast<Score_engraver*> (t);
152         }
153       
154       if (!e)
155         programming_error ("No score engraver!");
156       else
157         e->forbid_breaks ();
158     }
159 }
160
161
162 void 
163 Bar_engraver::do_pre_move_processing()
164 {
165   if (bar_p_) 
166     {
167       typeset_element (bar_p_);
168       bar_p_ =0;
169     }
170 }
171
172 void
173 Bar_engraver::do_post_move_processing()
174 {
175   bar_req_l_ = 0;
176 }
177
178
179
180 ADD_THIS_TRANSLATOR(Bar_engraver);
181
182