]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-engraver.cc
release: 1.3.107
[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_creation_processing ();
31   virtual void do_removal_processing ();
32   virtual void do_process_music();
33   virtual void do_pre_move_processing();
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   do_post_move_processing();
46 }
47
48 void
49 Bar_engraver::create_bar ()
50 {
51   if (!bar_p_)
52     {
53       bar_p_ = new Item (get_property ("BarLine"));
54
55       SCM gl = get_property ("whichBar");
56       if (scm_equal_p (gl, bar_p_->get_elt_property ("glyph")) != SCM_BOOL_T)
57           bar_p_->set_elt_property ("glyph", gl);
58       
59       announce_element (bar_p_, 0);
60     }
61 }
62
63 void 
64 Bar_engraver::do_creation_processing ()
65 {
66 }
67
68 void
69 Bar_engraver::do_removal_processing ()
70 {
71   typeset_bar ();
72 }
73
74 /*
75   Bar_engraver should come *after* any engravers that expect bars to
76   modify whichBar in do_process_music () be typeset
77 */
78 void
79 Bar_engraver::do_process_music()
80 {
81   SCM b =get_property ("whichBar");
82   if (gh_string_p (b))
83     {
84       create_bar ();
85     }
86 }
87
88 void
89 Bar_engraver::typeset_bar ()
90 {
91   if (bar_p_) 
92     {
93       typeset_element (bar_p_);
94       bar_p_ =0;
95     }
96 }
97
98 /*
99   lines may only be broken if there is a barline in all staffs 
100 */
101 void 
102 Bar_engraver::do_pre_move_processing()
103 {
104   if (!bar_p_)
105     {
106       Score_engraver * e = 0;
107       Translator * t  =  daddy_grav_l ();
108       for (; !e && t;  t = t->daddy_trans_l_)
109         {
110           e = dynamic_cast<Score_engraver*> (t);
111         }
112
113       if (!e)
114         programming_error ("No score engraver!");
115       else
116         e->forbid_breaks ();    // guh. Use properties!
117     }
118   else
119     typeset_bar ();
120 }
121
122 ADD_THIS_TRANSLATOR(Bar_engraver);