various fixes to named selection mgmt and display, plus fixes for xfade mgmt and...
[ardour.git] / libs / ardour / crossfade.cc
index 739ea1cc0e5cc89654c1bd99fefefd6ddad0e733..69f3cb32c1d577954b1c87a3a02a75c97eb55660 100644 (file)
@@ -20,6 +20,8 @@
 
 #include <sigc++/bind.h>
 
+#include <pbd/stacktrace.h>
+
 #include <ardour/types.h>
 #include <ardour/crossfade.h>
 #include <ardour/crossfade_compare.h>
@@ -80,17 +82,14 @@ Crossfade::Crossfade (boost::shared_ptr<AudioRegion> in, boost::shared_ptr<Audio
 {
        _in = in;
        _out = out;
+       
        _length = length;
        _position = position;
        _anchor_point = ap;
 
-       switch (Config->get_xfade_model()) {
-       case ShortCrossfade:
-               _follow_overlap = false;
-               break;
-       default:
-               _follow_overlap = true;
-       }
+       _follow_overlap = false;
+
+       cerr << "A: follow overlap = " << _follow_overlap << endl;
 
        _active = Config->get_xfades_active ();
        _fixed = true;
@@ -113,6 +112,7 @@ Crossfade::Crossfade (boost::shared_ptr<AudioRegion> a, boost::shared_ptr<AudioR
 
        initialize ();
 
+       cerr << "K: follow overlap = " << _follow_overlap << endl;
 }
 
 Crossfade::Crossfade (const Playlist& playlist, XMLNode& node)
@@ -160,11 +160,16 @@ Crossfade::Crossfade (const Playlist& playlist, XMLNode& node)
        }
 
        _length = 0;
+       _active = Config->get_xfades_active();
+
        initialize();
        
        if (set_state (node)) {
                throw failed_constructor();
        }
+
+       cerr << "D: follow overlap = " << _follow_overlap << endl;
+
 }
 
 Crossfade::Crossfade (const Crossfade &orig, boost::shared_ptr<AudioRegion> newin, boost::shared_ptr<AudioRegion> newout)
@@ -192,14 +197,16 @@ Crossfade::Crossfade (const Crossfade &orig, boost::shared_ptr<AudioRegion> newi
 
        // Let's make sure the fade isn't too long
        set_length(_length);
+
+       cerr << "B: follow overlap = " << _follow_overlap << endl;
+
 }
 
 
 Crossfade::~Crossfade ()
 {
-       cerr << "Deleting xfade @ " << this << endl;
-       Invalidated (this);
-       cerr << "invalidation signal sent\n";
+       cerr << this << " Crossfade deleted\n";
+       notify_callbacks ();
 }
 
 void
@@ -256,7 +263,7 @@ Crossfade::compute (boost::shared_ptr<AudioRegion> a, boost::shared_ptr<AudioReg
        /* first check for matching ends */
        
        if (top->first_frame() == bottom->first_frame()) {
-               
+
                /* Both regions start at the same point */
                
                if (top->last_frame() < bottom->last_frame()) {
@@ -357,15 +364,16 @@ Crossfade::compute (boost::shared_ptr<AudioRegion> a, boost::shared_ptr<AudioReg
 
                        _in = bottom;
                        _out = top;
-                       _position = bottom->first_frame();
                        _anchor_point = StartOfIn;
 
                        if (model == FullCrossfade) {
+                               _position = bottom->first_frame(); // "{"
                                _length = _out->first_frame() + _out->length() - _in->first_frame();
                                /* leave active alone */
                                _follow_overlap = true;
                        } else {
                                _length = min (short_xfade_length, top->length());
+                               _position = top->last_frame() - _length;  // "]" - length 
                                _active = true;
                                _follow_overlap = false;
                                
@@ -499,30 +507,27 @@ Crossfade::refresh ()
        /* crossfades must be between non-muted regions */
        
        if (_out->muted() || _in->muted()) {
-               Invalidated (this);
+               Invalidated (shared_from_this());
                return false;
        }
 
+//     if (_in->layer() < _out->layer()) {
+//             cerr << this << " layer change, invalidated, in on " << _in->layer() << " out on " << _out->layer() << endl;
+//             Invalidated (shared_from_this());
+//             return false;
+//     }
+
        /* overlap type must be Start, End or External */
 
        OverlapType ot;
        
        ot = _in->coverage (_out->first_frame(), _out->last_frame());
-       
-       switch (ot) {
-       case OverlapNone:
-       case OverlapInternal:
-               Invalidated (this);
-               return false;
-               
-       default:
-               break;
-       }
-               
+
        /* overlap type must not have altered */
        
        if (ot != overlap_type) {
-               Invalidated (this);
+               cerr << this << " Invalid B\n";
+               Invalidated (shared_from_this());
                return false;
        } 
 
@@ -536,14 +541,18 @@ Crossfade::update (bool force)
 {
        nframes_t newlen;
 
+       cerr << this << " update, " << _in->name() << " + " << _out->name() << " length = " << _length << endl;
+
        if (_follow_overlap) {
                newlen = _out->first_frame() + _out->length() - _in->first_frame();
+               cerr << "\tmodify length\n";
        } else {
                newlen = _length;
        }
 
        if (newlen == 0) {
-               Invalidated (this);
+               cerr << this << " Invalid C\n";
+               Invalidated (shared_from_this());
                return false;
        }
 
@@ -560,23 +569,19 @@ Crossfade::update (bool force)
 
        } 
 
+       cerr << "\tFover = " << _follow_overlap << endl;
+
        switch (_anchor_point) {
        case StartOfIn:
-               if (_position != _in->first_frame()) {
-                       _position = _in->first_frame();
-               }
+               _position = _in->first_frame();
                break;
 
        case EndOfIn:
-               if (_position != _in->last_frame() - _length) {
-                       _position = _in->last_frame() - _length;
-               }
+               _position = _in->last_frame() - _length;
                break;
 
        case EndOfOut:
-               if (_position != _out->last_frame() - _length) {
-                       _position = _out->last_frame() - _length;
-               }
+               _position = _out->last_frame() - _length;
        }
 
        /* UI's may need to know that the overlap changed even 
@@ -759,7 +764,7 @@ Crossfade::set_state (const XMLNode& node)
        
         /* fade out */
        
-       _fade_in.freeze ();
+       _fade_out.freeze ();
        _fade_out.clear ();
 
        children = fo->children();
@@ -865,5 +870,5 @@ Crossfade::set_short_xfade_length (nframes_t n)
 void
 Crossfade::invalidate ()
 {
-       Invalidated (this); /* EMIT SIGNAL */
+       Invalidated (shared_from_this()); /* EMIT SIGNAL */
 }