2 axis-group-engraver.cc -- implement Axis_group_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2005 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 staffline_->warning (_ ("Axis_group_engraver: vertical group already has a parent"));
113 staffline_->warning (_ ("are there two Axis_group_engravers?"));
114 staffline_->warning (_ ("removing this vertical group"));
115 staffline_->suicide ();
119 else if (elts_[i]->is_empty (Y_AXIS))
122 We have to do _something_, otherwise staff objects will
123 end up with System as parent.
126 elts_[i]->set_parent (staffline_, Y_AXIS);
129 add_element (elts_[i]);
136 Axis_group_engraver::add_element (Grob *e)
138 Axis_group_interface::add_element (staffline_, e);
141 /****************************************************************/
144 maybenot such a good idea after all., to put class declarations in
148 #include "hara-kiri-group-spanner.hh"
149 #include "rhythmic-head.hh"
151 class Hara_kiri_engraver : public Axis_group_engraver
154 virtual Spanner *get_spanner ();
155 virtual void acknowledge_grob (Grob_info);
156 virtual void add_element (Grob *e);
157 virtual void start_translation_timestep ();
161 TRANSLATOR_DECLARATIONS (Hara_kiri_engraver);
165 Hara_kiri_engraver::start_translation_timestep ()
167 Axis_group_engraver::start_translation_timestep ();
168 interesting_ = get_property ("keepAliveInterfaces");
173 Hara_kiri_engraver::add_element (Grob *e)
175 Hara_kiri_group_spanner::add_element (staffline_, e);
179 Hara_kiri_engraver::get_spanner ()
181 Spanner *sp = make_spanner ("RemoveEmptyVerticalGroup", SCM_EOL);
187 Hara_kiri_engraver::acknowledge_grob (Grob_info i)
189 Axis_group_engraver::acknowledge_grob (i);
192 for (SCM s = interesting_; scm_is_pair (s); s = scm_cdr (s))
194 if (i.grob_->internal_has_interface (scm_car (s)))
195 Hara_kiri_group_spanner::add_interesting_item (staffline_, i.grob_);
200 Hara_kiri_engraver::Hara_kiri_engraver ()
202 interesting_ = SCM_EOL;
205 ADD_TRANSLATOR (Hara_kiri_engraver,
206 /* descr */ "Like Axis_group_engraver, but make a hara-kiri spanner, and add "
207 "interesting items (ie. note heads, lyric syllables and normal rests) ",
208 /* creats*/ "RemoveEmptyVerticalGroup",
210 /* acks */ "grob-interface",
211 /* reads */ "keepAliveInterfaces",
214 ADD_TRANSLATOR (Axis_group_engraver,
215 /* descr */ "Group all objects created in this context in a VerticalAxisGroup spanner.",
216 /* creats*/ "VerticalAxisGroup",
218 /* acks */ "grob-interface",
219 /* reads */ "verticalExtent minimumVerticalExtent extraVerticalExtent",