]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-engraver.cc
71655de8e16ebe774472356c3de2ffebeee836f2
[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 "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.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 Staff_bar;
57       bar_p_->set_elt_property (break_priority_scm_sym, gh_int2scm (0));
58
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
66       /*
67         urg.  Why did I implement this?
68        */
69       Scalar prop = get_property ("barAtLineStart", 0);
70       if (prop.to_bool ())
71         {
72           bar_p_->at_line_start_b_ = true;
73         }
74       announce_element (Score_element_info (bar_p_, bar_req_l_));
75     }
76 }
77
78 void
79 Bar_engraver::request_bar (String type_str)
80 {
81   Scalar prop = get_property ("barAtLineStart", 0);
82   if (!now_mom ())
83     {
84       Scalar prop = get_property ("barAtLineStart", 0);
85       if (!prop.to_bool ())
86         return;
87     }
88   create_bar ();
89   if (((type_str == "|:") && (bar_p_->type_str_ == ":|"))
90     || ((type_str == ":|") && (bar_p_->type_str_ == "|:")))
91     bar_p_->type_str_ = ":|:";
92   else
93     bar_p_->type_str_ = type_str;
94 }
95
96 void 
97 Bar_engraver::do_creation_processing ()
98 {
99   create_bar ();
100   bar_p_->type_str_ = "";
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 if (!now_mom ())
123     {
124       create_bar ();
125       bar_p_->type_str_ = "|";
126     }
127   else 
128     {
129       Scalar nonauto = get_property ("barNonAuto", 0);
130       if (!nonauto.to_bool ())
131         {
132           Scalar always = get_property ("barAlways", 0);
133           if ((time && !time->whole_in_measure_) || always.to_bool ())
134             create_bar ();
135         }
136     }
137   
138   if (!bar_p_)
139     {
140       Break_req r;
141       r.penalty_i_ = Break_req::DISALLOW;
142       daddy_grav_l ()->try_music (&r);
143     }
144 }
145
146
147 void 
148 Bar_engraver::do_pre_move_processing()
149 {
150   if (bar_p_) 
151     {
152       typeset_element (bar_p_);
153       bar_p_ =0;
154     }
155 }
156
157 void
158 Bar_engraver::do_post_move_processing()
159 {
160   bar_req_l_ = 0;
161 }
162
163
164
165 ADD_THIS_TRANSLATOR(Bar_engraver);
166
167