Fix save/load of MIDI automation state. Fixes #3354.
[ardour.git] / libs / ardour / audioregion.cc
index 5f8b35256b7593c423d11e3ac3efcc3dd5d9591b..f0219ce729aa362c978e4bf999223a469d33bdff 100644 (file)
@@ -160,8 +160,10 @@ AudioRegion::AudioRegion (boost::shared_ptr<const AudioRegion> other, nframes64_
        , _automatable (other->session())
        , _fade_in (new AutomationList (*other->_fade_in))
        , _fade_out (new AutomationList (*other->_fade_out))
-         /* XXX is this guaranteed to work for all values of offset+offset_relative? */
-       , _envelope (new AutomationList (*other->_envelope, _start, _start + _length))
+         /* As far as I can see, the _envelope's times are relative to region position, and have nothing
+            to do with sources (and hence _start).  So when we copy the envelope, we just use the supplied offset.
+         */
+       , _envelope (new AutomationList (*other->_envelope, offset, other->_length))
        , _fade_in_suspended (0)
        , _fade_out_suspended (0)
 {
@@ -517,9 +519,9 @@ AudioRegion::_read_at (const SourceList& /*srcs*/, framecnt_t limit,
 }
 
 XMLNode&
-AudioRegion::state (bool full)
+AudioRegion::state ()
 {
-       XMLNode& node (Region::state (full));
+       XMLNode& node (Region::state ());
        XMLNode *child;
        char buf[64];
        LocaleGuard lg (X_("POSIX"));
@@ -527,34 +529,43 @@ AudioRegion::state (bool full)
        snprintf (buf, sizeof (buf), "%u", (uint32_t) _sources.size());
        node.add_property ("channels", buf);
 
-       if (full) {
-               Stateful::add_properties (node);
-       }
+       Stateful::add_properties (node);
 
        child = node.add_child ("Envelope");
 
-       if (full) {
-               bool default_env = false;
-
-               // If there are only two points, the points are in the start of the region and the end of the region
-               // so, if they are both at 1.0f, that means the default region.
-
-               if (_envelope->size() == 2 &&
-                   _envelope->front()->value == 1.0f &&
-                   _envelope->back()->value==1.0f) {
-                       if (_envelope->front()->when == 0 && _envelope->back()->when == _length) {
-                               default_env = true;
-                       }
+       bool default_env = false;
+       
+       // If there are only two points, the points are in the start of the region and the end of the region
+       // so, if they are both at 1.0f, that means the default region.
+       
+       if (_envelope->size() == 2 &&
+           _envelope->front()->value == 1.0f &&
+           _envelope->back()->value==1.0f) {
+               if (_envelope->front()->when == 0 && _envelope->back()->when == _length) {
+                       default_env = true;
                }
+       }
+       
+       if (default_env) {
+               child->add_property ("default", "yes");
+       } else {
+               child->add_child_nocopy (_envelope->get_state ());
+       }
 
-               if (default_env) {
-                       child->add_property ("default", "yes");
-               } else {
-                       child->add_child_nocopy (_envelope->get_state ());
-               }
+       child = node.add_child (X_("FadeIn"));
 
+       if (_default_fade_in) {
+               child->add_property ("default", "yes");
        } else {
+               child->add_child_nocopy (_fade_in->get_state ());
+       }
+
+       child = node.add_child (X_("FadeOut"));
+
+       if (_default_fade_out) {
                child->add_property ("default", "yes");
+       } else {
+               child->add_child_nocopy (_fade_out->get_state ());
        }
 
        return node;