remove Glib::ustring from libardour; allow any characters except '/' and '\' in paths...
[ardour.git] / libs / ardour / crossfade.cc
index eb1148fa2cdcf1044be1736683cba99c8ae8e2a2..6b0c0a9560d3248f38d1893364a6c521b3da88f8 100644 (file)
@@ -29,6 +29,7 @@
 #include "ardour/utils.h"
 #include "ardour/session.h"
 #include "ardour/source.h"
+#include "ardour/region_factory.h"
 
 #include "i18n.h"
 #include <locale.h>
@@ -144,8 +145,17 @@ Crossfade::Crossfade (const Playlist& playlist, XMLNode const & node)
 
        PBD::ID id (prop->value());
 
-       if ((r = playlist.find_region (id)) == 0) {
-               error << string_compose (_("Crossfade: no \"in\" region %1 found in playlist %2"), id, playlist.name())
+       r = playlist.find_region (id);
+
+       if (!r) {
+               /* the `in' region is not in a playlist, which probably means that this crossfade
+                  is in the undo record, so we have to find the region in the global region map.
+               */
+               r = RegionFactory::region_by_id (id);
+       }
+       
+       if (!r) {
+               error << string_compose (_("Crossfade: no \"in\" region %1 found in playlist %2 nor in region map"), id, playlist.name())
                      << endmsg;
                throw failed_constructor();
        }
@@ -161,8 +171,14 @@ Crossfade::Crossfade (const Playlist& playlist, XMLNode const & node)
 
        PBD::ID id2 (prop->value());
 
-       if ((r = playlist.find_region (id2)) == 0) {
-               error << string_compose (_("Crossfade: no \"out\" region %1 found in playlist %2"), id2, playlist.name())
+       r = playlist.find_region (id2);
+
+       if (!r) {
+               r = RegionFactory::region_by_id (id2);
+       }
+       
+       if (!r) {
+               error << string_compose (_("Crossfade: no \"out\" region %1 found in playlist %2 nor in region map"), id2, playlist.name())
                      << endmsg;
                throw failed_constructor();
        }
@@ -701,6 +717,8 @@ Crossfade::get_state ()
        char buf[64];
        LocaleGuard lg (X_("POSIX"));
 
+       id().print (buf, sizeof (buf));
+       node->add_property ("id", buf);
        _out->id().print (buf, sizeof (buf));
        node->add_property ("out", buf);
        _in->id().print (buf, sizeof (buf));
@@ -758,6 +776,10 @@ Crossfade::set_state (const XMLNode& node, int /*version*/)
        PropertyChange what_changed;
        framepos_t val;
 
+       if ((prop = node.property (X_("id")))) {
+               _id = prop->value();
+       }
+
        if ((prop = node.property ("position")) != 0) {
                sscanf (prop->value().c_str(), "%" PRId64, &val);
                if (val != _position) {