opaque xfade patch + a version of the editor ruler/playhead/click patch
[ardour.git] / libs / ardour / crossfade.cc
index 337911d3e489eea5cf2f0cb04ab61f37362b046b..e1df8228ce4957d632b8d9b990b4a40f9361cd37 100644 (file)
@@ -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$
 */
 
 #include <sigc++/bind.h>
@@ -227,9 +226,6 @@ Crossfade::initialize ()
        _fade_in.add (_length, 1.0);
        _fade_in.thaw ();
 
-       // _in->StateChanged.connect (sigc::mem_fun (*this, &Crossfade::member_changed));
-       // _out->StateChanged.connect (sigc::mem_fun (*this, &Crossfade::member_changed));
-
        overlap_type = _in->coverage (_out->position(), _out->last_frame());
        layer_relation = (int32_t) (_in->layer() - _out->layer());
 }      
@@ -272,6 +268,13 @@ Crossfade::read_at (Sample *buf, Sample *mixdown_buffer,
 
        offset = start - _position;
 
+       /* Prevent data from piling up inthe crossfade buffers when reading a transparent region */
+       if (!(_out->opaque())) {
+               memset (crossfade_buffer_out, 0, sizeof (Sample) * to_write);
+       } else if (!(_in->opaque())) {
+               memset (crossfade_buffer_in, 0, sizeof (Sample) * to_write);
+       }
+
        _out->read_at (crossfade_buffer_out, mixdown_buffer, gain_buffer, start, to_write, chan_n, read_frames, skip_frames);
        _in->read_at (crossfade_buffer_in, mixdown_buffer, gain_buffer, start, to_write, chan_n, read_frames, skip_frames);
 
@@ -336,6 +339,13 @@ Crossfade::refresh ()
                return false;
        }
 
+       /* Top layer shouldn't be transparent */
+
+       if (!((layer_relation > 0 ? _in : _out)->opaque())) {
+               Invalidated (shared_from_this());
+               return false;
+       }
+
        /* layer ordering cannot change */
 
        int32_t new_layer_relation = (int32_t) (_in->layer() - _out->layer());
@@ -554,7 +564,7 @@ Crossfade::compute (boost::shared_ptr<AudioRegion> a, boost::shared_ptr<AudioReg
 
                        _in = bottom;
                        _out = top;
-                       _anchor_point = StartOfIn;
+                       _anchor_point = EndOfOut;
 
                        if (model == FullCrossfade) {
                                _position = bottom->first_frame(); // "{"
@@ -599,26 +609,6 @@ Crossfade::compute (boost::shared_ptr<AudioRegion> a, boost::shared_ptr<AudioReg
        return 0;
 }
 
-void
-Crossfade::member_changed (Change what_changed)
-{
-       Change what_we_care_about = Change (Region::MuteChanged|
-                                           Region::LayerChanged|
-                                           BoundsChanged);
-
-       if (what_changed & what_we_care_about) {
-               try { 
-                       if (what_changed & what_we_care_about) {
-                               refresh ();
-                       }
-               }
-
-               catch (NoCrossfadeHere& err) {
-                       // relax, Invalidated inside refresh()
-               }
-       }
-}
-
 XMLNode&
 Crossfade::get_state () 
 {