]> git.donarmstrong.com Git - lilypond.git/blob - lily/axis-group-engraver.cc
Issue 2990: \RemoveEmptyStaves in StaffGroup context crashes
[lilypond.git] / lily / axis-group-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1999--2012 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 "axis-group-engraver.hh"
21
22 #include "axis-group-interface.hh"
23 #include "pointer-group-interface.hh"
24 #include "context.hh"
25 #include "international.hh"
26 #include "spanner.hh"
27 #include "warn.hh"
28
29 #include "translator.icc"
30
31 Axis_group_engraver::Axis_group_engraver ()
32 {
33   staffline_ = 0;
34 }
35
36 bool
37 Axis_group_engraver::must_be_last () const
38 {
39   return true;
40 }
41
42 void
43 Axis_group_engraver::process_music ()
44 {
45   if (!staffline_)
46     {
47       staffline_ = get_spanner ();
48       Grob *it = unsmob_grob (get_property ("currentCommandColumn"));
49       staffline_->set_bound (LEFT, it);
50     }
51 }
52
53 Spanner *
54 Axis_group_engraver::get_spanner ()
55 {
56   return make_spanner ("VerticalAxisGroup", SCM_EOL);
57 }
58
59 void
60 Axis_group_engraver::finalize ()
61 {
62   if (staffline_)
63     {
64       Grob *it = unsmob_grob (get_property ("currentCommandColumn"));
65       staffline_->set_bound (RIGHT, it);
66
67       Pointer_group_interface::set_ordered (staffline_, ly_symbol2scm ("elements"), false);
68     }
69 }
70
71 void
72 Axis_group_engraver::acknowledge_grob (Grob_info i)
73 {
74   if (!staffline_)
75     return;
76   if (i.grob ()->name () == "VerticalAxisGroup") {
77     i.grob ()->programming_error ("duplicate axis group");
78     if (staffline_->is_live ())
79       staffline_->suicide ();
80     staffline_ = 0;
81     elts_.clear ();
82     return;
83   }
84   elts_.push_back (i.grob ());
85 }
86
87 /*
88   maybe should check if our parent is set, because we now get a
89   cyclic parent relationship if we have two Axis_group_engravers in
90   the context.  */
91 void
92 Axis_group_engraver::process_acknowledged ()
93 {
94   if (!staffline_)
95     return;
96
97   for (vsize i = 0; i < elts_.size (); i++)
98     {
99       if (!unsmob_grob (elts_[i]->get_object ("axis-group-parent-Y")))
100         {
101           if (staffline_->get_parent (Y_AXIS)
102               && staffline_->get_parent (Y_AXIS) == elts_[i])
103             {
104               staffline_->warning (_ ("Axis_group_engraver: vertical group already has a parent"));
105               staffline_->warning (_ ("are there two Axis_group_engravers?"));
106               staffline_->warning (_ ("removing this vertical group"));
107               staffline_->suicide ();
108               staffline_ = 0;
109               break;
110             }
111           add_element (elts_[i]);
112         }
113     }
114   elts_.clear ();
115 }
116
117 void
118 Axis_group_engraver::add_element (Grob *e)
119 {
120   Axis_group_interface::add_element (staffline_, e);
121 }
122
123 ADD_ACKNOWLEDGER (Axis_group_engraver, grob);
124
125 ADD_TRANSLATOR (Axis_group_engraver,
126                 /* doc */
127                 "Group all objects created in this context in a"
128                 " @code{VerticalAxisGroup} spanner.",
129
130                 /* create */
131                 "VerticalAxisGroup ",
132
133                 /* read */
134                 "currentCommandColumn ",
135
136                 /* write */
137                 ""
138                );