display results of a bounce in the region list
[ardour.git] / libs / ardour / crossfade.cc
index bbe0c63b0a0f5d0d308eabbc0de8d450848036f8..32a9e2b533d832c1ef8b960ceb8521f756a1a8e0 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2003 Paul Davis 
+    Copyright (C) 2003-2006 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
@@ -35,8 +35,8 @@ using namespace std;
 using namespace ARDOUR;
 using namespace PBD;
 
-jack_nframes_t Crossfade::_short_xfade_length = 0;
-Change Crossfade::ActiveChanged = ARDOUR::new_change();
+nframes_t Crossfade::_short_xfade_length = 0;
+Change Crossfade::ActiveChanged = new_change();
 
 /* XXX if and when we ever implement parallel processing of the process()
    callback, these will need to be handled on a per-thread basis.
@@ -46,7 +46,7 @@ Sample* Crossfade::crossfade_buffer_out = 0;
 Sample* Crossfade::crossfade_buffer_in = 0;
 
 void
-Crossfade::set_buffer_size (jack_nframes_t sz)
+Crossfade::set_buffer_size (nframes_t sz)
 {
        if (crossfade_buffer_out) {
                delete [] crossfade_buffer_out;
@@ -70,15 +70,15 @@ Crossfade::operator== (const Crossfade& other)
        return (_in == other._in) && (_out == other._out);
 }
 
-Crossfade::Crossfade (ARDOUR::AudioRegion& in, ARDOUR::AudioRegion& out, 
-                     jack_nframes_t length,
-                     jack_nframes_t position,
+Crossfade::Crossfade (boost::shared_ptr<AudioRegion> in, boost::shared_ptr<AudioRegion> out, 
+                     nframes_t length,
+                     nframes_t position,
                      AnchorPoint ap)
        : _fade_in (0.0, 2.0, 1.0), // linear (gain coefficient) => -inf..+6dB
          _fade_out (0.0, 2.0, 1.0) // linear (gain coefficient) => -inf..+6dB
 {
-       _in = &in;
-       _out = &out;
+       _in = in;
+       _out = out;
        _length = length;
        _position = position;
        _anchor_point = ap;
@@ -89,7 +89,7 @@ Crossfade::Crossfade (ARDOUR::AudioRegion& in, ARDOUR::AudioRegion& out,
        initialize ();
 }
 
-Crossfade::Crossfade (ARDOUR::AudioRegion& a, ARDOUR::AudioRegion& b, CrossfadeModel model, bool act)
+Crossfade::Crossfade (boost::shared_ptr<AudioRegion> a, boost::shared_ptr<AudioRegion> b, CrossfadeModel model, bool act)
        : _fade_in (0.0, 2.0, 1.0), // linear (gain coefficient) => -inf..+6dB
          _fade_out (0.0, 2.0, 1.0) // linear (gain coefficient) => -inf..+6dB
 {
@@ -110,7 +110,7 @@ Crossfade::Crossfade (const Playlist& playlist, XMLNode& node)
        :  _fade_in (0.0, 2.0, 1.0), // linear (gain coefficient) => -inf..+6dB
           _fade_out (0.0, 2.0, 1.0) // linear (gain coefficient) => -inf..+6dB
 {
-       Region* r;
+       boost::shared_ptr<Region> r;
        XMLProperty* prop;
        LocaleGuard lg (X_("POSIX"));
 
@@ -129,7 +129,7 @@ Crossfade::Crossfade (const Playlist& playlist, XMLNode& node)
                throw failed_constructor();
        }
        
-       if ((_in = dynamic_cast<AudioRegion*> (r)) == 0) {
+       if ((_in = boost::dynamic_pointer_cast<AudioRegion> (r)) == 0) {
                throw failed_constructor();
        }
 
@@ -146,7 +146,7 @@ Crossfade::Crossfade (const Playlist& playlist, XMLNode& node)
                throw failed_constructor();
        }
        
-       if ((_out = dynamic_cast<AudioRegion*> (r)) == 0) {
+       if ((_out = boost::dynamic_pointer_cast<AudioRegion> (r)) == 0) {
                throw failed_constructor();
        }
 
@@ -160,7 +160,7 @@ Crossfade::Crossfade (const Playlist& playlist, XMLNode& node)
        save_state ("initial");
 }
 
-Crossfade::Crossfade (const Crossfade &orig, ARDOUR::AudioRegion *newin, ARDOUR::AudioRegion *newout)
+Crossfade::Crossfade (const Crossfade &orig, boost::shared_ptr<AudioRegion> newin, boost::shared_ptr<AudioRegion> newout)
        : _fade_in(orig._fade_in),
          _fade_out(orig._fade_out)
 {
@@ -236,20 +236,20 @@ Crossfade::initialize (bool savestate)
 }      
 
 int
-Crossfade::compute (AudioRegion& a, AudioRegion& b, CrossfadeModel model)
+Crossfade::compute (boost::shared_ptr<AudioRegion> a, boost::shared_ptr<AudioRegion> b, CrossfadeModel model)
 {
-       AudioRegion* top;
-       AudioRegion* bottom;
-       jack_nframes_t short_xfade_length;
+       boost::shared_ptr<AudioRegion> top;
+       boost::shared_ptr<AudioRegion> bottom;
+       nframes_t short_xfade_length;
 
        short_xfade_length = _short_xfade_length; 
 
-       if (a.layer() < b.layer()) {
-               top = &b;
-               bottom = &a;
+       if (a->layer() < b->layer()) {
+               top = b;
+               bottom = a;
        } else {
-               top = &a;
-               bottom = &b;
+               top = a;
+               bottom = b;
        }
        
        /* first check for matching ends */
@@ -400,13 +400,13 @@ Crossfade::compute (AudioRegion& a, AudioRegion& b, CrossfadeModel model)
        return 0;
 }
 
-jack_nframes_t 
+nframes_t 
 Crossfade::read_at (Sample *buf, Sample *mixdown_buffer, 
-                   float *gain_buffer, char * workbuf, jack_nframes_t start, jack_nframes_t cnt, uint32_t chan_n,
-                   jack_nframes_t read_frames, jack_nframes_t skip_frames)
+                   float *gain_buffer, nframes_t start, nframes_t cnt, uint32_t chan_n,
+                   nframes_t read_frames, nframes_t skip_frames)
 {
-       jack_nframes_t offset;
-       jack_nframes_t to_write;
+       nframes_t offset;
+       nframes_t to_write;
 
        if (!_active) {
                return 0;
@@ -438,8 +438,8 @@ Crossfade::read_at (Sample *buf, Sample *mixdown_buffer,
 
        offset = start - _position;
 
-       _out->read_at (crossfade_buffer_out, mixdown_buffer, gain_buffer, workbuf, start, to_write, chan_n, read_frames, skip_frames);
-       _in->read_at (crossfade_buffer_in, mixdown_buffer, gain_buffer, workbuf, start, to_write, chan_n, read_frames, skip_frames);
+       _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);
 
        float* fiv = new float[to_write];
        float* fov = new float[to_write];
@@ -453,7 +453,7 @@ Crossfade::read_at (Sample *buf, Sample *mixdown_buffer,
           position and length, and so we know precisely how much data they could return. 
        */
 
-       for (jack_nframes_t n = 0; n < to_write; ++n) {
+       for (nframes_t n = 0; n < to_write; ++n) {
                buf[n] = (crossfade_buffer_out[n] * fov[n]) + (crossfade_buffer_in[n] * fiv[n]);
        }
 
@@ -464,9 +464,9 @@ Crossfade::read_at (Sample *buf, Sample *mixdown_buffer,
 }      
 
 OverlapType 
-Crossfade::coverage (jack_nframes_t start, jack_nframes_t end) const
+Crossfade::coverage (nframes_t start, nframes_t end) const
 {
-       jack_nframes_t my_end = _position + _length;
+       nframes_t my_end = _position + _length;
 
        if ((start >= _position) && (end <= my_end)) {
                return OverlapInternal;
@@ -534,7 +534,7 @@ Crossfade::refresh ()
 bool
 Crossfade::update (bool force)
 {
-       jack_nframes_t newlen;
+       nframes_t newlen;
        bool save = false;
 
        if (_follow_overlap) {
@@ -605,7 +605,7 @@ Crossfade::member_changed (Change what_changed)
 {
        Change what_we_care_about = Change (Region::MuteChanged|
                                            Region::LayerChanged|
-                                           ARDOUR::BoundsChanged);
+                                           BoundsChanged);
 
        if (what_changed & what_we_care_about) {
                refresh ();
@@ -679,9 +679,9 @@ Crossfade::get_state ()
        char buf[64];
        LocaleGuard lg (X_("POSIX"));
 
-       _out->id().print (buf);
+       _out->id().print (buf, sizeof (buf));
        node->add_property ("out", buf);
-       _in->id().print (buf);
+       _in->id().print (buf, sizeof (buf));
        node->add_property ("in", buf);
        node->add_property ("active", (_active ? "yes" : "no"));
        node->add_property ("follow-overlap", (_follow_overlap ? "yes" : "no"));
@@ -700,9 +700,9 @@ Crossfade::get_state ()
 
                pnode = new XMLNode ("point");
 
-               snprintf (buf, sizeof (buf), "%" PRIu32, (jack_nframes_t) floor ((*ii)->when));
+               snprintf (buf, sizeof (buf), "%" PRIu32, (nframes_t) floor ((*ii)->when));
                pnode->add_property ("x", buf);
-               snprintf (buf, sizeof (buf), "%f", (*ii)->value);
+               snprintf (buf, sizeof (buf), "%.12g", (*ii)->value);
                pnode->add_property ("y", buf);
                child->add_child_nocopy (*pnode);
        }
@@ -714,9 +714,9 @@ Crossfade::get_state ()
 
                pnode = new XMLNode ("point");
 
-               snprintf (buf, sizeof (buf), "%" PRIu32, (jack_nframes_t) floor ((*ii)->when));
+               snprintf (buf, sizeof (buf), "%" PRIu32, (nframes_t) floor ((*ii)->when));
                pnode->add_property ("x", buf);
-               snprintf (buf, sizeof (buf), "%f", (*ii)->value);
+               snprintf (buf, sizeof (buf), "%.12g", (*ii)->value);
                pnode->add_property ("y", buf);
                child->add_child_nocopy (*pnode);
        }
@@ -796,7 +796,7 @@ Crossfade::set_state (const XMLNode& node)
        
        for (i = children.begin(); i != children.end(); ++i) {
                if ((*i)->name() == "point") {
-                       jack_nframes_t x;
+                       nframes_t x;
                        float y;
                        
                        prop = (*i)->property ("x");
@@ -817,7 +817,7 @@ Crossfade::set_state (const XMLNode& node)
        
        for (i = children.begin(); i != children.end(); ++i) {
                if ((*i)->name() == "point") {
-                       jack_nframes_t x;
+                       nframes_t x;
                        float y;
                        XMLProperty* prop;
 
@@ -856,10 +856,10 @@ Crossfade::set_follow_overlap (bool yn)
        }
 }
 
-jack_nframes_t
-Crossfade::set_length (jack_nframes_t len)
+nframes_t
+Crossfade::set_length (nframes_t len)
 {
-       jack_nframes_t limit;
+       nframes_t limit;
 
        switch (_anchor_point) {
        case StartOfIn:
@@ -894,7 +894,7 @@ Crossfade::set_length (jack_nframes_t len)
        return len;
 }
 
-jack_nframes_t
+nframes_t
 Crossfade::overlap_length () const
 {
        if (_fixed) {
@@ -904,7 +904,7 @@ Crossfade::overlap_length () const
 }
 
 void
-Crossfade::set_short_xfade_length (jack_nframes_t n)
+Crossfade::set_short_xfade_length (nframes_t n)
 {
        _short_xfade_length = n;
 }