Merge branch 'fret-diagram-details'
[lilypond/csorensen.git] / lily / bar-engraver.cc
blob61ec14aca1416586ffdbd16609634870c67ddf1f
1 /*
2 bar-engraver.cc -- implement Bar_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
8 */
10 #include "bar-line.hh"
11 #include "context.hh"
12 #include "score-engraver.hh"
13 #include "warn.hh"
14 #include "item.hh"
15 #include "spanner.hh"
17 #include "translator.icc"
20 generate bars. Either user ("|:"), or default (new measure)
22 class Bar_engraver : public Engraver
24 public:
25 TRANSLATOR_DECLARATIONS (Bar_engraver);
26 void request_bar (string type_string);
28 protected:
29 void stop_translation_timestep ();
30 void process_acknowledged ();
32 DECLARE_END_ACKNOWLEDGER (spanner);
34 private:
35 void create_bar ();
37 Item *bar_;
38 vector<Spanner*> spanners_;
41 Bar_engraver::Bar_engraver ()
43 bar_ = 0;
46 void
47 Bar_engraver::create_bar ()
49 if (!bar_)
51 bar_ = make_item ("BarLine", SCM_EOL);
52 SCM gl = get_property ("whichBar");
53 if (scm_equal_p (gl, bar_->get_property ("glyph")) != SCM_BOOL_T)
54 bar_->set_property ("glyph", gl);
59 Bar_engraver should come *after* any engravers that
60 modify whichBar
62 This is a little hairy : whichBar may be set by
63 Repeat_acknowledge_engraver::process_music, which is at score
64 context. This means that grobs could should be created after
65 process_music. We do stuff process_acknowledged (), just to be
66 on the safe side.
69 void
70 Bar_engraver::process_acknowledged ()
72 if (!bar_ && scm_is_string (get_property ("whichBar")))
73 create_bar ();
75 if (bar_)
76 for (vsize i = 0; i < spanners_.size (); i++)
77 spanners_[i]->set_bound (RIGHT, bar_);
81 lines may only be broken if there is a barline in all staves
83 void
84 Bar_engraver::stop_translation_timestep ()
86 if (!bar_)
87 context ()->get_score_context ()->set_property ("forbidBreak", SCM_BOOL_T);
89 bar_ = 0;
90 spanners_.clear ();
93 void
94 Bar_engraver::acknowledge_end_spanner (Grob_info gi)
96 Grob *g = gi.grob ();
98 if (to_boolean (g->get_property ("to-barline")))
99 spanners_.push_back (dynamic_cast<Spanner*> (g));
102 ADD_END_ACKNOWLEDGER (Bar_engraver, spanner);
104 ADD_TRANSLATOR (Bar_engraver,
105 /* doc */
106 "Create barlines. This engraver is controlled through the"
107 " @code{whichBar} property. If it has no bar line to create,"
108 " it will forbid a linebreak at this point.",
110 /* create */
111 "BarLine ",
113 /* read */
114 "whichBar ",
116 /* write */
117 "forbidBreak "