]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-engraver.cc
release: 1.1.53
[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 #include "score-engraver.hh"
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-engraver.hh"
17 #include "warn.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
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       prop = get_property ("barSize", 0);
66       if (prop.isnum_b ())
67         {
68           bar_p_->set_elt_property (bar_size_scm_sym, 
69                                     gh_double2scm (Real(prop)));
70         }
71       announce_element (Score_element_info (bar_p_, bar_req_l_));
72     }
73 }
74
75 /**
76    Make a barline.  If there are both |: and :| requested, merge them
77    to :|:
78
79 */
80 void
81 Bar_engraver::request_bar (String type_str)
82 {
83   Scalar prop = get_property ("barAtLineStart", 0);
84   if (!now_mom ())
85     {
86       Scalar prop = get_property ("barAtLineStart", 0);
87       if (!prop.to_bool ())
88         return;
89     }
90   create_bar ();
91
92   if (((type_str == "|:") && (bar_p_->type_str_ == ":|"))
93     || ((type_str == ":|") && (bar_p_->type_str_ == "|:")))
94     bar_p_->type_str_ = ":|:";
95   else if (type_str_.length_i ())
96     bar_p_->type_str_ = type_str;
97 }
98
99 void 
100 Bar_engraver::do_creation_processing ()
101 {
102   create_bar ();
103   bar_p_->type_str_ = "";
104 }
105
106 void
107 Bar_engraver::do_removal_processing ()
108 {
109   if (bar_p_) 
110     {
111       typeset_element (bar_p_);
112       bar_p_ =0;
113     }
114 }
115
116 void
117 Bar_engraver::do_process_requests()
118 {  
119   Time_description const *time = get_staff_info().time_C_;
120   if (bar_req_l_) 
121     {
122       create_bar ();    
123       bar_p_->type_str_ = bar_req_l_->type_str_;
124     }
125   else if (!now_mom ())
126     {
127       create_bar ();
128       bar_p_->type_str_ = "|";
129     }
130   else 
131     {
132       Scalar nonauto = get_property ("barNonAuto", 0);
133       if (!nonauto.to_bool ())
134         {
135           Scalar always = get_property ("barAlways", 0);
136           if ((time && !time->whole_in_measure_) || always.to_bool ())
137             create_bar ();
138         }
139     }
140   
141   if (!bar_p_)
142     {
143       Score_engraver * e = 0;
144       Translator * t  =  daddy_grav_l ();
145       for (; !e && t;  t = t->daddy_trans_l_)
146         {
147           e = dynamic_cast<Score_engraver*> (t);
148         }
149       
150       if (!e)
151         programming_error ("No score engraver!");
152       else
153         e->forbid_breaks ();
154     }
155 }
156
157
158 void 
159 Bar_engraver::do_pre_move_processing()
160 {
161   if (bar_p_) 
162     {
163       typeset_element (bar_p_);
164       bar_p_ =0;
165     }
166 }
167
168 void
169 Bar_engraver::do_post_move_processing()
170 {
171   bar_req_l_ = 0;
172 }
173
174
175
176 ADD_THIS_TRANSLATOR(Bar_engraver);
177
178