]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar-engraver.cc
Web-ja: update introduction
[lilypond.git] / lily / span-bar-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2015 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 "item.hh"
21 #include "engraver.hh"
22 #include "pointer-group-interface.hh"
23 #include "lily-imports.hh"
24
25 #include "translator.icc"
26
27 /**
28
29 Make bars that span multiple "staves". Catch bars, and span a
30 Span_bar over them if we find more than 2 bars.  Vertical alignment
31 of staves changes the appearance of spanbars.  It is up to the
32 aligner (Vertical_align_engraver, in this case, to add extra
33 dependencies to the spanbars.
34 */
35 class Span_bar_engraver : public Engraver
36 {
37   Item *spanbar_;
38   bool make_spanbar_;
39   vector<Item *> bars_;
40
41 public:
42   TRANSLATOR_DECLARATIONS (Span_bar_engraver);
43 protected:
44   void acknowledge_bar_line (Grob_info);
45   void stop_translation_timestep ();
46   void process_acknowledged ();
47 };
48
49 Span_bar_engraver::Span_bar_engraver (Context *c)
50   : Engraver (c)
51 {
52   spanbar_ = 0;
53   make_spanbar_ = false;
54 }
55
56 void
57 Span_bar_engraver::acknowledge_bar_line (Grob_info i)
58 {
59   int depth = i.origin_contexts (this).size ();
60   if (depth && !i.grob ()->internal_has_interface (ly_symbol2scm ("span-bar-interface")))
61     {
62       Item *it = dynamic_cast<Item *> (i.grob ());
63       bars_.push_back (it);
64
65       if (bars_.size () >= 2 && !spanbar_)
66         make_spanbar_ = true;
67     }
68 }
69
70 void
71 Span_bar_engraver::process_acknowledged ()
72 {
73   if (make_spanbar_)
74     {
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         Pointer_group_interface::add_grob (spanbar_, ly_symbol2scm ("elements"), bars_[i]);
80       make_spanbar_ = false;
81     }
82 }
83
84 void
85 Span_bar_engraver::stop_translation_timestep ()
86 {
87   if (spanbar_)
88     {
89       SCM vis = bars_[0]->get_property ("break-visibility");
90       if (ly_is_equal (spanbar_->get_property ("break-visibility"), vis))
91         spanbar_->set_property ("break-visibility", vis);
92       Lily::span_bar_notify_grobs_of_my_existence (spanbar_->self_scm ());
93       spanbar_ = 0;
94     }
95   bars_.resize (0);
96 }
97
98 void
99 Span_bar_engraver::boot ()
100 {
101   ADD_ACKNOWLEDGER (Span_bar_engraver, bar_line);
102 }
103
104 ADD_TRANSLATOR (Span_bar_engraver,
105                 /* doc */
106                 "Make cross-staff bar lines: It catches all normal bar lines"
107                 " and draws a single span bar across them.",
108
109                 /* create */
110                 "SpanBar ",
111
112                 /* read */
113                 "",
114
115                 /* write */
116                 ""
117                );