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