summaryrefslogtreecommitdiffstats
path: root/src/libs/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/client')
-rw-r--r--src/libs/client/Loader.cpp66
-rw-r--r--src/libs/client/OSCClientReceiver.cpp12
-rw-r--r--src/libs/client/PortModel.h66
3 files changed, 99 insertions, 45 deletions
diff --git a/src/libs/client/Loader.cpp b/src/libs/client/Loader.cpp
index 4ceb34d2..9c6f7fb0 100644
--- a/src/libs/client/Loader.cpp
+++ b/src/libs/client/Loader.cpp
@@ -52,7 +52,7 @@ Loader::load(const Glib::ustring& filename,
{
// FIXME: this whole thing is a mess
- std::map<Glib::ustring, bool> created;
+ std::map<Path, bool> created;
// FIXME: kluge
unsigned char* document_uri_str = raptor_uri_filename_to_uri_string(filename.c_str());
@@ -60,7 +60,7 @@ Loader::load(const Glib::ustring& filename,
//Glib::ustring document_uri = "file:///home/dave/code/codesonnet/ingen/src/progs/ingenuity/test2.ingen.ttl";
if (patch_uri == "")
- patch_uri = "<>";
+ patch_uri = "<>"; // FIXME: Will load every patch in the file?
cerr << "[Loader] Loading " << patch_uri << " from " << document_uri
<< " under " << parent << endl;
@@ -122,9 +122,11 @@ Loader::load(const Glib::ustring& filename,
const Glib::ustring& name = (*i)["name"];
const Glib::ustring& plugin = (*i)["plugin"];
- if (created.find(name) == created.end()) {
- _engine->create_node(patch_path.base() + name, plugin, false);
- created[name] = true;
+ const Path node_path = patch_path.base() + (string)name;
+
+ if (created.find(node_path) == created.end()) {
+ _engine->create_node(node_path, plugin, false);
+ created[node_path] = true;
}
Glib::ustring floatkey = _namespaces->qualify((*i)["floatkey"]);
@@ -139,16 +141,47 @@ Loader::load(const Glib::ustring& filename,
created.clear();
+ /* Set node port control values */
+
+ query = RDFQuery(Glib::ustring(
+ "SELECT DISTINCT ?nodename ?portname ?portval FROM <") + document_uri + "> WHERE {\n" +
+ patch_uri + " ingen:node ?node .\n"
+ "?node ingen:name ?nodename ;\n"
+ " ingen:port ?port .\n"
+ "?port ingen:name ?portname ;\n"
+ " ingen:value ?portval .\n"
+ "}\n");
+
+ results = query.run(document_uri);
+
+ for (RDFQuery::Results::iterator i = results.begin(); i != results.end(); ++i) {
+
+ const Glib::ustring& node_name = (*i)["nodename"];
+ const Glib::ustring& port_name = (*i)["portname"];
+ const Glib::ustring& portval = (*i)["portval"];
+
+ Path port_path = patch_path.base() + (const string&)node_name +"/"+ (const string&)port_name;
+
+ if (portval != "") {
+ const float val = atof(portval.c_str());
+ cerr << port_path << " VALUE: " << val << endl;
+ _engine->set_port_value(port_path, val);
+ }
+ }
+
+
/* Load this patch's ports */
query = RDFQuery(Glib::ustring(
- "SELECT DISTINCT ?port ?type ?name ?datatype ?floatkey ?floatval FROM <") + document_uri + "> WHERE {\n" +
+ "SELECT DISTINCT ?port ?type ?name ?datatype ?floatkey ?floatval ?portval 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"
+ "OPTIONAL { ?port ingen:value ?portval . \n"
+ " FILTER ( datatype(?portval) = xsd:decimal ) }\n"
"}");
results = query.run(document_uri);
@@ -158,21 +191,32 @@ Loader::load(const Glib::ustring& filename,
const Glib::ustring& type = _namespaces->qualify((*i)["type"]);
const Glib::ustring& datatype = (*i)["datatype"];
- if (created.find(name) == created.end()) {
+ const Path port_path = patch_path.base() + (string)name;
+
+ if (created.find(port_path) == created.end()) {
//cerr << "TYPE: " << type << endl;
bool is_output = (type == "ingen:OutputPort"); // FIXME: check validity
- _engine->create_port(patch_path.base() + name, datatype, is_output);
- created[name] = true;
+ _engine->create_port(port_path, datatype, is_output);
+ created[port_path] = true;
}
- Glib::ustring floatkey = _namespaces->qualify((*i)["floatkey"]);
- Glib::ustring floatval = (*i)["floatval"];
+ const Glib::ustring& portval = (*i)["portval"];
+ if (portval != "") {
+ const float val = atof(portval.c_str());
+ cerr << name << " VALUE: " << val << endl;
+ _engine->set_port_value(patch_path.base() + name, val);
+ }
+
+ const Glib::ustring& floatkey = _namespaces->qualify((*i)["floatkey"]);
+ const Glib::ustring& floatval = (*i)["floatval"];
if (floatkey != "" && floatval != "") {
const float val = atof(floatval.c_str());
_engine->set_metadata(patch_path.base() + name, floatkey, Atom(val));
}
}
+
+ created.clear();
/* Load connections */
diff --git a/src/libs/client/OSCClientReceiver.cpp b/src/libs/client/OSCClientReceiver.cpp
index 0dbf49ec..45b8d794 100644
--- a/src/libs/client/OSCClientReceiver.cpp
+++ b/src/libs/client/OSCClientReceiver.cpp
@@ -50,15 +50,19 @@ OSCClientReceiver::start()
if (_st != NULL)
return;
- if (_listen_port == 0) {
- _st = lo_server_thread_new(NULL, error_cb);
- _listen_port = lo_server_thread_get_port(_st);
- } else {
+ // Attempt preferred port
+ if (_listen_port != 0) {
char port_str[8];
snprintf(port_str, 8, "%d", _listen_port);
_st = lo_server_thread_new(port_str, error_cb);
}
+ // Find a free port
+ if (!_st) {
+ _st = lo_server_thread_new(NULL, error_cb);
+ _listen_port = lo_server_thread_get_port(_st);
+ }
+
if (_st == NULL) {
cerr << "[OSCClientReceiver] Could not start OSC listener. Aborting." << endl;
exit(EXIT_FAILURE);
diff --git a/src/libs/client/PortModel.h b/src/libs/client/PortModel.h
index adaaf803..eaea8f71 100644
--- a/src/libs/client/PortModel.h
+++ b/src/libs/client/PortModel.h
@@ -43,19 +43,27 @@ public:
// 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 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 string type() const { return _type; }
+ inline float value() const { return _current_val; }
+ inline bool connected() const { return (_connections > 0); }
+ inline bool is_input() const { return (_direction == INPUT); }
+ inline bool is_output() const { return (_direction == OUTPUT); }
+ inline bool is_audio() const { return (_type == "ingen:audio"); }
+ inline bool is_control() const { return (_type == "ingen:control"); }
+ inline bool is_midi() const { return (_type == "ingen:midi"); }
+ inline bool is_logarithmic() const { return (_hint == LOGARITHMIC); }
+ inline bool is_integer() const { return (_hint == INTEGER); }
+ inline bool is_toggle() const { return (_hint == TOGGLE); }
inline bool operator==(const PortModel& pm) const { return (_path == pm._path); }
+
+ inline void value(float val)
+ {
+ if (val != _current_val) {
+ _current_val = val;
+ control_change_sig.emit(val);
+ }
+ }
// Signals
sigc::signal<void, float> control_change_sig; ///< "Control" ports only
@@ -67,11 +75,11 @@ private:
PortModel(const Path& path, const string& type, Direction dir, Hint hint)
: ObjectModel(path),
- m_type(type),
- m_direction(dir),
- m_hint(hint),
- m_current_val(0.0f),
- m_connections(0)
+ _type(type),
+ _direction(dir),
+ _hint(hint),
+ _current_val(0.0f),
+ _connections(0)
{
if (!is_audio() && !is_control() && !is_input())
cerr << "[PortModel] Warning: Unknown port type" << endl;
@@ -79,29 +87,27 @@ private:
PortModel(const Path& path, const string& type, Direction dir)
: ObjectModel(path),
- m_type(type),
- m_direction(dir),
- m_hint(NONE),
- m_current_val(0.0f),
- m_connections(0)
+ _type(type),
+ _direction(dir),
+ _hint(NONE),
+ _current_val(0.0f),
+ _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); }
void add_child(SharedPtr<ObjectModel> c) { throw; }
void remove_child(SharedPtr<ObjectModel> c) { throw; }
- void connected_to(SharedPtr<PortModel> p) { ++m_connections; connection_sig.emit(p); }
- void disconnected_from(SharedPtr<PortModel> p) { --m_connections; disconnection_sig.emit(p); }
+ void connected_to(SharedPtr<PortModel> p) { ++_connections; connection_sig.emit(p); }
+ void disconnected_from(SharedPtr<PortModel> p) { --_connections; disconnection_sig.emit(p); }
- string m_type;
- Direction m_direction;
- Hint m_hint;
- float m_current_val;
- size_t m_connections;
+ string _type;
+ Direction _direction;
+ Hint _hint;
+ float _current_val;
+ size_t _connections;
};
typedef list<SharedPtr<PortModel> > PortModelList;