2 span-bar.cc -- implement Span_bar
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "font-interface.hh"
11 #include "dimensions.hh"
12 #include "paper-def.hh"
13 #include "molecule.hh"
15 #include "axis-group-interface.hh"
16 #include "group-interface.hh"
18 #include "bar-line.hh"
21 Span_bar::add_bar (Grob
*me
, Grob
*b
)
23 Pointer_group_interface::add_grob (me
, ly_symbol2scm ("elements"), b
);
25 me
->add_dependency (b
);
28 MAKE_SCHEME_CALLBACK (Span_bar
,brew_molecule
,1);
33 (1) Elements from 'me->get_grob_property ("elements")' must be
34 ordered according to their y coordinates relative to their common
35 axis group parent. Otherwise, the computation goes mad.
38 apply a sort algorithm that ensures this precondition.) However,
39 until now, I have seen no case where lily has not fulfilled this
42 (2) This method depends on bar_engraver not being removed from
43 staff context. If bar_engraver is removed, the size of the staff
44 lines is evaluated as 0, which results in a solid span bar line
45 with faulty y coordinate.
49 This routine was originally by Juergen Reuter, but it was a on the
50 bulky side. Rewritten by Han-Wen.
53 Span_bar::brew_molecule (SCM smobbed_me
)
55 Grob
*me
= unsmob_grob (smobbed_me
);
56 SCM first_elt
= me
->get_grob_property ("elements");
58 // compute common refpoint of elements
60 for (SCM elts
= first_elt
; gh_pair_p (elts
); elts
= ly_cdr (elts
))
62 SCM smobbed_staff_bar
= ly_car (elts
);
63 Grob
*staff_bar
= unsmob_grob (smobbed_staff_bar
);
64 refp
= staff_bar
->common_refpoint (refp
, Y_AXIS
);
67 Span_bar::evaluate_glyph(me
);
68 SCM glyph
= me
->get_grob_property ("glyph");
71 glyph may not be a string, when ME is killed by Hara Kiri in
74 if (!gh_string_p (glyph
))
77 String glyph_string
= ly_scm2string (glyph
);
79 // compose span_bar_mol
80 Molecule span_bar_mol
;
83 for (SCM elts
= first_elt
; gh_pair_p (elts
); elts
= ly_cdr (elts
))
85 SCM smobbed_staff_bar
= ly_car (elts
);
86 Grob
*staff_bar
= unsmob_grob (smobbed_staff_bar
);
87 Interval ext
= staff_bar
->extent (refp
, Y_AXIS
);
91 if (!prev_extent
.empty_b ())
93 Interval
l(prev_extent
[UP
],
98 /* there is overlap between the bar lines. We do nothign here.
104 = Bar_line::compound_barline (staff_bar
, glyph_string
, l
.length());
105 interbar
.translate_axis (l
.center (), Y_AXIS
);
106 span_bar_mol
.add_molecule (interbar
);
112 span_bar_mol
.translate_axis (- me
->relative_coordinate (refp
, Y_AXIS
), Y_AXIS
);
114 return span_bar_mol
.smobbed_copy ();
117 MAKE_SCHEME_CALLBACK (Span_bar
,width_callback
,2);
119 Span_bar::width_callback (SCM element_smob
, SCM scm_axis
)
121 Grob
*se
= unsmob_grob (element_smob
);
122 Axis a
= (Axis
) gh_scm2int (scm_axis
);
123 assert (a
== X_AXIS
);
124 String gl
= ly_scm2string (se
->get_grob_property ("glyph"));
129 Molecule m
= Bar_line::compound_barline (se
, gl
, 40 PT
);
131 return ly_interval2scm (m
.extent (X_AXIS
));
134 MAKE_SCHEME_CALLBACK (Span_bar
,before_line_breaking
,1);
136 Span_bar::before_line_breaking (SCM smob
)
138 evaluate_empty (unsmob_grob (smob
));
139 evaluate_glyph (unsmob_grob (smob
));
142 no need to call Bar_line::before_line_breaking (), because the info
143 in ELEMENTS already has been procced by Bar_line::before_line_breaking ().
145 return SCM_UNSPECIFIED
;
148 MAKE_SCHEME_CALLBACK (Span_bar
,center_on_spanned_callback
,2);
151 Span_bar::center_on_spanned_callback (SCM element_smob
, SCM axis
)
153 Grob
*me
= unsmob_grob (element_smob
);
154 Axis a
= (Axis
) gh_scm2int (axis
);
155 assert (a
== Y_AXIS
);
156 Interval
i (get_spanned_interval (me
));
159 Bar_line::brew_molecule delivers a barline of y-extent (-h/2,h/2), so
160 we have to translate ourselves to be in the center of the
161 interval that we span. */
165 return gh_double2scm (0.0);
168 return gh_double2scm (i
.center ());
172 Span_bar::evaluate_empty (Grob
*me
)
175 TODO: filter all hara-kiried out of ELEMENS list, and then
176 optionally do suicide. Call this cleanage function from
177 center_on_spanned_callback () as well.
180 if (!gh_pair_p (me
->get_grob_property ("elements")))
187 Span_bar::evaluate_glyph (Grob
*me
)
189 SCM elts
= me
->get_grob_property ("elements");
190 SCM glyph_symbol
= ly_symbol2scm ("glyph");
193 while (gh_pair_p (elts
))
195 gl
= unsmob_grob (gh_car (elts
))->internal_get_grob_property (glyph_symbol
);
196 if (gh_string_p (gl
))
201 if (!gh_string_p (gl
))
207 String type
= ly_scm2string (gl
);
212 else if (type
== ":|")
216 else if (type
== ":|:")
221 gl
= scm_makfrom0str (type
.to_str0 ());
222 if (scm_equal_p (me
->internal_get_grob_property (glyph_symbol
), gl
) != SCM_BOOL_T
)
223 me
->internal_set_grob_property (glyph_symbol
, gl
);
227 Span_bar::get_spanned_interval (Grob
*me
)
229 return ly_scm2interval (Axis_group_interface::group_extent_callback (me
->self_scm (), gh_int2scm (Y_AXIS
)));
233 MAKE_SCHEME_CALLBACK (Span_bar
,get_bar_size
,1);
235 Span_bar::get_bar_size (SCM smob
)
237 Grob
* me
= unsmob_grob (smob
);
238 Interval
iv (get_spanned_interval (me
));
242 This happens if the bars are hara-kiried from under us.
245 return gh_double2scm (-1);
247 return gh_double2scm (iv
.length ());
252 ADD_INTERFACE (Span_bar
,"span-bar-interface",
253 "A bar line that spans other barlines (typically used to get cross-staff barlines.",