Merge branch 'master' into cairocanvas
[ardour.git] / libs / ardour / audioregion.cc
index 41b3ceedc9ac11fc00ca5172c7272b79b8ec84bf..331de043cda7cc62cba212b59b726372786e9465 100644 (file)
@@ -26,7 +26,7 @@
 
 #include <boost/scoped_array.hpp>
 
-#include <glibmm/thread.h>
+#include <glibmm/threads.h>
 
 #include "pbd/basename.h"
 #include "pbd/xml++.h"
@@ -62,10 +62,6 @@ namespace ARDOUR {
                PBD::PropertyDescriptor<bool> fade_in_active;
                PBD::PropertyDescriptor<bool> fade_out_active;
                PBD::PropertyDescriptor<float> scale_amplitude;
-               PBD::PropertyDescriptor<bool> fade_out_is_xfade;
-               PBD::PropertyDescriptor<bool> fade_out_is_short;
-               PBD::PropertyDescriptor<bool> fade_in_is_xfade;
-               PBD::PropertyDescriptor<bool> fade_in_is_short;
                PBD::PropertyDescriptor<boost::shared_ptr<AutomationList> > fade_in;
                PBD::PropertyDescriptor<boost::shared_ptr<AutomationList> > inverse_fade_in;
                PBD::PropertyDescriptor<boost::shared_ptr<AutomationList> > fade_out;
@@ -82,9 +78,8 @@ static void
 reverse_curve (boost::shared_ptr<Evoral::ControlList> dst, boost::shared_ptr<const Evoral::ControlList> src)
 {
        size_t len = src->back()->when;
-       
-       for (Evoral::ControlList::const_iterator it = src->begin(); it!=src->end(); it++) {
-               dst->add (len - (*it)->when, (*it)->value);
+       for (Evoral::ControlList::const_reverse_iterator it = src->rbegin(); it!=src->rend(); it++) {
+               dst->fast_simple_add (len - (*it)->when, (*it)->value);
        }
 }
 
@@ -141,7 +136,7 @@ merge_curves (boost::shared_ptr<Evoral::ControlList> dst,
                interp += v2 * ( (double)count / (double)size );
 
                interp = dB_to_coefficient(interp);
-               dst->add ( (*c1)->when, interp );
+               dst->fast_simple_add ( (*c1)->when, interp );
                c1++;
                count++;
        }
@@ -162,14 +157,6 @@ AudioRegion::make_property_quarks ()
        DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for fade-out-active = %1\n",     Properties::fade_out_active.property_id));
        Properties::scale_amplitude.property_id = g_quark_from_static_string (X_("scale-amplitude"));
        DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for scale-amplitude = %1\n",     Properties::scale_amplitude.property_id));
-       Properties::fade_out_is_xfade.property_id = g_quark_from_static_string (X_("fade-out-is-xfade"));
-       DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for fade-out-is-xfade = %1\n",   Properties::fade_out_is_xfade.property_id));
-       Properties::fade_out_is_short.property_id = g_quark_from_static_string (X_("fade-out-is-short"));
-       DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for fade-out-is-short = %1\n",   Properties::fade_out_is_short.property_id));
-       Properties::fade_in_is_xfade.property_id = g_quark_from_static_string (X_("fade-in-is-xfade"));
-       DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for fade-in-is-xfade = %1\n",    Properties::fade_in_is_xfade.property_id));
-       Properties::fade_in_is_short.property_id = g_quark_from_static_string (X_("fade-in-is-short"));
-       DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for fade-in-is-short = %1\n",    Properties::fade_in_is_short.property_id));
        Properties::fade_in.property_id = g_quark_from_static_string (X_("FadeIn"));
        DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for FadeIn = %1\n",              Properties::fade_in.property_id));
        Properties::inverse_fade_in.property_id = g_quark_from_static_string (X_("InverseFadeIn"));
@@ -193,10 +180,6 @@ AudioRegion::register_properties ()
        add_property (_fade_in_active);
        add_property (_fade_out_active);
        add_property (_scale_amplitude);
-       add_property (_fade_out_is_xfade);
-       add_property (_fade_out_is_short);
-       add_property (_fade_in_is_xfade);
-       add_property (_fade_in_is_short);
        add_property (_fade_in);
        add_property (_inverse_fade_in);
        add_property (_fade_out);
@@ -211,10 +194,6 @@ AudioRegion::register_properties ()
        , _fade_in_active (Properties::fade_in_active, true) \
        , _fade_out_active (Properties::fade_out_active, true) \
        , _scale_amplitude (Properties::scale_amplitude, 1.0) \
-       , _fade_in_is_xfade (Properties::fade_in_is_xfade, false) \
-       , _fade_out_is_xfade (Properties::fade_out_is_xfade, false) \
-       , _fade_in_is_short (Properties::fade_in_is_short, false) \
-       , _fade_out_is_short (Properties::fade_out_is_short, false) \
        , _fade_in (Properties::fade_in, boost::shared_ptr<AutomationList> (new AutomationList (Evoral::Parameter (FadeInAutomation)))) \
        , _inverse_fade_in (Properties::inverse_fade_in, boost::shared_ptr<AutomationList> (new AutomationList (Evoral::Parameter (FadeInAutomation)))) \
        , _fade_out (Properties::fade_out, boost::shared_ptr<AutomationList> (new AutomationList (Evoral::Parameter (FadeOutAutomation)))) \
@@ -227,10 +206,6 @@ AudioRegion::register_properties ()
        , _fade_in_active (Properties::fade_in_active, other->_fade_in_active) \
        , _fade_out_active (Properties::fade_out_active, other->_fade_out_active) \
        , _scale_amplitude (Properties::scale_amplitude, other->_scale_amplitude) \
-       , _fade_in_is_xfade (Properties::fade_in_is_xfade, other->_fade_in_is_xfade) \
-       , _fade_out_is_xfade (Properties::fade_out_is_xfade, other->_fade_out_is_xfade) \
-       , _fade_in_is_short (Properties::fade_in_is_short, other->_fade_in_is_short) \
-       , _fade_out_is_short (Properties::fade_out_is_short, other->_fade_out_is_short) \
        , _fade_in (Properties::fade_in, boost::shared_ptr<AutomationList> (new AutomationList (*other->_fade_in.val()))) \
        , _inverse_fade_in (Properties::fade_in, boost::shared_ptr<AutomationList> (new AutomationList (*other->_inverse_fade_in.val()))) \
        , _fade_out (Properties::fade_in, boost::shared_ptr<AutomationList> (new AutomationList (*other->_fade_out.val()))) \
@@ -434,14 +409,22 @@ AudioRegion::set_envelope_active (bool yn)
        }
 }
 
+/** @param buf Buffer to put peak data in.
+ *  @param npeaks Number of peaks to read (ie the number of PeakDatas in buf)
+ *  @param offset Start position, as an offset from the start of this region's source.
+ *  @param cnt Number of samples to read.
+ *  @param chan_n Channel.
+ *  @param frames_per_pixel Number of samples to use to generate one peak value.
+ */
 ARDOUR::framecnt_t
-AudioRegion::read_peaks (PeakData *buf, framecnt_t npeaks, framecnt_t offset, framecnt_t cnt, uint32_t chan_n, double samples_per_unit) const
+AudioRegion::read_peaks (PeakData *buf, framecnt_t npeaks, framecnt_t offset, framecnt_t cnt, uint32_t chan_n, double frames_per_pixel) const
 {
        if (chan_n >= _sources.size()) {
                return 0;
        }
 
-       if (audio_source(chan_n)->read_peaks (buf, npeaks, offset, cnt, samples_per_unit)) {
+       if (audio_source(chan_n)->read_peaks (buf, npeaks, offset, cnt, frames_per_pixel)) {
                return 0;
        } else {
                if (_scale_amplitude != 1.0f) {
@@ -506,11 +489,6 @@ AudioRegion::read_at (Sample *buf, Sample *mixdown_buffer, float *gain_buffer,
                return 0;
        }
 
-       if (muted()) {
-               return 0; /* read nothing */
-       }
-
-       
        /* WORK OUT WHERE TO GET DATA FROM */
 
        framecnt_t to_read;
@@ -766,7 +744,7 @@ AudioRegion::read_from_sources (SourceList const & srcs, framecnt_t limit, Sampl
 
                        /* copy an existing channel's data in for this non-existant one */
 
-                       uint32_t channel = n_channels() % chan_n;
+                       uint32_t channel = chan_n % n_channels();
                        boost::shared_ptr<AudioSource> src = boost::dynamic_pointer_cast<AudioSource> (srcs[channel]);
 
                        if (src->read (buf, _start + internal_offset, to_read) != to_read) {
@@ -784,17 +762,24 @@ AudioRegion::read_from_sources (SourceList const & srcs, framecnt_t limit, Sampl
 }
 
 XMLNode&
-AudioRegion::state ()
+AudioRegion::get_basic_state ()
 {
        XMLNode& node (Region::state ());
-       XMLNode *child;
        char buf[64];
        LocaleGuard lg (X_("POSIX"));
 
        snprintf (buf, sizeof (buf), "%u", (uint32_t) _sources.size());
        node.add_property ("channels", buf);
 
-       Stateful::add_properties (node);
+       return node;
+}
+
+XMLNode&
+AudioRegion::state ()
+{
+       XMLNode& node (get_basic_state());
+       XMLNode *child;
+       LocaleGuard lg (X_("POSIX"));
 
        child = node.add_child ("Envelope");
 
@@ -826,7 +811,7 @@ AudioRegion::state ()
        }
 
        if (_inverse_fade_in) {
-               child = node.add_child (X_("InvFadeIn"));
+               child = node.add_child (X_("InverseFadeIn"));
                child->add_child_nocopy (_inverse_fade_in->get_state ());
        }
 
@@ -839,7 +824,7 @@ AudioRegion::state ()
        }
 
        if (_inverse_fade_out) {
-               child = node.add_child (X_("InvFadeOut"));
+               child = node.add_child (X_("InverseFadeOut"));
                child->add_child_nocopy (_inverse_fade_out->get_state ());
        }
 
@@ -917,12 +902,6 @@ AudioRegion::_set_state (const XMLNode& node, int version, PropertyChange& what_
                                }
                        }
 
-                       /* legacy a3 */
-
-                       if ((prop = child->property ("is-xfade")) != 0) {
-                               _fade_in_is_xfade = string_is_affirmative (prop->value());
-                       }
-
                } else if (child->name() == "FadeOut") {
 
                        _fade_out->clear ();
@@ -943,19 +922,13 @@ AudioRegion::_set_state (const XMLNode& node, int version, PropertyChange& what_
                                        set_fade_out_active (false);
                                }
                        }
-
-                       /* legacy a3 */
-
-                       if ((prop = child->property ("is-xfade")) != 0) {
-                               _fade_out_is_xfade = string_is_affirmative (prop->value());
-                       }
-                       
-               } else if (child->name() == "InvFadeIn") {
+       
+               } else if (child->name() == "InverseFadeIn") {
                        XMLNode* grandchild = child->child ("AutomationList");
                        if (grandchild) {
                                _inverse_fade_in->set_state (*grandchild, version);
                        }
-               } else if (child->name() == "InvFadeOut") {
+               } else if (child->name() == "InverseFadeOut") {
                        XMLNode* grandchild = child->child ("AutomationList");
                        if (grandchild) {
                                _inverse_fade_out->set_state (*grandchild, version);
@@ -1171,20 +1144,6 @@ AudioRegion::set_fade_in_length (framecnt_t len)
                        _inverse_fade_in->extend_to (len);
                }
 
-               if (_session.config.get_xfade_model() == FullCrossfade &&
-                   _session.config.get_auto_xfade() && 
-                   _fade_in_is_xfade && !_fade_in_is_short) {
-
-                       /* trim a single other region below us to the new start
-                          of the fade.
-                       */
-
-                       boost::shared_ptr<Region> other = get_single_other_xfade_region (true);
-                       if (other) {
-                               other->trim_end (position() + len);
-                       }
-               }
-
                _default_fade_in = false;
                send_change (PropertyChange (Properties::fade_in));
        }
@@ -1209,20 +1168,6 @@ AudioRegion::set_fade_out_length (framecnt_t len)
                        _inverse_fade_out->extend_to (len);
                }
                _default_fade_out = false;
-               
-               if (_session.config.get_xfade_model() == FullCrossfade &&
-                   _session.config.get_auto_xfade() && 
-                   _fade_out_is_xfade && !_fade_out_is_short) {
-
-                       /* trim a single other region below us to the new start
-                          of the fade.
-                       */
-
-                       boost::shared_ptr<Region> other = get_single_other_xfade_region (false);
-                       if (other) {
-                               other->trim_front (last_frame() - len);
-                       }
-               }
 
                send_change (PropertyChange (Properties::fade_out));
        }
@@ -1265,8 +1210,6 @@ void
 AudioRegion::set_default_fade_in ()
 {
        _fade_in_suspended = 0;
-       _fade_in_is_xfade = false;
-       _fade_in_is_short = true;
        set_fade_in (FadeLinear, 64);
 }
 
@@ -1274,8 +1217,6 @@ void
 AudioRegion::set_default_fade_out ()
 {
        _fade_out_suspended = 0;
-       _fade_out_is_xfade = false;
-       _fade_out_is_short = true;
        set_fade_out (FadeLinear, 64);
 }
 
@@ -1844,51 +1785,6 @@ AudioRegion::body_range () const
        return Evoral::Range<framepos_t> (first_frame() + _fade_in->back()->when + 1, last_frame() - _fade_out->back()->when);
 }
 
-void
-AudioRegion::set_fade_in_is_xfade (bool yn)
-{
-       if (yn == _fade_in_is_xfade) {
-               return;
-       }
-
-       _fade_in_is_xfade = yn;
-       send_change (PropertyChange (Properties::fade_in_is_xfade));
-}
-
-void
-AudioRegion::set_fade_out_is_xfade (bool yn)
-{
-       if (yn == _fade_out_is_xfade) {
-               return;
-       }
-
-       _fade_out_is_xfade = yn;
-       send_change (PropertyChange (Properties::fade_out_is_xfade));
-}
-
-void
-AudioRegion::set_fade_in_is_short (bool yn)
-{
-       if (yn == _fade_in_is_short) {
-               return;
-       }
-
-       _fade_in_is_short = yn;
-       send_change (PropertyChange (Properties::fade_in_is_short));
-
-}
-
-void
-AudioRegion::set_fade_out_is_short (bool yn)
-{
-       if (yn == _fade_out_is_short) {
-               return;
-       }
-
-       _fade_out_is_short = yn;
-       send_change (PropertyChange (Properties::fade_out_is_short));
-}
-
 boost::shared_ptr<Region>
 AudioRegion::get_single_other_xfade_region (bool start) const
 {
@@ -1964,22 +1860,3 @@ AudioRegion::verify_xfade_bounds (framecnt_t len, bool start)
                
 }
 
-extern "C" {
-
-       int region_read_peaks_from_c (void *arg, uint32_t npeaks, uint32_t start, uint32_t cnt, intptr_t data, uint32_t n_chan, double samples_per_unit)
-{
-       return ((AudioRegion *) arg)->read_peaks ((PeakData *) data, (framecnt_t) npeaks, (framepos_t) start, (framecnt_t) cnt, n_chan,samples_per_unit);
-}
-
-uint32_t region_length_from_c (void *arg)
-{
-
-       return ((AudioRegion *) arg)->length();
-}
-
-uint32_t sourcefile_length_from_c (void *arg, double zoom_factor)
-{
-       return ( (AudioRegion *) arg)->audio_source()->available_peaks (zoom_factor) ;
-}
-
-} /* extern "C" */