lilypond-1.3.19
[lilypond.git] / lily / bar-engraver.cc
blob45636011c048182d9a6a30caeb9e3c49f678c9be
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 "score-engraver.hh"
11 #include "bar-engraver.hh"
12 #include "staff-bar.hh"
13 #include "musical-request.hh"
14 #include "multi-measure-rest.hh"
15 #include "command-request.hh"
16 #include "timing-engraver.hh"
17 #include "engraver-group-engraver.hh"
18 #include "warn.hh"
20 Bar_engraver::Bar_engraver()
22 bar_p_ =0;
23 do_post_move_processing();
29 void
30 Bar_engraver::create_bar ()
32 if (!bar_p_)
34 bar_p_ = new Staff_bar;
35 bar_p_->set_elt_property ("break-aligned", SCM_BOOL_T);
37 // urg: "" != empty...
38 SCM default_type = get_property ("defaultBarType", 0);
39 if (gh_string_p (default_type))
41 bar_p_->set_elt_property ("glyph", default_type); // gu.h
44 #if 0
46 urg. Why did I implement this? And did I implement this so
47 clumsily? */
48 SCM prop = get_property ("barAtLineStart", 0);
49 if (to_boolean (prop))
51 bar_p_->set_elt_property ("at-line-start", SCM_BOOL_T);
53 #endif
54 announce_element (Score_element_info (bar_p_, 0));
58 /**
59 Make a barline. If there are both |: and :| requested, merge them
60 to :|:.
63 void
64 Bar_engraver::request_bar (String requested_type)
66 if (!now_mom ())
68 SCM prop = get_property ("barAtLineStart", 0);
69 if (!to_boolean (prop))
70 return;
72 bool bar_existed = bar_p_;
73 create_bar ();
74 if (bar_existed && requested_type == "")
76 return;
79 String current = ly_scm2string (bar_p_->get_elt_property ("glyph"));
81 if ((requested_type == "|:" && current== ":|")
82 || (requested_type == ":|" && current == "|:"))
83 requested_type = ":|:";
86 bar_p_->set_elt_property ("glyph",
87 ly_str02scm (requested_type.ch_C ()));
90 void
91 Bar_engraver::do_creation_processing ()
95 void
96 Bar_engraver::do_removal_processing ()
98 if (bar_p_)
100 typeset_element (bar_p_);
101 bar_p_ =0;
105 void
106 Bar_engraver::do_process_requests()
108 Translator * t = daddy_grav_l ()->get_simple_translator ("Timing_engraver");
110 Timing_engraver * te = dynamic_cast<Timing_engraver*>(t);
111 String which = (te) ? te->which_bar () : "";
113 if (which.length_i ())
115 create_bar();
116 bar_p_->set_elt_property ("glyph", ly_str02scm (which.ch_C ()));
119 if (!bar_p_)
121 Score_engraver * e = 0;
122 Translator * t = daddy_grav_l ();
123 for (; !e && t; t = t->daddy_trans_l_)
125 e = dynamic_cast<Score_engraver*> (t);
128 if (!e)
129 programming_error ("No score engraver!");
130 else
131 e->forbid_breaks ();
136 void
137 Bar_engraver::do_pre_move_processing()
139 if (bar_p_)
141 typeset_element (bar_p_);
142 bar_p_ =0;
146 ADD_THIS_TRANSLATOR(Bar_engraver);