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