summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2006-12-12 23:30:38 +0000
committerDavid Robillard <d@drobilla.net>2006-12-12 23:30:38 +0000
commitf63c29df622dd4f4fde6de3906ec53765117fb79 (patch)
tree7e0731aa77fb3629ec9b517757135919c7e99b9f
parent71f632d459471c2e75ed04b808df9671539a182c (diff)
downloadingen-f63c29df622dd4f4fde6de3906ec53765117fb79.tar.gz
ingen-f63c29df622dd4f4fde6de3906ec53765117fb79.tar.bz2
ingen-f63c29df622dd4f4fde6de3906ec53765117fb79.zip
Loading subpatches (ie not just into root).
Initial patch metadata. Subpatch browsing (via double clicking modules). git-svn-id: http://svn.drobilla.net/lad/ingen@218 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--src/libs/client/Loader.cpp124
-rw-r--r--src/libs/client/Loader.h7
-rw-r--r--src/libs/client/RDFQuery.cpp12
-rw-r--r--src/libs/client/RDFQuery.h2
-rw-r--r--src/progs/ingenuity/NodeModule.cpp10
-rw-r--r--src/progs/ingenuity/PatchPortModule.cpp8
-rw-r--r--src/progs/ingenuity/ThreadedLoader.cpp4
7 files changed, 118 insertions, 49 deletions
diff --git a/src/libs/client/Loader.cpp b/src/libs/client/Loader.cpp
index e1590540..68b04b58 100644
--- a/src/libs/client/Loader.cpp
+++ b/src/libs/client/Loader.cpp
@@ -15,6 +15,7 @@
*/
#include <iostream>
+#include <raptor.h>
#include "Loader.h"
#include "RDFQuery.h"
#include "ModelEngineInterface.h"
@@ -42,36 +43,85 @@ Loader::Loader(SharedPtr<ModelEngineInterface> engine, SharedPtr<Namespaces> nam
* @param parent Path of parent under which to load objects.
* @return whether or not load was successful.
*/
-void
+bool
Loader::load(const Glib::ustring& filename,
- const Path& parent)
+ const Path& parent,
+ Glib::ustring patch_uri,
+ MetadataMap data)
{
+ // FIXME: this whole thing is a mess
+
std::map<Glib::ustring, bool> created;
+ // FIXME: kluge
+ unsigned char* document_uri_str = raptor_uri_filename_to_uri_string(filename.c_str());
+ Glib::ustring document_uri = (const char*)document_uri_str;
+ //Glib::ustring document_uri = "file:///home/dave/code/codesonnet/ingen/src/progs/ingenuity/test2.ingen.ttl";
+
+ if (patch_uri == "")
+ patch_uri = "<>";
+
+ cerr << "[Loader] Loading " << patch_uri << " from " << document_uri
+ << " under " << parent << endl;
+
+ /* Get polyphony (mandatory) */
+
+ // FIXME: polyphony datatype
+ RDFQuery query(Glib::ustring(
+ "SELECT DISTINCT ?poly \nFROM <") + document_uri + ">\nWHERE {\n\t" +
+ patch_uri + " ingen:polyphony ?poly .\n"
+ "}");
+
+ RDFQuery::Results results = query.run(document_uri);
+
+ if (results.size() == 0) {
+ cerr << "[Loader] ERROR: No polyphony found!" << endl;
+ return false;
+ }
+
+ size_t patch_poly = atoi(((*results.begin())["poly"]).c_str());
+
+
+ /* Get name (if available) */
+
+ query = RDFQuery(Glib::ustring(
+ "SELECT DISTINCT ?name \nFROM <") + document_uri + ">\nWHERE {\n\t" +
+ patch_uri + " ingen:name ?name .\n"
+ "}");
+
+ results = query.run(document_uri);
+
+ string patch_name = string(filename.substr(filename.find_last_of("/")+1));
+ Path patch_path = parent.base() + string(filename.substr(filename.find_last_of("/")+1));
+
+ if (results.size() > 0)
+ patch_path = parent.base() + string((*results.begin())["name"]);
+
+ cerr << "************ PATCH: " << patch_path << ", poly = " << patch_poly << endl;
+
+ _engine->create_patch(patch_path, patch_poly);
+
/* Load nodes */
- RDFQuery query(Glib::ustring(
- "SELECT DISTINCT ?patch ?name ?plugin ?floatkey ?floatval FROM <") + filename + "> WHERE {\n"
- "?patch ingen:node ?node .\n"
- "?node ingen:name ?name ;\n"
- " ingen:plugin ?plugin ;\n"
+ query = RDFQuery(Glib::ustring(
+ "SELECT DISTINCT ?name ?plugin ?floatkey ?floatval FROM <") + document_uri + "> WHERE {\n" +
+ patch_uri + " ingen:node ?node .\n"
+ "?node ingen:name ?name ;\n"
+ " ingen:plugin ?plugin .\n"
"OPTIONAL { ?node ?floatkey ?floatval . \n"
" FILTER ( datatype(?floatval) = xsd:decimal ) }\n"
"}");
- RDFQuery::Results nodes = query.run(filename);
+ results = query.run(document_uri);
- for (RDFQuery::Results::iterator i = nodes.begin(); i != nodes.end(); ++i) {
+ for (RDFQuery::Results::iterator i = results.begin(); i != results.end(); ++i) {
- const Glib::ustring& patch = (*i)["patch"];
const Glib::ustring& name = (*i)["name"];
const Glib::ustring& plugin = (*i)["plugin"];
- cerr << "LOADING NODE IN PATCH : " << patch << endl;
-
if (created.find(name) == created.end()) {
- _engine->create_node(parent.base() + name, plugin, false);
+ _engine->create_node(patch_path.base() + name, plugin, false);
created[name] = true;
}
@@ -80,28 +130,28 @@ Loader::load(const Glib::ustring& filename,
if (floatkey != "" && floatval != "") {
const float val = atof(floatval.c_str());
- _engine->set_metadata(parent.base() + name, floatkey, Atom(val));
+ _engine->set_metadata(patch_path.base() + name, floatkey, Atom(val));
}
}
created.clear();
- /* Load patch ports */
+ /* Load this patch's ports */
query = RDFQuery(Glib::ustring(
- "SELECT DISTINCT ?port ?type ?name ?datatype ?floatkey ?floatval FROM <") + filename + "> WHERE {\n"
- "?patch ingen:port ?port .\n"
- "?port a ?type ;\n"
- " ingen:name ?name ;\n"
- " ingen:dataType ?datatype .\n"
+ "SELECT DISTINCT ?port ?type ?name ?datatype ?floatkey ?floatval FROM <") + document_uri + "> WHERE {\n" +
+ patch_uri + " ingen:port ?port .\n"
+ "?port a ?type ;\n"
+ " ingen:name ?name ;\n"
+ " ingen:dataType ?datatype .\n"
"OPTIONAL { ?port ?floatkey ?floatval . \n"
" FILTER ( datatype(?floatval) = xsd:decimal ) }\n"
"}");
- RDFQuery::Results ports = query.run(filename);
+ results = query.run(document_uri);
- for (RDFQuery::Results::iterator i = ports.begin(); i != ports.end(); ++i) {
+ for (RDFQuery::Results::iterator i = results.begin(); i != results.end(); ++i) {
const Glib::ustring& name = (*i)["name"];
const Glib::ustring& type = _namespaces->qualify((*i)["type"]);
const Glib::ustring& datatype = (*i)["datatype"];
@@ -109,7 +159,7 @@ Loader::load(const Glib::ustring& filename,
if (created.find(name) == created.end()) {
//cerr << "TYPE: " << type << endl;
bool is_output = (type == "ingen:OutputPort"); // FIXME: check validity
- _engine->create_port(parent.base() + name, datatype, is_output);
+ _engine->create_port(patch_path.base() + name, datatype, is_output);
created[name] = true;
}
@@ -118,14 +168,15 @@ Loader::load(const Glib::ustring& filename,
if (floatkey != "" && floatval != "") {
const float val = atof(floatval.c_str());
- _engine->set_metadata(parent.base() + name, floatkey, Atom(val));
+ _engine->set_metadata(patch_path.base() + name, floatkey, Atom(val));
}
}
/* Load connections */
+ // FIXME: path?
query = RDFQuery(Glib::ustring(
- "SELECT DISTINCT ?srcnode ?src ?dstnode ?dst FROM <") + filename + "> WHERE {\n"
+ "SELECT DISTINCT ?srcnode ?src ?dstnode ?dst FROM <") + document_uri + "> WHERE {\n" +
"?srcnoderef ingen:port ?srcref .\n"
"?dstnoderef ingen:port ?dstref .\n"
"?dstref ingen:connectedTo ?srcref .\n"
@@ -135,28 +186,29 @@ Loader::load(const Glib::ustring& filename,
"OPTIONAL { ?dstnoderef ingen:name ?dstnode }\n"
"}\n");
- cerr << "*************\n" << query.string() << "*****************\n";
-
- RDFQuery::Results connections = query.run(filename);
+ results = query.run(document_uri);
- for (RDFQuery::Results::iterator i = connections.begin(); i != connections.end(); ++i) {
- // FIXME: kludge
- Path src_node = string("/");
+ for (RDFQuery::Results::iterator i = results.begin(); i != results.end(); ++i) {
+ Path src_node = patch_path;
if ((*i).find("srcnode") != (*i).end())
- src_node += string((*i)["srcnode"]);
+ src_node = patch_path.base() + string((*i)["srcnode"]);
Path src_port = src_node.base() + string((*i)["src"]);
- Path dst_node = string("/");
+ Path dst_node = patch_path;
if ((*i).find("dstnode") != (*i).end())
- dst_node += string((*i)["dstnode"]);
+ dst_node = patch_path.base() + string((*i)["dstnode"]);
Path dst_port = dst_node.base() + string((*i)["dst"]);
- cerr << "CONNECTION: " << src_port << " -> " << dst_port << endl;
+ //cerr << "CONNECTION: " << src_port << " -> " << dst_port << endl;
_engine->connect(src_port, dst_port);
}
+
+ // Set passed metadata last to override any loaded values
+ for (MetadataMap::const_iterator i = data.begin(); i != data.end(); ++i)
+ _engine->set_metadata(patch_path, i->first, i->second);
-
+ return true;
}
diff --git a/src/libs/client/Loader.h b/src/libs/client/Loader.h
index 3176c2f6..86317c1f 100644
--- a/src/libs/client/Loader.h
+++ b/src/libs/client/Loader.h
@@ -21,6 +21,7 @@
#include "raul/SharedPtr.h"
#include "raul/Path.h"
#include "Namespaces.h"
+#include "ObjectModel.h"
namespace Ingen {
namespace Client {
@@ -34,8 +35,10 @@ class Loader {
public:
Loader(SharedPtr<ModelEngineInterface> engine, SharedPtr<Namespaces> = SharedPtr<Namespaces>());
- void load(const Glib::ustring& filename,
- const Path& parent);
+ bool load(const Glib::ustring& filename,
+ const Path& parent,
+ Glib::ustring patch_uri = "",
+ MetadataMap initial_data = MetadataMap());
private:
//string _patch_search_path;
diff --git a/src/libs/client/RDFQuery.cpp b/src/libs/client/RDFQuery.cpp
index 3993de20..196868b8 100644
--- a/src/libs/client/RDFQuery.cpp
+++ b/src/libs/client/RDFQuery.cpp
@@ -27,7 +27,7 @@ namespace Client {
RDFQuery::Results
-RDFQuery::run(const Glib::ustring filename) const
+RDFQuery::run(const Glib::ustring base_uri_str) const
{
Results result;
@@ -35,7 +35,11 @@ RDFQuery::run(const Glib::ustring filename) const
rasqal_query *rq = rasqal_new_query("sparql", NULL);
- rasqal_query_prepare(rq, (unsigned char*)_query.c_str(), NULL);
+ raptor_uri* base_uri = NULL;
+ if (base_uri_str != "")
+ base_uri = raptor_new_uri((const unsigned char*)base_uri_str.c_str());
+ rasqal_query_prepare(rq, (unsigned char*)_query.c_str(), base_uri);
+
rasqal_query_results* results = rasqal_query_execute(rq);
assert(results);
@@ -62,6 +66,10 @@ RDFQuery::run(const Glib::ustring filename) const
rasqal_free_query_results(results);
rasqal_free_query(rq);
+
+ if (base_uri)
+ raptor_free_uri(base_uri);
+
rasqal_finish();
return result;
diff --git a/src/libs/client/RDFQuery.h b/src/libs/client/RDFQuery.h
index 990d9e4f..065664e9 100644
--- a/src/libs/client/RDFQuery.h
+++ b/src/libs/client/RDFQuery.h
@@ -45,7 +45,7 @@ public:
_query = _prefix_header + query;
}
- Results run(const Glib::ustring filename) const;
+ Results run(const Glib::ustring base_uri) const;
Glib::ustring string() const { return _query; };
diff --git a/src/progs/ingenuity/NodeModule.cpp b/src/progs/ingenuity/NodeModule.cpp
index 73b87b5b..bec6e89c 100644
--- a/src/progs/ingenuity/NodeModule.cpp
+++ b/src/progs/ingenuity/NodeModule.cpp
@@ -27,6 +27,7 @@
#include "RenameWindow.h"
#include "PatchWindow.h"
#include "WindowFactory.h"
+#include "SubpatchModule.h"
namespace Ingenuity {
@@ -51,8 +52,13 @@ NodeModule::NodeModule(boost::shared_ptr<PatchCanvas> canvas, SharedPtr<NodeMode
boost::shared_ptr<NodeModule>
NodeModule::create(boost::shared_ptr<PatchCanvas> canvas, SharedPtr<NodeModel> node)
{
- boost::shared_ptr<NodeModule> ret = boost::shared_ptr<NodeModule>(
- new NodeModule(canvas, node));
+ boost::shared_ptr<NodeModule> ret;
+
+ SharedPtr<PatchModel> patch = PtrCast<PatchModel>(node);
+ if (patch)
+ ret = boost::shared_ptr<NodeModule>(new SubpatchModule(canvas, patch));
+ else
+ ret = boost::shared_ptr<NodeModule>(new NodeModule(canvas, node));
for (MetadataMap::const_iterator m = node->metadata().begin(); m != node->metadata().end(); ++m)
ret->metadata_update(m->first, m->second);
diff --git a/src/progs/ingenuity/PatchPortModule.cpp b/src/progs/ingenuity/PatchPortModule.cpp
index 315aacab..e1fb37a8 100644
--- a/src/progs/ingenuity/PatchPortModule.cpp
+++ b/src/progs/ingenuity/PatchPortModule.cpp
@@ -68,13 +68,13 @@ PatchPortModule::create(boost::shared_ptr<PatchCanvas> canvas, SharedPtr<PortMod
new PatchPortModule(canvas, port));
assert(ret);
- for (MetadataMap::const_iterator m = port->metadata().begin(); m != port->metadata().end(); ++m)
- ret->metadata_update(m->first, m->second);
-
- ret->m_patch_port = boost::shared_ptr<Port>(new Port(ret->shared_from_this(), port, true));
+ ret->m_patch_port = boost::shared_ptr<Port>(new Port(ret, port, true));
ret->add_port(ret->m_patch_port);
ret->resize();
+
+ for (MetadataMap::const_iterator m = port->metadata().begin(); m != port->metadata().end(); ++m)
+ ret->metadata_update(m->first, m->second);
return ret;
}
diff --git a/src/progs/ingenuity/ThreadedLoader.cpp b/src/progs/ingenuity/ThreadedLoader.cpp
index fbd64d3d..a3920665 100644
--- a/src/progs/ingenuity/ThreadedLoader.cpp
+++ b/src/progs/ingenuity/ThreadedLoader.cpp
@@ -73,9 +73,9 @@ ThreadedLoader::load_patch(bool merge,
cerr << "FIXME: load under root only\n";
- _events.push_back(sigc::bind(
+ _events.push_back(sigc::hide_return(sigc::bind(
sigc::mem_fun(_loader, &Loader::load),
- data_base_uri, "/"));
+ data_base_uri, "/", "", engine_data)));
_mutex.unlock();