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