lilypond-1.1.55
[lilypond.git] / lily / bar-engraver.cc
blobe38ad23499bbc842f100535a1ad7105752756e7a
1 /*
2 bar-engraver.cc -- implement Bar_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997, 1998, 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
8 */
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"
18 Bar_engraver::Bar_engraver()
20 bar_p_ =0;
21 do_post_move_processing();
24 bool
25 Bar_engraver::do_try_music (Music*r_l)
27 if (Bar_req * b= dynamic_cast <Bar_req *> (r_l))
29 if (bar_req_l_ && bar_req_l_->equal_b (b)) // huh?
30 return false;
32 bar_req_l_ = b;
33 return true;
36 return false;
42 void
43 Bar_engraver::create_bar ()
45 if (!bar_p_)
47 bar_p_ = new Staff_bar;
48 bar_p_->set_elt_property (break_priority_scm_sym, gh_int2scm (0));
50 // urg: "" != empty...
51 String default_type = get_property ("defaultBarType", 0);
52 if (default_type.length_i ())
54 bar_p_->type_str_ = default_type;
58 urg. Why did I implement this?
60 Scalar prop = get_property ("barAtLineStart", 0);
61 if (prop.to_bool ())
63 bar_p_->set_elt_property (at_line_start_scm_sym, SCM_BOOL_T);
65 announce_element (Score_element_info (bar_p_, bar_req_l_));
69 void
70 Bar_engraver::request_bar (String type_str)
72 Scalar prop = get_property ("barAtLineStart", 0);
73 if (!now_mom ())
75 Scalar prop = get_property ("barAtLineStart", 0);
76 if (!prop.to_bool ())
77 return;
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;
87 void
88 Bar_engraver::do_creation_processing ()
90 create_bar ();
91 bar_p_->type_str_ = "";
94 void
95 Bar_engraver::do_removal_processing ()
97 if (bar_p_)
99 typeset_element (bar_p_);
100 bar_p_ =0;
104 void
105 Bar_engraver::do_process_requests()
107 Time_description const *time = get_staff_info().time_C_;
108 if (bar_req_l_)
110 create_bar ();
111 bar_p_->type_str_ = bar_req_l_->type_str_;
113 else if (!now_mom ())
115 create_bar ();
116 bar_p_->type_str_ = "|";
118 else
120 Scalar nonauto = get_property ("barNonAuto", 0);
121 if (!nonauto.to_bool ())
123 Scalar always = get_property ("barAlways", 0);
124 if ((time && !time->whole_in_measure_) || always.to_bool ())
125 create_bar ();
129 if (!bar_p_)
131 Break_req r;
132 r.penalty_i_ = Break_req::DISALLOW;
133 daddy_grav_l ()->try_music (&r);
138 void
139 Bar_engraver::do_pre_move_processing()
141 if (bar_p_)
143 typeset_element (bar_p_);
144 bar_p_ =0;
148 void
149 Bar_engraver::do_post_move_processing()
151 bar_req_l_ = 0;
156 ADD_THIS_TRANSLATOR(Bar_engraver);