(staff_eligible): new function.
[lilypond.git] / lily / axis-group-engraver.cc
blobf2750d77321a38d9c65fcab883ea02b4358a61a6
1 /*
2 axis-group-engraver.cc -- implement Axis_group_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2003 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"
15 /**
16 Put stuff in a Spanner with an Axis_group_interface.
17 Use as last element of a context.
19 class Axis_group_engraver : public Engraver
21 protected:
22 Spanner *staffline_;
23 Link_array<Grob> elts_;
24 virtual void initialize ();
25 virtual void finalize ();
26 virtual void acknowledge_grob (Grob_info);
27 virtual void process_acknowledged_grobs ();
28 virtual Spanner* get_spanner () const;
29 virtual void add_element (Grob*) ;
30 public:
31 TRANSLATOR_DECLARATIONS(Axis_group_engraver );
36 Axis_group_engraver::Axis_group_engraver ()
38 staffline_ = 0;
41 void
42 Axis_group_engraver::initialize ()
44 staffline_ = get_spanner ();
46 Grob * it = unsmob_grob (get_property ("currentCommandColumn"));
48 staffline_->set_bound (LEFT,it);
50 announce_grob(staffline_, SCM_EOL);
53 Spanner*
54 Axis_group_engraver::get_spanner () const
56 return new Spanner (get_property ("VerticalAxisGroup"));
59 void
60 Axis_group_engraver::finalize ()
62 String type = get_daddy_grav ()->context_name ();
63 SCM dims = get_property ("verticalExtent");
65 if (gh_pair_p (dims) && gh_number_p (ly_car (dims))
66 && gh_number_p (ly_cdr (dims)))
68 staffline_->set_extent (Grob::preset_extent_proc, Y_AXIS);
69 staffline_->set_grob_property ("Y-extent", dims);
72 dims = get_property ("minimumVerticalExtent");
73 if (gh_pair_p (dims) && gh_number_p (ly_car (dims))
74 && gh_number_p (ly_cdr (dims)))
75 staffline_->set_grob_property ("minimum-Y-extent", dims);
77 dims = get_property ("extraVerticalExtent");
78 if (gh_pair_p (dims) && gh_number_p (ly_car (dims))
79 && gh_number_p (ly_cdr (dims)))
80 staffline_->set_grob_property ("extra-Y-extent", dims);
82 Grob * it = unsmob_grob (get_property ("currentCommandColumn"));
85 staffline_->set_bound (RIGHT,it);
87 typeset_grob (staffline_);
88 staffline_ = 0;
91 void
92 Axis_group_engraver::acknowledge_grob (Grob_info i)
94 elts_.push (i.grob_);
98 maybe should check if our parent is set, because we now get a
99 cyclic parent relationship if we have two Axis_group_engravers in
100 the context. */
101 void
102 Axis_group_engraver::process_acknowledged_grobs ()
104 /* UGH UGH UGH */
105 for (int i=0; i < elts_.size (); i++)
107 Grob *par = elts_[i]->get_parent (Y_AXIS);
109 if ((!par || !Axis_group_interface::has_interface (par))
110 && ! elts_[i]->empty_b (Y_AXIS))
111 add_element (elts_[i]);
113 elts_.clear ();
116 void
117 Axis_group_engraver::add_element (Grob*e)
119 Axis_group_interface::add_element (staffline_, e);
122 ////////////////////////////////////////////////////////
123 // maybenot such a good idea after all., to put classes in .cc
125 #include "hara-kiri-group-spanner.hh"
126 #include "rhythmic-head.hh"
128 class Hara_kiri_engraver : public Axis_group_engraver
130 protected:
131 virtual Spanner*get_spanner ()const;
132 virtual void acknowledge_grob (Grob_info);
133 virtual void add_element (Grob *e);
134 public:
135 TRANSLATOR_DECLARATIONS(Hara_kiri_engraver);
138 void
139 Hara_kiri_engraver::add_element (Grob*e)
141 Hara_kiri_group_spanner::add_element (staffline_, e);
145 Spanner*
146 Hara_kiri_engraver::get_spanner () const
148 Spanner * sp = new Spanner (get_property ("RemoveEmptyVerticalGroup"));
150 return sp;
153 void
154 Hara_kiri_engraver::acknowledge_grob (Grob_info i)
156 Axis_group_engraver::acknowledge_grob (i);
157 if (i.grob_->internal_has_interface (ly_symbol2scm ("rhythmic-grob-interface")))
159 Hara_kiri_group_spanner::add_interesting_item (staffline_, i.grob_);
164 Hara_kiri_engraver::Hara_kiri_engraver()
168 ENTER_DESCRIPTION(Hara_kiri_engraver,
169 /* descr */ "Like Axis_group_engraver, but make a hara kiri spanner, and add "
170 "interesting items (ie. note heads, lyric syllables and normal rests) ",
171 /* creats*/ "RemoveEmptyVerticalGroup",
172 /* accepts */ "",
173 /* acks */ "grob-interface",
174 /* reads */ "",
175 /* write */ "");
177 ENTER_DESCRIPTION(Axis_group_engraver,
178 /* descr */ "Group all objects created in this context in a VerticalAxisGroup spanner.",
179 /* creats*/ "VerticalAxisGroup",
180 /* accepts */ "",
181 /* acks */ "grob-interface",
182 /* reads */ "verticalExtent minimumVerticalExtent extraVerticalExtent",
183 /* write */ "");