Fix crash on out of range MIDI events (though this shouldn't be possible at all....
[ardour.git] / libs / ardour / curve.cc
index 3aa9de91272c3737758adfb0b9fe1e2e1e701619..dcce3c0c6cd9f938c539f6d5b4f4063538e57846 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2001-2003 Paul Davis 
+    Copyright (C) 2001-2007 Paul Davis 
 
     Contains ideas derived from "Constrained Cubic Spline Interpolation" 
     by CJC Kruger (www.korf.co.uk/spline.pdf).
@@ -41,39 +41,12 @@ using namespace sigc;
 using namespace PBD;
 
 Curve::Curve (const AutomationList& al)
-       : _list (al)
-       , _dirty (true)
+       : _dirty (true)
+       , _list (al)
 {
        _list.Dirty.connect(mem_fun(*this, &Curve::on_list_dirty));
 }
 
-Curve::Curve (const Curve& other)
-       : _list (other._list)
-       , _dirty (true)
-{
-       _list.Dirty.connect(mem_fun(*this, &Curve::on_list_dirty));
-}
-#if 0
-Curve::Curve (const Curve& other, double start, double end)
-       : _list (other._list)
-{
-       _min_yval = other._min_yval;
-       _max_yval = other._max_yval;
-}
-
-/** \a id is used for legacy sessions where the type is not present
- * in or below the <AutomationList> node.  It is used if \a id is non-null.
- */
-Curve::Curve (const XMLNode& node, ParamID id)
-       : AutomationList (node, id)
-{
-}
-#endif
-
-Curve::~Curve ()
-{
-}
-
 void
 Curve::solve ()
 {
@@ -102,7 +75,7 @@ Curve::solve ()
 
                double lp0, lp1, fpone;
 
-               lp0 =(x[1] - x[0])/(y[1] - y[0]);
+               lp0 = (x[1] - x[0])/(y[1] - y[0]);
                lp1 = (x[2] - x[1])/(y[2] - y[1]);
 
                if (lp0*lp1 < 0) {
@@ -188,6 +161,7 @@ Curve::solve ()
 
                        /* store */
 
+                       (*xx)->create_coeffs();
                        (*xx)->coeff[0] = y[i-1] - (b * x[i-1]) - (c * xim12) - (d * xim13);
                        (*xx)->coeff[1] = b;
                        (*xx)->coeff[2] = c;
@@ -374,10 +348,9 @@ Curve::multipoint_eval (double x)
             (lookup_cache.range.first == _list.events().end()) || 
             ((*lookup_cache.range.second)->when < x))) {
                
-               AutomationList::TimeComparator cmp;
                ControlEvent cp (x, 0.0);
 
-               lookup_cache.range = equal_range (_list.events().begin(), _list.events().end(), &cp, cmp);
+               lookup_cache.range = equal_range (_list.events().begin(), _list.events().end(), &cp, AutomationList::time_comparator);
        }
 
        range = lookup_cache.range;