]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar-engraver.cc
Merge branch 'master' into lilypond/translation
[lilypond.git] / lily / span-bar-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "bar-line.hh"
21 #include "item.hh"
22 #include "span-bar.hh"
23 #include "engraver.hh"
24
25 /**
26
27 Make bars that span multiple "staves". Catch bars, and span a
28 Span_bar over them if we find more than 2 bars.  Vertical alignment
29 of staves changes the appearance of spanbars.  It is up to the
30 aligner (Vertical_align_engraver, in this case, to add extra
31 dependencies to the spanbars.
32 */
33 class Span_bar_engraver : public Engraver
34 {
35   Item *spanbar_;
36   bool make_spanbar_;
37   vector<Item *> bars_;
38
39 public:
40   TRANSLATOR_DECLARATIONS (Span_bar_engraver);
41 protected:
42   DECLARE_ACKNOWLEDGER (bar_line);
43   void stop_translation_timestep ();
44   void process_acknowledged ();
45 };
46
47 Span_bar_engraver::Span_bar_engraver ()
48 {
49   spanbar_ = 0;
50   make_spanbar_ = false;
51 }
52
53 void
54 Span_bar_engraver::acknowledge_bar_line (Grob_info i)
55 {
56   int depth = i.origin_contexts (this).size ();
57   if (depth && !Span_bar::has_interface (i.grob ()))
58     {
59       Item *it = dynamic_cast<Item *> (i.grob ());
60       bars_.push_back (it);
61
62       if (bars_.size () >= 2 && !spanbar_)
63         make_spanbar_ = true;
64     }
65 }
66
67 void
68 Span_bar_engraver::process_acknowledged ()
69 {
70   if (make_spanbar_)
71     {
72       Grob *vag = Grob::get_root_vertical_alignment (bars_[0]);
73       if (vag)
74         vector_sort (bars_, Grob::vertical_less);
75       spanbar_ = make_item ("SpanBar", SCM_EOL);
76
77       spanbar_->set_parent (bars_[0], X_AXIS);
78       for (vsize i = 0; i < bars_.size (); i++)
79         Span_bar::add_bar (spanbar_, bars_[i]);
80       make_spanbar_ = false;
81     }
82 }
83
84 void
85 Span_bar_engraver::stop_translation_timestep ()
86 {
87   if (spanbar_)
88     {
89       vector_sort (bars_, Grob::vertical_less);
90       for (vsize i = 0; i < bars_.size (); i++)
91         Span_bar::add_bar (spanbar_, bars_[i]);
92
93       SCM vissym = ly_symbol2scm ("break-visibility");
94       SCM vis = bars_[0]->internal_get_property (vissym);
95       if (ly_is_equal (spanbar_->internal_get_property (vissym), vis))
96         spanbar_->set_property (vissym, vis);
97
98       spanbar_ = 0;
99     }
100   bars_.resize (0);
101 }
102
103 #include "translator.icc"
104
105 ADD_ACKNOWLEDGER (Span_bar_engraver, bar_line);
106 ADD_TRANSLATOR (Span_bar_engraver,
107                 /* doc */
108                 "Make cross-staff bar lines: It catches all normal bar lines"
109                 " and draws a single span bar across them.",
110
111                 /* create */
112                 "SpanBar ",
113
114                 /* read */
115                 "",
116
117                 /* write */
118                 ""
119                );