]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-engraver.cc
release: 1.1.43
[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
18 Bar_engraver::Bar_engraver()
19 {
20   bar_p_ =0;
21   do_post_move_processing();
22 }
23
24 bool
25 Bar_engraver::do_try_music (Music*r_l)
26 {
27   if (Bar_req  * b= dynamic_cast <Bar_req *> (r_l))
28     {
29       if (bar_req_l_ && bar_req_l_->equal_b (b)) // huh?
30         return false;
31       
32       bar_req_l_ = b;
33       return true;
34     }
35   
36   return false;
37
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       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   Scalar prop = get_property ("barAtLineStart", 0);
73   if (!now_mom ())
74     {
75       Scalar prop = get_property ("barAtLineStart", 0);
76       if (!prop.to_bool ())
77         return;
78     }
79   create_bar ();
80   if (((type_str == "|:") && (bar_p_->type_str_ == ":|"))
81     || ((type_str == ":|") && (bar_p_->type_str_ == "|:")))
82     bar_p_->type_str_ = ":|:";
83   else
84     bar_p_->type_str_ = type_str;
85 }
86
87 void 
88 Bar_engraver::do_creation_processing ()
89 {
90   create_bar ();
91   bar_p_->type_str_ = "";
92 }
93
94 void
95 Bar_engraver::do_removal_processing ()
96 {
97   if (bar_p_) 
98     {
99       typeset_element (bar_p_);
100       bar_p_ =0;
101     }
102 }
103
104 void
105 Bar_engraver::do_process_requests()
106 {  
107   Time_description const *time = get_staff_info().time_C_;
108   if (bar_req_l_) 
109     {
110       create_bar ();    
111       bar_p_->type_str_ = bar_req_l_->type_str_;
112     }
113   else if (!now_mom ())
114     {
115       create_bar ();
116       bar_p_->type_str_ = "|";
117     }
118   else 
119     {
120       Scalar nonauto = get_property ("barNonAuto", 0);
121       if (!nonauto.to_bool ())
122         {
123           Scalar always = get_property ("barAlways", 0);
124           if ((time && !time->whole_in_measure_) || always.to_bool ())
125             create_bar ();
126         }
127     }
128   
129   if (!bar_p_)
130     {
131       Break_req r;
132       r.penalty_i_ = Break_req::DISALLOW;
133       daddy_grav_l ()->try_music (&r);
134     }
135 }
136
137
138 void 
139 Bar_engraver::do_pre_move_processing()
140 {
141   if (bar_p_) 
142     {
143       typeset_element (bar_p_);
144       bar_p_ =0;
145     }
146 }
147
148 void
149 Bar_engraver::do_post_move_processing()
150 {
151   bar_req_l_ = 0;
152 }
153
154
155
156 ADD_THIS_TRANSLATOR(Bar_engraver);
157
158