summaryrefslogtreecommitdiffstats
path: root/src/libs/client
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2006-12-11 22:32:31 +0000
committerDavid Robillard <d@drobilla.net>2006-12-11 22:32:31 +0000
commit9e2a757e026abf79d0cdcf12a18796fa89973356 (patch)
treeb739d65e9d15415b5fbfd1e9969e2efd7b498c25 /src/libs/client
parentc9fdc9d94f3d6081e36e98f5ae6cc03f361e8057 (diff)
downloadingen-9e2a757e026abf79d0cdcf12a18796fa89973356.tar.gz
ingen-9e2a757e026abf79d0cdcf12a18796fa89973356.tar.bz2
ingen-9e2a757e026abf79d0cdcf12a18796fa89973356.zip
Serialization of patch ports.
git-svn-id: http://svn.drobilla.net/lad/ingen@216 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/libs/client')
-rw-r--r--src/libs/client/DeprecatedSerializer.cpp12
-rw-r--r--src/libs/client/Loader.cpp54
-rw-r--r--src/libs/client/PortModel.h39
-rw-r--r--src/libs/client/RDFQuery.cpp2
-rw-r--r--src/libs/client/RDFQuery.h4
-rw-r--r--src/libs/client/Serializer.cpp2
-rw-r--r--src/libs/client/Store.cpp10
7 files changed, 80 insertions, 43 deletions
diff --git a/src/libs/client/DeprecatedSerializer.cpp b/src/libs/client/DeprecatedSerializer.cpp
index d3d5a09f..b8156a95 100644
--- a/src/libs/client/DeprecatedSerializer.cpp
+++ b/src/libs/client/DeprecatedSerializer.cpp
@@ -425,22 +425,22 @@ DeprecatedSerializer::load_node(const Path& parent, xmlDocPtr doc, const xmlNode
if (plugin_type == "Internal") {
if (plugin_label == "audio_input") {
- _engine->create_port(path, "AUDIO", false);
+ _engine->create_port(path, "ingen:audio", false);
is_port = true;
} else if (plugin_label == "audio_output") {
- _engine->create_port(path, "AUDIO", true);
+ _engine->create_port(path, "ingen:audio", true);
is_port = true;
} else if (plugin_label == "control_input") {
- _engine->create_port(path, "CONTROL", false);
+ _engine->create_port(path, "ingen:control", false);
is_port = true;
} else if (plugin_label == "control_output" ) {
- _engine->create_port(path, "CONTROL", true);
+ _engine->create_port(path, "ingen:control", true);
is_port = true;
} else if (plugin_label == "midi_input") {
- _engine->create_port(path, "MIDI", false);
+ _engine->create_port(path, "ingen:midi", false);
is_port = true;
} else if (plugin_label == "midi_output" ) {
- _engine->create_port(path, "MIDI", true);
+ _engine->create_port(path, "ingen:midi", true);
is_port = true;
}
}
diff --git a/src/libs/client/Loader.cpp b/src/libs/client/Loader.cpp
index ac661e58..fe1af795 100644
--- a/src/libs/client/Loader.cpp
+++ b/src/libs/client/Loader.cpp
@@ -31,6 +31,7 @@ Loader::Loader(SharedPtr<ModelEngineInterface> engine, SharedPtr<Namespaces> nam
_namespaces = SharedPtr<Namespaces>(new Namespaces());
// FIXME: hack
+ _namespaces->add("ingen", "http://codeson.net/ns/ingen#");
_namespaces->add("ingenuity", "http://codeson.net/ns/ingenuity#");
}
@@ -47,14 +48,16 @@ Loader::load(const Glib::ustring& filename,
{
std::map<Glib::ustring, bool> created;
+
+ /* Load nodes */
+
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"
+ "OPTIONAL { ?node ?floatkey ?floatval . \n"
+ " FILTER ( datatype(?floatval) = xsd:decimal ) }\n"
"}");
RDFQuery::Results nodes = query.run(filename);
@@ -64,7 +67,6 @@ Loader::load(const Glib::ustring& filename,
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;
}
@@ -72,13 +74,49 @@ Loader::load(const Glib::ustring& filename,
Glib::ustring floatkey = _namespaces->qualify((*i)["floatkey"]);
Glib::ustring floatval = (*i)["floatval"];
- float val = atof(floatval.c_str());
+ if (floatkey != "" && floatval != "") {
+ const float val = atof(floatval.c_str());
+ _engine->set_metadata(parent.base() + name, floatkey, Atom(val));
+ }
+ }
+
+ created.clear();
- cerr << floatkey << " = " << val << endl;
- _engine->set_metadata(parent.base() + name, floatkey, Atom(val));
- }
+ /* Load patch 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"
+ "OPTIONAL { ?port ?floatkey ?floatval . \n"
+ " FILTER ( datatype(?floatval) = xsd:decimal ) }\n"
+ "}");
+
+ RDFQuery::Results ports = query.run(filename);
+
+ for (RDFQuery::Results::iterator i = ports.begin(); i != ports.end(); ++i) {
+ const Glib::ustring& name = (*i)["name"];
+ const Glib::ustring& type = _namespaces->qualify((*i)["type"]);
+ const Glib::ustring& datatype = (*i)["datatype"];
+
+ 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);
+ created[name] = true;
+ }
+
+ Glib::ustring floatkey = _namespaces->qualify((*i)["floatkey"]);
+ Glib::ustring floatval = (*i)["floatval"];
+
+ if (floatkey != "" && floatval != "") {
+ const float val = atof(floatval.c_str());
+ _engine->set_metadata(parent.base() + name, floatkey, Atom(val));
+ }
+ }
}
diff --git a/src/libs/client/PortModel.h b/src/libs/client/PortModel.h
index e5ce23fc..1dc68ccd 100644
--- a/src/libs/client/PortModel.h
+++ b/src/libs/client/PortModel.h
@@ -18,13 +18,14 @@
#define PORTMODEL_H
#include <cstdlib>
+#include <iostream>
#include <string>
#include <list>
#include <sigc++/sigc++.h>
#include "ObjectModel.h"
#include "raul/SharedPtr.h"
#include "raul/Path.h"
-using std::string; using std::list;
+using std::string; using std::list; using std::cerr; using std::endl;
namespace Ingen {
namespace Client {
@@ -37,22 +38,22 @@ namespace Client {
class PortModel : public ObjectModel
{
public:
- // FIXME: metadataify
- enum Type { CONTROL, AUDIO, MIDI };
enum Direction { INPUT, OUTPUT };
+
+ // FIXME: metadataify
enum Hint { NONE, INTEGER, TOGGLE, LOGARITHMIC };
- inline float value() const { return m_current_val; }
- inline bool connected() const { return (m_connections > 0); }
- inline Type type() const { return m_type; }
- inline bool is_input() const { return (m_direction == INPUT); }
- inline bool is_output() const { return (m_direction == OUTPUT); }
- inline bool is_audio() const { return (m_type == AUDIO); }
- inline bool is_control() const { return (m_type == CONTROL); }
- inline bool is_midi() const { return (m_type == MIDI); }
- inline bool is_logarithmic() const { return (m_hint == LOGARITHMIC); }
- inline bool is_integer() const { return (m_hint == INTEGER); }
- inline bool is_toggle() const { return (m_hint == TOGGLE); }
+ inline float value() const { return m_current_val; }
+ inline bool connected() const { return (m_connections > 0); }
+ inline string type() const { return m_type; }
+ inline bool is_input() const { return (m_direction == INPUT); }
+ inline bool is_output() const { return (m_direction == OUTPUT); }
+ inline bool is_audio() const { return (m_type == "ingen:audio"); }
+ inline bool is_control() const { return (m_type == "ingen:control"); }
+ inline bool is_midi() const { return (m_type == "ingen:midi"); }
+ inline bool is_logarithmic() const { return (m_hint == LOGARITHMIC); }
+ inline bool is_integer() const { return (m_hint == INTEGER); }
+ inline bool is_toggle() const { return (m_hint == TOGGLE); }
inline bool operator==(const PortModel& pm) const { return (_path == pm._path); }
@@ -64,7 +65,7 @@ public:
private:
friend class Store;
- PortModel(const Path& path, Type type, Direction dir, Hint hint)
+ PortModel(const Path& path, const string& type, Direction dir, Hint hint)
: ObjectModel(path),
m_type(type),
m_direction(dir),
@@ -72,9 +73,11 @@ private:
m_current_val(0.0f),
m_connections(0)
{
+ if (!is_audio() && !is_control() && !is_input())
+ cerr << "[PortModel] Warning: Unknown port type" << endl;
}
- PortModel(const Path& path, Type type, Direction dir)
+ PortModel(const Path& path, const string& type, Direction dir)
: ObjectModel(path),
m_type(type),
m_direction(dir),
@@ -82,6 +85,8 @@ private:
m_current_val(0.0f),
m_connections(0)
{
+ if (!is_audio() && !is_control() && !is_input())
+ cerr << "[PortModel] Warning: Unknown port type" << endl;
}
inline void value(float f) { m_current_val = f; control_change_sig.emit(f); }
@@ -92,7 +97,7 @@ private:
void connected_to(SharedPtr<PortModel> p) { ++m_connections; connection_sig.emit(p); }
void disconnected_from(SharedPtr<PortModel> p) { --m_connections; disconnection_sig.emit(p); }
- Type m_type;
+ string m_type;
Direction m_direction;
Hint m_hint;
float m_current_val;
diff --git a/src/libs/client/RDFQuery.cpp b/src/libs/client/RDFQuery.cpp
index 178e2eba..02a491bb 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)
+RDFQuery::run(const Glib::ustring filename) const
{
Results result;
diff --git a/src/libs/client/RDFQuery.h b/src/libs/client/RDFQuery.h
index e22f3ae7..990d9e4f 100644
--- a/src/libs/client/RDFQuery.h
+++ b/src/libs/client/RDFQuery.h
@@ -45,9 +45,9 @@ public:
_query = _prefix_header + query;
}
- Results run(const Glib::ustring filename);
+ Results run(const Glib::ustring filename) const;
- Glib::ustring string() { return _query; }
+ Glib::ustring string() const { return _query; };
private:
diff --git a/src/libs/client/Serializer.cpp b/src/libs/client/Serializer.cpp
index b8929546..d57f908f 100644
--- a/src/libs/client/Serializer.cpp
+++ b/src/libs/client/Serializer.cpp
@@ -305,6 +305,8 @@ Serializer::serialize_port(SharedPtr<PortModel> port, unsigned depth)
_writer.write(port_id, NS_RDF("type"), NS_INGEN("OutputPort"));
_writer.write(port_id, NS_INGEN("name"), Atom(port->path().name().c_str()));
+
+ _writer.write(port_id, NS_INGEN("dataType"), Atom(port->type()));
if (port->metadata().size() > 0) {
for (MetadataMap::const_iterator m = port->metadata().begin(); m != port->metadata().end(); ++m) {
diff --git a/src/libs/client/Store.cpp b/src/libs/client/Store.cpp
index 75667ee6..69358d0c 100644
--- a/src/libs/client/Store.cpp
+++ b/src/libs/client/Store.cpp
@@ -378,17 +378,9 @@ Store::new_node_event(const string& plugin_uri, const Path& node_path, bool is_p
void
Store::new_port_event(const Path& path, const string& type, bool is_output)
{
- // FIXME: this sucks
-
- PortModel::Type ptype = PortModel::CONTROL;
- if (type == "AUDIO") ptype = PortModel::AUDIO;
- else if (type == "CONTROL") ptype = PortModel::CONTROL;
- else if (type== "MIDI") ptype = PortModel::MIDI;
- else cerr << "[Store] WARNING: Unknown port type received (" << type << ")" << endl;
-
PortModel::Direction pdir = is_output ? PortModel::OUTPUT : PortModel::INPUT;
- SharedPtr<PortModel> p(new PortModel(path, ptype, pdir));
+ SharedPtr<PortModel> p(new PortModel(path, type, pdir));
add_object(p);
if (p->parent())
resolve_connection_orphans(p);