summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2008-11-16 21:31:17 +0000
committerDavid Robillard <d@drobilla.net>2008-11-16 21:31:17 +0000
commitf30290370005de12e5061716c5508fc3e552a0ce (patch)
tree6b5d445e26e9bb236cb3a9df5d104003a9aee0a2 /src
parent3ca54a45867cc7a344be1f9a754bb0f17758951a (diff)
downloadingen-f30290370005de12e5061716c5508fc3e552a0ce.tar.gz
ingen-f30290370005de12e5061716c5508fc3e552a0ce.tar.bz2
ingen-f30290370005de12e5061716c5508fc3e552a0ce.zip
Fix shitty LADSPA name clash avoidance (fix ticket #226).
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@1735 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/engine/LADSPANode.cpp54
1 files changed, 29 insertions, 25 deletions
diff --git a/src/engine/LADSPANode.cpp b/src/engine/LADSPANode.cpp
index 4845b62c..7915566a 100644
--- a/src/engine/LADSPANode.cpp
+++ b/src/engine/LADSPANode.cpp
@@ -18,6 +18,7 @@
#include <iostream>
#include <cassert>
#include <cmath>
+#include <map>
#include <stdint.h>
#include "raul/Maid.hpp"
#include <boost/optional.hpp>
@@ -155,35 +156,38 @@ LADSPANode::instantiate()
}
}
- string port_name;
- string port_path;
-
PortImpl* port = NULL;
-
- for (size_t j=0; j < _descriptor->PortCount; ++j) {
- port_name = nameify_if_invalid(_descriptor->PortNames[j]);
-
- string::size_type slash_index;
-
- // Name mangling, to guarantee port names are unique
- for (size_t k=0; k < _descriptor->PortCount; ++k) {
- assert(_descriptor->PortNames[k] != NULL);
- if (k != j && port_name == _descriptor->PortNames[k]) { // clash
- if (LADSPA_IS_PORT_CONTROL(_descriptor->PortDescriptors[j]))
- port_name += "(CR)";
- else
- port_name += "(AR)";
+ std::map<std::string, uint32_t> names;
+
+ for (uint32_t j=0; j < _descriptor->PortCount; ++j) {
+ string port_name = nameify_if_invalid(_descriptor->PortNames[j]);
+
+ string name = port_name;
+ std::map<std::string, uint32_t>::iterator existing = names.find(port_name);
+ uint32_t offset = 2;
+ bool type_clash = false;
+ while (existing != names.end()) {
+ const uint32_t e = existing->second;
+ if (!type_clash && LADSPA_IS_PORT_CONTROL(_descriptor->PortDescriptors[j])
+ && LADSPA_IS_PORT_AUDIO(_descriptor->PortDescriptors[e])) {
+ name = port_name + "_CR";
+ type_clash = true;
+ } else if (!type_clash && LADSPA_IS_PORT_AUDIO(_descriptor->PortDescriptors[j])
+ && LADSPA_IS_PORT_CONTROL(_descriptor->PortDescriptors[e])) {
+ name = port_name + "_AR";
+ type_clash = true;
+ } else {
+ std::ostringstream ss;
+ ss << port_name << "_" << offset;
+ name = ss.str();
}
- // Replace all slashes with "-" (so they don't screw up paths)
- while ((slash_index = port_name.find("/")) != string::npos)
- port_name[slash_index] = '-';
+ existing = names.find(name);
}
-
- /*if (_descriptor->PortNames[j] != port_name)
- cerr << "NOTICE: Translated LADSPA port name: " <<
- _descriptor->PortNames[j] << " -> " << port_name << endl;*/
- port_path = path() + "/" + port_name;
+ port_name = name;
+ names.insert(make_pair(port_name, j));
+
+ string port_path = path() + "/" + port_name;
DataType type = DataType::AUDIO;
port_buffer_size = _buffer_size;