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.
46 Span_bar::brew_molecule (SCM smobbed_me)
48 Grob *me = unsmob_grob (smobbed_me);
49 SCM first_elt = me->get_grob_property ("elements");
50 Grob *first_staff_bar = unsmob_grob (gh_car (first_elt));
51 Grob *last_staff_bar = 0;
53 // compute common refpoint of elements & last_staff_bar
55 for (SCM elts = first_elt;
59 SCM smobbed_staff_bar = gh_car (elts);
60 Grob *staff_bar = unsmob_grob (smobbed_staff_bar);
61 refp = staff_bar->common_refpoint (refp, Y_AXIS);
62 last_staff_bar = staff_bar;
65 // determine refp->extent, but ignore lyrics etc. above and below
68 first_staff_bar->relative_coordinate (refp, (Axis)Y_AXIS) -
69 0.5 * (first_staff_bar->extent (refp, Y_AXIS)[UP] -
70 first_staff_bar->extent (refp, Y_AXIS)[DOWN]);
72 last_staff_bar->relative_coordinate (refp, (Axis)Y_AXIS) +
73 0.5 * (last_staff_bar->extent (refp, Y_AXIS)[UP] -
74 last_staff_bar->extent (refp, Y_AXIS)[DOWN]);
76 // global yoffs correction (compensate centering around refp)
77 Real yoffs = 0.5 * (refp_extent[LEFT] - refp_extent[RIGHT]);
80 Span_bar::evaluate_glyph(me);
81 SCM glyph = me->get_grob_property (ly_symbol2scm ("glyph"));
85 glyph may not be a string, when ME is killed by Hara Kiri in
88 if (!gh_string_p (glyph))
91 String glyph_str = ly_scm2string (glyph);
93 // compose span_bar_mol
94 Molecule span_bar_mol = Molecule::Molecule ();
96 for (SCM elts = first_elt;
100 SCM smobbed_staff_bar = gh_car (elts);
101 Grob *staff_bar = unsmob_grob (smobbed_staff_bar);
102 Interval ext = staff_bar->extent (refp, Y_AXIS);
107 if (!prev_extent.empty_b ()) {
110 l[LEFT] = prev_extent[UP];
111 l[RIGHT] = ext[DOWN];
113 //SCM smobbed_staff_bar = gh_car (elts);
114 //Grob *staff_bar = unsmob_grob (smobbed_staff_bar);
115 SCM smobbed_interstaff_bar_molecule =
116 Bar::compound_barline (staff_bar, glyph_str, l.length()).
119 Molecule *interstaff_bar_mol =
120 unsmob_molecule (smobbed_interstaff_bar_molecule);
122 yoffs += prev_extent.length (); // skip staff bar
123 yoffs += 0.5 * (l[RIGHT] - l[LEFT]); // compensate interstaff bar centering
124 interstaff_bar_mol->translate_axis (yoffs, Y_AXIS);
125 yoffs += 0.5 * (l[RIGHT] - l[LEFT]);
127 span_bar_mol.add_molecule (*interstaff_bar_mol);
132 return span_bar_mol.smobbed_copy ();
135 MAKE_SCHEME_CALLBACK (Span_bar,width_callback,2);
137 Span_bar::width_callback (SCM element_smob, SCM scm_axis)
139 Grob *se = unsmob_grob (element_smob);
140 Axis a = (Axis) gh_scm2int (scm_axis);
141 assert (a == X_AXIS);
142 String gl = ly_scm2string (se->get_grob_property ("glyph"));
147 Molecule m = Bar::compound_barline (se, gl, 40 PT);
149 return ly_interval2scm (m.extent (X_AXIS));
152 MAKE_SCHEME_CALLBACK (Span_bar,before_line_breaking,1);
154 Span_bar::before_line_breaking (SCM smob)
156 evaluate_empty (unsmob_grob (smob));
157 evaluate_glyph (unsmob_grob (smob));
160 no need to call Bar::before_line_breaking (), because the info
161 in ELEMENTS already has been procced by Bar::before_line_breaking ().
163 return SCM_UNSPECIFIED;
166 MAKE_SCHEME_CALLBACK (Span_bar,center_on_spanned_callback,2);
169 Span_bar::center_on_spanned_callback (SCM element_smob, SCM axis)
171 Grob *me = unsmob_grob (element_smob);
172 Axis a = (Axis) gh_scm2int (axis);
173 assert (a == Y_AXIS);
174 Interval i (get_spanned_interval (me));
177 Bar::brew_molecule delivers a barline of y-extent (-h/2,h/2), so
178 we have to translate ourselves to be in the center of the
179 interval that we span. */
183 return gh_double2scm (0.0);
186 return gh_double2scm (i.center ());
190 Span_bar::evaluate_empty (Grob*me)
193 TODO: filter all hara-kiried out of ELEMENS list, and then
194 optionally do suicide. Call this cleanage function from
195 center_on_spanned_callback () as well.
198 if (!gh_pair_p (me->get_grob_property ("elements")))
205 Span_bar::evaluate_glyph (Grob*me)
207 SCM elts = me->get_grob_property ("elements");
208 Grob * b = unsmob_grob (gh_car (elts));
209 SCM glsym =ly_symbol2scm ("glyph");
210 SCM gl =b ->get_grob_property (glsym);
211 if (!gh_string_p (gl))
217 String type = ly_scm2string (gl);
223 else if (type== ":|")
227 else if (type== ":|:")
232 gl = ly_str02scm (type.ch_C ());
233 if (scm_equal_p (me->get_grob_property (glsym), gl) != SCM_BOOL_T)
234 me->set_grob_property (glsym, gl);
238 Span_bar::get_spanned_interval (Grob*me)
240 return ly_scm2interval (Axis_group_interface::group_extent_callback (me->self_scm (), gh_int2scm (Y_AXIS)));
244 MAKE_SCHEME_CALLBACK (Span_bar,get_bar_size,1);
246 Span_bar::get_bar_size (SCM smob)
248 Grob* me = unsmob_grob (smob);
249 Interval iv (get_spanned_interval (me));
253 This happens if the bars are hara-kiried from under us.
256 return gh_double2scm (-1);
258 return gh_double2scm (iv.length ());
262 Span_bar::set_interface (Grob *me)
264 Bar::set_interface (me);
266 me->set_interface (ly_symbol2scm ("span-bar-interface"));
267 me->set_extent_callback (SCM_EOL, Y_AXIS);
271 Span_bar::has_interface (Grob*m)
273 return m && m->has_interface (ly_symbol2scm ("span-bar-interface"));