diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/client/Loader.cpp | 46 | ||||
-rw-r--r-- | src/libs/client/Loader.h | 4 | ||||
-rw-r--r-- | src/libs/client/Makefile.am | 2 | ||||
-rw-r--r-- | src/libs/client/Namespaces.cpp | 43 | ||||
-rw-r--r-- | src/libs/client/Namespaces.h | 44 | ||||
-rw-r--r-- | src/libs/client/RDFQuery.cpp | 6 | ||||
-rw-r--r-- | src/libs/client/RDFQuery.h | 2 | ||||
-rw-r--r-- | src/progs/patch_loader/Makefile.am | 4 | ||||
-rw-r--r-- | src/progs/patch_loader/patch_loader.cpp | 12 |
9 files changed, 143 insertions, 20 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"; diff --git a/src/progs/patch_loader/Makefile.am b/src/progs/patch_loader/Makefile.am index 5b5d5db9..da9ba356 100644 --- a/src/progs/patch_loader/Makefile.am +++ b/src/progs/patch_loader/Makefile.am @@ -1,7 +1,7 @@ EXTRA_DIST = README -ingen_load_CXXFLAGS = -I$(top_srcdir)/src/libs/client -I$(top_srcdir)/src/common @LSIGCPP_CFLAGS@ @RAUL_CFLAGS@ -ingen_load_LDADD = ../../libs/client/libingenclient.la @RAUL_LIBS@ @LSIGCPP_LIBS@ +ingen_load_CXXFLAGS = -I$(top_srcdir)/src/libs/client -I$(top_srcdir)/src/common @LSIGCPP_CFLAGS@ @RAUL_CFLAGS@ @GLIBMM_CFLAGS@ @RASQAL_CFLAGS@ +ingen_load_LDADD = ../../libs/client/libingenclient.la @RAUL_LIBS@ @LSIGCPP_LIBS@ @GLIBMM_LIBS@ @RASQAL_LIBS@ bin_PROGRAMS = ingen_load diff --git a/src/progs/patch_loader/patch_loader.cpp b/src/progs/patch_loader/patch_loader.cpp index eb222c33..ab5c2c53 100644 --- a/src/progs/patch_loader/patch_loader.cpp +++ b/src/progs/patch_loader/patch_loader.cpp @@ -14,9 +14,8 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - #include "OSCModelEngineInterface.h" -//#include "Serializer.h" +#include "Loader.h" #include "PatchModel.h" #include "raul/Path.h" #include <iostream> @@ -53,7 +52,7 @@ int main(int argc, char** argv) SharedPtr<OSCModelEngineInterface> engine(new OSCModelEngineInterface(engine_url)); - //Serializer serializer(engine); + Loader loader(engine); /* Connect to engine */ engine->attach(-1, client_port); @@ -71,10 +70,9 @@ int main(int argc, char** argv) // Load patches for (uint i=0; i < args_info.inputs_num; ++i) { - cerr << "FIXME: load patch" << endl; - //SharedPtr<PatchModel> pm(new PatchModel("", 0)); - //pm->filename(args_info.inputs[i]); - //serializer.load_patch(pm, true); + cerr << "FIXME: load patch under root" << endl; + cerr << "Load " << args_info.inputs[i] << endl; + loader.load(args_info.inputs[i], "/"); } return 0; |