]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-engraver.cc
release: 1.3.109
[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--2000 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   Bar_engraver();
26   VIRTUAL_COPY_CONS(Translator);
27   void request_bar (String type_str);
28     
29 protected:
30   virtual void do_removal_processing ();
31   void deprecated_process_music();
32   virtual void stop_translation_timestep();
33   virtual void create_grobs ();
34
35 private:
36   void typeset_bar ();
37   void create_bar ();
38
39   Item * bar_p_;
40 };
41
42 Bar_engraver::Bar_engraver()
43 {
44   bar_p_ =0;
45 }
46
47 void
48 Bar_engraver::create_bar ()
49 {
50   if (!bar_p_)
51     {
52       bar_p_ = new Item (get_property ("BarLine"));
53
54       SCM gl = get_property ("whichBar");
55       if (scm_equal_p (gl, bar_p_->get_grob_property ("glyph")) != SCM_BOOL_T)
56           bar_p_->set_grob_property ("glyph", gl);
57       
58       announce_grob (bar_p_, 0);
59     }
60 }
61
62 void
63 Bar_engraver::do_removal_processing ()
64 {
65   typeset_bar ();
66 }
67
68 /*
69   Bar_engraver should come *after* any engravers that expect bars to
70   modify whichBar in  deprecated_process_music () be typeset
71 */
72 void
73 Bar_engraver::deprecated_process_music()
74 {
75   if (!bar_p_ && gh_string_p (get_property ("whichBar")))
76     {
77       create_bar ();
78     }
79 }
80
81 void
82 Bar_engraver::create_grobs ()
83 {
84   deprecated_process_music ();
85 }
86
87 void
88 Bar_engraver::typeset_bar ()
89 {
90   if (bar_p_) 
91     {
92       typeset_grob (bar_p_);
93       bar_p_ =0;
94     }
95 }
96
97 /*
98   lines may only be broken if there is a barline in all staffs 
99 */
100 void 
101 Bar_engraver::stop_translation_timestep()
102 {
103   if (!bar_p_)
104     {
105       Score_engraver * e = 0;
106       Translator * t  =  daddy_grav_l ();
107       for (; !e && t;  t = t->daddy_trans_l_)
108         {
109           e = dynamic_cast<Score_engraver*> (t);
110         }
111
112       if (!e)
113         programming_error ("No score engraver!");
114       else
115         e->forbid_breaks ();    // guh. Use properties!
116     }
117   else
118     typeset_bar ();
119 }
120
121 ADD_THIS_TRANSLATOR(Bar_engraver);