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