2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1999--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
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.
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.
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/>.
20 #include "engraver.hh"
22 #include "axis-group-interface.hh"
23 #include "hara-kiri-group-spanner.hh"
24 #include "pointer-group-interface.hh"
26 #include "international.hh"
30 #include "translator.icc"
33 Put stuff in a Spanner with an Axis_group_interface.
34 Use as last element of a context.
36 class Axis_group_engraver : public Engraver
43 void process_music ();
44 virtual void initialize ();
45 virtual void finalize ();
46 void acknowledge_grob (Grob_info);
47 void process_acknowledged ();
48 virtual Spanner *get_spanner ();
49 virtual void add_element (Grob *);
50 virtual bool must_be_last () const;
51 virtual void derived_mark () const;
54 TRANSLATOR_DECLARATIONS (Axis_group_engraver);
58 Axis_group_engraver::Axis_group_engraver (Context *c)
62 interesting_ = SCM_EOL;
67 Axis_group_engraver::initialize ()
69 active_ = !to_boolean (get_property ("hasAxisGroup"));
71 context ()->set_property ("hasAxisGroup", SCM_BOOL_T);
75 Axis_group_engraver::derived_mark () const
77 scm_gc_mark (interesting_);
82 Axis_group_engraver::must_be_last () const
88 Axis_group_engraver::process_music ()
90 if (!staffline_ && active_)
92 staffline_ = get_spanner ();
93 Grob *it = unsmob<Grob> (get_property ("currentCommandColumn"));
94 staffline_->set_bound (LEFT, it);
96 interesting_ = get_property ("keepAliveInterfaces");
100 Axis_group_engraver::get_spanner ()
102 return make_spanner ("VerticalAxisGroup", SCM_EOL);
106 Axis_group_engraver::finalize ()
110 Grob *it = unsmob<Grob> (get_property ("currentCommandColumn"));
111 staffline_->set_bound (RIGHT, it);
113 Pointer_group_interface::set_ordered (staffline_, ly_symbol2scm ("elements"), false);
118 Axis_group_engraver::acknowledge_grob (Grob_info i)
123 elts_.push_back (i.grob ());
125 if (to_boolean (staffline_->get_property ("remove-empty")))
127 for (SCM s = interesting_; scm_is_pair (s); s = scm_cdr (s))
129 if (i.grob ()->internal_has_interface (scm_car (s)))
131 Hara_kiri_group_spanner::add_interesting_item (staffline_, i.grob ());
139 maybe should check if our parent is set, because we now get a
140 cyclic parent relationship if we have two Axis_group_engravers in
143 Axis_group_engraver::process_acknowledged ()
148 for (vsize i = 0; i < elts_.size (); i++)
150 if (!unsmob<Grob> (elts_[i]->get_object ("axis-group-parent-Y")))
152 if (staffline_->get_parent (Y_AXIS)
153 && staffline_->get_parent (Y_AXIS) == elts_[i])
155 staffline_->warning (_ ("Axis_group_engraver: vertical group already has a parent"));
156 staffline_->warning (_ ("are there two Axis_group_engravers?"));
157 staffline_->warning (_ ("removing this vertical group"));
158 staffline_->suicide ();
162 add_element (elts_[i]);
169 Axis_group_engraver::add_element (Grob *e)
171 Axis_group_interface::add_element (staffline_, e);
176 Axis_group_engraver::boot ()
178 ADD_ACKNOWLEDGER (Axis_group_engraver, grob);
181 ADD_TRANSLATOR (Axis_group_engraver,
183 "Group all objects created in this context in a"
184 " @code{VerticalAxisGroup} spanner.",
187 "VerticalAxisGroup ",
190 "currentCommandColumn "
191 "keepAliveInterfaces "