fix crash when copy'ing latent plugins
[ardour.git] / libs / ardour / event_type_map.cc
index 14f609bd8a5615d0634bac6f1fc8885c5d69527d..28f688df8124a0f656decbfb853c1a403987e60b 100644 (file)
@@ -22,6 +22,7 @@
 #include <cstdio>
 #include "ardour/types.h"
 #include "ardour/event_type_map.h"
+#include "ardour/parameter_descriptor.h"
 #include "ardour/parameter_types.h"
 #include "ardour/uri_map.h"
 #include "evoral/Parameter.hpp"
@@ -40,7 +41,11 @@ EventTypeMap&
 EventTypeMap::instance()
 {
        if (!EventTypeMap::event_type_map) {
-               EventTypeMap::event_type_map = new EventTypeMap(URIMap::instance());
+#ifdef LV2_SUPPORT
+               EventTypeMap::event_type_map = new EventTypeMap(&URIMap::instance());
+#else
+               EventTypeMap::event_type_map = new EventTypeMap(NULL);
+#endif
        }
        return *EventTypeMap::event_type_map;
 }
@@ -125,6 +130,8 @@ EventTypeMap::from_symbol(const string& str) const
 
        if (str == "gain") {
                p_type = GainAutomation;
+       } else if (str == "trim") {
+               p_type = TrimAutomation;
        } else if (str == "solo") {
                p_type = SoloAutomation;
        } else if (str == "mute") {
@@ -148,14 +155,16 @@ EventTypeMap::from_symbol(const string& str) const
        } else if (str.length() > 10 && str.substr(0, 10) == "parameter-") {
                p_type = PluginAutomation;
                p_id = atoi(str.c_str()+10);
+#ifdef LV2_SUPPORT
        } else if (str.length() > 9 && str.substr(0, 9) == "property-") {
                p_type = PluginPropertyAutomation;
                const char* name = str.c_str() + 9;
                if (isdigit(str.c_str()[0])) {
                        p_id = atoi(name);
                } else {
-                       p_id = _uri_map.uri_to_id(name);
+                       p_id = _uri_map->uri_to_id(name);
                }
+#endif
        } else if (str.length() > 7 && str.substr(0, 7) == "midicc-") {
                p_type = MidiCCAutomation;
                uint32_t channel = 0;
@@ -186,7 +195,7 @@ EventTypeMap::from_symbol(const string& str) const
        } else {
                PBD::warning << "Unknown Parameter '" << str << "'" << endmsg;
        }
-       
+
        return Evoral::Parameter(p_type, p_channel, p_id);
 }
 
@@ -200,6 +209,8 @@ EventTypeMap::to_symbol(const Evoral::Parameter& param) const
 
        if (t == GainAutomation) {
                return "gain";
+       } else if (t == TrimAutomation) {
+                return "trim";
        } else if (t == PanAzimuthAutomation) {
                 return "pan-azimuth";
        } else if (t == PanElevationAutomation) {
@@ -222,13 +233,15 @@ EventTypeMap::to_symbol(const Evoral::Parameter& param) const
                return "envelope";
        } else if (t == PluginAutomation) {
                return string_compose("parameter-%1", param.id());
+#ifdef LV2_SUPPORT
        } else if (t == PluginPropertyAutomation) {
-               const char* uri = _uri_map.id_to_uri(param.id());
+               const char* uri = _uri_map->id_to_uri(param.id());
                if (uri) {
                        return string_compose("property-%1", uri);
                } else {
                        return string_compose("property-%1", param.id());
                }
+#endif
        } else if (t == MidiCCAutomation) {
                return string_compose("midicc-%1-%2", int(param.channel()), param.id());
        } else if (t == MidiPgmChangeAutomation) {
@@ -243,13 +256,17 @@ EventTypeMap::to_symbol(const Evoral::Parameter& param) const
        }
 }
 
-const Evoral::ParameterDescriptor&
+Evoral::ParameterDescriptor
 EventTypeMap::descriptor(const Evoral::Parameter& param) const
 {
-       static const Evoral::ParameterDescriptor nil;
-
+       // Found an existing (perhaps custom) descriptor
        Descriptors::const_iterator d = _descriptors.find(param);
-       return (d != _descriptors.end()) ? d->second : nil;
+       if (d != _descriptors.end()) {
+               return d->second;
+       }
+
+       // Add default descriptor and return that
+       return ARDOUR::ParameterDescriptor(param);
 }
 
 void