2 span-bar.cc -- implement Span_bar
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 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"
21 Span_bar::add_bar (Grob*me, Grob*b)
23 Pointer_group_interface::add_element (me,"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. (TODO:
36 * apply a sort algorithm that ensures this precondition.) However,
37 * until now, I have seen no case where lily has not fulfilled this
40 * (2) This method depends on bar_engraver not being removed from
41 * staff context. If bar_engraver is removed, the size of the staff
42 * lines is evaluated as 0, which results in a solid span bar line
43 * with faulty y coordinate.
47 This routine was originally by Juergen Reuter, but it was a on the
48 bulky side. Rewritten by Han-Wen.
51 Span_bar::brew_molecule (SCM smobbed_me)
53 Grob *me = unsmob_grob (smobbed_me);
54 SCM first_elt = me->get_grob_property ("elements");
56 // compute common refpoint of elements
58 for (SCM elts = first_elt; gh_pair_p (elts); elts = gh_cdr (elts))
60 SCM smobbed_staff_bar = gh_car (elts);
61 Grob *staff_bar = unsmob_grob (smobbed_staff_bar);
62 refp = staff_bar->common_refpoint (refp, Y_AXIS);
65 Span_bar::evaluate_glyph(me);
66 SCM glyph = me->get_grob_property (ly_symbol2scm ("glyph"));
69 glyph may not be a string, when ME is killed by Hara Kiri in
72 if (!gh_string_p (glyph))
75 String glyph_str = ly_scm2string (glyph);
77 // compose span_bar_mol
78 Molecule span_bar_mol;
79 Grob *prev_staff_bar = 0;
80 for (SCM elts = first_elt; gh_pair_p (elts); elts = gh_cdr (elts))
82 SCM smobbed_staff_bar = gh_car (elts);
83 Grob *staff_bar = unsmob_grob (smobbed_staff_bar);
86 Interval l(prev_staff_bar->extent (refp, Y_AXIS)[UP],
87 staff_bar->extent (refp, Y_AXIS)[DOWN]);
90 = Bar::compound_barline (staff_bar, glyph_str, l.length());
91 interbar.translate_axis (l.center (), Y_AXIS);
92 span_bar_mol.add_molecule (interbar);
94 prev_staff_bar = staff_bar;
97 span_bar_mol.translate_axis (- me->relative_coordinate (refp, Y_AXIS), Y_AXIS);
99 return span_bar_mol.smobbed_copy ();
102 MAKE_SCHEME_CALLBACK (Span_bar,width_callback,2);
104 Span_bar::width_callback (SCM element_smob, SCM scm_axis)
106 Grob *se = unsmob_grob (element_smob);
107 Axis a = (Axis) gh_scm2int (scm_axis);
108 assert (a == X_AXIS);
109 String gl = ly_scm2string (se->get_grob_property ("glyph"));
114 Molecule m = Bar::compound_barline (se, gl, 40 PT);
116 return ly_interval2scm (m.extent (X_AXIS));
119 MAKE_SCHEME_CALLBACK (Span_bar,before_line_breaking,1);
121 Span_bar::before_line_breaking (SCM smob)
123 evaluate_empty (unsmob_grob (smob));
124 evaluate_glyph (unsmob_grob (smob));
127 no need to call Bar::before_line_breaking (), because the info
128 in ELEMENTS already has been procced by Bar::before_line_breaking ().
130 return SCM_UNSPECIFIED;
133 MAKE_SCHEME_CALLBACK (Span_bar,center_on_spanned_callback,2);
136 Span_bar::center_on_spanned_callback (SCM element_smob, SCM axis)
138 Grob *me = unsmob_grob (element_smob);
139 Axis a = (Axis) gh_scm2int (axis);
140 assert (a == Y_AXIS);
141 Interval i (get_spanned_interval (me));
144 Bar::brew_molecule delivers a barline of y-extent (-h/2,h/2), so
145 we have to translate ourselves to be in the center of the
146 interval that we span. */
150 return gh_double2scm (0.0);
153 return gh_double2scm (i.center ());
157 Span_bar::evaluate_empty (Grob*me)
160 TODO: filter all hara-kiried out of ELEMENS list, and then
161 optionally do suicide. Call this cleanage function from
162 center_on_spanned_callback () as well.
165 if (!gh_pair_p (me->get_grob_property ("elements")))
172 Span_bar::evaluate_glyph (Grob*me)
174 SCM elts = me->get_grob_property ("elements");
175 Grob * b = unsmob_grob (gh_car (elts));
176 SCM glsym =ly_symbol2scm ("glyph");
177 SCM gl =b ->get_grob_property (glsym);
178 if (!gh_string_p (gl))
184 String type = ly_scm2string (gl);
190 else if (type== ":|")
194 else if (type== ":|:")
199 gl = ly_str02scm (type.ch_C ());
200 if (scm_equal_p (me->get_grob_property (glsym), gl) != SCM_BOOL_T)
201 me->set_grob_property (glsym, gl);
205 Span_bar::get_spanned_interval (Grob*me)
207 return ly_scm2interval (Axis_group_interface::group_extent_callback (me->self_scm (), gh_int2scm (Y_AXIS)));
211 MAKE_SCHEME_CALLBACK (Span_bar,get_bar_size,1);
213 Span_bar::get_bar_size (SCM smob)
215 Grob* me = unsmob_grob (smob);
216 Interval iv (get_spanned_interval (me));
220 This happens if the bars are hara-kiried from under us.
223 return gh_double2scm (-1);
225 return gh_double2scm (iv.length ());
229 Span_bar::set_interface (Grob *me)
231 Bar::set_interface (me);
233 me->set_interface (ly_symbol2scm ("span-bar-interface"));
234 me->set_extent_callback (SCM_EOL, Y_AXIS);
238 Span_bar::has_interface (Grob*m)
240 return m && m->has_interface (ly_symbol2scm ("span-bar-interface"));