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 ();
95 Grob *prev_staff_bar = 0;
96 Real prev_staff_bar_length = 0.0;
97 for (SCM elts = first_elt;
101 SCM smobbed_staff_bar = gh_car (elts);
102 SCM smobbed_staff_bar_molecule =
103 Bar::brew_molecule (smobbed_staff_bar);
104 Grob *staff_bar = unsmob_grob (smobbed_staff_bar);
105 Real staff_bar_length =
106 unsmob_molecule (smobbed_staff_bar_molecule)->
107 extent (Y_AXIS).length ();
109 if (prev_staff_bar) {
112 l[LEFT] = prev_staff_bar->extent (refp, Y_AXIS)[UP];
113 l[RIGHT] = staff_bar->extent (refp, Y_AXIS)[DOWN];
115 SCM smobbed_staff_bar = gh_car (elts);
116 Grob *staff_bar = unsmob_grob (smobbed_staff_bar);
117 SCM smobbed_interstaff_bar_molecule =
118 Bar::compound_barline (staff_bar, glyph_str, l.length()).
121 Molecule *interstaff_bar_mol =
122 unsmob_molecule (smobbed_interstaff_bar_molecule);
124 yoffs += prev_staff_bar_length; // skip staff bar
125 yoffs += 0.5 * (l[RIGHT] - l[LEFT]); // compensate interstaff bar centering
126 interstaff_bar_mol->translate_axis (yoffs, Y_AXIS);
127 yoffs += 0.5 * (l[RIGHT] - l[LEFT]);
129 span_bar_mol.add_molecule (*interstaff_bar_mol);
131 prev_staff_bar = staff_bar;
132 prev_staff_bar_length = staff_bar_length;
135 return span_bar_mol.smobbed_copy ();
138 MAKE_SCHEME_CALLBACK (Span_bar,width_callback,2);
140 Span_bar::width_callback (SCM element_smob, SCM scm_axis)
142 Grob *se = unsmob_grob (element_smob);
143 Axis a = (Axis) gh_scm2int (scm_axis);
144 assert (a == X_AXIS);
145 String gl = ly_scm2string (se->get_grob_property ("glyph"));
150 Molecule m = Bar::compound_barline (se, gl, 40 PT);
152 return ly_interval2scm (m.extent (X_AXIS));
155 MAKE_SCHEME_CALLBACK (Span_bar,before_line_breaking,1);
157 Span_bar::before_line_breaking (SCM smob)
159 evaluate_empty (unsmob_grob (smob));
160 evaluate_glyph (unsmob_grob (smob));
163 no need to call Bar::before_line_breaking (), because the info
164 in ELEMENTS already has been procced by Bar::before_line_breaking ().
166 return SCM_UNSPECIFIED;
169 MAKE_SCHEME_CALLBACK (Span_bar,center_on_spanned_callback,2);
172 Span_bar::center_on_spanned_callback (SCM element_smob, SCM axis)
174 Grob *me = unsmob_grob (element_smob);
175 Axis a = (Axis) gh_scm2int (axis);
176 assert (a == Y_AXIS);
177 Interval i (get_spanned_interval (me));
180 Bar::brew_molecule delivers a barline of y-extent (-h/2,h/2), so
181 we have to translate ourselves to be in the center of the
182 interval that we span. */
186 return gh_double2scm (0.0);
189 return gh_double2scm (i.center ());
193 Span_bar::evaluate_empty (Grob*me)
196 TODO: filter all hara-kiried out of ELEMENS list, and then
197 optionally do suicide. Call this cleanage function from
198 center_on_spanned_callback () as well.
201 if (!gh_pair_p (me->get_grob_property ("elements")))
208 Span_bar::evaluate_glyph (Grob*me)
210 SCM elts = me->get_grob_property ("elements");
211 Grob * b = unsmob_grob (gh_car (elts));
212 SCM glsym =ly_symbol2scm ("glyph");
213 SCM gl =b ->get_grob_property (glsym);
214 if (!gh_string_p (gl))
220 String type = ly_scm2string (gl);
226 else if (type== ":|")
230 else if (type== ":|:")
235 gl = ly_str02scm (type.ch_C ());
236 if (scm_equal_p (me->get_grob_property (glsym), gl) != SCM_BOOL_T)
237 me->set_grob_property (glsym, gl);
241 Span_bar::get_spanned_interval (Grob*me)
243 return ly_scm2interval (Axis_group_interface::group_extent_callback (me->self_scm (), gh_int2scm (Y_AXIS)));
247 MAKE_SCHEME_CALLBACK (Span_bar,get_bar_size,1);
249 Span_bar::get_bar_size (SCM smob)
251 Grob* me = unsmob_grob (smob);
252 Interval iv (get_spanned_interval (me));
256 This happens if the bars are hara-kiried from under us.
259 return gh_double2scm (-1);
261 return gh_double2scm (iv.length ());
265 Span_bar::set_interface (Grob *me)
267 Bar::set_interface (me);
269 me->set_interface (ly_symbol2scm ("span-bar-interface"));
270 me->set_extent_callback (SCM_EOL, Y_AXIS);
274 Span_bar::has_interface (Grob*m)
276 return m && m->has_interface (ly_symbol2scm ("span-bar-interface"));