2 slur.cc -- implement external interface for Slur
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2004 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 "group-interface.hh"
18 #include "lily-guile.hh"
20 #include "main.hh" // DEBUG_SLUR_SCORING
21 #include "note-column.hh"
22 #include "output-def.hh"
26 #include "staff-symbol-referencer.hh"
27 #include "staff-symbol.hh"
30 #include "text-item.hh"
32 #include "slur-scoring.hh"
34 MAKE_SCHEME_CALLBACK (Slur, height, 2);
36 Slur::height (SCM smob, SCM ax)
38 Axis a = (Axis)scm_to_int (ax);
39 Grob *me = unsmob_grob (smob);
42 SCM mol = me->get_uncached_stencil ();
44 if (Stencil *m = unsmob_stencil (mol))
46 return ly_interval2scm (ext);
50 Ugh should have dash-length + dash-period
52 MAKE_SCHEME_CALLBACK (Slur, print,1);
54 Slur::print (SCM smob)
56 Grob *me = unsmob_grob (smob);
57 if (!scm_ilength (me->get_property ("note-columns")))
63 Real base_thick = robust_scm2double (me->get_property ("thickness"), 1);
64 Real thick = base_thick * Staff_symbol_referencer::line_thickness (me);
66 Real ss = Staff_symbol_referencer::staff_space (me);
67 Bezier one = get_curve (me);
72 TODO: replace dashed with generic property.
74 SCM d = me->get_property ("dashed");
75 if (scm_is_number (d))
76 a = Lookup::dashed_slur (one, thick, thick * robust_scm2double (d, 0));
78 a = Lookup::slur (one, get_grob_direction (me) * base_thick * ss / 10.0,
81 #if DEBUG_SLUR_SCORING
82 SCM quant_score = me->get_property ("quant-score");
84 if (to_boolean (me->get_paper ()
85 ->lookup_variable (ly_symbol2scm ("debug-slur-scoring")))
86 && scm_is_string (quant_score))
89 SCM properties = Font_interface::text_font_alist_chain (me);
91 Stencil tm = *unsmob_stencil (Text_interface::interpret_markup
92 (me->get_paper ()->self_scm (), properties,
94 a.add_at_edge (Y_AXIS, get_grob_direction (me), tm, 1.0, 0);
98 return a.smobbed_copy ();
103 Slur::get_curve (Grob*me)
107 for (SCM s = me->get_property ("control-points"); s != SCM_EOL;
109 b.control_[i++] = ly_scm2offset (scm_car (s));
115 Slur::add_column (Grob*me, Grob*n)
117 Pointer_group_interface::add_grob (me, ly_symbol2scm ("note-columns"), n);
118 add_bound_item (dynamic_cast<Spanner*> (me), dynamic_cast<Item*> (n));
123 Slur::add_extra_encompass (Grob*me, Grob*n)
125 Pointer_group_interface::add_grob (me, ly_symbol2scm ("encompass-objects"), n);
130 MAKE_SCHEME_CALLBACK (Slur, outside_slur_callback, 2);
132 Slur::outside_slur_callback (SCM grob, SCM axis)
134 Grob *script = unsmob_grob (grob);
135 Axis a = Axis (scm_to_int (axis));
136 assert (a == Y_AXIS);
138 Grob *slur = unsmob_grob (script->get_property ("slur"));
141 return scm_from_int (0);
143 Grob *cx = script->common_refpoint (slur, X_AXIS);
144 Grob *cy = script->common_refpoint (slur, Y_AXIS);
146 Bezier curve = Slur::get_curve (slur);
148 curve.translate (Offset (slur->relative_coordinate (cx, X_AXIS),
149 slur->relative_coordinate (cy, Y_AXIS)));
151 Interval yext = robust_relative_extent (script, cy, Y_AXIS);
152 Interval xext = robust_relative_extent (script, cx, X_AXIS);
155 Real slur_padding = robust_scm2double (script->get_property ("slur-padding"),
156 0.0); // todo: slur property, script property?
157 yext.widen (slur_padding);
160 Interval bezext (curve.control_[0][X_AXIS],
161 curve.control_[3][X_AXIS]);
163 bool consider[] = { false, false, false };
164 Real ys[] = {0, 0, 0};
166 bool do_shift = false;
168 for (Direction d = LEFT ; d <= RIGHT; d = Direction (d + 1))
170 Real x = xext.linear_combination (d);
171 consider[k] = bezext.contains (x);
176 (fabs(bezext[LEFT] - x) < EPS)
177 ? curve.control_[0][Y_AXIS]
178 : ((fabs(bezext[RIGHT] - x) < EPS)
179 ? curve.control_[3][Y_AXIS]
180 : curve.get_other_coordinate (X_AXIS, x));
183 if (yext.contains (ys[k]))
191 Direction dir = get_grob_direction (script);
192 for (Direction d = LEFT ; d <= RIGHT; d = Direction (d + 1))
195 dir * (dir * offset >? dir * (ys[k]
196 - yext[-dir] + dir * slur_padding));
201 return scm_make_real (offset);
205 get_default_dir (Grob*me)
207 Link_array<Grob> encompasses
208 = Pointer_group_interface__extract_grobs (me, (Grob*) 0, "note-columns");
211 for (int i= 0; i < encompasses.size (); i ++)
213 if (Note_column::dir (encompasses[i]) < 0)
223 MAKE_SCHEME_CALLBACK (Slur, after_line_breaking,1);
225 Slur::after_line_breaking (SCM smob)
227 Spanner *me = dynamic_cast<Spanner*> (unsmob_grob (smob));
228 if (!scm_ilength (me->get_property ("note-columns")))
231 return SCM_UNSPECIFIED;
234 if (!get_grob_direction (me))
235 set_grob_direction (me, get_default_dir (me));
237 if (scm_ilength (me->get_property ("control-points")) < 4)
238 set_slur_control_points (me);
240 return SCM_UNSPECIFIED;
243 ADD_INTERFACE (Slur, "slur-interface",
245 "quant-score excentricity encompass-objects control-points dashed slur-details direction height-limit note-columns ratio thickness");