]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-engraver.cc
patch::: 1.1.27.jcn3: geen genade
[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
10 #include "bar-engraver.hh"
11 #include "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.hh"
17 #include "repeated-music.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 void
42 Bar_engraver::acknowledge_element (Score_element_info i)
43 {
44   if (Bar *b = dynamic_cast<Bar *> (i.elem_l_))
45     {
46       // only bar-engraver should create bars
47       assert (0);
48     }
49 }
50
51 void
52 Bar_engraver::create_bar ()
53 {
54   if (!bar_p_)
55     {
56       bar_p_ = new Bar;
57       bar_p_->break_priority_i_  = 0;
58       // urg: "" != empty...
59       String default_type = get_property ("defaultBarType", 0);
60       if (default_type.length_i ())
61         {
62           bar_p_->type_str_ = default_type;
63         }
64       Scalar prop = get_property ("barAtLineStart", 0);
65       if (prop.to_bool ())
66         {
67           bar_p_->at_line_start_b_ = true;
68         }
69       announce_element (Score_element_info (bar_p_, bar_req_l_));
70     }
71 }
72
73 void
74 Bar_engraver::request_bar (String type_str)
75 {
76   Scalar prop = get_property ("barAtLineStart", 0);
77   if (!now_mom ())
78     {
79       Scalar prop = get_property ("barAtLineStart", 0);
80       if (!prop.to_bool ())
81         return;
82     }
83   create_bar ();
84   if (((type_str == "|:") && (bar_p_->type_str_ == ":|"))
85     || ((type_str == ":|") && (bar_p_->type_str_ == "|:")))
86     bar_p_->type_str_ = ":|:";
87   else
88     bar_p_->type_str_ = type_str;
89 }
90
91 void 
92 Bar_engraver::do_creation_processing ()
93 {
94   create_bar ();
95   bar_p_->type_str_ = "";
96   Scalar prop = get_property ("barAuto", 0);
97   auto_create_bar_b_ = prop.to_bool ();
98 }
99
100 void
101 Bar_engraver::do_removal_processing ()
102 {
103   if (bar_p_) 
104     {
105       typeset_element (bar_p_);
106       bar_p_ =0;
107     }
108 }
109
110 void
111 Bar_engraver::do_process_requests()
112 {  
113   Time_description const *time = get_staff_info().time_C_;
114   if (bar_req_l_) 
115     {
116       create_bar ();    
117       bar_p_->type_str_ = bar_req_l_->type_str_;
118     }
119   else if (!now_mom ())
120     {
121       create_bar ();
122       bar_p_->type_str_ = "";
123     }
124   else 
125     {
126       Scalar always = get_property ("barAlways", 0);
127       if ((time && !time->whole_in_measure_) || always.to_bool ())
128         {
129           if (auto_create_bar_b_)
130             create_bar ();
131           Scalar prop = get_property ("barAuto", 0);
132           auto_create_bar_b_ = prop.to_bool ();
133         }
134     }
135   
136   if (!bar_p_)
137     {
138       Break_req r;
139       r.penalty_i_ = Break_req::DISALLOW;
140       daddy_grav_l ()->try_music (&r);
141     }
142 }
143
144
145 void 
146 Bar_engraver::do_pre_move_processing()
147 {
148   if (bar_p_) 
149     {
150       typeset_element (bar_p_);
151       bar_p_ =0;
152     }
153 }
154
155 void
156 Bar_engraver::do_post_move_processing()
157 {
158   bar_req_l_ = 0;
159 }
160
161
162
163 ADD_THIS_TRANSLATOR(Bar_engraver);
164
165