Only create a Curve for an AutomationList if we need it.
authorDavid Robillard <d@drobilla.net>
Thu, 19 Feb 2009 19:42:25 +0000 (19:42 +0000)
committerDavid Robillard <d@drobilla.net>
Thu, 19 Feb 2009 19:42:25 +0000 (19:42 +0000)
Fix crash on crossfade editor show (ticket 2442).

git-svn-id: svn://localhost/ardour2/branches/3.0@4641 d708f5d6-7413-0410-9779-e7cbd77b26cf

13 files changed:
gtk2_ardour/audio_region_view.cc
gtk2_ardour/crossfade_edit.cc
gtk2_ardour/crossfade_edit.h
libs/ardour/ardour/automation_list.h
libs/ardour/ardour/session.h
libs/ardour/audio_track.cc
libs/ardour/audioregion.cc
libs/ardour/automation_list.cc
libs/ardour/panner.cc
libs/ardour/route.cc
libs/ardour/session_command.cc
libs/evoral/evoral/ControlList.hpp
libs/evoral/src/ControlList.cpp

index 4ec3531000ba9754f9705a8ca5a8e5509127877c..6af8496e9bc825a906e2086a128eab4cb2722c47 100644 (file)
@@ -33,6 +33,8 @@
 #include <pbd/memento_command.h>
 #include <pbd/stacktrace.h>
 
+#include <evoral/Curve.hpp>
+
 #include "streamview.h"
 #include "audio_region_view.h"
 #include "audio_time_axis.h"
index eb5cb2fba96879ac1838709a1002f1fa9d67106f..f6a0d7e1f71b128bed17fe2d2e7f7667d330fef9 100644 (file)
@@ -66,10 +66,9 @@ CrossfadeEditor::Presets* CrossfadeEditor::fade_in_presets = 0;
 CrossfadeEditor::Presets* CrossfadeEditor::fade_out_presets = 0;
 
 CrossfadeEditor::Half::Half ()
-       : line (0), 
-         //normative_curve (Evoral::Parameter(GainAutomation, 0.0, 1.0, 1.0)), // FIXME: GainAutomation?
-         normative_curve (Evoral::Parameter(GainAutomation)),
-         gain_curve (Evoral::Parameter(GainAutomation))
+       : line (0)
+       , normative_curve (Evoral::Parameter(GainAutomation))
+       , gain_curve (Evoral::Parameter(GainAutomation))
 {
 }
 
@@ -726,7 +725,7 @@ CrossfadeEditor::redraw ()
        fade[current].shading->property_points() = spts;
 
        for (vector<ArdourCanvas::WaveView*>::iterator i = fade[current].waves.begin(); i != fade[current].waves.end(); ++i) {
-               (*i)->property_gain_src() = &fade[current].gain_curve;
+               (*i)->property_gain_src() = static_cast<Evoral::Curve*>(&fade[current].gain_curve.curve());
        }
 }
 
@@ -1124,7 +1123,7 @@ CrossfadeEditor::make_waves (boost::shared_ptr<AudioRegion> region, WhichFade wh
                        waveview->property_sourcefile_length_function() = (void*) sourcefile_length_from_c;
                        waveview->property_peak_function() = (void*) region_read_peaks_from_c;
                        waveview->property_gain_function() = (void*) curve_get_vector_from_c;
-                       waveview->property_gain_src() = &fade[which].gain_curve;
+                       waveview->property_gain_src() = static_cast<Evoral::Curve*>(&fade[which].gain_curve.curve());
                        waveview->property_x() = canvas_border;
                        waveview->property_y() = yoff;
                        waveview->property_height() = ht;
index f7f607393f5a62c56623ee46fc9d1bb5d0b5de47..685dc43772da2719c557dcf0bdaa530b503b9f49 100644 (file)
@@ -96,8 +96,7 @@ class CrossfadeEditor : public ArdourDialog
            void move_to (double x, double y, double xfract, double yfract);
        };
        
-       struct PointSorter 
-       {
+       struct PointSorter {
            bool operator() (const CrossfadeEditor::Point* a, const CrossfadeEditor::Point *b) {
                    return a->x < b->x;
            }
index 923967448cf572b18035f7c79edd1fdca9233472..7ede9f019adebd26839bdee2bb5da3540ce9eabc 100644 (file)
@@ -85,6 +85,7 @@ class AutomationList : public PBD::StatefulDestructible, public Evoral::ControlL
        XMLNode& serialize_events ();
 
   private:
+       void create_curve_if_necessary ();
        int deserialize_events (const XMLNode&);
        
        void maybe_signal_changed ();
index 23155c7ab1784d6f5c27d8c00b2550a03e2b0fdd..b42699d9643aca4f66230deea2cb75efdd0e0381 100644 (file)
@@ -703,7 +703,6 @@ class Session : public PBD::StatefulDestructible, public boost::noncopyable
        sigc::signal<void> NamedSelectionRemoved;
 
        /* Curves and AutomationLists (TODO when they go away) */
-       void add_curve(Evoral::Curve*);
        void add_automation_list(AutomationList*);
 
        /* fade curves */
index 104815b9dce81199fafebdf52293031124aa5c10..df648bc05568f6b59a6cb8c61d484f61672a85f2 100644 (file)
@@ -24,6 +24,8 @@
 #include <pbd/error.h>
 #include <pbd/enumwriter.h>
 
+#include <evoral/Curve.hpp>
+
 #include <ardour/audio_track.h>
 #include <ardour/audio_diskstream.h>
 #include <ardour/session.h>
index 1559827b42bf2a55c9e054f069223e5a99cc4d96..e48f2ae586cd84813f8b83528339eb4331e56cdf 100644 (file)
@@ -35,6 +35,8 @@
 #include <pbd/enumwriter.h>
 #include <pbd/convert.h>
 
+#include <evoral/Curve.hpp>
+
 #include <ardour/audioregion.h>
 #include <ardour/session.h>
 #include <ardour/gain.h>
index 0066e71c3cae9d62c7e88fceb76ef7c9880f9b1e..7493df26ac30c47b70e17a9ede49cff3c7d083c5 100644 (file)
@@ -50,7 +50,6 @@ static void dumpit (const AutomationList& al, string prefix = "")
 }
 #endif
 
-/* XXX: min_val max_val redundant? (param.min() param.max()) */
 AutomationList::AutomationList (Evoral::Parameter id)
        : ControlList(id)
 {
@@ -58,6 +57,8 @@ AutomationList::AutomationList (Evoral::Parameter id)
        _style = Absolute;
        _touching = false;
 
+       create_curve_if_necessary();
+
        assert(_parameter.type() != NullAutomation);
        AutomationListCreated(this);
 }
@@ -69,6 +70,8 @@ AutomationList::AutomationList (const AutomationList& other)
        _state = other._state;
        _touching = other._touching;
        
+       create_curve_if_necessary();
+       
        assert(_parameter.type() != NullAutomation);
        AutomationListCreated(this);
 }
@@ -79,6 +82,8 @@ AutomationList::AutomationList (const AutomationList& other, double start, doubl
        _style = other._style;
        _state = other._state;
        _touching = other._touching;
+       
+       create_curve_if_necessary();
 
        assert(_parameter.type() != NullAutomation);
        AutomationListCreated(this);
@@ -96,8 +101,11 @@ AutomationList::AutomationList (const XMLNode& node, Evoral::Parameter id)
        
        set_state (node);
 
-       if (id)
+       if (id) {
                _parameter = id;
+       }
+       
+       create_curve_if_necessary();
 
        assert(_parameter.type() != NullAutomation);
        AutomationListCreated(this);
@@ -114,6 +122,22 @@ AutomationList::create(Evoral::Parameter id)
        return boost::shared_ptr<Evoral::ControlList>(new AutomationList(id));
 }
 
+void
+AutomationList::create_curve_if_necessary()
+{
+       switch (_parameter.type()) {
+       case GainAutomation:
+       case PanAutomation:
+       case FadeInAutomation:
+       case FadeOutAutomation:
+       case EnvelopeAutomation:
+               create_curve();
+               break;
+       default:
+               break;
+       }
+}
+
 bool
 AutomationList::operator== (const AutomationList& other)
 {
index b7dfd7906859962a1966514675327fb30e95718c..0bd40d9e459dfcd81ed74914e8dffc43505e337d 100644 (file)
@@ -37,6 +37,8 @@
 #include <pbd/xml++.h>
 #include <pbd/enumwriter.h>
 
+#include <evoral/Curve.hpp>
+
 #include <ardour/session.h>
 #include <ardour/panner.h>
 #include <ardour/utils.h>
index ea2a4724959f92ed2e4d0ac5f8048545e2fa4896..a80ceb70ef4dd043cf01ed56245d49fef5dabbab 100644 (file)
@@ -27,6 +27,8 @@
 #include <pbd/stacktrace.h>
 #include <pbd/memento_command.h>
 
+#include <evoral/Curve.hpp>
+
 #include <ardour/timestamps.h>
 #include <ardour/audioengine.h>
 #include <ardour/route.h>
index bb51d51c43965f95ba8217a9c50eac747d0d8d97..bedbe7211ff62c11a89d3ae16cf1959f1fb3a3fd 100644 (file)
@@ -35,6 +35,7 @@
 #include <pbd/id.h>
 #include <pbd/statefuldestructible.h>
 #include <pbd/failed_constructor.h>
+#include <evoral/Curve.hpp>
 
 using namespace PBD;
 using namespace ARDOUR;
index 70488b60be6e1ade383d6e9038875ccc34d7bc46..c9f791ec17be0e7457e9bf96f481e7d9ad7b80d7 100644 (file)
 #include <glibmm/thread.h>
 #include "evoral/types.hpp"
 #include "evoral/Parameter.hpp"
-#include "evoral/Curve.hpp"
 
 namespace Evoral {
 
+class Curve;
 
 /** A single event (time-stamped value) for a control
  */
@@ -216,8 +216,11 @@ public:
        bool rt_safe_earliest_event (double start, double end, double& x, double& y, bool start_inclusive=false) const;
        bool rt_safe_earliest_event_unlocked (double start, double end, double& x, double& y, bool start_inclusive=false) const;
 
-       Curve&       curve()       { return *_curve; }
-       const Curve& curve() const { return *_curve; }
+       void create_curve();
+       void destroy_curve();
+
+       Curve&       curve()       { assert(_curve); return *_curve; }
+       const Curve& curve() const { assert(_curve); return *_curve; }
        
        virtual void mark_dirty () const;
 
index 0677c622ee0e7fe84c8256864938b7e4f01a6e84..dee024214304e6d56baaa6b2b2cd211fddd19dda 100644 (file)
@@ -21,6 +21,7 @@
 #include <utility>
 #include <iostream>
 #include "evoral/ControlList.hpp"
+#include "evoral/Curve.hpp"
 
 using namespace std;
 
@@ -36,7 +37,7 @@ inline bool event_time_less_than (ControlEvent* a, ControlEvent* b)
 ControlList::ControlList (const Parameter& id)
        : _parameter(id)
        , _interpolation(Linear)
-       , _curve(new Curve(*this))
+       , _curve(0)
 {      
        _frozen = 0;
        _changed_when_thawed = false;
@@ -54,7 +55,7 @@ ControlList::ControlList (const Parameter& id)
 ControlList::ControlList (const ControlList& other)
        : _parameter(other._parameter)
        , _interpolation(Linear)
-       , _curve(new Curve(*this))
+       , _curve(0)
 {
        _frozen = 0;
        _changed_when_thawed = false;
@@ -70,14 +71,14 @@ ControlList::ControlList (const ControlList& other)
        for (const_iterator i = other._events.begin(); i != other._events.end(); ++i) {
                _events.push_back (new ControlEvent (**i));
        }
-
+       
        mark_dirty ();
 }
 
 ControlList::ControlList (const ControlList& other, double start, double end)
        : _parameter(other._parameter)
        , _interpolation(Linear)
-       , _curve(new Curve(*this))
+       , _curve(0)
 {
        _frozen = 0;
        _changed_when_thawed = false;
@@ -99,7 +100,7 @@ ControlList::ControlList (const ControlList& other, double start, double end)
                        _events.push_back (new ControlEvent ((*i)->when, (*i)->value));
                }
        }
-
+       
        mark_dirty ();
 }
 
@@ -147,6 +148,19 @@ ControlList::operator= (const ControlList& other)
        return *this;
 }
 
+void
+ControlList::create_curve()
+{
+       _curve = new Curve(*this);
+}
+
+void
+ControlList::destroy_curve()
+{
+       delete _curve;
+       _curve = NULL;
+}
+
 void
 ControlList::maybe_signal_changed ()
 {