lilypond-1.5.10
[lilypond.git] / lily / axis-group-engraver.cc
blob1a68c4251fd3fbeb155ac0594e371727dfa5c1f3
1 /*
2 axis-group-engraver.cc -- implement Axis_group_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2001 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_p_;
23 Link_array<Grob> elts_;
24 virtual void initialize ();
25 virtual void finalize ();
26 virtual void acknowledge_grob (Grob_info);
27 virtual void create_grobs ();
28 virtual Spanner* get_spanner_p () const;
29 virtual void add_element (Grob*) ;
30 public:
31 VIRTUAL_COPY_CONS (Translator);
32 Axis_group_engraver ();
35 ADD_THIS_TRANSLATOR (Axis_group_engraver);
37 Axis_group_engraver::Axis_group_engraver ()
39 staffline_p_ = 0;
42 void
43 Axis_group_engraver::initialize ()
45 staffline_p_ = get_spanner_p ();
46 Axis_group_interface::set_interface (staffline_p_);
47 Axis_group_interface::set_axes (staffline_p_, Y_AXIS, Y_AXIS);
49 Grob * it = unsmob_grob (get_property ("currentCommandColumn"));
51 staffline_p_->set_bound (LEFT,it);
53 announce_grob (staffline_p_, 0);
56 Spanner*
57 Axis_group_engraver::get_spanner_p () const
59 return new Spanner (get_property ("VerticalAxisGroup"));
62 void
63 Axis_group_engraver::finalize ()
65 String type = daddy_grav_l ()->type_str_ ;
66 SCM dims = get_property ("VerticalExtent");
68 if (gh_pair_p (dims) && gh_number_p (gh_car (dims))
69 && gh_number_p (gh_cdr (dims)))
71 staffline_p_->set_extent_callback (Grob::preset_extent_proc, Y_AXIS);
72 staffline_p_->set_grob_property ("extent-Y", dims);
75 dims = get_property ("MinimumVerticalExtent");
76 if (gh_pair_p (dims) && gh_number_p (gh_car (dims))
77 && gh_number_p (gh_cdr (dims)))
78 staffline_p_->set_grob_property ("minimum-extent-Y", dims);
80 dims = get_property ("ExtraVerticalExtent");
81 if (gh_pair_p (dims) && gh_number_p (gh_car (dims))
82 && gh_number_p (gh_cdr (dims)))
83 staffline_p_->set_grob_property ("extra-extent-Y", dims);
85 Grob * it = unsmob_grob (get_property ("currentCommandColumn"));
88 staffline_p_->set_bound (RIGHT,it);
90 typeset_grob (staffline_p_);
91 staffline_p_ = 0;
94 void
95 Axis_group_engraver::acknowledge_grob (Grob_info i)
97 elts_.push (i.elem_l_);
101 maybe should check if our parent_l is set, because we now get a
102 cyclic parent relationship if we have two Axis_group_engravers in
103 the context. */
104 void
105 Axis_group_engraver::create_grobs ()
107 /* UGH UGH UGH */
108 for (int i=0; i < elts_.size (); i++)
110 Grob *par = elts_[i]->parent_l (Y_AXIS);
112 if ((!par || !Axis_group_interface::has_interface (par))
113 && ! elts_[i]->empty_b (Y_AXIS))
114 add_element (elts_[i]);
116 elts_.clear ();
119 void
120 Axis_group_engraver::add_element (Grob*e)
122 Axis_group_interface::add_element (staffline_p_, e);
125 ////////////////////////////////////////////////////////
126 // maybenot such a good idea after all., to put classes in .cc
128 #include "hara-kiri-group-spanner.hh"
129 #include "rhythmic-head.hh"
131 class Hara_kiri_engraver : public Axis_group_engraver
133 protected:
134 virtual Spanner*get_spanner_p ()const;
135 virtual void acknowledge_grob (Grob_info);
136 virtual void add_element (Grob *e);
137 public:
138 VIRTUAL_COPY_CONS (Translator);
141 void
142 Hara_kiri_engraver::add_element (Grob*e)
144 Hara_kiri_group_spanner::add_element (staffline_p_, e);
148 Spanner*
149 Hara_kiri_engraver::get_spanner_p () const
151 Spanner * sp = new Spanner (get_property ("HaraKiriVerticalGroup"));
152 Hara_kiri_group_spanner::set_interface (sp);
153 return sp;
156 void
157 Hara_kiri_engraver::acknowledge_grob (Grob_info i)
159 Axis_group_engraver::acknowledge_grob (i);
160 if (Rhythmic_head::has_interface (i.elem_l_)
161 || i.elem_l_->has_interface (ly_symbol2scm ("lyric-syllable-interface")))
163 Hara_kiri_group_spanner::add_interesting_item (staffline_p_, i.elem_l_);
166 ADD_THIS_TRANSLATOR (Hara_kiri_engraver);