summaryrefslogtreecommitdiffstats
path: root/src/libs/client
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2006-12-09 19:08:03 +0000
committerDavid Robillard <d@drobilla.net>2006-12-09 19:08:03 +0000
commitc9fdc9d94f3d6081e36e98f5ae6cc03f361e8057 (patch)
tree8cfe823900c227341a051c0f96d9783dbbb6e64e /src/libs/client
parentd5e8ce8127784fc67953ab3b6247e911be697cc2 (diff)
downloadingen-c9fdc9d94f3d6081e36e98f5ae6cc03f361e8057.tar.gz
ingen-c9fdc9d94f3d6081e36e98f5ae6cc03f361e8057.tar.bz2
ingen-c9fdc9d94f3d6081e36e98f5ae6cc03f361e8057.zip
More loading progress (node positions restore).
git-svn-id: http://svn.drobilla.net/lad/ingen@215 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/libs/client')
-rw-r--r--src/libs/client/Loader.cpp46
-rw-r--r--src/libs/client/Loader.h4
-rw-r--r--src/libs/client/Makefile.am2
-rw-r--r--src/libs/client/Namespaces.cpp43
-rw-r--r--src/libs/client/Namespaces.h44
-rw-r--r--src/libs/client/RDFQuery.cpp6
-rw-r--r--src/libs/client/RDFQuery.h2
7 files changed, 136 insertions, 11 deletions
diff --git a/src/libs/client/Loader.cpp b/src/libs/client/Loader.cpp
index 7816e88a..ac661e58 100644
--- a/src/libs/client/Loader.cpp
+++ b/src/libs/client/Loader.cpp
@@ -23,9 +23,15 @@ namespace Ingen {
namespace Client {
-Loader::Loader(SharedPtr<ModelEngineInterface> engine)
+Loader::Loader(SharedPtr<ModelEngineInterface> engine, SharedPtr<Namespaces> namespaces)
: _engine(engine)
+ , _namespaces(namespaces)
{
+ if (!_namespaces)
+ _namespaces = SharedPtr<Namespaces>(new Namespaces());
+
+ // FIXME: hack
+ _namespaces->add("ingenuity", "http://codeson.net/ns/ingenuity#");
}
@@ -39,16 +45,40 @@ void
Loader::load(const Glib::ustring& filename,
const Path& parent)
{
- RDFQuery query(Glib::ustring("SELECT DISTINCT ?name ?plugin FROM <") + filename + "> WHERE {\n"
- + "?patch ingen:node ?node .\n"
- + "?node ingen:name ?name ;\n"
- + " ingen:plugin ?plugin .\n"
- + "}");
+ std::map<Glib::ustring, bool> created;
+
+ RDFQuery query(Glib::ustring(
+ "SELECT DISTINCT ?name ?plugin ?floatkey ?floatval FROM <") + filename + "> WHERE {\n"
+ "?patch ingen:node ?node .\n"
+ "?node ingen:name ?name ;\n"
+ " ingen:plugin ?plugin ;\n"
+ "OPTIONAL { ?node ?floatkey ?floatval . \n"
+ " FILTER ( datatype(?floatval) = xsd:decimal )\n"
+ " }\n"
+ "}");
RDFQuery::Results nodes = query.run(filename);
- for (RDFQuery::Results::iterator i = nodes.begin(); i != nodes.end(); ++i)
- _engine->create_node(parent.base() + (*i)["name"], (*i)["plugin"], false);
+ for (RDFQuery::Results::iterator i = nodes.begin(); i != nodes.end(); ++i) {
+ const Glib::ustring& name = (*i)["name"];
+ const Glib::ustring& plugin = (*i)["plugin"];
+
+ if (created.find(name) == created.end()) {
+ cerr << "CREATING " << name << endl;
+ _engine->create_node(parent.base() + name, plugin, false);
+ created[name] = true;
+ }
+
+ Glib::ustring floatkey = _namespaces->qualify((*i)["floatkey"]);
+ Glib::ustring floatval = (*i)["floatval"];
+
+ float val = atof(floatval.c_str());
+
+ cerr << floatkey << " = " << val << endl;
+
+ _engine->set_metadata(parent.base() + name, floatkey, Atom(val));
+ }
+
}
diff --git a/src/libs/client/Loader.h b/src/libs/client/Loader.h
index 5fd31d52..3176c2f6 100644
--- a/src/libs/client/Loader.h
+++ b/src/libs/client/Loader.h
@@ -20,6 +20,7 @@
#include <glibmm/ustring.h>
#include "raul/SharedPtr.h"
#include "raul/Path.h"
+#include "Namespaces.h"
namespace Ingen {
namespace Client {
@@ -31,7 +32,7 @@ class ModelEngineInterface;
*/
class Loader {
public:
- Loader(SharedPtr<ModelEngineInterface> engine);
+ Loader(SharedPtr<ModelEngineInterface> engine, SharedPtr<Namespaces> = SharedPtr<Namespaces>());
void load(const Glib::ustring& filename,
const Path& parent);
@@ -39,6 +40,7 @@ public:
private:
//string _patch_search_path;
SharedPtr<ModelEngineInterface> _engine;
+ SharedPtr<Namespaces> _namespaces;
};
diff --git a/src/libs/client/Makefile.am b/src/libs/client/Makefile.am
index 48811414..732dc55c 100644
--- a/src/libs/client/Makefile.am
+++ b/src/libs/client/Makefile.am
@@ -32,6 +32,8 @@ libingenclient_la_SOURCES = \
RDFWriter.cpp \
RDFQuery.h \
RDFQuery.cpp \
+ Namespaces.h \
+ Namespaces.cpp \
Serializer.h \
Serializer.cpp \
Loader.h \
diff --git a/src/libs/client/Namespaces.cpp b/src/libs/client/Namespaces.cpp
new file mode 100644
index 00000000..005cce61
--- /dev/null
+++ b/src/libs/client/Namespaces.cpp
@@ -0,0 +1,43 @@
+/* This file is part of Ingen. Copyright (C) 2006 Dave Robillard.
+ *
+ * Ingen is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "Namespaces.h"
+
+namespace Ingen {
+namespace Client {
+
+
+/** Create a prefixed qname from @a uri, if possible.
+ *
+ * If @a uri can not be qualified with the namespaces currently in this
+ * Namespaces, @a uri will be returned unmodified.
+ */
+string
+Namespaces::qualify(string uri)
+{
+ for (std::map<string,string>::iterator i = _namespaces.begin(); i != _namespaces.end(); ++i) {
+ size_t ns_len = i->second.length();
+
+ if (uri.substr(0, ns_len) == i->second)
+ return i->first + ":" + uri.substr(ns_len);
+ }
+
+ return uri;
+}
+
+
+} // namespace Client
+} // namespace Ingen
diff --git a/src/libs/client/Namespaces.h b/src/libs/client/Namespaces.h
new file mode 100644
index 00000000..100f4e9a
--- /dev/null
+++ b/src/libs/client/Namespaces.h
@@ -0,0 +1,44 @@
+/* This file is part of Ingen. Copyright (C) 2006 Dave Robillard.
+ *
+ * Ingen is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef NAMESPACES_H
+#define NAMESPACES_H
+
+#include <map>
+#include <string>
+using std::string;
+
+namespace Ingen {
+namespace Client {
+
+
+/** Collection of RDF namespaces with prefixes.
+ */
+class Namespaces {
+public:
+ void add(string prefix, string uri) { _namespaces[prefix] = uri; }
+
+ string qualify(string uri);
+
+private:
+ std::map<string, string> _namespaces; ///< (prefix, URI)
+};
+
+
+} // namespace Client
+} // namespace Ingen
+
+#endif // NAMESPACES_H
diff --git a/src/libs/client/RDFQuery.cpp b/src/libs/client/RDFQuery.cpp
index 8e08848a..178e2eba 100644
--- a/src/libs/client/RDFQuery.cpp
+++ b/src/libs/client/RDFQuery.cpp
@@ -19,6 +19,9 @@
#include <rasqal.h>
#include "RDFQuery.h"
+#include <iostream>
+using std::cerr; using std::endl;
+
namespace Ingen {
namespace Client {
@@ -43,10 +46,9 @@ RDFQuery::run(const Glib::ustring filename)
for (int i=0; i < rasqal_query_results_get_bindings_count(results); i++) {
const unsigned char* rname = rasqal_query_results_get_binding_name(results, i);
rasqal_literal* rvalue = rasqal_query_results_get_binding_value(results, i);
-
Glib::ustring name((const char*)rname);
+
Glib::ustring value((const char*)rasqal_literal_as_string(rvalue));
-
bindings.insert(std::make_pair(name, value));
}
diff --git a/src/libs/client/RDFQuery.h b/src/libs/client/RDFQuery.h
index 3e7a1521..e22f3ae7 100644
--- a/src/libs/client/RDFQuery.h
+++ b/src/libs/client/RDFQuery.h
@@ -37,6 +37,8 @@ public:
RDFQuery(Glib::ustring query)
{
const char* const _prefix_header =
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n"
"PREFIX ingen: <http://codeson.net/ns/ingen#>\n"
"PREFIX lv2: <http://lv2plug.in/ontology#>\n";