2 slur.cc -- implement external interface for Slur
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
15 #include "directional-element-interface.hh"
16 #include "font-interface.hh"
17 #include "pointer-group-interface.hh"
19 #include "main.hh" // DEBUG_SLUR_SCORING
20 #include "note-column.hh"
21 #include "output-def.hh"
23 #include "staff-symbol-referencer.hh"
24 #include "staff-symbol.hh"
26 #include "text-interface.hh"
28 #include "slur-scoring.hh"
30 #include "script-interface.hh"
34 MAKE_SCHEME_CALLBACK(Slur, calc_direction, 1)
36 Slur::calc_direction (SCM smob)
38 Grob *me = unsmob_grob (smob);
39 extract_grob_set (me, "note-columns", encompasses);
41 if (encompasses.is_empty ())
48 for (int i = 0; i < encompasses.size (); i++)
50 if (Note_column::dir (encompasses[i]) < 0)
56 return scm_from_int (d);
59 MAKE_SCHEME_CALLBACK (Slur, height, 2);
61 Slur::height (SCM smob, SCM ax)
63 Axis a = (Axis)scm_to_int (ax);
64 Grob *me = unsmob_grob (smob);
68 Stencil *m = me->get_stencil ();
69 return m ? ly_interval2scm (m->extent (a)) : ly_interval2scm (Interval ());
73 Ugh should have dash-length + dash-period
75 MAKE_SCHEME_CALLBACK (Slur, print, 1);
77 Slur::print (SCM smob)
79 Grob *me = unsmob_grob (smob);
80 extract_grob_set (me, "note-columns", encompasses);
81 if (encompasses.is_empty ())
87 Real staff_thick = Staff_symbol_referencer::line_thickness (me);
88 Real base_thick = robust_scm2double (me->get_property ("thickness"), 1);
89 Real thick = base_thick * staff_thick;
90 Bezier one = get_curve (me);
94 TODO: replace dashed with generic property.
96 SCM p = me->get_property ("dash-period");
97 SCM f = me->get_property ("dash-fraction");
98 if (scm_is_number (p) && scm_is_number (f))
99 a = Lookup::dashed_slur (one, thick, robust_scm2double (p, 1.0),
100 robust_scm2double (f, 0));
102 a = Lookup::slur (one,
103 get_grob_direction (me) * staff_thick * 1.0,
106 #if DEBUG_SLUR_SCORING
107 SCM quant_score = me->get_property ("quant-score");
109 if (to_boolean (me->get_layout ()
110 ->lookup_variable (ly_symbol2scm ("debug-slur-scoring")))
111 && scm_is_string (quant_score))
114 SCM properties = Font_interface::text_font_alist_chain (me);
116 Stencil tm = *unsmob_stencil (Text_interface::interpret_markup
117 (me->get_layout ()->self_scm (), properties,
119 a.add_at_edge (Y_AXIS, get_grob_direction (me), tm, 1.0, 0);
123 return a.smobbed_copy ();
127 Slur::get_curve (Grob *me)
131 for (SCM s = me->get_property ("control-points"); s != SCM_EOL;
133 b.control_[i++] = ly_scm2offset (scm_car (s));
139 Slur::add_column (Grob *me, Grob *n)
141 Pointer_group_interface::add_grob (me, ly_symbol2scm ("note-columns"), n);
142 add_bound_item (dynamic_cast<Spanner *> (me), dynamic_cast<Item *> (n));
146 Slur::add_extra_encompass (Grob *me, Grob *n)
148 Pointer_group_interface::add_grob (me, ly_symbol2scm ("encompass-objects"), n);
152 MAKE_SCHEME_CALLBACK (Slur, outside_slur_callback, 2);
154 Slur::outside_slur_callback (SCM grob, SCM axis)
156 Grob *script = unsmob_grob (grob);
157 Axis a = Axis (scm_to_int (axis));
159 assert (a == Y_AXIS);
161 Grob *slur = unsmob_grob (script->get_object ("slur"));
164 return scm_from_int (0);
166 Direction dir = get_grob_direction (script);
168 return scm_from_int (0);
170 Grob *cx = script->common_refpoint (slur, X_AXIS);
171 Grob *cy = script->common_refpoint (slur, Y_AXIS);
173 Bezier curve = Slur::get_curve (slur);
175 curve.translate (Offset (slur->relative_coordinate (cx, X_AXIS),
176 slur->relative_coordinate (cy, Y_AXIS)));
178 Interval yext = robust_relative_extent (script, cy, Y_AXIS);
179 Interval xext = robust_relative_extent (script, cx, X_AXIS);
181 /* FIXME: slur property, script property? */
182 Real slur_padding = robust_scm2double (script->get_property ("slur-padding"),
184 yext.widen (slur_padding);
187 Interval bezext (curve.control_[0][X_AXIS], curve.control_[3][X_AXIS]);
188 bool consider[] = { false, false, false };
189 Real ys[] = {0, 0, 0};
190 bool do_shift = false;
191 SCM avoid = script->get_property ("avoid-slur");
193 for (int d = LEFT, k = 0; d <= RIGHT; d++, k++)
195 Real x = xext.linear_combination ((Direction) d);
196 consider[k] = bezext.contains (x);
201 = (fabs (bezext[LEFT] - x) < EPS)
202 ? curve.control_[0][Y_AXIS]
203 : ((fabs (bezext[RIGHT] - x) < EPS)
204 ? curve.control_[3][Y_AXIS]
205 : curve.get_other_coordinate (X_AXIS, x));
208 /* Request shift if slur is contained script's Y, or if
209 script is inside slur and avoid == outside. */
210 if (yext.contains (ys[k])
211 || (avoid == ly_symbol2scm ("outside")
212 && dir * ys[k] > dir * yext[-dir]))
219 for (int d = LEFT, k = 0; d <= RIGHT; d++, k++)
220 offset = dir * (max (dir * offset,
221 dir * (ys[k] - yext[-dir] + dir * slur_padding)));
224 return scm_from_double (offset);
229 ADD_INTERFACE (Slur, "slur-interface",