]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-engraver.cc
e5eafb06e3c3a499ab4910ac52db8578f7c01edc
[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 "multi-measure-rest.hh"
14 #include "command-request.hh"
15
16 #include "engraver-group-engraver.hh"
17 #include "warn.hh"
18 #include "item.hh"
19 #include "engraver.hh"
20
21 /**
22   generate bars. Either user ("|:"), or default (new measure)
23   */
24 class Bar_engraver : public Engraver
25 {
26 public:
27   Bar_engraver();
28   VIRTUAL_COPY_CONS(Translator);
29   void request_bar (String type_str);
30     
31 protected:
32   virtual void do_creation_processing ();
33   virtual void do_removal_processing ();
34   virtual void do_process_music();
35   virtual void do_pre_move_processing();
36
37 private:
38   void typeset_bar ();
39   void create_bar ();
40
41   Item * bar_p_;
42 };
43
44 Bar_engraver::Bar_engraver()
45 {
46   bar_p_ =0;
47   do_post_move_processing();
48 }
49
50 void
51 Bar_engraver::create_bar ()
52 {
53   if (!bar_p_)
54     {
55       bar_p_ = new Item (get_property ("BarLine"));
56
57       SCM gl = get_property ("whichBar");
58       if (scm_equal_p (gl, bar_p_->get_elt_property ("glyph")) != SCM_BOOL_T)
59           bar_p_->set_elt_property ("glyph", gl);
60       
61       announce_element (bar_p_, 0);
62     }
63 }
64
65 void 
66 Bar_engraver::do_creation_processing ()
67 {
68 }
69
70 void
71 Bar_engraver::do_removal_processing ()
72 {
73   typeset_bar ();
74 }
75
76 /*
77   Bar_engraver should come *after* any engravers that expect bars to
78   modify whichBar in do_process_music () be typeset
79 */
80 void
81 Bar_engraver::do_process_music()
82 {
83   SCM b =get_property ("whichBar");
84   if (gh_string_p (b))
85     {
86       create_bar ();
87     }
88 }
89
90 void
91 Bar_engraver::typeset_bar ()
92 {
93   if (bar_p_) 
94     {
95       typeset_element (bar_p_);
96       bar_p_ =0;
97     }
98 }
99
100 /*
101   lines may only be broken if there is a barline in all staffs 
102 */
103 void 
104 Bar_engraver::do_pre_move_processing()
105 {
106   if (!bar_p_)
107     {
108       Score_engraver * e = 0;
109       Translator * t  =  daddy_grav_l ();
110       for (; !e && t;  t = t->daddy_trans_l_)
111         {
112           e = dynamic_cast<Score_engraver*> (t);
113         }
114
115       if (!e)
116         programming_error ("No score engraver!");
117       else
118         e->forbid_breaks ();    // guh. Use properties!
119     }
120   else
121     typeset_bar ();
122 }
123
124 ADD_THIS_TRANSLATOR(Bar_engraver);