convert audioregion xfade stuff to properties, add "is-short" property for fade in...
authorPaul Davis <paul@linuxaudiosystems.com>
Sat, 26 May 2012 01:24:01 +0000 (01:24 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Sat, 26 May 2012 01:24:01 +0000 (01:24 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@12452 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/audioregion.h
libs/ardour/audio_playlist.cc
libs/ardour/audioregion.cc

index c03f32cb636d6ad72dbc9cdc076fd327de81a744..0d83b33539f1036e8f64155614934e1f46f4c297 100644 (file)
@@ -94,6 +94,11 @@ class AudioRegion : public Region
        bool fade_out_is_xfade() const { return _fade_out_is_xfade; }
        void set_fade_out_is_xfade (bool yn);
 
+       bool fade_in_is_short() const { return _fade_in_is_short; }
+       void set_fade_in_is_short (bool yn);
+       bool fade_out_is_short() const { return _fade_out_is_short; }
+       void set_fade_out_is_short (bool yn);
+
        boost::shared_ptr<AutomationList> fade_in()  { return _fade_in; }
        boost::shared_ptr<AutomationList> inverse_fade_in()  { return _inverse_fade_in; }
        boost::shared_ptr<AutomationList> fade_out() { return _fade_out; }
@@ -199,6 +204,10 @@ class AudioRegion : public Region
        PBD::Property<bool>     _fade_out_active;
        /** linear gain to apply to the whole region */
        PBD::Property<gain_t>   _scale_amplitude;
+       PBD::Property<bool>     _fade_in_is_xfade;
+       PBD::Property<bool>     _fade_out_is_xfade;
+       PBD::Property<bool>     _fade_in_is_short;
+       PBD::Property<bool>     _fade_out_is_short;
 
        void register_properties ();
        void post_set (const PBD::PropertyChange&);
@@ -231,11 +240,6 @@ class AudioRegion : public Region
        boost::shared_ptr<AutomationList> _envelope;
        uint32_t                          _fade_in_suspended;
        uint32_t                          _fade_out_suspended;
-       /* This is not a Property because its not subject to user control,
-          or undo/redo. XXX this may prove to be a mistake.
-       */
-       bool                              _fade_in_is_xfade;
-       bool                              _fade_out_is_xfade;
 
        boost::shared_ptr<ARDOUR::Region> get_single_other_xfade_region (bool start) const;
 
index 76cab14699c73df03fc9ea50266aa0bea48dd3dd..2ebbdd5131569b75e8c97be78f321c10e16f5f0b 100644 (file)
@@ -313,40 +313,51 @@ AudioPlaylist::check_crossfades (Evoral::Range<framepos_t> range)
 
                                        /* Top's fade-in will cause an implicit fade-out of bottom */
                                        
-                                       framecnt_t len = 0;
+                                       if (top->fade_in_is_xfade() && top->fade_in_is_short()) {
+
+                                               /* its already an xfade. if its
+                                                * really short, leave it
+                                                * alone.
+                                                */
 
-                                       if (_capture_insertion_underway) {
-                                               len = _session.config.get_short_xfade_seconds() * _session.frame_rate();
                                        } else {
-                                               switch (_session.config.get_xfade_model()) {
-                                               case FullCrossfade:
-                                                       len = bottom->last_frame () - top->first_frame ();
-                                                       break;
-                                               case ShortCrossfade:
+                                               framecnt_t len = 0;
+                                               
+                                               if (_capture_insertion_underway) {
                                                        len = _session.config.get_short_xfade_seconds() * _session.frame_rate();
+                                               } else {
+                                                       switch (_session.config.get_xfade_model()) {
+                                                       case FullCrossfade:
+                                                               len = bottom->last_frame () - top->first_frame ();
+                                                               top->set_fade_in_is_short (false);
+                                                               break;
+                                                       case ShortCrossfade:
+                                                               len = _session.config.get_short_xfade_seconds() * _session.frame_rate();
+                                                               top->set_fade_in_is_short (true);
+                                                               break;
+                                                       }
+                                               }
+                                               
+                                               top->set_fade_in_active (true);
+                                               top->set_fade_in_is_xfade (true);
+                                               
+                                               /* XXX may 2012: -3dB and -6dB curves
+                                                * are the same right now 
+                                                */
+                                               
+                                               switch (_session.config.get_xfade_choice ()) {
+                                               case ConstantPowerMinus3dB:
+                                                       top->set_fade_in (FadeConstantPower, len);
+                                                       break;
+                                               case ConstantPowerMinus6dB:
+                                                       top->set_fade_in (FadeConstantPower, len);
+                                                       break;
+                                               case RegionFades:
+                                                       top->set_fade_in_length (len);
                                                        break;
                                                }
                                        }
-                                       
-                                       top->set_fade_in_active (true);
-                                       top->set_fade_in_is_xfade (true);
-
-                                       /* XXX may 2012: -3dB and -6dB curves
-                                        * are the same right now 
-                                        */
-
-                                       switch (_session.config.get_xfade_choice ()) {
-                                       case ConstantPowerMinus3dB:
-                                               top->set_fade_in (FadeConstantPower, len);
-                                               break;
-                                       case ConstantPowerMinus6dB:
-                                               top->set_fade_in (FadeConstantPower, len);
-                                               break;
-                                       case RegionFades:
-                                               top->set_fade_in_length (len);
-                                               break;
-                                       }
-                                       
+
                                        done_start.insert (top);
                                }
 
@@ -361,35 +372,45 @@ AudioPlaylist::check_crossfades (Evoral::Range<framepos_t> range)
                                if (done_end.find (top) == done_end.end() && done_start.find (bottom) == done_start.end ()) {
                                        /* Top's fade-out will cause an implicit fade-in of bottom */
                                        
-                                       framecnt_t len = 0;
+                                       
+                                       if (top->fade_out_is_xfade() && top->fade_out_is_short()) {
+
+                                               /* its already an xfade. if its
+                                                * really short, leave it
+                                                * alone.
+                                                */
 
-                                       if (_capture_insertion_underway) {
-                                               len = _session.config.get_short_xfade_seconds() * _session.frame_rate();
                                        } else {
-                                               switch (_session.config.get_xfade_model()) {
-                                               case FullCrossfade:
-                                                       len = top->last_frame () - bottom->first_frame ();
-                                                       break;
-                                               case ShortCrossfade:
+                                               framecnt_t len = 0;
+                                               
+                                               if (_capture_insertion_underway) {
                                                        len = _session.config.get_short_xfade_seconds() * _session.frame_rate();
+                                               } else {
+                                                       switch (_session.config.get_xfade_model()) {
+                                                       case FullCrossfade:
+                                                               len = top->last_frame () - bottom->first_frame ();
+                                                               break;
+                                                       case ShortCrossfade:
+                                                               len = _session.config.get_short_xfade_seconds() * _session.frame_rate();
+                                                               break;
+                                                       }
+                                               }
+                                               
+                                               top->set_fade_out_active (true);
+                                               top->set_fade_out_is_xfade (true);
+                                               
+                                               switch (_session.config.get_xfade_choice ()) {
+                                               case ConstantPowerMinus3dB:
+                                                       top->set_fade_out (FadeConstantPower, len);
+                                                       break;
+                                               case ConstantPowerMinus6dB:
+                                                       top->set_fade_out (FadeConstantPower, len);
+                                                       break;
+                                               case RegionFades:
+                                                       top->set_fade_out_length (len);
                                                        break;
                                                }
                                        }
-                                       
-                                       top->set_fade_out_active (true);
-                                       top->set_fade_out_is_xfade (true);
-
-                                       switch (_session.config.get_xfade_choice ()) {
-                                       case ConstantPowerMinus3dB:
-                                               top->set_fade_out (FadeConstantPower, len);
-                                               break;
-                                       case ConstantPowerMinus6dB:
-                                               top->set_fade_out (FadeConstantPower, len);
-                                               break;
-                                       case RegionFades:
-                                               top->set_fade_out_length (len);
-                                               break;
-                                       }
 
                                        done_end.insert (top);
                                }
index a57aecb38820134774b2702a5262da734e082bc9..66b978131dab0ec908ed09127fe2888dbdcfbac6 100644 (file)
@@ -61,6 +61,10 @@ 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;
        }
 }
 
@@ -164,6 +168,14 @@ 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));
 }
 
 void
@@ -177,6 +189,10 @@ 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);
 }
 
 #define AUDIOREGION_STATE_DEFAULT \
@@ -185,7 +201,11 @@ AudioRegion::register_properties ()
        , _default_fade_out (Properties::default_fade_out, true) \
        , _fade_in_active (Properties::fade_in_active, true) \
        , _fade_out_active (Properties::fade_out_active, true) \
-       , _scale_amplitude (Properties::scale_amplitude, 1.0)
+       , _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) 
 
 #define AUDIOREGION_COPY_STATE(other) \
        _envelope_active (Properties::envelope_active, other->_envelope_active) \
@@ -193,7 +213,11 @@ AudioRegion::register_properties ()
        , _default_fade_out (Properties::default_fade_out, other->_default_fade_out) \
        , _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)
+       , _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)
 /* a Session will reset these to its chosen defaults by calling AudioRegion::set_default_fade() */
 
 void
@@ -223,8 +247,6 @@ AudioRegion::AudioRegion (Session& s, framepos_t start, framecnt_t len, std::str
        , _envelope (new AutomationList(Evoral::Parameter(EnvelopeAutomation)))
        , _fade_in_suspended (0)
        , _fade_out_suspended (0)
-       , _fade_in_is_xfade (false)
-       , _fade_out_is_xfade (false)
 {
        init ();
        assert (_sources.size() == _master_sources.size());
@@ -242,8 +264,6 @@ AudioRegion::AudioRegion (const SourceList& srcs)
        , _envelope (new AutomationList(Evoral::Parameter(EnvelopeAutomation)))
        , _fade_in_suspended (0)
        , _fade_out_suspended (0)
-       , _fade_in_is_xfade (false)
-       , _fade_out_is_xfade (false)
 {
        init ();
        assert (_sources.size() == _master_sources.size());
@@ -263,8 +283,6 @@ AudioRegion::AudioRegion (boost::shared_ptr<const AudioRegion> other)
        , _envelope (new AutomationList (*other->_envelope, 0, other->_length))
        , _fade_in_suspended (0)
        , _fade_out_suspended (0)
-       , _fade_in_is_xfade (false)
-       , _fade_out_is_xfade (false)
 {
        /* don't use init here, because we got fade in/out from the other region
        */
@@ -291,8 +309,6 @@ AudioRegion::AudioRegion (boost::shared_ptr<const AudioRegion> other, framecnt_t
        , _envelope (new AutomationList (*other->_envelope, offset, other->_length))
        , _fade_in_suspended (0)
        , _fade_out_suspended (0)
-       , _fade_in_is_xfade (false)
-       , _fade_out_is_xfade (false)
 {
        /* don't use init here, because we got fade in/out from the other region
        */
@@ -316,8 +332,6 @@ AudioRegion::AudioRegion (boost::shared_ptr<const AudioRegion> other, const Sour
        , _envelope (new AutomationList (*other->_envelope))
        , _fade_in_suspended (0)
        , _fade_out_suspended (0)
-       , _fade_in_is_xfade (false)
-       , _fade_out_is_xfade (false)
 {
        /* make-a-sort-of-copy-with-different-sources constructor (used by audio filter) */
 
@@ -341,8 +355,6 @@ AudioRegion::AudioRegion (SourceList& srcs)
        , _envelope (new AutomationList(Evoral::Parameter(EnvelopeAutomation)))
        , _fade_in_suspended (0)
        , _fade_out_suspended (0)
-       , _fade_in_is_xfade (false)
-       , _fade_out_is_xfade (false)
 {
        init ();
 
@@ -806,7 +818,6 @@ AudioRegion::state ()
        }
 
        child = node.add_child (X_("FadeIn"));
-       child->add_property ("is-xfade", (_fade_in_is_xfade ? "yes" : "no"));
 
        if (_default_fade_in) {
                child->add_property ("default", "yes");
@@ -820,7 +831,6 @@ AudioRegion::state ()
        }
 
        child = node.add_child (X_("FadeOut"));
-       child->add_property ("is-xfade", (_fade_out_is_xfade ? "yes" : "no"));
 
        if (_default_fade_out) {
                child->add_property ("default", "yes");
@@ -899,12 +909,6 @@ AudioRegion::_set_state (const XMLNode& node, int version, PropertyChange& what_
                                }
                        }
 
-                       if ((prop = child->property ("is-xfade")) != 0) {
-                               _fade_in_is_xfade = string_is_affirmative (prop->value());
-                       } else {
-                               _fade_in_is_xfade = false;
-                       }
-
                        if ((prop = child->property ("active")) != 0) {
                                if (string_is_affirmative (prop->value())) {
                                        set_fade_in_active (true);
@@ -913,6 +917,14 @@ 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 {
+                               _fade_in_is_xfade = false;
+                       }
+
                } else if (child->name() == "FadeOut") {
 
                        _fade_out->clear ();
@@ -925,14 +937,8 @@ AudioRegion::_set_state (const XMLNode& node, int version, PropertyChange& what_
                                        _fade_out->set_state (*grandchild, version);
                                }
                        }
-
-                       if ((prop = child->property ("is-xfade")) != 0) {
-                               _fade_out_is_xfade = string_is_affirmative (prop->value());
-                       } else {
-                               _fade_out_is_xfade = false;
-                       }
-       
-               if ((prop = child->property ("active")) != 0) {
+                       
+                       if ((prop = child->property ("active")) != 0) {
                                if (string_is_affirmative (prop->value())) {
                                        set_fade_out_active (true);
                                } else {
@@ -940,6 +946,14 @@ AudioRegion::_set_state (const XMLNode& node, int version, PropertyChange& what_
                                }
                        }
 
+                       /* legacy a3 */
+
+                       if ((prop = child->property ("is-xfade")) != 0) {
+                               _fade_out_is_xfade = string_is_affirmative (prop->value());
+                       } else {
+                               _fade_out_is_xfade = false;
+                       }
+                       
                } else if (child->name() == "InvFadeIn") {
                        XMLNode* grandchild = child->child ("AutomationList");
                        if (grandchild) {
@@ -1163,7 +1177,7 @@ AudioRegion::set_fade_in_length (framecnt_t len)
 
                if (_session.config.get_xfade_model() == FullCrossfade &&
                    _session.config.get_auto_xfade() && 
-                   _fade_in_is_xfade) {
+                   _fade_in_is_xfade && !_fade_in_is_short) {
 
                        /* trim a single other region below us to the new start
                           of the fade.
@@ -1202,7 +1216,7 @@ AudioRegion::set_fade_out_length (framecnt_t len)
                
                if (_session.config.get_xfade_model() == FullCrossfade &&
                    _session.config.get_auto_xfade() && 
-                   _fade_out_is_xfade) {
+                   _fade_out_is_xfade && !_fade_out_is_short) {
 
                        /* trim a single other region below us to the new start
                           of the fade.
@@ -1256,6 +1270,7 @@ AudioRegion::set_default_fade_in ()
 {
        _fade_in_suspended = 0;
        _fade_in_is_xfade = false;
+       _fade_in_is_short = true;
        set_fade_in (FadeLinear, 64);
 }
 
@@ -1264,6 +1279,7 @@ AudioRegion::set_default_fade_out ()
 {
        _fade_out_suspended = 0;
        _fade_out_is_xfade = false;
+       _fade_out_is_short = true;
        set_fade_out (FadeLinear, 64);
 }
 
@@ -1835,13 +1851,46 @@ AudioRegion::body_range () const
 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>