Update from Andrew: tweaks for cross-staff chords snippet.
[lilypond.git] / lily / span-bar-engraver.cc
blob1062817a02e54b43d3fd16679932a7aa783e3eae
1 /*
2 span-bar-engraver.cc -- implement Span_bar_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "bar-line.hh"
10 #include "item.hh"
11 #include "span-bar.hh"
12 #include "engraver.hh"
14 /**
16 Make bars that span multiple "staves". Catch bars, and span a
17 Span_bar over them if we find more than 2 bars. Vertical alignment
18 of staves 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.
22 class Span_bar_engraver : public Engraver
24 Item *spanbar_;
25 vector<Item*> bars_;
27 public:
28 TRANSLATOR_DECLARATIONS (Span_bar_engraver);
29 protected:
30 DECLARE_ACKNOWLEDGER (bar_line);
31 void stop_translation_timestep ();
34 Span_bar_engraver::Span_bar_engraver ()
36 spanbar_ = 0;
39 void
40 Span_bar_engraver::acknowledge_bar_line (Grob_info i)
42 int depth = i.origin_contexts (this).size ();
43 if (depth && Bar_line::has_interface (i.grob ()))
45 Item *it = dynamic_cast<Item *> (i.grob ());
46 bars_.push_back (it);
48 if (bars_.size () >= 2 && !spanbar_)
50 spanbar_ = make_item ("SpanBar", SCM_EOL);
52 spanbar_->set_parent (bars_[0], X_AXIS);
57 void
58 Span_bar_engraver::stop_translation_timestep ()
60 if (spanbar_)
62 for (vsize i = 0; i < bars_.size (); i++)
63 Span_bar::add_bar (spanbar_, bars_[i]);
65 SCM vissym = ly_symbol2scm ("break-visibility");
66 SCM vis = bars_[0]->internal_get_property (vissym);
67 if (ly_is_equal (spanbar_->internal_get_property (vissym), vis))
68 spanbar_->set_property (vissym, vis);
70 spanbar_ = 0;
72 bars_.resize (0);
75 #include "translator.icc"
77 ADD_ACKNOWLEDGER (Span_bar_engraver, bar_line);
78 ADD_TRANSLATOR (Span_bar_engraver,
79 /* doc */
80 "Make cross-staff bar lines: It catches all normal bar lines"
81 " and draws a single span bar across them.",
83 /* create */
84 "SpanBar ",
86 /* read */
87 "",
89 /* write */