fix for deferred saves by StateManager-derivatives; changes to new/copy/clear playlis...
[ardour.git] / libs / ardour / insert.cc
index 80bc0ce862b2c40f9f78ae5bb95e1c321f9ad83b..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;
                }
        }
@@ -522,7 +522,7 @@ PluginInsert::plugin_factory (Plugin& other)
 #endif
        }
 
-       fatal << compose (_("programming error: %1"),
+       fatal << string_compose (_("programming error: %1"),
                          X_("unknown plugin type in PluginInsert::plugin_factory"))
              << endmsg;
        /*NOTREACHED*/
@@ -597,7 +597,12 @@ 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));
-       node->add_property("count", compose("%1", _plugins.size()));
+       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());
 
        /* add port automation 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) {
@@ -644,12 +650,17 @@ PluginInsert::set_state(const XMLNode& node)
        } else if (prop->value() == X_("vst")) {
                type = PluginInfo::VST;
        } else {
-               error << compose (_("unknown plugin type %1 in plugin insert state"),
+               error << string_compose (_("unknown plugin type %1 in plugin insert state"),
                                  prop->value())
                      << endmsg;
                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,8 +668,14 @@ PluginInsert::set_state(const XMLNode& node)
 
        Plugin* plugin;
        
-       if ((plugin = find_plugin (_session, prop->value(), type)) == 0) {
-               error << compose(_("Found a reference to a plugin (\"%1\") that is unknown.\n"
+       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;
                return -1;
@@ -701,7 +718,7 @@ PluginInsert::set_state(const XMLNode& node)
        }
 
        if (niter == nlist.end()) {
-               error << compose(_("XML node describing a plugin insert is missing the `%1' information"), plugin->state_node_name()) << endmsg;
+               error << string_compose(_("XML node describing a plugin insert is missing the `%1' information"), plugin->state_node_name()) << endmsg;
                return -1;
        }
        
@@ -748,9 +765,11 @@ PluginInsert::set_state(const XMLNode& node)
        } 
 
        if (niter == nlist.end()) {
-               warning << compose(_("XML node describing a port automation is missing the `%1' information"), port_automation_node_name) << endmsg;
+               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;
 }