]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-engraver.cc
release: 1.1.31
[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 }
97
98 void
99 Bar_engraver::do_removal_processing ()
100 {
101   if (bar_p_) 
102     {
103       typeset_element (bar_p_);
104       bar_p_ =0;
105     }
106 }
107
108 void
109 Bar_engraver::do_process_requests()
110 {  
111   Time_description const *time = get_staff_info().time_C_;
112   if (bar_req_l_) 
113     {
114       create_bar ();    
115       bar_p_->type_str_ = bar_req_l_->type_str_;
116     }
117   else if (!now_mom ())
118     {
119       create_bar ();
120       bar_p_->type_str_ = "|";
121     }
122   else 
123     {
124       Scalar nonauto = get_property ("barNonAuto", 0);
125       if (!nonauto.to_bool ())
126         {
127           Scalar always = get_property ("barAlways", 0);
128           if ((time && !time->whole_in_measure_) || always.to_bool ())
129             create_bar ();
130         }
131     }
132   
133   if (!bar_p_)
134     {
135       Break_req r;
136       r.penalty_i_ = Break_req::DISALLOW;
137       daddy_grav_l ()->try_music (&r);
138     }
139 }
140
141
142 void 
143 Bar_engraver::do_pre_move_processing()
144 {
145   if (bar_p_) 
146     {
147       typeset_element (bar_p_);
148       bar_p_ =0;
149     }
150 }
151
152 void
153 Bar_engraver::do_post_move_processing()
154 {
155   bar_req_l_ = 0;
156 }
157
158
159
160 ADD_THIS_TRANSLATOR(Bar_engraver);
161
162