]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-engraver.cc
* flower
[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--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #include "bar-line.hh"
11 #include "score-engraver.hh"
12 #include "warn.hh"
13 #include "item.hh"
14
15 /*
16   generate bars. Either user ("|:"), or default (new measure)
17 */
18 class Bar_engraver : public Engraver
19 {
20 public:
21   TRANSLATOR_DECLARATIONS (Bar_engraver);
22   void request_bar (String type_string);
23
24 protected:
25   virtual void finalize ();
26   virtual void stop_translation_timestep ();
27   virtual void process_acknowledged_grobs ();
28
29 private:
30   void typeset_bar ();
31   void create_bar ();
32
33   Item *bar_;
34 };
35
36 Bar_engraver::Bar_engraver ()
37 {
38   bar_ = 0;
39 }
40
41 void
42 Bar_engraver::create_bar ()
43 {
44   if (!bar_)
45     {
46       bar_ = make_item ("BarLine", SCM_EOL);
47       SCM gl = get_property ("whichBar");
48       if (scm_equal_p (gl, bar_->get_property ("glyph")) != SCM_BOOL_T)
49         bar_->set_property ("glyph", gl);
50     }
51 }
52
53 void
54 Bar_engraver::finalize ()
55 {
56   typeset_bar ();
57 }
58
59 /*
60   Bar_engraver should come *after* any engravers that
61   modify whichBar
62
63   This is a little hairy : whichBar may be set by
64   Repeat_acknowledge_engraver::process_music, which is at score
65   context. This means that grobs could should be created after
66   process_music. We do stuff process_acknowledged_grobs (), just to be
67   on the safe side.
68 */
69
70 void
71 Bar_engraver::process_acknowledged_grobs ()
72 {
73   if (!bar_ && scm_is_string (get_property ("whichBar")))
74     create_bar ();
75 }
76
77 void
78 Bar_engraver::typeset_bar ()
79 {
80   bar_ = 0;
81 }
82
83 /*
84   lines may only be broken if there is a barline in all staves
85 */
86 void
87 Bar_engraver::stop_translation_timestep ()
88 {
89   if (!bar_)
90     /* guh. Use properties! */
91     get_score_engraver ()->forbid_breaks ();
92   else
93     typeset_bar ();
94 }
95
96 ADD_TRANSLATOR (Bar_engraver,
97                 /* descr */ "Create barlines. This engraver is controlled through the "
98                 "@code{whichBar} property. If it has no bar line to create, it will forbid a linebreak at this point",
99                 /* creats*/ "BarLine",
100                 /* accepts */ "",
101                 /* acks  */ "",
102                 /* reads */ "whichBar",
103                 /* write */ "");