]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar-engraver.cc
release: 1.3.50
[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() 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() const
45 {
46   return new Span_bar;
47 }
48
49
50 void
51 Span_bar_engraver::acknowledge_element (Score_element_info i)
52 {
53   int depth = i.origin_trans_l_arr (this).size();
54   if (depth > 1
55       && dynamic_cast<Bar *> (i.elem_l_)) 
56     {
57       bar_l_arr_.push (dynamic_cast<Bar *> (i.elem_l_));
58
59       if (bar_l_arr_.size() >= 2 && !spanbar_p_) 
60         {
61           spanbar_p_ = get_span_bar_p();
62           spanbar_p_->set_parent (bar_l_arr_[0], Y_AXIS);
63           spanbar_p_->set_parent (bar_l_arr_[0], X_AXIS);
64
65           SCM v = bar_l_arr_[0]->get_elt_property ("visibility-lambda");
66           if (gh_procedure_p (v))
67             spanbar_p_->set_elt_property ("visibility-lambda",v);
68
69           spanbar_p_->set_parent (bar_l_arr_[0], X_AXIS);
70           announce_element (Score_element_info (spanbar_p_,0));
71           if (!gh_string_p (spanbar_p_->get_elt_property ("glyph")))
72             spanbar_p_-> set_elt_property ("glyph",
73                                            bar_l_arr_[0]->get_elt_property ("glyph"));
74         }
75     }
76 }
77
78 void
79 Span_bar_engraver::do_pre_move_processing()
80 {
81   if (spanbar_p_) 
82     {
83       for (int i=0; i < bar_l_arr_.size() ; i++)
84         spanbar_p_->add_bar (bar_l_arr_[i]);
85       typeset_element (spanbar_p_);
86       spanbar_p_ =0;
87     }
88   bar_l_arr_.set_size (0);
89 }
90
91
92
93 ADD_THIS_TRANSLATOR(Span_bar_engraver);
94
95
96