modify folder segv fix, opengl pbfr resource conflict fix
[goodguy/history.git] / cinelerra-5.1 / cinelerra / pluginlv2config.C
index 776f9d67b15b53982b14d593a8dbf965465067f4..32721c523dc7a638103ec49d7c598135ff5b488d 100644 (file)
 #include "arraylist.h"
 #include "cstrdup.h"
 #include "language.h"
+#include "pluginlv2.h"
 #include "pluginlv2config.h"
 
 #include <ctype.h>
 #include <string.h>
 
 PluginLV2UriTable::PluginLV2UriTable()
+ : Mutex("PluginLV2UriTable::PluginLV2UriTable")
 {
        set_array_delete();
 }
@@ -40,18 +42,21 @@ PluginLV2UriTable::~PluginLV2UriTable()
 
 LV2_URID PluginLV2UriTable::map(const char *uri)
 {
-       mLock locker(uri_table_lock);
-       for( int i=0; i<size(); ++i )
-               if( !strcmp(uri, get(i)) ) return i+1;
-       append(cstrdup(uri));
-       return size();
+       lock("PluginLV2UriTable::map");
+       int i = 0, n = size();
+       while( i<n && strcmp(uri, get(i)) ) ++i;
+       if( i >= n ) append(cstrdup(uri));
+       unlock();
+       return i+1;
 }
 
 const char *PluginLV2UriTable::unmap(LV2_URID urid)
 {
-       mLock locker(uri_table_lock);
+       lock("PluginLV2UriTable::unmap");
        int idx = urid - 1;
-       return idx>=0 && idx<size() ? get(idx) : 0;
+       const char *ret = idx>=0 && idx<size() ? get(idx) : 0;
+       unlock();
+       return ret;
 }
 
 PluginLV2Client_OptName:: PluginLV2Client_OptName(PluginLV2Client_Opt *opt)
@@ -123,6 +128,7 @@ PluginLV2ClientConfig::PluginLV2ClientConfig()
        mins = 0;
        maxs = 0;
        ctls = 0;
+       ports = 0;
        nb_ports = 0;
 }
 
@@ -138,10 +144,12 @@ void PluginLV2ClientConfig::reset()
                delete [] names[i];
                delete [] syms[i];
        }
-       delete [] names; names = 0;
-       delete [] mins;  mins = 0;
-       delete [] maxs;  maxs = 0;
-       delete [] ctls;  ctls = 0;
+       delete [] names;  names = 0;
+       delete [] syms;   syms = 0;
+       delete [] mins;   mins = 0;
+       delete [] maxs;   maxs = 0;
+       delete [] ctls;   ctls = 0;
+       delete [] ports;  ports = 0;
        nb_ports = 0;
 }
 
@@ -167,6 +175,7 @@ void PluginLV2ClientConfig::copy_from(PluginLV2ClientConfig &that)
                mins  = new float[nb_ports];
                maxs  = new float[nb_ports];
                ctls  = new float[nb_ports];
+               ports = new int[nb_ports];
        }
        for( int i=0; i<nb_ports; ++i ) {
                delete [] names[i];  names[i] = cstrdup(that.names[i]);
@@ -174,6 +183,7 @@ void PluginLV2ClientConfig::copy_from(PluginLV2ClientConfig &that)
                mins[i] = that.mins[i];
                maxs[i] = that.maxs[i];
                ctls[i] = that.ctls[i];
+               ports[i] = ports[i];
        }
        remove_all_objects();
        for( int i=0; i<that.size(); ++i ) {
@@ -187,7 +197,7 @@ void PluginLV2ClientConfig::interpolate(PluginLV2ClientConfig &prev, PluginLV2Cl
        copy_from(prev);
 }
 
-void PluginLV2ClientConfig::init_lv2(const LilvPlugin *lilv)
+void PluginLV2ClientConfig::init_lv2(const LilvPlugin *lilv, PluginLV2 *lv2)
 {
        reset();
        nb_ports = lilv_plugin_get_num_ports(lilv);
@@ -196,6 +206,7 @@ void PluginLV2ClientConfig::init_lv2(const LilvPlugin *lilv)
        mins  = new float[nb_ports];
        maxs  = new float[nb_ports];
        ctls  = new float[nb_ports];
+       ports = new int[nb_ports];
        lilv_plugin_get_port_ranges_float(lilv, mins, maxs, ctls);
        for( int i=0; i<nb_ports; ++i ) {
                const LilvPort *lp = lilv_plugin_get_port_by_index(lilv, i);
@@ -204,6 +215,13 @@ void PluginLV2ClientConfig::init_lv2(const LilvPlugin *lilv)
                lilv_node_free(pnm);
                const LilvNode *sym = lilv_port_get_symbol(lilv, lp);
                syms[i] = cstrdup(lilv_node_as_string(sym));
+               int port = 0;
+               if( lilv_port_is_a(lilv, lp, lv2->lv2_AudioPort) )   port |= PORTS_AUDIO;
+               if( lilv_port_is_a(lilv, lp, lv2->lv2_ControlPort) ) port |= PORTS_CONTROL;
+               if( lilv_port_is_a(lilv, lp, lv2->lv2_InputPort) )   port |= PORTS_INPUT;
+               if( lilv_port_is_a(lilv, lp, lv2->lv2_OutputPort) )  port |= PORTS_OUTPUT;
+               if( lilv_port_is_a(lilv, lp, lv2->atom_AtomPort) )   port |= PORTS_ATOM;
+               ports[i] = port;
        }
 }