2 span-bar.cc -- implement Span_bar
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "font-interface.hh"
12 #include "dimensions.hh"
13 #include "output-def.hh"
16 #include "axis-group-interface.hh"
17 #include "bar-line.hh"
20 Span_bar::add_bar (Grob *me, Grob *b)
22 Pointer_group_interface::add_grob (me, ly_symbol2scm ("elements"), b);
24 me->add_dependency (b);
27 MAKE_SCHEME_CALLBACK (Span_bar, print, 1);
31 (1) Elements from 'me->get_property ("elements")' must be
32 ordered according to their y coordinates relative to their common
33 axis group parent. Otherwise, the computation goes mad.
35 (2) This method depends on bar_engraver not being removed from
36 staff context. If bar_engraver is removed, the size of the staff
37 lines is evaluated as 0, which results in a solid span bar line
38 with faulty y coordinate. */
40 /* This routine was originally by Juergen Reuter, but it was a on the
41 bulky side. Rewritten by Han-Wen. */
43 Span_bar::print (SCM smobbed_me)
45 Grob *me = unsmob_grob (smobbed_me);
46 SCM elements = me->get_property ("elements");
48 Grob *refp = common_refpoint_of_list (elements, me, Y_AXIS);
49 Span_bar::evaluate_glyph (me);
50 SCM glyph = me->get_property ("glyph");
52 /* glyph may not be a string, when ME is killed by Hara Kiri in
54 if (!scm_is_string (glyph))
57 String glyph_string = ly_scm2string (glyph);
59 /* compose span_bar_mol */
60 Array<Interval> extents;
62 for (SCM elts = elements; scm_is_pair (elts); elts = scm_cdr (elts))
64 Grob *bar = unsmob_grob (scm_car (elts));
65 Interval ext = bar->extent (refp, Y_AXIS);
76 extents.sort (&Interval::left_comparison);
79 for (int i = 1; i < extents.size (); i ++)
81 Interval prev_extent = extents[i-1];
82 Interval ext = extents[i];
83 if (!prev_extent.is_empty ())
85 Interval l (prev_extent [UP],
90 /* There is overlap between the bar lines. Do nothing. */
94 Stencil interbar = Bar_line::compound_barline (model_bar,
98 interbar.translate_axis (l.center (), Y_AXIS);
99 span_bar.add_stencil (interbar);
105 span_bar.translate_axis (- me->relative_coordinate (refp, Y_AXIS),
108 return span_bar.smobbed_copy ();
111 MAKE_SCHEME_CALLBACK (Span_bar, width_callback, 2);
113 Span_bar::width_callback (SCM element_smob, SCM scm_axis)
115 Grob *se = unsmob_grob (element_smob);
118 assert ( (Axis) scm_to_int (scm_axis) == X_AXIS);
119 String gl = ly_scm2string (se->get_property ("glyph"));
124 Stencil m = Bar_line::compound_barline (se, gl, 40 PT, false);
126 return ly_interval2scm (m.extent (X_AXIS));
129 MAKE_SCHEME_CALLBACK (Span_bar, before_line_breaking, 1);
131 Span_bar::before_line_breaking (SCM smob)
133 Grob *g = unsmob_grob (smob);
137 /* No need to call Bar_line::before_line_breaking (), because the info
138 in ELEMENTS already has been procced by
139 Bar_line::before_line_breaking (). */
140 return SCM_UNSPECIFIED;
143 MAKE_SCHEME_CALLBACK (Span_bar, center_on_spanned_callback, 2);
146 Span_bar::center_on_spanned_callback (SCM element_smob, SCM axis)
148 Grob *me = unsmob_grob (element_smob);
150 assert (scm_to_int (axis) == Y_AXIS);
151 Interval i (get_spanned_interval (me));
153 /* Bar_line::print delivers a barline of y-extent (-h/2, h/2), so
154 we have to translate ourselves to be in the center of the
155 interval that we span. */
159 return scm_make_real (0.0);
162 return scm_make_real (i.center ());
166 Span_bar::evaluate_empty (Grob *me)
168 /* TODO: filter all hara-kiried out of ELEMENS list, and then
169 optionally do suicide. Call this cleanage function from
170 center_on_spanned_callback () as well. */
171 if (!scm_is_pair (me->get_property ("elements")))
178 Span_bar::evaluate_glyph (Grob *me)
180 SCM gl = me->get_property ("glyph");
182 if (scm_is_string (gl))
185 for (SCM s = me->get_property ("elements");
186 !scm_is_string (gl) && scm_is_pair (s); s = scm_cdr (s))
188 gl = unsmob_grob (scm_car (s))
189 ->get_property ("glyph");
192 if (!scm_is_string (gl))
198 String type = ly_scm2string (gl);
203 else if (type == ":|")
207 else if (type == ":|:")
212 gl = scm_makfrom0str (type.to_str0 ());
213 if (scm_equal_p (me->get_property ("glyph"), gl)
215 me->set_property ("glyph", gl);
219 Span_bar::get_spanned_interval (Grob *me)
221 return ly_scm2interval (Axis_group_interface::group_extent_callback
222 (me->self_scm (), scm_int2num (Y_AXIS)));
225 MAKE_SCHEME_CALLBACK (Span_bar, get_bar_size, 1);
227 Span_bar::get_bar_size (SCM smob)
229 Grob *me = unsmob_grob (smob);
230 Interval iv (get_spanned_interval (me));
233 /* This happens if the bars are hara-kiried from under us. */
235 return scm_make_real (-1);
237 return scm_make_real (iv.length ());
240 ADD_INTERFACE (Span_bar, "span-bar-interface",
241 "A bar line that spanned between other barlines. This interface is "
242 " used for bar lines that connect different staves.",