]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-engraver.cc
2003 -> 2004
[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 "event.hh"
13 #include "engraver-group-engraver.hh"
14 #include "warn.hh"
15 #include "item.hh"
16 #include "engraver.hh"
17
18 /*
19   generate bars. Either user ("|:"), or default (new measure)
20
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   virtual void stop_translation_timestep ();
31   virtual void process_acknowledged_grobs ();
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");
51       SCM gl = get_property ("whichBar");
52       if (scm_equal_p (gl, bar_->get_grob_property ("glyph")) != SCM_BOOL_T)
53           bar_->set_grob_property ("glyph", gl);
54       
55       announce_grob(bar_, SCM_EOL);
56     }
57 }
58
59 void
60 Bar_engraver::finalize ()
61 {
62   typeset_bar ();
63 }
64
65 /*
66   Bar_engraver should come *after* any engravers that  
67   modify whichBar
68
69   This is a little hairy : whichBar may be set by
70   Repeat_acknowledge_engraver::process_music, which is at score
71   context. This means that grobs could should be created after
72   process_music. We do stuff process_acknowledged_grobs(), just to be
73   on the safe side.
74      
75 */
76
77 void
78 Bar_engraver::process_acknowledged_grobs ()
79 {
80   if (!bar_ && gh_string_p (get_property ("whichBar")))
81     {
82       create_bar ();
83     }
84 }
85
86 void
87 Bar_engraver::typeset_bar ()
88 {
89   if (bar_) 
90     {
91       typeset_grob (bar_);
92       bar_ =0;
93     }
94 }
95
96 /*
97   lines may only be broken if there is a barline in all staves 
98 */
99 void 
100 Bar_engraver::stop_translation_timestep ()
101 {
102   if (!bar_)
103     {
104       top_engraver ()->forbid_breaks ();        // guh. Use properties!
105     }
106   else
107     typeset_bar ();
108 }
109
110
111 ENTER_DESCRIPTION(Bar_engraver,
112 /* descr */       "Create barlines. This engraver is controlled through the "
113 "@code{whichBar} property. If it has no bar line to create, it will forbid a linebreak at this point",
114 /* creats*/       "BarLine",
115 /* accepts */     "",
116 /* acks  */      "",
117 /* reads */       "whichBar",
118 /* write */       "");