assert() to help find some possible causes of #2991. Fix some confusion with GTK...
[ardour.git] / libs / ardour / ardour / crossfade.h
index 946d35b8e02d18cdbc64f279f025e1ee8791f368..5e25bbe00db436a2cdb356909f6b095bf77593ef 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2000 Paul Davis 
+    Copyright (C) 2000 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -15,7 +15,6 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 */
 
 #ifndef __ardour_overlap_h__
 #include <vector>
 #include <algorithm>
 #include <boost/shared_ptr.hpp>
-#include <boost/enable_shared_from_this.hpp>
 
-#include <sigc++/signal.h>
 
-#include <pbd/undo.h>
-#include <pbd/statefuldestructible.h> 
+#include "pbd/undo.h"
+#include "pbd/statefuldestructible.h"
 
-#include <ardour/ardour.h>
-#include <ardour/curve.h>
-#include <ardour/audioregion.h>
-#include <ardour/crossfade_compare.h>
+#include "ardour/ardour.h"
+#include "ardour/audioregion.h"
+#include "ardour/crossfade_compare.h"
+#include "evoral/Curve.hpp"
 
 namespace ARDOUR {
 
 class AudioRegion;
 class Playlist;
 
-class Crossfade : public PBD::StatefulDestructible, public boost::enable_shared_from_this<ARDOUR::Crossfade>
+class Crossfade : public ARDOUR::AudioRegion
 {
   public:
 
        class NoCrossfadeHere: std::exception {
-         public:
+       public:
                virtual const char *what() const throw() { return "no crossfade should be constructed here"; }
        };
-       
+
        /* constructor for "fixed" xfades at each end of an internal overlap */
 
        Crossfade (boost::shared_ptr<ARDOUR::AudioRegion> in, boost::shared_ptr<ARDOUR::AudioRegion> out,
-                  nframes_t position,
-                  nframes_t initial_length,
-                  AnchorPoint);
+                       nframes_t position,
+                       nframes_t initial_length,
+                       AnchorPoint);
 
        /* constructor for xfade between two regions that are overlapped in any way
           except the "internal" case.
        */
-       
+
        Crossfade (boost::shared_ptr<ARDOUR::AudioRegion> in, boost::shared_ptr<ARDOUR::AudioRegion> out, CrossfadeModel, bool active);
 
 
        /* copy constructor to copy a crossfade with new regions. used (for example)
-          when a playlist copy is made 
+          when a playlist copy is made
        */
-       Crossfade (const Crossfade &, boost::shared_ptr<ARDOUR::AudioRegion>, boost::shared_ptr<ARDOUR::AudioRegion>);
-       
+       Crossfade (boost::shared_ptr<Crossfade>, boost::shared_ptr<ARDOUR::AudioRegion>, boost::shared_ptr<ARDOUR::AudioRegion>);
+
        /* the usual XML constructor */
 
        Crossfade (const Playlist&, XMLNode&);
@@ -77,17 +74,17 @@ class Crossfade : public PBD::StatefulDestructible, public boost::enable_shared_
        bool operator== (const ARDOUR::Crossfade&);
 
        XMLNode& get_state (void);
-       int set_state (const XMLNode&);
+       int set_state (const XMLNode&, int version);
 
        boost::shared_ptr<ARDOUR::AudioRegion> in() const { return _in; }
        boost::shared_ptr<ARDOUR::AudioRegion> out() const { return _out; }
-       
-       nframes_t read_at (Sample *buf, Sample *mixdown_buffer, 
-                               float *gain_buffer, nframes_t position, nframes_t cnt, 
-                               uint32_t chan_n,
-                               nframes_t read_frames = 0,
-                               nframes_t skip_frames = 0);
-       
+
+       nframes_t read_at (Sample *buf, Sample *mixdown_buffer,
+                       float *gain_buffer, sframes_t position, nframes_t cnt,
+                       uint32_t chan_n,
+                       nframes_t read_frames = 0,
+                       nframes_t skip_frames = 0) const;
+
        bool refresh ();
 
        uint32_t upper_layer () const {
@@ -106,14 +103,10 @@ class Crossfade : public PBD::StatefulDestructible, public boost::enable_shared_
                return (_in == a && _out == b) || (_in == b && _out == a);
        }
 
-       nframes_t length() const { return _length; }
        nframes_t overlap_length() const;
-       nframes_t position() const { return _position; }
-
-       void invalidate();
 
-       sigc::signal<void,boost::shared_ptr<Crossfade> > Invalidated;
-       sigc::signal<void,Change>     StateChanged;
+       PBD::Signal1<void,boost::shared_ptr<Region> > Invalidated;
+       PBD::Signal1<void,Change>     StateChanged;
 
        bool covers (nframes_t frame) const {
                return _position <= frame && frame < _position + _length;
@@ -130,11 +123,16 @@ class Crossfade : public PBD::StatefulDestructible, public boost::enable_shared_
        bool can_follow_overlap() const;
        void set_follow_overlap (bool yn);
 
-       Curve& fade_in() { return _fade_in; } 
-       Curve& fade_out() { return _fade_out; }
+       AutomationList& fade_in() { return _fade_in; }
+       AutomationList& fade_out() { return _fade_out; }
+
+       nframes_t set_xfade_length (nframes_t);
+
+       bool is_dependent() const { return true; }
+       bool depends_on (boost::shared_ptr<Region> other) const {
+               return other == _in || other == _out;
+       }
 
-       nframes_t set_length (nframes_t);
-       
        static nframes_t short_xfade_length() { return _short_xfade_length; }
        static void set_short_xfade_length (nframes_t n);
 
@@ -152,25 +150,27 @@ class Crossfade : public PBD::StatefulDestructible, public boost::enable_shared_
        bool                 _active;
        bool                 _in_update;
        OverlapType           overlap_type;
-       nframes_t       _length;
-       nframes_t       _position;
        AnchorPoint          _anchor_point;
        bool                 _follow_overlap;
        bool                 _fixed;
-       Curve _fade_in;
-       Curve _fade_out;
+       int32_t               layer_relation;
+
+
+       mutable AutomationList _fade_in;
+       mutable AutomationList _fade_out;
 
        static Sample* crossfade_buffer_out;
        static Sample* crossfade_buffer_in;
 
        void initialize ();
        int  compute (boost::shared_ptr<ARDOUR::AudioRegion>, boost::shared_ptr<ARDOUR::AudioRegion>, CrossfadeModel);
-       bool update (bool force);
+       bool update ();
 
-       void member_changed (ARDOUR::Change);
+  protected:
+       nframes_t read_raw_internal (Sample*, sframes_t, nframes_t, int) const;
 };
 
 
 } // namespace ARDOUR
 
-#endif /* __ardour_overlap_h__ */      
+#endif /* __ardour_overlap_h__ */