]> git.donarmstrong.com Git - lilypond.git/blob - lily/slur.cc
(SLIB_PATH): add SLIB_PATH to
[lilypond.git] / lily / slur.cc
1 /*
2   slur.cc -- implement external interface for Slur
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10
11 #include <math.h>
12
13 #include "beam.hh"
14 #include "bezier.hh"
15 #include "directional-element-interface.hh"
16 #include "font-interface.hh"
17 #include "group-interface.hh"
18 #include "lily-guile.hh"
19 #include "lookup.hh"
20 #include "main.hh"
21 #include "note-column.hh"
22 #include "output-def.hh"
23 #include "rod.hh"
24 #include "slur.hh"
25 #include "spanner.hh"
26 #include "staff-symbol-referencer.hh"
27 #include "staff-symbol.hh"
28 #include "stem.hh"
29 #include "stencil.hh"
30 #include "text-item.hh"
31 #include "warn.hh"
32
33 MAKE_SCHEME_CALLBACK (Slur, height, 2);
34 SCM
35 Slur::height (SCM smob, SCM ax)
36 {
37   Axis a = (Axis)scm_to_int (ax);
38   Grob *me = unsmob_grob (smob);
39   assert (a == Y_AXIS);
40
41   SCM mol = me->get_uncached_stencil ();
42   Interval ext;
43   if (Stencil *m = unsmob_stencil (mol))
44     ext = m->extent (a);
45   return ly_interval2scm (ext);
46 }
47
48 /*
49   Ugh should have dash-length + dash-period
50 */
51 MAKE_SCHEME_CALLBACK (Slur, print,1);
52 SCM
53 Slur::print (SCM smob)
54 {
55   Grob *me = unsmob_grob (smob);
56   if (!scm_ilength (me->get_property ("note-columns")))
57     {
58       me->suicide ();
59       return SCM_EOL;
60     }
61
62   Real base_thick = robust_scm2double (me->get_property ("thickness"), 1);
63   Real thick = base_thick * Staff_symbol_referencer::line_thickness (me);
64
65   Real ss = Staff_symbol_referencer::staff_space (me);
66   Bezier one = get_curve (me);
67
68   Stencil a;
69
70   /*
71     TODO: replace dashed with generic property.
72   */
73   SCM d =  me->get_property ("dashed");
74   if (scm_is_number (d))
75     a = Lookup::dashed_slur (one, thick, thick * robust_scm2double (d, 0));
76   else
77     a = Lookup::slur (one, get_grob_direction (me) * base_thick * ss / 10.0,
78                       thick);
79
80 #if DEBUG_SLUR_QUANTING
81   SCM quant_score = me->get_property ("quant-score");
82
83   if (to_boolean (me->get_paper ()
84                   ->lookup_variable (ly_symbol2scm ("debug-slur-scoring")))
85       && scm_is_string (quant_score))
86     {
87       String str;
88       SCM properties = Font_interface::text_font_alist_chain (me);
89
90       Stencil tm = *unsmob_stencil (Text_item::interpret_markup
91                                     (me->get_paper ()->self_scm (), properties,
92                                      quant_score));
93       a.add_at_edge (Y_AXIS, get_grob_direction (me), tm, 1.0, 0);
94     }
95 #endif
96
97   return a.smobbed_copy ();
98 }
99
100
101 Bezier
102 Slur::get_curve (Grob*me)
103 {
104   Bezier b;
105   int i = 0;
106   for (SCM s = me->get_property ("control-points"); s != SCM_EOL;
107        s = ly_cdr (s))
108     b.control_[i++] = ly_scm2offset (ly_car (s));
109
110   return b;
111 }
112
113 void
114 Slur::add_column (Grob*me, Grob*n)
115 {
116   Pointer_group_interface::add_grob (me, ly_symbol2scm ("note-columns"), n);
117   add_bound_item (dynamic_cast<Spanner*> (me), dynamic_cast<Item*> (n));
118 }
119
120
121 void
122 Slur::add_extra_encompass (Grob*me, Grob*n)
123 {
124   Pointer_group_interface::add_grob (me, ly_symbol2scm ("encompass-objects"), n);
125 }
126
127
128
129 MAKE_SCHEME_CALLBACK (Slur, outside_slur_callback, 2);
130 SCM
131 Slur::outside_slur_callback (SCM grob, SCM axis)
132 {
133   Grob *script = unsmob_grob (grob);
134   Axis a = Axis (scm_to_int (axis));
135   assert (a == Y_AXIS);
136
137   Grob *slur = unsmob_grob (script->get_property ("slur"));
138
139   if (!slur)
140     return scm_from_int (0);
141   
142   Grob *cx = script->common_refpoint (slur, X_AXIS);
143   Grob *cy = script->common_refpoint (slur, Y_AXIS);
144
145   Bezier curve = Slur::get_curve (slur);
146
147   curve.translate (Offset (slur->relative_coordinate (cx, X_AXIS),
148                            slur->relative_coordinate (cy, Y_AXIS)));
149
150   Interval yext = robust_relative_extent (script, cy, Y_AXIS);
151   Interval xext = robust_relative_extent (script, cx, X_AXIS);
152
153
154   Real slur_padding = 0.2;      // todo: slur property, script property?
155   yext.widen (slur_padding);
156   
157   Interval bezext (curve.control_[0][X_AXIS],
158                    curve.control_[3][X_AXIS]);
159
160   Real x = xext.center ();
161   if (bezext.contains (x))
162     ;
163   else if (!bezext.contains (xext[RIGHT]))
164     x = xext[LEFT];
165   else if (!bezext.contains (xext[LEFT]))
166     x = xext[RIGHT];
167
168   
169   if (!bezext.contains (x))
170     return scm_make_real (0);
171
172   Real y = curve.get_other_coordinate (X_AXIS, x);
173   if (yext.contains (y)) 
174     {
175       Direction dir = get_grob_direction (script); 
176       return scm_make_real (y - yext[-dir] + dir * slur_padding);
177     }
178   return scm_make_real (0.0);
179 }
180
181
182 ADD_INTERFACE (Slur, "slur-interface",
183                "A slur",
184                "quant-score excentricity encompass-objects control-points dashed slur-details direction height-limit note-columns ratio thickness");
185