]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-engraver.cc
patch::: 1.1.22.jcn4: laat
[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   bar_l_ =0;
23   do_post_move_processing();
24 }
25
26 bool
27 Bar_engraver::do_try_music (Music*r_l)
28 {
29   if (Bar_req  * b= dynamic_cast <Bar_req *> (r_l))
30     {
31       if (bar_req_l_ && bar_req_l_->equal_b (b)) // huh?
32         return false;
33       
34       bar_req_l_ = b;
35
36       return true;
37     }
38   
39   return false;
40
41 }
42
43 void
44 Bar_engraver::acknowledge_element (Score_element_info i)
45 {
46   if (Bar *b = dynamic_cast<Bar *> (i.elem_l_))
47     {
48       bar_l_ = b;
49       //      auto_create_bar_b_ = false;
50     }
51 }
52
53 void
54 Bar_engraver::create_bar ()
55 {
56   if (!bar_p_)
57     {
58       bar_p_ = new Bar;
59       bar_p_->break_priority_i_  = 0;
60       // urg: "" != empty...
61       String default_type = get_property ("defaultBarType", 0);
62       if (default_type.length_i ())
63         {
64           bar_p_->type_str_ = default_type;
65         }
66       announce_element (Score_element_info (bar_p_, bar_req_l_));
67     }
68 }
69
70
71 void 
72 Bar_engraver::do_creation_processing ()
73 {
74   create_bar ();
75   bar_p_->type_str_ = "";
76   Scalar prop = get_property ("barAuto", 0);
77   auto_create_bar_b_ = prop.to_bool ();
78 }
79
80 void
81 Bar_engraver::do_removal_processing ()
82 {
83   if (bar_p_) 
84     {
85       typeset_element (bar_p_);
86       bar_p_ =0;
87     }
88 }
89
90 void
91 Bar_engraver::do_process_requests()
92 {  
93   Time_description const *time = get_staff_info().time_C_;
94   if (bar_req_l_) 
95     {
96       if (!bar_p_)
97         create_bar ();    
98
99       bar_p_->type_str_ = bar_req_l_->type_str_;
100     }
101   else 
102     {
103       Scalar always = get_property ("barAlways", 0);
104       if ((time && !time->whole_in_measure_) || always.to_bool ())
105         {
106           if (auto_create_bar_b_)
107             create_bar ();
108           Scalar prop = get_property ("barAuto", 0);
109           auto_create_bar_b_ = prop.to_bool ();
110         }
111     }
112   
113   /*
114     hmm, perhaps it's Better to create empty bars if you want none
115     displayed, and keep bars for breakpoints ?
116    */
117 #if 0
118   if ((time && time->whole_in_measure_)
119       && !always.to_bool ()
120       && !bar_p_ && !bar_l_)
121 #endif
122   if (!bar_p_ && !bar_l_)
123     {
124       Break_req r;
125       r.penalty_i_ = Break_req::DISALLOW;
126       daddy_grav_l ()->try_music (&r);
127     }
128 }
129
130
131 void 
132 Bar_engraver::do_pre_move_processing()
133 {
134   if (bar_l_)
135     {
136       bar_l_ = 0;
137       if (bar_p_)
138         {
139           bar_p_->unlink ();
140           bar_p_ = 0;
141         }
142     }
143   if (bar_p_) 
144     {
145       typeset_element (bar_p_);
146       bar_p_ =0;
147     }
148 }
149
150 void
151 Bar_engraver::do_post_move_processing()
152 {
153   bar_req_l_ = 0;
154 }
155
156
157
158 ADD_THIS_TRANSLATOR(Bar_engraver);
159
160