summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/Builder.cpp44
-rw-r--r--src/shared/Builder.hpp7
-rw-r--r--src/shared/ClashAvoider.cpp51
-rw-r--r--src/shared/ClashAvoider.hpp6
4 files changed, 60 insertions, 48 deletions
diff --git a/src/shared/Builder.cpp b/src/shared/Builder.cpp
index 28833fc9..3bd9e75a 100644
--- a/src/shared/Builder.cpp
+++ b/src/shared/Builder.cpp
@@ -36,56 +36,68 @@ Builder::Builder(CommonInterface& interface)
void
-Builder::build(const Raul::Path& prefix, SharedPtr<const GraphObject> object)
+Builder::build(SharedPtr<const GraphObject> object)
{
SharedPtr<const Patch> patch = PtrCast<const Patch>(object);
if (patch) {
if (object->path() != "/") {
- const string path_str = prefix.base() + object->path().substr(1);
+ const string path_str = object->path();
_interface.new_patch(path_str, patch->internal_polyphony());
}
- build_object(prefix, object);
- for (Patch::Connections::const_iterator i = patch->connections().begin();
+ build_object(object);
+ /*for (Patch::Connections::const_iterator i = patch->connections().begin();
i != patch->connections().end(); ++i) {
- string base = prefix.base() + object->path().substr(1);
- _interface.connect(base + (*i)->src_port_path().substr(1),
- base + (*i)->dst_port_path().substr(1));
- }
+ _interface.connect((*i)->src_port_path(), (*i)->dst_port_path());
+ }*/
return;
}
SharedPtr<const Node> node = PtrCast<const Node>(object);
if (node) {
- Raul::Path path = prefix.base() + node->path().substr(1);
+ Raul::Path path = node->path();
_interface.new_node(path, node->plugin()->uri());
- build_object(prefix, object);
+ build_object(object);
return;
}
SharedPtr<const Port> port = PtrCast<const Port>(object);
if (port) {
- Raul::Path path = prefix.base() + port->path().substr(1);
+ Raul::Path path = port->path();
_interface.new_port(path, port->type().uri(), port->index(), !port->is_input());
- build_object(prefix, object);
+ build_object(object);
+ return;
+ }
+}
+
+
+void
+Builder::connect(SharedPtr<const GraphObject> object)
+{
+ SharedPtr<const Patch> patch = PtrCast<const Patch>(object);
+ if (patch) {
+ for (Patch::Connections::const_iterator i = patch->connections().begin();
+ i != patch->connections().end(); ++i) {
+ _interface.connect((*i)->src_port_path(), (*i)->dst_port_path());
+ }
return;
}
}
void
-Builder::build_object(const Raul::Path& prefix, SharedPtr<const GraphObject> object)
+Builder::build_object(SharedPtr<const GraphObject> object)
{
for (GraphObject::Variables::const_iterator i = object->variables().begin();
i != object->variables().end(); ++i)
- _interface.set_variable(prefix.base() + object->path().substr(1), i->first, i->second);
+ _interface.set_variable(object->path(), i->first, i->second);
for (GraphObject::Properties::const_iterator i = object->properties().begin();
i != object->properties().end(); ++i) {
if (object->path() == "/")
continue;
- string path_str = prefix.base() + object->path().substr(1);
- _interface.set_property(prefix.base() + object->path().substr(1), i->first, i->second);
+ string path_str = object->path();
+ _interface.set_property(object->path(), i->first, i->second);
}
}
diff --git a/src/shared/Builder.hpp b/src/shared/Builder.hpp
index f4b33538..c49937fe 100644
--- a/src/shared/Builder.hpp
+++ b/src/shared/Builder.hpp
@@ -39,12 +39,11 @@ public:
Builder(CommonInterface& interface);
virtual ~Builder() {}
- void build(const Raul::Path& prefix,
- SharedPtr<const GraphObject> object);
+ void build(SharedPtr<const GraphObject> object);
+ void connect(SharedPtr<const GraphObject> object);
private:
- void build_object(const Raul::Path& prefix,
- SharedPtr<const GraphObject> object);
+ void build_object(SharedPtr<const GraphObject> object);
CommonInterface& _interface;
};
diff --git a/src/shared/ClashAvoider.cpp b/src/shared/ClashAvoider.cpp
index 637872ef..10d22d5d 100644
--- a/src/shared/ClashAvoider.cpp
+++ b/src/shared/ClashAvoider.cpp
@@ -28,7 +28,8 @@ namespace Shared {
const Raul::Path
ClashAvoider::map_path(const Raul::Path& in)
{
- //cout << "MAP PATH: " << in << endl;
+ //cout << "MAP PATH: " << in;
+ //cout << endl << "**** MAP PATH: " << in << endl;
unsigned offset = 0;
bool has_offset = false;
@@ -38,14 +39,14 @@ ClashAvoider::map_path(const Raul::Path& in)
has_offset = (sscanf(trailing.c_str(), "%u", &offset) > 0);
}
- //cout << "HAS OFFSET: " << offset << endl;
+ //cout << "OFFSET: " << offset << endl;
// Path without _n suffix
Path base_path = in;
if (has_offset)
base_path = base_path.substr(0, base_path.find_last_of("_"));
- //cout << "\tBASE: " << base_path << endl;
+ //cout << "BASE: " << base_path << endl;
SymbolMap::iterator m = _symbol_map.find(in);
if (m != _symbol_map.end()) {
@@ -53,36 +54,36 @@ ClashAvoider::map_path(const Raul::Path& in)
return m->second;
} else {
typedef std::pair<SymbolMap::iterator, bool> InsertRecord;
+
+ // See if parent is mapped
+ Path parent = in.parent();
+ do {
+ //cout << "CHECK: " << parent << endl;
+ SymbolMap::iterator p = _symbol_map.find(parent);
+ if (p != _symbol_map.end()) {
+ const Path mapped = p->second.base() + in.substr(parent.base().length());
+ InsertRecord i = _symbol_map.insert(make_pair(in, mapped));
+ //cout << " (2) " << i.first->second << endl;
+ return i.first->second;
+ }
+ parent = parent.parent();
+ } while (parent != "/");
// No clash, use symbol unmodified
if (!exists(in) && _symbol_map.find(in) == _symbol_map.end()) {
InsertRecord i = _symbol_map.insert(make_pair(in, in));
assert(i.second);
- //cout << " (2) " << i.first->second << endl;;
+ //cout << " (3) " << i.first->second << endl;;
return i.first->second;
+
+ // Append _2 _3 etc until an unused symbol is found
} else {
-
- // See if the parent is mapped
- // FIXME: do this the other way around
- Path parent = in.parent();
- do {
- SymbolMap::iterator p = _symbol_map.find(parent);
- if (p != _symbol_map.end()) {
- const Path mapped = p->second.base() + in.substr(parent.base().length());
- InsertRecord i = _symbol_map.insert(make_pair(in, mapped));
- //cout << " (3) " << _prefix.base() + i.first->second.substr(1) << endl;
- return i.first->second;
- }
- parent = parent.parent();
- } while (parent != "/");
-
- // Append _2 _3 etc until an unused symbol is found
while (true) {
Offsets::iterator o = _offsets.find(base_path);
if (o != _offsets.end()) {
offset = ++o->second;
} else {
- string parent_str = _prefix.base() + in.parent().base().substr(1);
+ string parent_str = in.parent().base();
parent_str = parent_str.substr(0, parent_str.find_last_of("/"));
if (parent_str == "")
parent_str = "/";
@@ -95,10 +96,11 @@ ClashAvoider::map_path(const Raul::Path& in)
std::stringstream ss;
ss << base_path << "_" << offset;
if (!exists(ss.str())) {
+ const string name = (base_path.length() > 1) ? base_path.name() : "_";
string str = ss.str();
InsertRecord i = _symbol_map.insert(make_pair(in, str));
//cout << "HIT: offset = " << offset << ", str = " << str << endl;
- offset = _store.child_name_offset(in.parent(), base_path.name(), false);
+ offset = _store.child_name_offset(in.parent(), name, false);
_offsets.insert(make_pair(base_path, offset));
//cout << " (4) " << i.first->second << endl;;
return i.first->second;
@@ -118,7 +120,7 @@ ClashAvoider::map_path(const Raul::Path& in)
bool
ClashAvoider::exists(const Raul::Path& path) const
{
- bool exists = (_store.find(_prefix.base() + path.substr(1)) != _store.end());
+ bool exists = (_store.find(path) != _store.end());
if (exists)
return true;
@@ -140,7 +142,8 @@ void
ClashAvoider::new_patch(const std::string& path,
uint32_t poly)
{
- _target.new_patch(map_path(path), poly);
+ if (path != "/")
+ _target.new_patch(map_path(path), poly);
}
diff --git a/src/shared/ClashAvoider.hpp b/src/shared/ClashAvoider.hpp
index efdebf98..91c58c0e 100644
--- a/src/shared/ClashAvoider.hpp
+++ b/src/shared/ClashAvoider.hpp
@@ -37,9 +37,8 @@ class Store;
class ClashAvoider : public CommonInterface
{
public:
- ClashAvoider(Store& store, const Raul::Path& prefix, CommonInterface& target,
- Store* also_avoid=NULL)
- : _prefix(prefix), _store(store), _target(target), _also_avoid(also_avoid) {}
+ ClashAvoider(Store& store, CommonInterface& target, Store* also_avoid=NULL)
+ : _store(store), _target(target), _also_avoid(also_avoid) {}
void set_target(CommonInterface& target) { _target = target; }
@@ -88,7 +87,6 @@ public:
private:
const Raul::Path map_path(const Raul::Path& in);
- const Raul::Path& _prefix;
Store& _store;
CommonInterface& _target;