]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-engraver.cc
release: 1.5.13
[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--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #include "bar.hh"
11 #include "score-engraver.hh"
12 #include "musical-request.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_str);
27     
28 protected:
29   virtual void finalize ();
30   virtual void stop_translation_timestep ();
31   virtual void create_grobs ();
32
33 private:
34   void typeset_bar ();
35   void create_bar ();
36
37   Item * bar_p_;
38 };
39
40 Bar_engraver::Bar_engraver ()
41 {
42   bar_p_ =0;
43 }
44
45 void
46 Bar_engraver::create_bar ()
47 {
48   if (!bar_p_)
49     {
50       bar_p_ = new Item (get_property ("BarLine"));
51
52       SCM gl = get_property ("whichBar");
53       if (scm_equal_p (gl, bar_p_->get_grob_property ("glyph")) != SCM_BOOL_T)
54           bar_p_->set_grob_property ("glyph", gl);
55       
56       announce_grob (bar_p_, 0);
57     }
58 }
59
60 void
61 Bar_engraver::finalize ()
62 {
63   typeset_bar ();
64 }
65
66 /*
67   Bar_engraver should come *after* any engravers that  
68   modify whichBar
69 */
70 void
71 Bar_engraver::create_grobs ()
72 {
73   if (!bar_p_ && gh_string_p (get_property ("whichBar")))
74     {
75       create_bar ();
76     }
77 }
78
79 void
80 Bar_engraver::typeset_bar ()
81 {
82   if (bar_p_) 
83     {
84       typeset_grob (bar_p_);
85       bar_p_ =0;
86     }
87 }
88
89 /*
90   lines may only be broken if there is a barline in all staves 
91 */
92 void 
93 Bar_engraver::stop_translation_timestep ()
94 {
95   if (!bar_p_)
96     {
97       Score_engraver * e = 0;
98       Translator * t  =  daddy_grav_l ();
99       for (; !e && t;  t = t->daddy_trans_l_)
100         {
101           e = dynamic_cast<Score_engraver*> (t);
102         }
103
104       if (!e)
105         programming_error ("No score engraver!");
106       else
107         e->forbid_breaks ();    // guh. Use properties!
108     }
109   else
110     typeset_bar ();
111 }
112
113
114 ENTER_DESCRIPTION(Bar_engraver,
115 /* descr */       "Create barlines. This engraver is controlled through the
116 @code{whichBar} property. If it has no bar line to create, it will forbid a linebreak at this point",
117 /* creats*/       "BarLine",
118 /* acks  */       "",
119 /* reads */       "whichBar stavesFound",
120 /* write */       "");