]> git.donarmstrong.com Git - lilypond.git/blob - lily/axis-group-engraver.cc
Merge branch 'master' of /home/jcharles/GIT/Lily/. into translation
[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 "engraver.hh"
21
22 #include "axis-group-interface.hh"
23 #include "hara-kiri-group-spanner.hh"
24 #include "pointer-group-interface.hh"
25 #include "context.hh"
26 #include "international.hh"
27 #include "spanner.hh"
28 #include "warn.hh"
29
30 #include "translator.icc"
31
32 /**
33    Put stuff in a Spanner with an Axis_group_interface.
34    Use as last element of a context.
35 */
36 class Axis_group_engraver : public Engraver
37 {
38 protected:
39   Spanner *staffline_;
40   SCM interesting_;
41   vector<Grob *> elts_;
42   void process_music ();
43   virtual void finalize ();
44   DECLARE_ACKNOWLEDGER (grob);
45   void process_acknowledged ();
46   virtual Spanner *get_spanner ();
47   virtual void add_element (Grob *);
48   virtual bool must_be_last () const;
49   virtual void derived_mark () const;
50
51 public:
52   TRANSLATOR_DECLARATIONS (Axis_group_engraver);
53 };
54
55
56 Axis_group_engraver::Axis_group_engraver ()
57 {
58   staffline_ = 0;
59   interesting_ = SCM_EOL;
60 }
61
62 void
63 Axis_group_engraver::derived_mark () const
64 {
65   scm_gc_mark (interesting_);
66 }
67
68
69 bool
70 Axis_group_engraver::must_be_last () const
71 {
72   return true;
73 }
74
75 void
76 Axis_group_engraver::process_music ()
77 {
78   if (!staffline_)
79     {
80       staffline_ = get_spanner ();
81       Grob *it = unsmob_grob (get_property ("currentCommandColumn"));
82       staffline_->set_bound (LEFT, it);
83     }
84   interesting_ = get_property ("keepAliveInterfaces");
85 }
86
87 Spanner *
88 Axis_group_engraver::get_spanner ()
89 {
90   return make_spanner ("VerticalAxisGroup", SCM_EOL);
91 }
92
93 void
94 Axis_group_engraver::finalize ()
95 {
96   if (staffline_)
97     {
98       Grob *it = unsmob_grob (get_property ("currentCommandColumn"));
99       staffline_->set_bound (RIGHT, it);
100
101       Pointer_group_interface::set_ordered (staffline_, ly_symbol2scm ("elements"), false);
102     }
103 }
104
105 void
106 Axis_group_engraver::acknowledge_grob (Grob_info i)
107 {
108   if (!staffline_)
109     return;
110   if (i.grob ()->name () == "VerticalAxisGroup") {
111     i.grob ()->programming_error ("duplicate axis group");
112     if (staffline_->is_live ())
113       staffline_->suicide ();
114     staffline_ = 0;
115     elts_.clear ();
116     return;
117   }
118   elts_.push_back (i.grob ());
119
120   if (staffline_ && to_boolean(staffline_->get_property("remove-empty")))
121     {
122       for (SCM s = interesting_; scm_is_pair (s); s = scm_cdr (s))
123         {
124           if (i.grob ()->internal_has_interface (scm_car (s)))
125             Hara_kiri_group_spanner::add_interesting_item (staffline_, i.grob ());
126         }
127     }
128 }
129
130 /*
131   maybe should check if our parent is set, because we now get a
132   cyclic parent relationship if we have two Axis_group_engravers in
133   the context.  */
134 void
135 Axis_group_engraver::process_acknowledged ()
136 {
137   if (!staffline_)
138     return;
139
140   for (vsize i = 0; i < elts_.size (); i++)
141     {
142       if (!unsmob_grob (elts_[i]->get_object ("axis-group-parent-Y")))
143         {
144           if (staffline_->get_parent (Y_AXIS)
145               && staffline_->get_parent (Y_AXIS) == elts_[i])
146             {
147               staffline_->warning (_ ("Axis_group_engraver: vertical group already has a parent"));
148               staffline_->warning (_ ("are there two Axis_group_engravers?"));
149               staffline_->warning (_ ("removing this vertical group"));
150               staffline_->suicide ();
151               staffline_ = 0;
152               break;
153             }
154           add_element (elts_[i]);
155         }
156     }
157   elts_.clear ();
158 }
159
160 void
161 Axis_group_engraver::add_element (Grob *e)
162 {
163   Axis_group_interface::add_element (staffline_, e);
164 }
165
166 ADD_ACKNOWLEDGER (Axis_group_engraver, grob);
167
168 ADD_TRANSLATOR (Axis_group_engraver,
169                 /* doc */
170                 "Group all objects created in this context in a"
171                 " @code{VerticalAxisGroup} spanner.",
172
173                 /* create */
174                 "VerticalAxisGroup ",
175
176                 /* read */
177                 "currentCommandColumn "
178                 "keepAliveInterfaces ",
179
180                 /* write */
181                 ""
182                );