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