]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-engraver.cc
(DECLARE_EVENT_SWALLOWER): ENTER_DESCRIPTION -> ADD_TRANSLATOR
[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--2004 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   */
19 class Bar_engraver : public Engraver
20 {
21 public:
22   TRANSLATOR_DECLARATIONS (Bar_engraver);
23   void request_bar (String type_string);
24     
25 protected:
26   virtual void finalize ();
27   virtual void stop_translation_timestep ();
28   virtual void process_acknowledged_grobs ();
29
30 private:
31   void typeset_bar ();
32   void create_bar ();
33
34   Item * bar_;
35 };
36
37 Bar_engraver::Bar_engraver ()
38 {
39   bar_ = 0;
40 }
41
42 void
43 Bar_engraver::create_bar ()
44 {
45   if (!bar_)
46     {
47       bar_ = make_item ("BarLine", SCM_EOL);
48       SCM gl = get_property ("whichBar");
49       if (scm_equal_p (gl, bar_->get_property ("glyph")) != SCM_BOOL_T)
50           bar_->set_property ("glyph", gl);
51     }
52 }
53
54 void
55 Bar_engraver::finalize ()
56 {
57   typeset_bar ();
58 }
59
60 /*
61   Bar_engraver should come *after* any engravers that  
62   modify whichBar
63
64   This is a little hairy : whichBar may be set by
65   Repeat_acknowledge_engraver::process_music, which is at score
66   context. This means that grobs could should be created after
67   process_music. We do stuff process_acknowledged_grobs (), just to be
68   on the safe side.
69      
70 */
71
72 void
73 Bar_engraver::process_acknowledged_grobs ()
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
99 ADD_TRANSLATOR (Bar_engraver,
100 /* descr */       "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 /* creats*/       "BarLine",
103 /* accepts */     "",
104 /* acks  */      "",
105 /* reads */       "whichBar",
106 /* write */       "");