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>
16 #include "directional-element-interface.hh"
17 #include "font-interface.hh"
18 #include "group-interface.hh"
20 #include "main.hh" // DEBUG_SLUR_SCORING
21 #include "note-column.hh"
22 #include "output-def.hh"
24 #include "staff-symbol-referencer.hh"
25 #include "staff-symbol.hh"
27 #include "text-item.hh"
29 #include "slur-scoring.hh"
31 MAKE_SCHEME_CALLBACK (Slur, height, 2);
33 Slur::height (SCM smob, SCM ax)
35 Axis a = (Axis)scm_to_int (ax);
36 Grob *me = unsmob_grob (smob);
39 SCM mol = me->get_uncached_stencil ();
41 if (Stencil *m = unsmob_stencil (mol))
43 return ly_interval2scm (ext);
47 Ugh should have dash-length + dash-period
49 MAKE_SCHEME_CALLBACK (Slur, print, 1);
51 Slur::print (SCM smob)
53 Grob *me = unsmob_grob (smob);
54 if (!scm_ilength (me->get_property ("note-columns")))
60 Real staff_thick = Staff_symbol_referencer::line_thickness (me);
61 Real base_thick = robust_scm2double (me->get_property ("thickness"), 1);
62 Real thick = base_thick * staff_thick;
64 Real ss = Staff_symbol_referencer::staff_space (me);
65 Bezier one = get_curve (me);
70 TODO: replace dashed with generic property.
72 SCM p = me->get_property ("dash-period");
73 SCM f = me->get_property ("dash-fraction");
74 if (scm_is_number (p) && scm_is_number (f))
75 a = Lookup::dashed_slur (one, thick, robust_scm2double (p, 1.0),
76 robust_scm2double (f, 0));
78 a = Lookup::slur (one,
79 get_grob_direction (me) * staff_thick * 1.0,
82 #if DEBUG_SLUR_SCORING
83 SCM quant_score = me->get_property ("quant-score");
85 if (to_boolean (me->get_layout ()
86 ->lookup_variable (ly_symbol2scm ("debug-slur-scoring")))
87 && scm_is_string (quant_score))
90 SCM properties = Font_interface::text_font_alist_chain (me);
92 Stencil tm = *unsmob_stencil (Text_interface::interpret_markup
93 (me->get_layout ()->self_scm (), properties,
95 a.add_at_edge (Y_AXIS, get_grob_direction (me), tm, 1.0, 0);
99 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));
122 Slur::add_extra_encompass (Grob *me, Grob *n)
124 Pointer_group_interface::add_grob (me, ly_symbol2scm ("encompass-objects"), n);
127 MAKE_SCHEME_CALLBACK (Slur, outside_slur_callback, 2);
129 Slur::outside_slur_callback (SCM grob, SCM axis)
131 Grob *script = unsmob_grob (grob);
132 Axis a = Axis (scm_to_int (axis));
134 assert (a == Y_AXIS);
136 Grob *slur = unsmob_grob (script->get_property ("slur"));
139 return scm_from_int (0);
141 Grob *cx = script->common_refpoint (slur, X_AXIS);
142 Grob *cy = script->common_refpoint (slur, Y_AXIS);
144 Bezier curve = Slur::get_curve (slur);
146 curve.translate (Offset (slur->relative_coordinate (cx, X_AXIS),
147 slur->relative_coordinate (cy, Y_AXIS)));
149 Interval yext = robust_relative_extent (script, cy, Y_AXIS);
150 Interval xext = robust_relative_extent (script, cx, X_AXIS);
152 Real slur_padding = robust_scm2double (script->get_property ("slur-padding"),
153 0.0); // todo: slur property, script property?
154 yext.widen (slur_padding);
157 Interval bezext (curve.control_[0][X_AXIS],
158 curve.control_[3][X_AXIS]);
160 bool consider[] = { false, false, false };
161 Real ys[] = {0, 0, 0};
163 bool do_shift = false;
165 for (int d = LEFT; d <= RIGHT; d++)
167 Real x = xext.linear_combination ((Direction) d);
168 consider[k] = bezext.contains (x);
173 = (fabs (bezext[LEFT] - x) < EPS)
174 ? curve.control_[0][Y_AXIS]
175 : ((fabs (bezext[RIGHT] - x) < EPS)
176 ? curve.control_[3][Y_AXIS]
177 : curve.get_other_coordinate (X_AXIS, x));
180 if (yext.contains (ys[k]))
188 Direction dir = get_grob_direction (script);
189 for (int d = LEFT; d <= RIGHT; d++)
191 offset = dir * (max (dir * offset,
192 dir * (ys[k] - yext[-dir] + dir * slur_padding)));
197 return scm_make_real (offset);
201 get_default_dir (Grob *me)
203 Link_array<Grob> encompasses
204 = extract_grob_array (me, ly_symbol2scm ("note-columns"));
207 for (int i = 0; i < encompasses.size (); i++)
209 if (Note_column::dir (encompasses[i]) < 0)
218 MAKE_SCHEME_CALLBACK (Slur, after_line_breaking, 1);
220 Slur::after_line_breaking (SCM smob)
222 Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
223 if (!scm_ilength (me->get_property ("note-columns")))
226 return SCM_UNSPECIFIED;
229 if (!get_grob_direction (me))
230 set_grob_direction (me, get_default_dir (me));
232 if (scm_ilength (me->get_property ("control-points")) < 4)
233 set_slur_control_points (me);
235 return SCM_UNSPECIFIED;
238 ADD_INTERFACE (Slur, "slur-interface",
240 "positions quant-score excentricity encompass-objects control-points dash-period dash-fraction slur-details direction height-limit note-columns ratio thickness");