lilypond-1.3.145
[lilypond.git] / lily / bar-engraver.cc
blob23e22f0e168de1fbcc5592a3ebf8f42728eda4c5
1 /*
2 bar-engraver.cc -- implement Bar_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
8 */
10 #include "bar.hh"
11 #include "score-engraver.hh"
12 #include "musical-request.hh"
13 #include "engraver-group-engraver.hh"
14 #include "warn.hh"
15 #include "item.hh"
16 #include "engraver.hh"
19 generate bars. Either user ("|:"), or default (new measure)
22 class Bar_engraver : public Engraver
24 public:
25 Bar_engraver ();
26 VIRTUAL_COPY_CONS (Translator);
27 void request_bar (String type_str);
29 protected:
30 virtual void finalize ();
31 virtual void stop_translation_timestep ();
32 virtual void create_grobs ();
34 private:
35 void typeset_bar ();
36 void create_bar ();
38 Item * bar_p_;
41 Bar_engraver::Bar_engraver ()
43 bar_p_ =0;
46 void
47 Bar_engraver::create_bar ()
49 if (!bar_p_)
51 bar_p_ = new Item (get_property ("BarLine"));
53 SCM gl = get_property ("whichBar");
54 if (scm_equal_p (gl, bar_p_->get_grob_property ("glyph")) != SCM_BOOL_T)
55 bar_p_->set_grob_property ("glyph", gl);
57 announce_grob (bar_p_, 0);
61 void
62 Bar_engraver::finalize ()
64 typeset_bar ();
68 Bar_engraver should come *after* any engravers that expect bars to
69 modify whichBar in deprecated_process_music () be typeset
71 void
72 Bar_engraver::create_grobs ()
74 if (!bar_p_ && gh_string_p (get_property ("whichBar")))
76 create_bar ();
80 void
81 Bar_engraver::typeset_bar ()
83 if (bar_p_)
85 typeset_grob (bar_p_);
86 bar_p_ =0;
91 lines may only be broken if there is a barline in all staffs
93 void
94 Bar_engraver::stop_translation_timestep ()
96 if (!bar_p_)
98 Score_engraver * e = 0;
99 Translator * t = daddy_grav_l ();
100 for (; !e && t; t = t->daddy_trans_l_)
102 e = dynamic_cast<Score_engraver*> (t);
105 if (!e)
106 programming_error ("No score engraver!");
107 else
108 e->forbid_breaks (); // guh. Use properties!
110 else
111 typeset_bar ();
114 ADD_THIS_TRANSLATOR (Bar_engraver);