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>
10 #include "paper-column.hh"
11 #include "axis-group-interface.hh"
12 #include "engraver-group-engraver.hh"
17 Put stuff in a Spanner with an Axis_group_interface.
18 Use as last element of a context.
20 class Axis_group_engraver : public Engraver
24 Link_array<Grob> elts_;
25 virtual void process_music ();
26 virtual void finalize ();
27 virtual void acknowledge_grob (Grob_info);
28 virtual void process_acknowledged_grobs ();
29 virtual Spanner* get_spanner () ;
30 virtual void add_element (Grob*) ;
32 TRANSLATOR_DECLARATIONS (Axis_group_engraver);
35 Axis_group_engraver::Axis_group_engraver ()
42 Axis_group_engraver::process_music ()
46 staffline_ = get_spanner ();
47 Grob * it = unsmob_grob (get_property ("currentCommandColumn"));
48 staffline_->set_bound (LEFT,it);
53 Axis_group_engraver::get_spanner ()
55 return make_spanner ("VerticalAxisGroup", SCM_EOL);
59 TODO: should we junk minimumVerticalExtent/extraVerticalExtent ?
63 Axis_group_engraver::finalize ()
68 String type = context ()->context_name ();
69 SCM dims = get_property ("verticalExtent");
71 if (is_number_pair (dims))
72 staffline_->set_extent (dims, Y_AXIS);
74 dims = get_property ("minimumVerticalExtent");
75 if (is_number_pair (dims) )
76 staffline_->set_property ("minimum-Y-extent", dims);
78 dims = get_property ("extraVerticalExtent");
79 if (is_number_pair (dims))
80 staffline_->set_property ("extra-Y-extent", dims);
82 Grob * it = unsmob_grob (get_property ("currentCommandColumn"));
84 staffline_->set_bound (RIGHT,it);
90 Axis_group_engraver::acknowledge_grob (Grob_info i)
96 maybe should check if our parent is set, because we now get a
97 cyclic parent relationship if we have two Axis_group_engravers in
100 Axis_group_engraver::process_acknowledged_grobs ()
105 for (int i = 0; i < elts_.size (); i++)
107 if (!unsmob_grob (elts_[i]->get_property ("axis-group-parent-Y")))
109 if (staffline_->get_parent (Y_AXIS)
110 && staffline_->get_parent (Y_AXIS) == elts_[i])
112 String msg = _("Axis_group_engraver: vertical group already has a parent.\n"
113 "Do you have two Axis_group_engravers?\n"
114 "Killing this vertical group.");
115 staffline_->warning (msg);
116 staffline_->suicide ();
120 else if (elts_[i]->is_empty (Y_AXIS))
123 We have to do _something_, otherwise staff objects will
124 end up with System as parent.
127 elts_[i]->set_parent (staffline_, Y_AXIS);
130 add_element (elts_[i]);
137 Axis_group_engraver::add_element (Grob*e)
139 Axis_group_interface::add_element (staffline_, e);
142 /****************************************************************/
146 maybenot such a good idea after all., to put class declarations in
151 #include "hara-kiri-group-spanner.hh"
152 #include "rhythmic-head.hh"
154 class Hara_kiri_engraver : public Axis_group_engraver
157 virtual Spanner*get_spanner ();
158 virtual void acknowledge_grob (Grob_info);
159 virtual void add_element (Grob *e);
161 TRANSLATOR_DECLARATIONS (Hara_kiri_engraver);
165 Hara_kiri_engraver::add_element (Grob*e)
167 Hara_kiri_group_spanner::add_element (staffline_, e);
172 Hara_kiri_engraver::get_spanner ()
174 Spanner * sp = make_spanner ("RemoveEmptyVerticalGroup", SCM_EOL);
180 Hara_kiri_engraver::acknowledge_grob (Grob_info i)
182 Axis_group_engraver::acknowledge_grob (i);
184 && (i.grob_->internal_has_interface (ly_symbol2scm ("rhythmic-grob-interface"))
185 || i.grob_->internal_has_interface (ly_symbol2scm ("lyric-interface")))
188 Hara_kiri_group_spanner::add_interesting_item (staffline_, i.grob_);
193 Hara_kiri_engraver::Hara_kiri_engraver ()
197 ADD_TRANSLATOR (Hara_kiri_engraver,
198 /* descr */ "Like Axis_group_engraver, but make a hara-kiri spanner, and add "
199 "interesting items (ie. note heads, lyric syllables and normal rests) ",
200 /* creats*/ "RemoveEmptyVerticalGroup",
202 /* acks */ "grob-interface",
206 ADD_TRANSLATOR (Axis_group_engraver,
207 /* descr */ "Group all objects created in this context in a VerticalAxisGroup spanner.",
208 /* creats*/ "VerticalAxisGroup",
210 /* acks */ "grob-interface",
211 /* reads */ "verticalExtent minimumVerticalExtent extraVerticalExtent",