]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar-engraver.cc
release: 1.3.62
[lilypond.git] / lily / span-bar-engraver.cc
1 /*
2   span-bar-grav.cc -- implement Span_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 */
8
9 #include "dimension-cache.hh"
10 #include "lily-guile.hh"
11 #include "span-bar.hh"
12 #include "engraver.hh"
13
14 /** 
15
16   Make bars that span multiple "staffs". Catch bars, and span a
17   Span_bar over them if we find more than 2 bars.  Vertical alignment
18   of staffs changes the appearance of spanbars.  It is up to the
19   aligner (Vertical_align_engraver, in this case, to add extra
20   dependencies to the spanbars.
21
22   */
23 class Span_bar_engraver : public Engraver
24 {
25   Span_bar * spanbar_p_;
26   Link_array<Bar> bar_l_arr_;
27
28 public:
29   VIRTUAL_COPY_CONS(Translator);
30   Span_bar_engraver();
31 protected:
32   virtual void acknowledge_element (Score_element_info);
33   virtual void do_pre_move_processing();
34   virtual Span_bar* get_span_bar_p(SCM) const;
35 };
36
37
38 Span_bar_engraver::Span_bar_engraver()
39 {
40   spanbar_p_ =0;
41 }
42
43 Span_bar*
44 Span_bar_engraver::get_span_bar_p(SCM s) const
45 {
46   Span_bar * sp= new Span_bar (s);
47   return sp;
48 }
49
50
51 void
52 Span_bar_engraver::acknowledge_element (Score_element_info i)
53 {
54   int depth = i.origin_trans_l_arr (this).size();
55   if (depth > 1
56       && dynamic_cast<Bar *> (i.elem_l_)) 
57     {
58       bar_l_arr_.push (dynamic_cast<Bar *> (i.elem_l_));
59
60       if (bar_l_arr_.size() >= 2 && !spanbar_p_) 
61         {
62           spanbar_p_ = get_span_bar_p (get_property ("basicSpanBarProperties"));
63           spanbar_p_->set_elt_property ("glyph", bar_l_arr_[0]->get_elt_property ("glyph"));
64           spanbar_p_->set_elt_property ("visibility-lambda",
65                                         bar_l_arr_[0]->get_elt_property ("visibility-lambda"));   
66                                         
67           spanbar_p_->set_parent (bar_l_arr_[0], Y_AXIS);
68           spanbar_p_->set_parent (bar_l_arr_[0], X_AXIS);
69
70           announce_element (Score_element_info (spanbar_p_,0));
71         }
72     }
73 }
74 void
75 Span_bar_engraver::do_pre_move_processing()
76 {
77   if (spanbar_p_) 
78     {
79       for (int i=0; i < bar_l_arr_.size() ; i++)
80         spanbar_p_->add_bar (bar_l_arr_[i]);
81       typeset_element (spanbar_p_);
82       spanbar_p_ =0;
83     }
84   bar_l_arr_.set_size (0);
85 }
86
87
88
89 ADD_THIS_TRANSLATOR(Span_bar_engraver);
90
91
92