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
);
158 TRANSLATOR_DECLARATIONS (Hara_kiri_engraver
);
162 Hara_kiri_engraver::add_element (Grob
*e
)
164 Hara_kiri_group_spanner::add_element (staffline_
, e
);
168 Hara_kiri_engraver::get_spanner ()
170 Spanner
*sp
= make_spanner ("RemoveEmptyVerticalGroup", SCM_EOL
);
176 Hara_kiri_engraver::acknowledge_grob (Grob_info i
)
178 Axis_group_engraver::acknowledge_grob (i
);
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",
196 /* acks */ "grob-interface",
200 ADD_TRANSLATOR (Axis_group_engraver
,
201 /* descr */ "Group all objects created in this context in a VerticalAxisGroup spanner.",
202 /* creats*/ "VerticalAxisGroup",
204 /* acks */ "grob-interface",
205 /* reads */ "verticalExtent minimumVerticalExtent extraVerticalExtent",