* lily/parser.yy (context_def_mod): remove \consistsend
[lilypond.git] / lily / axis-group-engraver.cc
blobc28584909f16745e782a86819e1a623b6971ccdd
1 /*
2 axis-group-engraver.cc -- implement Axis_group_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "spanner.hh"
10 #include "paper-column.hh"
11 #include "axis-group-interface.hh"
12 #include "engraver.hh"
13 #include "engraver-group-engraver.hh"
14 #include "warn.hh"
15 #include "context.hh"
17 /**
18 Put stuff in a Spanner with an Axis_group_interface.
19 Use as last element of a context.
21 class Axis_group_engraver : public Engraver
23 protected:
24 Spanner *staffline_;
25 Link_array<Grob> elts_;
26 virtual void process_music ();
27 virtual void finalize ();
28 virtual void acknowledge_grob (Grob_info);
29 virtual void process_acknowledged_grobs ();
30 virtual Spanner* get_spanner () ;
31 virtual void add_element (Grob*) ;
32 public:
33 TRANSLATOR_DECLARATIONS (Axis_group_engraver);
36 Axis_group_engraver::Axis_group_engraver ()
38 must_be_last_ = true;
39 staffline_ = 0;
42 void
43 Axis_group_engraver::process_music ()
45 if (!staffline_)
47 staffline_ = get_spanner ();
49 Grob * it = unsmob_grob (get_property ("currentCommandColumn"));
51 staffline_->set_bound (LEFT,it);
55 Spanner*
56 Axis_group_engraver::get_spanner ()
58 return make_spanner ("VerticalAxisGroup", SCM_EOL);
62 TODO: should we junk minimumVerticalExtent/extraVerticalExtent ?
65 void
66 Axis_group_engraver::finalize ()
68 if (!staffline_)
69 return ;
71 String type = context ()->context_name ();
72 SCM dims = get_property ("verticalExtent");
74 if (is_number_pair (dims))
75 staffline_->set_extent (dims, Y_AXIS);
77 dims = get_property ("minimumVerticalExtent");
78 if (is_number_pair (dims) )
79 staffline_->set_property ("minimum-Y-extent", dims);
81 dims = get_property ("extraVerticalExtent");
82 if (is_number_pair (dims))
83 staffline_->set_property ("extra-Y-extent", dims);
85 Grob * it = unsmob_grob (get_property ("currentCommandColumn"));
87 staffline_->set_bound (RIGHT,it);
89 staffline_ = 0;
92 void
93 Axis_group_engraver::acknowledge_grob (Grob_info i)
95 elts_.push (i.grob_);
99 maybe should check if our parent is set, because we now get a
100 cyclic parent relationship if we have two Axis_group_engravers in
101 the context. */
102 void
103 Axis_group_engraver::process_acknowledged_grobs ()
105 if (!staffline_)
106 return ;
108 for (int i=0; i < elts_.size (); i++)
110 Grob *par = elts_[i]->get_parent (Y_AXIS);
112 if (!par || !Axis_group_interface::has_interface (par))
114 if (staffline_->get_parent (Y_AXIS)
115 && staffline_->get_parent (Y_AXIS) == elts_[i])
117 String msg = _("Axis_group_engraver: vertical group already has a parent.\n"
118 "Do you have two Axis_group_engravers?\n"
119 "Killing this vertical group.");
120 staffline_->warning (msg);
121 staffline_->suicide ();
122 staffline_ = 0;
123 break ;
125 else if (elts_[i]->is_empty (Y_AXIS))
128 We have to do _something_, otherwise staff objects will
129 end up with System as parent.
132 elts_[i]->set_parent (staffline_, Y_AXIS);
134 else
135 add_element (elts_[i]);
138 elts_.clear ();
141 void
142 Axis_group_engraver::add_element (Grob*e)
144 Axis_group_interface::add_element (staffline_, e);
147 /****************************************************************/
151 maybenot such a good idea after all., to put class declarations in
156 #include "hara-kiri-group-spanner.hh"
157 #include "rhythmic-head.hh"
159 class Hara_kiri_engraver : public Axis_group_engraver
161 protected:
162 virtual Spanner*get_spanner ();
163 virtual void acknowledge_grob (Grob_info);
164 virtual void add_element (Grob *e);
165 public:
166 TRANSLATOR_DECLARATIONS (Hara_kiri_engraver);
169 void
170 Hara_kiri_engraver::add_element (Grob*e)
172 Hara_kiri_group_spanner::add_element (staffline_, e);
176 Spanner*
177 Hara_kiri_engraver::get_spanner ()
179 Spanner * sp = make_spanner ("RemoveEmptyVerticalGroup", SCM_EOL);
181 return sp;
184 void
185 Hara_kiri_engraver::acknowledge_grob (Grob_info i)
187 Axis_group_engraver::acknowledge_grob (i);
188 if (staffline_
189 && (i.grob_->internal_has_interface (ly_symbol2scm ("rhythmic-grob-interface"))
190 || i.grob_->internal_has_interface (ly_symbol2scm ("lyric-interface")))
193 Hara_kiri_group_spanner::add_interesting_item (staffline_, i.grob_);
198 Hara_kiri_engraver::Hara_kiri_engraver ()
202 ENTER_DESCRIPTION (Hara_kiri_engraver,
203 /* descr */ "Like Axis_group_engraver, but make a hara-kiri spanner, and add "
204 "interesting items (ie. note heads, lyric syllables and normal rests) ",
205 /* creats*/ "RemoveEmptyVerticalGroup",
206 /* accepts */ "",
207 /* acks */ "grob-interface",
208 /* reads */ "",
209 /* write */ "");
211 ENTER_DESCRIPTION (Axis_group_engraver,
212 /* descr */ "Group all objects created in this context in a VerticalAxisGroup spanner.",
213 /* creats*/ "VerticalAxisGroup",
214 /* accepts */ "",
215 /* acks */ "grob-interface",
216 /* reads */ "verticalExtent minimumVerticalExtent extraVerticalExtent",
217 /* write */ "");