2 slur.cc -- implement external interface for Slur
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2006 Han-Wen Nienhuys <hanwen@xs4all.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.empty ())
48 for (vsize 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, 1);
61 Slur::height (SCM smob)
63 Grob *me = unsmob_grob (smob);
66 Stencil *m = me->get_stencil ();
67 return m ? ly_interval2scm (m->extent (Y_AXIS))
68 : ly_interval2scm (Interval ());
72 Ugh should have dash-length + dash-period
74 MAKE_SCHEME_CALLBACK (Slur, print, 1);
76 Slur::print (SCM smob)
78 Grob *me = unsmob_grob (smob);
79 extract_grob_set (me, "note-columns", encompasses);
80 if (encompasses.empty ())
86 Real staff_thick = Staff_symbol_referencer::line_thickness (me);
87 Real base_thick = robust_scm2double (me->get_property ("thickness"), 1);
88 Real thick = base_thick * staff_thick;
89 Bezier one = get_curve (me);
93 TODO: replace dashed with generic property.
95 SCM p = me->get_property ("dash-period");
96 SCM f = me->get_property ("dash-fraction");
97 if (scm_is_number (p) && scm_is_number (f))
98 a = Lookup::dashed_slur (one, thick, robust_scm2double (p, 1.0),
99 robust_scm2double (f, 0));
101 a = Lookup::slur (one,
102 get_grob_direction (me) * staff_thick * 1.0,
105 #if DEBUG_SLUR_SCORING
106 SCM quant_score = me->get_property ("quant-score");
108 if (to_boolean (me->layout ()
109 ->lookup_variable (ly_symbol2scm ("debug-slur-scoring")))
110 && scm_is_string (quant_score))
113 SCM properties = Font_interface::text_font_alist_chain (me);
115 Stencil tm = *unsmob_stencil (Text_interface::interpret_markup
116 (me->layout ()->self_scm (), properties,
118 a.add_at_edge (Y_AXIS, get_grob_direction (me), tm, 1.0, 0);
122 return a.smobbed_copy ();
126 Slur::get_curve (Grob *me)
130 for (SCM s = me->get_property ("control-points"); s != SCM_EOL;
132 b.control_[i++] = ly_scm2offset (scm_car (s));
138 Slur::add_column (Grob *me, Grob *n)
140 Pointer_group_interface::add_grob (me, ly_symbol2scm ("note-columns"), n);
141 add_bound_item (dynamic_cast<Spanner *> (me), dynamic_cast<Item *> (n));
145 Slur::add_extra_encompass (Grob *me, Grob *n)
147 Pointer_group_interface::add_grob (me, ly_symbol2scm ("encompass-objects"), n);
151 MAKE_SCHEME_CALLBACK (Slur, outside_slur_callback, 2);
153 Slur::outside_slur_callback (SCM grob, SCM offset_scm)
155 Grob *script = unsmob_grob (grob);
156 Grob *slur = unsmob_grob (script->get_object ("slur"));
161 SCM avoid = script->get_property ("avoid-slur");
162 if (avoid != ly_symbol2scm ("outside")
163 && avoid != ly_symbol2scm ("around"))
166 Direction dir = get_grob_direction (script);
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 yext.translate (robust_scm2double (offset_scm, 0));
184 /* FIXME: slur property, script property? */
185 Real slur_padding = robust_scm2double (script->get_property ("slur-padding"),
187 yext.widen (slur_padding);
190 Interval bezext (curve.control_[0][X_AXIS], curve.control_[3][X_AXIS]);
191 bool consider[] = { false, false, false };
192 Real ys[] = {0, 0, 0};
193 bool do_shift = false;
195 for (int d = LEFT, k = 0; d <= RIGHT; d++, k++)
197 Real x = xext.linear_combination ((Direction) d);
198 consider[k] = bezext.contains (x);
203 = (fabs (bezext[LEFT] - x) < EPS)
204 ? curve.control_[0][Y_AXIS]
205 : ((fabs (bezext[RIGHT] - x) < EPS)
206 ? curve.control_[3][Y_AXIS]
207 : curve.get_other_coordinate (X_AXIS, x));
210 /* Request shift if slur is contained script's Y, or if
211 script is inside slur and avoid == outside. */
212 if (yext.contains (ys[k])
213 || (dir * ys[k] > dir * yext[-dir] && avoid == ly_symbol2scm ("outside")))
218 Real avoidance_offset = 0.0;
221 for (int d = LEFT, k = 0; d <= RIGHT; d++, k++)
222 avoidance_offset = dir * (max (dir * avoidance_offset,
223 dir * (ys[k] - yext[-dir] + dir * slur_padding)));
226 return scm_from_double (scm_to_double (offset_scm) + avoidance_offset);
231 ADD_INTERFACE (Slur, "slur-interface",