fix for deferred saves by StateManager-derivatives; changes to new/copy/clear playlis...
[ardour.git] / libs / ardour / insert.cc
index f405af506975663b9485e1768aa1a24708c4a630..1c73ef9d79c9a061eb15853f27e7c8c5e4c92015 100644 (file)
@@ -320,14 +320,14 @@ void
 PluginInsert::automation_snapshot (jack_nframes_t now)
 {
        map<uint32_t,AutomationList*>::iterator li;
-
+       
        for (li = parameter_automation.begin(); li != parameter_automation.end(); ++li) {
                
-               AutomationList& alist (*((*li).second));
-               if (alist.automation_write ()) {
+               AutomationList *alist = ((*li).second);
+               if (alist != 0 && alist->automation_write ()) {
                        
                        float val = _plugins[0]->get_parameter ((*li).first);
-                       alist.rt_add (now, val);
+                       alist->rt_add (now, val);
                        last_automation_snapshot = now;
                }
        }
@@ -597,6 +597,11 @@ PluginInsert::state (bool full)
        node->add_property ("type", _plugins[0]->state_node_name());
        snprintf(buf, sizeof(buf), "%s", _plugins[0]->name());
        node->add_property("id", string(buf));
+       if (_plugins[0]->state_node_name() == "ladspa") {
+               char buf[32];
+               snprintf (buf, 31, "%ld", _plugins[0]->get_info().unique_id); 
+               node->add_property("unique-id", string(buf));
+       }
        node->add_property("count", string_compose("%1", _plugins.size()));
        node->add_child_nocopy (_plugins[0]->get_state());
 
@@ -632,6 +637,7 @@ PluginInsert::set_state(const XMLNode& node)
        XMLNodeIterator niter;
        XMLPropertyList plist;
        const XMLProperty *prop;
+       long unique = 0;
        PluginInfo::Type type;
 
        if ((prop = node.property ("type")) == 0) {
@@ -650,6 +656,11 @@ PluginInsert::set_state(const XMLNode& node)
                return -1;
        }
 
+       prop = node.property ("unique-id");
+       if (prop != 0) {
+               unique = atol(prop->value().c_str());
+       }
+
        if ((prop = node.property ("id")) == 0) {
                error << _("XML node describing insert is missing the `id' field") << endmsg;
                return -1;
@@ -657,7 +668,13 @@ PluginInsert::set_state(const XMLNode& node)
 
        Plugin* plugin;
        
-       if ((plugin = find_plugin (_session, prop->value(), type)) == 0) {
+       if (unique != 0) {
+               plugin = find_plugin (_session, "", unique, type);      
+       } else {
+               plugin = find_plugin (_session, prop->value(), 0, type);        
+       }
+
+       if (plugin == 0) {
                error << string_compose(_("Found a reference to a plugin (\"%1\") that is unknown.\n"
                                   "Perhaps it was removed or moved since it was last used."), prop->value()) 
                      << endmsg;
@@ -751,6 +768,8 @@ PluginInsert::set_state(const XMLNode& node)
                warning << string_compose(_("XML node describing a port automation is missing the `%1' information"), port_automation_node_name) << endmsg;
        }
        
+       // The name of the PluginInsert comes from the plugin, nothing else
+       set_name(plugin->get_info().name,this);
        
        return 0;
 }