source file of the GNU LilyPond music typesetter
- (c) 1998--2000 Jan Nieuwenhuizen <janneke@gnu.org>
+ (c) 1998--2002 Jan Nieuwenhuizen <janneke@gnu.org>
*/
#include <math.h>
+
#include "bezier-bow.hh"
#include "misc.hh"
#include "bezier.hh"
-#include "dimensions.hh"
-#include "direction.hh"
-#include "debug.hh"
-#include "main.hh"
-#include "lily-guile.hh"
-#include "paper-def.hh"
-Bezier_bow::Bezier_bow (Array<Offset> encompass, Direction dir)
+static Real
+F0_1 (Real x)
{
- alpha_ = 0;
- dir_ = dir;
- encompass_ = encompass;
- to_canonical_form ();
+ return 2 / M_PI * atan (M_PI * x / 2);
}
-Bezier
-Bezier_bow::get_bezier () const
+Real
+slur_height (Real width, Real h_inf, Real r_0)
{
- Bezier rv = curve_;
- if (dir_ == DOWN)
- {
- rv.flip (Y_AXIS);
- }
-
- rv.rotate (alpha_);
- rv.translate (origin_);
-
- return rv;
+ return F0_1 (width * r_0 / h_inf) * h_inf;
}
-void
-Bezier_bow::to_canonical_form ()
-{
- origin_ = encompass_[0];
- translate (&encompass_, -origin_);
-
- Offset delta = encompass_.top () - encompass_[0];
- alpha_ = delta.arg ();
-
- rotate (&encompass_, -alpha_);
- if (dir_ == DOWN)
- {
- flip (&encompass_, Y_AXIS);
- }
-
- while (encompass_.size () > 1 && encompass_[1][X_AXIS] <= 0.0)
- {
- programming_error ("Degenerate bow: infinite steepness reqd");
- encompass_.del (1);
- }
-
- Real l = encompass_.top ()[X_AXIS];
- while (encompass_.size () > 1 && encompass_.top (1)[X_AXIS] >= l)
- {
- programming_error ("Degenerate bow: infinite steepness reqd");
- encompass_.del (encompass_.size ()-2);
- }
-}
+ /*
+ For small w, the height should be proportional to w, for w ->
+ infinity, the height should rise to a limit asymptotically.
-void
-Bezier_bow::set_default_bezier (Real h_inf, Real r_0)
-{
- curve_ = get_default_bezier (h_inf, r_0);
-}
+ Hence we take F (x) such that
+ F (0) = 0 , F' (0) = 1, and F (infty) = 1
+
+ and use
+
+ h = h_infinity * F (x * r_0 / h_infinity)
+
+
+ Examples:
+
+ * F (x) = 2/pi * atan (pi x/2)
+
+ * F (x) 1/alpha * x^alpha / (1 + x^alpha)
+
+ * (etc.)
+
+ [with the 2nd recipe you can determine how quickly the conversion from
+ `small' slurs to `big' slurs occurs.]
+
+ Although this might seem cand_idates to SCM-ify, it is not all clear
+ which parameters (ie. h_inf, r_0, F (.)) should be candidates for
+ this. At present h_inf and r_0 come from paper settings, but we did
+ no experiments for determining the best combinations of F, h_inf and
+ r_0.
+
+ */
-/*
- See Documentation/programmer/fonts.doc
- */
Bezier
-Bezier_bow::get_default_bezier (Real h_inf, Real r_0) const
+slur_shape (Real width, Real h_inf, Real r_0)
{
- Offset delta (encompass_.top ()[X_AXIS] - encompass_[0][X_AXIS], 0);
- Real b = delta.length ();
- Real height = get_default_height (h_inf, r_0, b);
- // urg: scmify this?
+ Bezier curve;
+ Real height = slur_height (width, h_inf, r_0);
Real indent = height;
- Bezier curve;
curve.control_[0] = Offset (0, 0);
curve.control_[1] = Offset (indent, height);
- curve.control_[2] = Offset (b - indent, height);
- curve.control_[3] = Offset (b, 0);
+ curve.control_[2] = Offset (width - indent, height);
+ curve.control_[3] = Offset (width, 0);
return curve;
}
-/*
- See Documentation/programmer/fonts.doc
- */
-Real
-Bezier_bow::get_default_height (Real h_inf, Real r_0, Real b) const
-{
-#if 0
- Real pi = M_PI;
-
- Real alpha = 2.0 * h_inf / pi;
- Real beta = pi * r_0 / (2.0 * h_inf);
-
- return alpha * atan (beta * b);
-#else
- SCM h = scm_eval (scm_listify (ly_symbol2scm ("slur-default-height"),
- gh_double2scm (h_inf),
- gh_double2scm (r_0),
- gh_double2scm (b),
- SCM_UNDEFINED));
- return gh_scm2double (h);
-#endif
-}
-