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