]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-1.3.65
authorfred <fred>
Tue, 26 Mar 2002 23:23:44 +0000 (23:23 +0000)
committerfred <fred>
Tue, 26 Mar 2002 23:23:44 +0000 (23:23 +0000)
flower/direction.cc [new file with mode: 0644]
lily/include/slur-bezier-bow.hh [new file with mode: 0644]
lily/include/slur.hh
lily/slur-bezier-bow.cc [new file with mode: 0644]
ly/declarations.ly

diff --git a/flower/direction.cc b/flower/direction.cc
new file mode 100644 (file)
index 0000000..aeddc31
--- /dev/null
@@ -0,0 +1,25 @@
+/*   
+  direction.cc --  implement Direction
+  
+  source file of the GNU LilyPond music typesetter
+  
+  (c) 1998--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  
+ */
+
+#include "direction.hh"
+
+String
+direction_str (Direction d, Axis a)
+{
+  String s("center");
+  if (a == Y_AXIS)
+    {
+       s =( d == UP ? "up" : "down");
+    }
+  else if (a == X_AXIS)
+    {
+      s = (d == LEFT ? "left" : "right" );
+    }
+  return s;
+}
diff --git a/lily/include/slur-bezier-bow.hh b/lily/include/slur-bezier-bow.hh
new file mode 100644 (file)
index 0000000..7fbbffd
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+  slur-bezier-bow.hh -- declare Slur_bezier_bow
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 2000  Jan Nieuwenhuizen <janneke@gnu.org>
+*/
+
+#ifndef SLUR_BEZIER_BOW_HH
+#define SLUR_BEZIER_BOW_HH
+
+#include "bezier-bow.hh"
+
+class Slur_bezier_bow : public Bezier_bow
+{
+public:
+  Slur_bezier_bow (Array<Offset> encompass, Direction dir);
+  Array<Real> area_x_gradients_array (Real area);
+  void blow_fit ();
+  Real enclosed_area_f () const;
+  Real fit_factor () const;
+  void minimise_enclosed_area (Paper_def* paper_l, Real default_height);
+};
+#endif /* SLUR_BEZIER_BOW_HH */
index 654bc45685dec606e24036afc8f73c3d4db4ca50..80b18fbfc7569a1100ad96951262969011140aec 100644 (file)
@@ -26,17 +26,12 @@ public:
   virtual Array<Offset> get_encompass_offset_arr () const;
   Bezier get_curve () const;
 
-  /*
-    JUNKME
-   */
-  Drul_array<Real> dy_f_drul_;
-  Drul_array<Real> dx_f_drul_;
-
   virtual Direction get_default_dir () const;
   SCM member_after_line_breaking ();
   static SCM after_line_breaking (SCM);
   virtual void do_add_processing ();
   Array<Rod> get_rods () const;
+  Offset get_attachment (Direction dir) const;
 
 private:  
   void de_uglyfy (Slur_bezier_bow* bb, Real default_height);
diff --git a/lily/slur-bezier-bow.cc b/lily/slur-bezier-bow.cc
new file mode 100644 (file)
index 0000000..0dc7ba2
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+  slur-bezier-bow.cc -- implement Slur_bezier_bow
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 2000  Jan Nieuwenhuizen <janneke@gnu.org>
+*/
+
+#include "debug.hh"
+#include "paper-def.hh"
+#include "slur-bezier-bow.hh"
+#include "main.hh"
+
+Slur_bezier_bow::Slur_bezier_bow (Array<Offset> encompass, Direction dir)
+  : Bezier_bow (encompass, dir)
+{
+}
+
+void
+Slur_bezier_bow::blow_fit ()
+{
+  Real len = curve_.control_[3][X_AXIS]; 
+  Real h = curve_.control_[1][Y_AXIS] * fit_factor () / len;
+  curve_.control_[1][Y_AXIS] = h * len;
+  curve_.control_[2][Y_AXIS] = h * len;  
+  curve_.assert_sanity ();
+}
+
+
+Real
+Slur_bezier_bow::enclosed_area_f () const
+{
+  Real a = 0;
+  for (int i=0; i < encompass_.size (); i++)
+    {
+      Interval x;
+      Interval y;
+      if (i == 0)
+       {
+         x = Interval (0, encompass_[1][X_AXIS] / 2);
+         y = Interval (0,
+                       curve_.get_other_coordinate (X_AXIS,
+                                                    encompass_[1][X_AXIS]
+                                                    / 2));
+       }
+      else if (i == encompass_.size () - 1)
+       {
+         x = Interval ((encompass_[i-1][X_AXIS] + encompass_[i][X_AXIS])/2, 
+                       encompass_[i][X_AXIS]);
+         y = Interval (0,
+                       (curve_.get_other_coordinate (X_AXIS,
+                                                     (x[MIN] + x[MAX]) / 2)));
+       }
+      else
+       {
+         x = Interval ((encompass_[i-1][X_AXIS] + encompass_[i][X_AXIS]) / 2, 
+                       (encompass_[i][X_AXIS] + encompass_[i+1][X_AXIS]) / 2);
+         y = Interval (encompass_[i][Y_AXIS],
+                       (curve_.get_other_coordinate (X_AXIS, x[MIN])
+                        + curve_.get_other_coordinate (X_AXIS,
+                                                       (x[MIN] + x[MAX]) / 2)
+                        + curve_.get_other_coordinate (X_AXIS, x[MAX])) / 3);
+       }
+      
+      Real da = x.length () * y.length ();
+      a += da;
+    }
+  return a;
+}
+
+Array<Real>
+Slur_bezier_bow::area_x_gradients_array (Real area)
+{
+  Real len = curve_.control_[3][X_AXIS]; 
+  Real grow = len / 10.0;
+  Array<Real> da (2);
+  for (int i=0; i < 2; i++)
+    {
+      Real r = curve_.control_[i+1][X_AXIS];
+      curve_.control_[i+1][X_AXIS] += grow;
+      da[i] = (enclosed_area_f () - area) / grow;
+      curve_.control_[i+1][X_AXIS] = r; 
+    }
+  return da;
+}
+
+void
+Slur_bezier_bow::minimise_enclosed_area (Paper_def* paper_l,
+                                        Real default_height)
+{
+  Real length = curve_.control_[3][X_AXIS]; 
+  Real sb = paper_l->get_var ("slur_beautiful");
+  Real beautiful = length * default_height * sb;
+
+  DEBUG_OUT << to_str ("Beautiful: %f\n", beautiful);
+  DEBUG_OUT << to_str ("Length: %f\n", length);
+  DEBUG_OUT << to_str ("D-height: %f\n", default_height);
+  DEBUG_OUT << to_str ("FitFac: %f\n", fit_factor ());
+
+  if (fit_factor () > 1.0)
+    blow_fit ();
+  
+  Real pct_c0 = paper_l->get_var ("bezier_pct_c0");
+  Real pct_c3 = paper_l->get_var ("bezier_pct_c3");
+  Real pct_in_max = paper_l->get_var ("bezier_pct_in_max");
+  Real pct_out_max = paper_l->get_var ("bezier_pct_out_max");
+  Real steps = paper_l->get_var ("bezier_area_steps");
+
+  for (int i=0; i < steps; i++)
+    {
+      Real area = enclosed_area_f ();
+      if (!i)
+       DEBUG_OUT << to_str ("Init area: %f\n", area);
+
+      if (area <= beautiful)
+       break;
+
+      Array<Real> da = area_x_gradients_array (area);
+
+      // urg
+      Real pct = pct_c0 + pct_c3 * length * length * length;
+      pct *= (steps - i) / steps;
+      if (da[0] > 0 || da[1] < 0)
+       pct = pct <? pct_out_max;
+      else
+       pct = pct <? pct_in_max;
+
+      Real u = (abs (curve_.control_[1][X_AXIS] / da[0])
+               <? abs ((curve_.control_[3][X_AXIS]
+                        - curve_.control_[2][X_AXIS]) / da[1]));
+
+      DEBUG_OUT << to_str ("pct: %f\n", pct);
+      DEBUG_OUT << to_str ("u: %f\n", u);
+
+      DEBUG_OUT << to_str ("da: (%f, %f)\n", da[0], da[1]);
+      DEBUG_OUT << to_str ("da*u: (%f, %f)\n", da[0]*u*pct, da[1]*u*pct);
+      DEBUG_OUT << to_str ("cx: (%f, %f)\n", curve_.control_[1][X_AXIS],
+                          curve_.control_[2][X_AXIS]);
+
+      curve_.control_[1][X_AXIS] -= da[0] * u * pct;
+      curve_.control_[2][X_AXIS] -= da[1] * u * pct;
+    }
+
+  Real area = enclosed_area_f ();
+  DEBUG_OUT << to_str ("Exarea: %f\n", area);
+}
+
+
+
+/*
+  max ( encompass.y / curve.y )
+  
+ */
+Real
+Slur_bezier_bow::fit_factor () const
+{
+  Real x1 = encompass_[0][X_AXIS];
+  Real x2 = encompass_.top ()[X_AXIS];
+
+  Real factor = 0.0;
+  for (int i=1; i < encompass_.size ()-1; i++)
+    {
+      if (encompass_[i][X_AXIS] > x1 && encompass_[i][X_AXIS] < x2)
+       {
+        Real y = curve_.get_other_coordinate (X_AXIS, encompass_[i][X_AXIS]);
+        if (y>0)
+          {
+            Real f = encompass_[i][Y_AXIS] / y;
+            factor = factor >? f;
+          }
+       }
+    }
+
+
+  return factor;
+}
+
+
+
+
index e6f16c153990b2bd36921c4a15db6494995cf6af..ec640fb578d0d2522df10b4bb185498f3f447ef1 100644 (file)
@@ -6,6 +6,9 @@ maxima = \duration #'( -3 0 )
 
 #(eval-string (ly-gulp-file "generic-property.scm"))
 
+% urg, move to basic property?
+#(eval-string (ly-gulp-file "slur.scm"))
+
 \include "nederlands.ly"               % dutch
 \include "chord-modifiers.ly"
 \include "script.ly"