*** empty log message ***
[lilypond/patrick.git] / lily / axis-group-engraver.cc
blob88c7be909c1e7916942158d9e02a61b46b0162d1
1 /*
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>
7 */
9 #include "spanner.hh"
10 #include "paper-column.hh"
11 #include "axis-group-interface.hh"
12 #include "engraver-group-engraver.hh"
13 #include "warn.hh"
14 #include "context.hh"
16 /**
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
22 protected:
23 Spanner *staffline_;
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 *);
31 public:
32 TRANSLATOR_DECLARATIONS (Axis_group_engraver);
35 Axis_group_engraver::Axis_group_engraver ()
37 must_be_last_ = true;
38 staffline_ = 0;
41 void
42 Axis_group_engraver::process_music ()
44 if (!staffline_)
46 staffline_ = get_spanner ();
47 Grob *it = unsmob_grob (get_property ("currentCommandColumn"));
48 staffline_->set_bound (LEFT, it);
52 Spanner *
53 Axis_group_engraver::get_spanner ()
55 return make_spanner ("VerticalAxisGroup", SCM_EOL);
59 TODO: should we junk minimumVerticalExtent/extraVerticalExtent ?
62 void
63 Axis_group_engraver::finalize ()
65 if (!staffline_)
66 return;
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);
86 staffline_ = 0;
89 void
90 Axis_group_engraver::acknowledge_grob (Grob_info i)
92 elts_.push (i.grob_);
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
98 the context. */
99 void
100 Axis_group_engraver::process_acknowledged_grobs ()
102 if (!staffline_)
103 return;
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 ();
116 staffline_ = 0;
117 break;
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);
128 else
129 add_element (elts_[i]);
132 elts_.clear ();
135 void
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
153 protected:
154 virtual Spanner *get_spanner ();
155 virtual void acknowledge_grob (Grob_info);
156 virtual void add_element (Grob *e);
157 public:
158 TRANSLATOR_DECLARATIONS (Hara_kiri_engraver);
161 void
162 Hara_kiri_engraver::add_element (Grob *e)
164 Hara_kiri_group_spanner::add_element (staffline_, e);
167 Spanner *
168 Hara_kiri_engraver::get_spanner ()
170 Spanner *sp = make_spanner ("RemoveEmptyVerticalGroup", SCM_EOL);
172 return sp;
175 void
176 Hara_kiri_engraver::acknowledge_grob (Grob_info i)
178 Axis_group_engraver::acknowledge_grob (i);
179 if (staffline_
180 && (i.grob_->internal_has_interface (ly_symbol2scm ("rhythmic-grob-interface"))
181 || i.grob_->internal_has_interface (ly_symbol2scm ("lyric-interface"))))
183 Hara_kiri_group_spanner::add_interesting_item (staffline_, i.grob_);
187 Hara_kiri_engraver::Hara_kiri_engraver ()
191 ADD_TRANSLATOR (Hara_kiri_engraver,
192 /* descr */ "Like Axis_group_engraver, but make a hara-kiri spanner, and add "
193 "interesting items (ie. note heads, lyric syllables and normal rests) ",
194 /* creats*/ "RemoveEmptyVerticalGroup",
195 /* accepts */ "",
196 /* acks */ "grob-interface",
197 /* reads */ "",
198 /* write */ "");
200 ADD_TRANSLATOR (Axis_group_engraver,
201 /* descr */ "Group all objects created in this context in a VerticalAxisGroup spanner.",
202 /* creats*/ "VerticalAxisGroup",
203 /* accepts */ "",
204 /* acks */ "grob-interface",
205 /* reads */ "verticalExtent minimumVerticalExtent extraVerticalExtent",
206 /* write */ "");