]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-engraver.cc
release: 1.1.37
[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
42
43 void
44 Bar_engraver::create_bar ()
45 {
46   if (!bar_p_)
47     {
48       bar_p_ = new Staff_bar;
49       bar_p_->set_elt_property (break_priority_scm_sym, gh_int2scm (0));
50
51       // urg: "" != empty...
52       String default_type = get_property ("defaultBarType", 0);
53       if (default_type.length_i ())
54         {
55           bar_p_->type_str_ = default_type;
56         }
57
58       /*
59         urg.  Why did I implement this?
60        */
61       Scalar prop = get_property ("barAtLineStart", 0);
62       if (prop.to_bool ())
63         {
64           bar_p_->set_elt_property (at_line_start_scm_sym, SCM_BOOL_T);
65         }
66       announce_element (Score_element_info (bar_p_, bar_req_l_));
67     }
68 }
69
70 void
71 Bar_engraver::request_bar (String type_str)
72 {
73   Scalar prop = get_property ("barAtLineStart", 0);
74   if (!now_mom ())
75     {
76       Scalar prop = get_property ("barAtLineStart", 0);
77       if (!prop.to_bool ())
78         return;
79     }
80   create_bar ();
81   if (((type_str == "|:") && (bar_p_->type_str_ == ":|"))
82     || ((type_str == ":|") && (bar_p_->type_str_ == "|:")))
83     bar_p_->type_str_ = ":|:";
84   else
85     bar_p_->type_str_ = type_str;
86 }
87
88 void 
89 Bar_engraver::do_creation_processing ()
90 {
91   create_bar ();
92   bar_p_->type_str_ = "";
93 }
94
95 void
96 Bar_engraver::do_removal_processing ()
97 {
98   if (bar_p_) 
99     {
100       typeset_element (bar_p_);
101       bar_p_ =0;
102     }
103 }
104
105 void
106 Bar_engraver::do_process_requests()
107 {  
108   Time_description const *time = get_staff_info().time_C_;
109   if (bar_req_l_) 
110     {
111       create_bar ();    
112       bar_p_->type_str_ = bar_req_l_->type_str_;
113     }
114   else if (!now_mom ())
115     {
116       create_bar ();
117       bar_p_->type_str_ = "|";
118     }
119   else 
120     {
121       Scalar nonauto = get_property ("barNonAuto", 0);
122       if (!nonauto.to_bool ())
123         {
124           Scalar always = get_property ("barAlways", 0);
125           if ((time && !time->whole_in_measure_) || always.to_bool ())
126             create_bar ();
127         }
128     }
129   
130   if (!bar_p_)
131     {
132       Break_req r;
133       r.penalty_i_ = Break_req::DISALLOW;
134       daddy_grav_l ()->try_music (&r);
135     }
136 }
137
138
139 void 
140 Bar_engraver::do_pre_move_processing()
141 {
142   if (bar_p_) 
143     {
144       typeset_element (bar_p_);
145       bar_p_ =0;
146     }
147 }
148
149 void
150 Bar_engraver::do_post_move_processing()
151 {
152   bar_req_l_ = 0;
153 }
154
155
156
157 ADD_THIS_TRANSLATOR(Bar_engraver);
158
159