Don't raise an error when trying to auto-connect master to physical outputs if the...
[ardour.git] / libs / ardour / crossfade.cc
index 05ea7765f0a25bf7153b60bc2b13f1befc4a99ea..86d509ec664c9799192ff859563852ace9c16f8e 100644 (file)
 
 #include <sigc++/bind.h>
 
-#include <pbd/stacktrace.h>
+#include "pbd/stacktrace.h"
 
-#include <ardour/types.h>
-#include <ardour/crossfade.h>
-#include <ardour/crossfade_compare.h>
-#include <ardour/audioregion.h>
-#include <ardour/playlist.h>
-#include <ardour/utils.h>
-#include <ardour/session.h>
-#include <ardour/source.h>
+#include "ardour/types.h"
+#include "ardour/crossfade.h"
+#include "ardour/crossfade_compare.h"
+#include "ardour/audioregion.h"
+#include "ardour/playlist.h"
+#include "ardour/utils.h"
+#include "ardour/session.h"
+#include "ardour/source.h"
 
 #include "i18n.h"
 #include <locale.h>
@@ -51,15 +51,11 @@ Sample* Crossfade::crossfade_buffer_in = 0;
 void
 Crossfade::set_buffer_size (nframes_t sz)
 {
-       if (crossfade_buffer_out) {
-               delete [] crossfade_buffer_out;
-               crossfade_buffer_out = 0;
-       }
+       delete [] crossfade_buffer_out;
+       crossfade_buffer_out = 0;
 
-       if (crossfade_buffer_in) {
-               delete [] crossfade_buffer_in;
-               crossfade_buffer_in = 0;
-       }
+       delete [] crossfade_buffer_in;
+       crossfade_buffer_in = 0;
 
        if (sz) {
                crossfade_buffer_out = new Sample[sz];
@@ -87,7 +83,7 @@ Crossfade::Crossfade (boost::shared_ptr<AudioRegion> in, boost::shared_ptr<Audio
        _anchor_point = ap;
        _follow_overlap = false;
 
-       _active = Config->get_xfades_active ();
+       _active = _session.config.get_xfades_active ();
        _fixed = true;
 
        initialize ();
@@ -100,6 +96,7 @@ Crossfade::Crossfade (boost::shared_ptr<AudioRegion> a, boost::shared_ptr<AudioR
 {
        _in_update = false;
        _fixed = false;
+       _follow_overlap = false;
 
        if (compute (a, b, model)) {
                throw failed_constructor();
@@ -108,8 +105,6 @@ Crossfade::Crossfade (boost::shared_ptr<AudioRegion> a, boost::shared_ptr<AudioR
        _active = act;
 
        initialize ();
-
-
 }
 
 Crossfade::Crossfade (const Playlist& playlist, XMLNode& node)
@@ -191,7 +186,7 @@ Crossfade::Crossfade (boost::shared_ptr<Crossfade> orig, boost::shared_ptr<Audio
        layer_relation = (int32_t) (_in->layer() - _out->layer());
 
        // Let's make sure the fade isn't too long
-       set_length(_length);
+       set_xfade_length(_length);
 }
 
 
@@ -217,22 +212,57 @@ Crossfade::initialize ()
 
        _fade_out.freeze ();
        _fade_out.clear ();
-       _fade_out.add (0.0, 1.0);
-       _fade_out.add ((_length * 0.1), 0.99);
-       _fade_out.add ((_length * 0.2), 0.97);
-       _fade_out.add ((_length * 0.8), 0.03);
-       _fade_out.add ((_length * 0.9), 0.01);
-       _fade_out.add (_length, 0.0);
+
+#define EQUAL_POWER_MINUS_3DB
+#ifdef  EQUAL_POWER_MINUS_3DB
+
+       _fade_out.add ((_length * 0.000000), 1.000000);
+       _fade_out.add ((_length * 0.166667), 0.948859);
+       _fade_out.add ((_length * 0.333333), 0.851507);
+       _fade_out.add ((_length * 0.500000), 0.707946);
+       _fade_out.add ((_length * 0.666667), 0.518174);
+       _fade_out.add ((_length * 0.833333), 0.282192);
+       _fade_out.add ((_length * 1.000000), 0.000000);
+
+#else // EQUAL_POWER_MINUS_6DB
+
+       _fade_out.add ((_length * 0.000000), 1.000000);
+       _fade_out.add ((_length * 0.166667), 0.833033);
+       _fade_out.add ((_length * 0.333333), 0.666186);
+       _fade_out.add ((_length * 0.500000), 0.499459);
+       _fade_out.add ((_length * 0.666667), 0.332853);
+       _fade_out.add ((_length * 0.833333), 0.166366);
+       _fade_out.add ((_length * 1.000000), 0.000000);
+#endif
+
        _fade_out.thaw ();
        
        _fade_in.freeze ();
        _fade_in.clear ();
-       _fade_in.add (0.0, 0.0);
-       _fade_in.add ((_length * 0.1),  0.01);
-       _fade_in.add ((_length * 0.2),  0.03);
-       _fade_in.add ((_length * 0.8),  0.97);
-       _fade_in.add ((_length * 0.9),  0.99);
-       _fade_in.add (_length, 1.0);
+
+#define EQUAL_POWER_MINUS_3DB
+#ifdef  EQUAL_POWER_MINUS_3DB
+
+       _fade_in.add ((_length * 0.000000), 0.000000);
+       _fade_in.add ((_length * 0.166667), 0.282192);
+       _fade_in.add ((_length * 0.333333), 0.518174);
+       _fade_in.add ((_length * 0.500000), 0.707946);
+       _fade_in.add ((_length * 0.666667), 0.851507);
+       _fade_in.add ((_length * 0.833333), 0.948859);
+       _fade_in.add ((_length * 1.000000), 1.000000);
+
+#else // EQUAL_POWER_MINUS_SIX_DB
+
+       _fade_in.add ((_length * 0.000000), 0.000000);
+       _fade_in.add ((_length * 0.166667), 0.166366);
+       _fade_in.add ((_length * 0.333333), 0.332853);
+       _fade_in.add ((_length * 0.500000), 0.499459);
+       _fade_in.add ((_length * 0.666667), 0.666186);
+       _fade_in.add ((_length * 0.833333), 0.833033);
+       _fade_in.add ((_length * 1.000000), 1.000000);
+
+#endif
+
        _fade_in.thaw ();
 
        overlap_type = _in->coverage (_out->position(), _out->last_frame());
@@ -240,8 +270,9 @@ Crossfade::initialize ()
 }      
 
 nframes_t 
-Crossfade::read_raw_internal (Sample* buf, nframes_t start, nframes_t cnt) const
+Crossfade::read_raw_internal (Sample* /*buf*/, sframes_t /*start*/, nframes_t cnt, int /*channel*/) const
 {
+       // FIXME: Why is this disabled?
 #if 0
        Sample* mixdown = new Sample[cnt];
        float* gain = new float[cnt];
@@ -259,7 +290,7 @@ Crossfade::read_raw_internal (Sample* buf, nframes_t start, nframes_t cnt) const
 
 nframes_t 
 Crossfade::read_at (Sample *buf, Sample *mixdown_buffer, 
-                   float *gain_buffer, nframes_t start, nframes_t cnt, uint32_t chan_n,
+                   float *gain_buffer, sframes_t start, nframes_t cnt, uint32_t chan_n,
                    nframes_t read_frames, nframes_t skip_frames) const
 {
        nframes_t offset;
@@ -289,7 +320,7 @@ Crossfade::read_at (Sample *buf, Sample *mixdown_buffer,
 
        } else {
                
-               to_write = min (_length - (start - _position), cnt);
+               to_write = min (nframes_t(_length - (start - _position)), cnt);
                
        }
 
@@ -377,7 +408,7 @@ Crossfade::refresh ()
 
        int32_t new_layer_relation = (int32_t) (_in->layer() - _out->layer());
 
-       if (new_layer_relation * layer_relation < 0) { // different sign, layers rotated 
+       if (new_layer_relation * layer_relation < 0) { // different sign, layers rotated
                Invalidated (shared_from_this ());
                return false;
        }
@@ -396,7 +427,7 @@ Crossfade::refresh ()
                if (_follow_overlap) {
 
                        try {
-                               compute (_in, _out, Config->get_xfade_model());
+                               compute (_in, _out, _session.config.get_xfade_model());
                        } 
 
                        catch (NoCrossfadeHere& err) {
@@ -407,7 +438,6 @@ Crossfade::refresh ()
                        send_signal = true;
 
                } else {
-
                        Invalidated (shared_from_this ());
                        return false;
                }
@@ -837,16 +867,16 @@ Crossfade::set_follow_overlap (bool yn)
        _follow_overlap = yn;
 
        if (!yn) {
-               set_length (_short_xfade_length);
+               set_xfade_length (_short_xfade_length);
        } else {
-               set_length (_out->first_frame() + _out->length() - _in->first_frame());
+               set_xfade_length (_out->first_frame() + _out->length() - _in->first_frame());
        }
 
        StateChanged (FollowOverlapChanged);
 }
 
 nframes_t
-Crossfade::set_length (nframes_t len)
+Crossfade::set_xfade_length (nframes_t len)
 {
        nframes_t limit = 0;
 
@@ -895,9 +925,3 @@ Crossfade::set_short_xfade_length (nframes_t n)
 {
        _short_xfade_length = n;
 }
-
-void
-Crossfade::invalidate ()
-{
-       Invalidated (shared_from_this ()); /* EMIT SIGNAL */
-}