diff options
62 files changed, 878 insertions, 1243 deletions
diff --git a/src/client/DeprecatedLoader.cpp b/src/client/DeprecatedLoader.cpp index 794816bb..ac693421 100644 --- a/src/client/DeprecatedLoader.cpp +++ b/src/client/DeprecatedLoader.cpp @@ -140,12 +140,12 @@ DeprecatedLoader::translate_load_path(const string& path) } -/** Add a piece of data to a Variables, translating from deprecated unqualified keys +/** Add a piece of data to a Properties, translating from deprecated unqualified keys * * Adds a namespace prefix for known keys, and ignores the rest. */ void -DeprecatedLoader::add_variable(GraphObject::Variables& data, string old_key, string value) +DeprecatedLoader::add_variable(GraphObject::Properties& data, string old_key, string value) { string key = ""; if (old_key == "module-x") @@ -207,7 +207,7 @@ DeprecatedLoader::load_patch(const Glib::ustring& filename, bool merge, boost::optional<Path> parent_path, boost::optional<Symbol> name, - GraphObject::Variables initial_data, + GraphObject::Properties initial_data, bool existing) { cerr << "[DeprecatedLoader] Loading patch " << filename << " under " @@ -222,7 +222,7 @@ DeprecatedLoader::load_patch(const Glib::ustring& filename, size_t poly = 0; /* Use parameter overridden polyphony, if given */ - GraphObject::Variables::iterator poly_param = initial_data.find("ingen:polyphony"); + GraphObject::Properties::iterator poly_param = initial_data.find("ingen:polyphony"); if (poly_param != initial_data.end() && poly_param->second.type() == Atom::INT) poly = poly_param->second.get_int32(); @@ -291,7 +291,7 @@ DeprecatedLoader::load_patch(const Glib::ustring& filename, // Create it, if we're not merging if (!existing && path != "/") { _engine->new_patch(path, poly); - for (GraphObject::Variables::const_iterator i = initial_data.begin(); i != initial_data.end(); ++i) + for (GraphObject::Properties::const_iterator i = initial_data.begin(); i != initial_data.end(); ++i) _engine->set_variable(path, i->first, i->second); } @@ -346,11 +346,11 @@ DeprecatedLoader::load_patch(const Glib::ustring& filename, xmlCleanupParser(); // Done above.. late enough? - //for (Variables::const_iterator i = data.begin(); i != data.end(); ++i) + //for (Properties::const_iterator i = data.begin(); i != data.end(); ++i) // _engine->set_variable(subject, i->first, i->second); if (!existing) - _engine->set_property(path, "ingen:enabled", (bool)true); + _engine->set_variable(path, "ingen:enabled", (bool)true); _load_path_translations.clear(); @@ -375,7 +375,7 @@ DeprecatedLoader::load_node(const Path& parent, xmlDocPtr doc, const xmlNodePtr string library_name; // deprecated string plugin_label; // deprecated - GraphObject::Variables initial_data; + GraphObject::Properties initial_data; while (cur != NULL) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); @@ -489,7 +489,7 @@ DeprecatedLoader::load_node(const Path& parent, xmlDocPtr doc, const xmlNodePtr path = new_path; - for (GraphObject::Variables::const_iterator i = initial_data.begin(); i != initial_data.end(); ++i) + for (GraphObject::Properties::const_iterator i = initial_data.begin(); i != initial_data.end(); ++i) _engine->set_variable(path, i->first, i->second); return SharedPtr<NodeModel>(); @@ -510,9 +510,9 @@ DeprecatedLoader::load_node(const Path& parent, xmlDocPtr doc, const xmlNodePtr else _engine->new_node_deprecated(path, plugin_type, library_name, plugin_label); - _engine->set_property(path, "ingen:polyphonic", polyphonic); + _engine->set_variable(path, "ingen:polyphonic", bool(polyphonic)); - for (GraphObject::Variables::const_iterator i = initial_data.begin(); i != initial_data.end(); ++i) + for (GraphObject::Properties::const_iterator i = initial_data.begin(); i != initial_data.end(); ++i) _engine->set_variable(path, i->first, i->second); return true; @@ -521,8 +521,8 @@ DeprecatedLoader::load_node(const Path& parent, xmlDocPtr doc, const xmlNodePtr // Not deprecated } else { _engine->new_node(path, plugin_uri); - _engine->set_property(path, "ingen:polyphonic", polyphonic); - for (GraphObject::Variables::const_iterator i = initial_data.begin(); i != initial_data.end(); ++i) + _engine->set_variable(path, "ingen:polyphonic", bool(polyphonic)); + for (GraphObject::Properties::const_iterator i = initial_data.begin(); i != initial_data.end(); ++i) _engine->set_variable(path, i->first, i->second); return true; } @@ -541,7 +541,7 @@ DeprecatedLoader::load_subpatch(const string& base_filename, const Path& parent, string filename = ""; size_t poly = 0; - GraphObject::Variables initial_data; + GraphObject::Properties initial_data; while (cur != NULL) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); diff --git a/src/client/DeprecatedLoader.hpp b/src/client/DeprecatedLoader.hpp index 37d31f3f..dd391ca1 100644 --- a/src/client/DeprecatedLoader.hpp +++ b/src/client/DeprecatedLoader.hpp @@ -67,11 +67,11 @@ public: bool merge, boost::optional<Path> parent_path, boost::optional<Symbol> name, - GraphObject::Variables initial_data, + GraphObject::Properties initial_data, bool existing = false); private: - void add_variable(GraphObject::Variables& data, string key, string value); + void add_variable(GraphObject::Properties& data, string key, string value); string nameify_if_invalid(const string& name); string translate_load_path(const string& path); diff --git a/src/client/ObjectModel.cpp b/src/client/ObjectModel.cpp index 80460547..f5972af5 100644 --- a/src/client/ObjectModel.cpp +++ b/src/client/ObjectModel.cpp @@ -47,7 +47,7 @@ ObjectModel::get_variable(const string& key) const { static const Atom null_atom; - Variables::const_iterator i = _variables.find(key); + Properties::const_iterator i = _variables.find(key); if (i != _variables.end()) return i->second; else @@ -64,7 +64,7 @@ ObjectModel::get_variable( string& key) { static Atom null_atom; - Variables::iterator i = _variables.find(key); + Properties::iterator i = _variables.find(key); if (i != _variables.end()) return i->second; else @@ -75,7 +75,7 @@ ObjectModel::get_variable( string& key) bool ObjectModel::polyphonic() const { - const Raul::Atom& polyphonic = get_property("ingen:polyphonic"); + const Raul::Atom& polyphonic = get_variable("ingen:polyphonic"); return (polyphonic.is_valid() && polyphonic.get_bool()); } @@ -91,14 +91,6 @@ ObjectModel::set(SharedPtr<ObjectModel> o) assert(_path == o->path()); if (o->_parent) _parent = o->_parent; - - for (Variables::const_iterator v = o->variables().begin(); v != o->variables().end(); ++v) { - Variables::const_iterator mine = _variables.find(v->first); - if (mine != _variables.end()) - cerr << "WARNING: " << _path << "Client/Server variable mismatch: " << v->first << endl; - _variables[v->first] = v->second; - signal_variable.emit(v->first, v->second); - } for (Properties::const_iterator v = o->properties().begin(); v != o->properties().end(); ++v) { const Raul::Atom& mine = get_property(v->first); @@ -107,6 +99,14 @@ ObjectModel::set(SharedPtr<ObjectModel> o) ResourceImpl::set_property(v->first, v->second); signal_variable.emit(v->first, v->second); } + + for (Properties::const_iterator v = o->variables().begin(); v != o->variables().end(); ++v) { + Properties::const_iterator mine = _variables.find(v->first); + if (mine != _variables.end()) + cerr << "WARNING: " << _path << "Client/Server variable mismatch: " << v->first << endl; + _variables[v->first] = v->second; + signal_variable.emit(v->first, v->second); + } } diff --git a/src/client/ObjectModel.hpp b/src/client/ObjectModel.hpp index f1850d94..4d02e546 100644 --- a/src/client/ObjectModel.hpp +++ b/src/client/ObjectModel.hpp @@ -70,8 +70,8 @@ public: virtual void set_variable(const string& key, const Atom& value) { _variables[key] = value; signal_variable.emit(key, value); } - const Variables& variables() const { return _variables; } - Variables& variables() { return _variables; } + const Properties& variables() const { return _variables; } + Properties& variables() { return _variables; } const Path path() const { return _path; } const Symbol symbol() const { return _path.name(); } SharedPtr<ObjectModel> parent() const { return _parent; } @@ -102,7 +102,7 @@ protected: Path _path; SharedPtr<ObjectModel> _parent; - Variables _variables; + Properties _variables; }; diff --git a/src/client/PatchModel.cpp b/src/client/PatchModel.cpp index c27ff718..980a902c 100644 --- a/src/client/PatchModel.cpp +++ b/src/client/PatchModel.cpp @@ -163,14 +163,15 @@ PatchModel::remove_connection(const string& src_port_path, const string& dst_por bool PatchModel::enabled() const { - const Raul::Atom& enabled = get_property("ingen:enabled"); + const Raul::Atom& enabled = get_variable("ingen:enabled"); return (enabled.is_valid() && enabled.get_bool()); } - + + void -PatchModel::set_property(const std::string& key, const Atom& value) +PatchModel::set_variable(const std::string& key, const Atom& value) { - ResourceImpl::set_property(key, value); + NodeModel::set_variable(key, value); if (key == "ingen:polyphony") _poly = value.get_int32(); } diff --git a/src/client/PatchModel.hpp b/src/client/PatchModel.hpp index 35b11e15..4a8b3ee7 100644 --- a/src/client/PatchModel.hpp +++ b/src/client/PatchModel.hpp @@ -63,7 +63,7 @@ public: signal_editable.emit(e); } } - virtual void set_property(const string& key, const Atom& value); + virtual void set_variable(const string& key, const Atom& value); // Signals sigc::signal<void, SharedPtr<NodeModel> > signal_new_node; diff --git a/src/common/interface/GraphObject.hpp b/src/common/interface/GraphObject.hpp index eac5bf86..d4483b91 100644 --- a/src/common/interface/GraphObject.hpp +++ b/src/common/interface/GraphObject.hpp @@ -43,16 +43,14 @@ class GraphObject : public Raul::Deletable , public virtual Resource { public: - typedef std::map<std::string, Raul::Atom> Variables; - typedef Raul::PathTable< SharedPtr<GraphObject> >::const_iterator const_iterator; virtual void set_path(const Raul::Path& path) = 0; virtual const Raul::Path path() const = 0; virtual const Raul::Symbol symbol() const = 0; - virtual const Variables& variables() const = 0; - virtual Variables& variables() = 0; + virtual const Properties& variables() const = 0; + virtual Properties& variables() = 0; virtual bool polyphonic() const = 0; // FIXME: return WeakPtr, and stupid name diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index 23316bdf..41004b97 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -36,7 +36,6 @@ #include "QueuedEventSource.hpp" #include "PostProcessor.hpp" #include "events/CreatePatchEvent.hpp" -#include "events/EnablePatchEvent.hpp" #include "PostProcessor.hpp" #include "AudioDriver.hpp" #include "ProcessSlave.hpp" diff --git a/src/engine/EventBuffer.hpp b/src/engine/EventBuffer.hpp index 7c2d9d20..9ff91cc7 100644 --- a/src/engine/EventBuffer.hpp +++ b/src/engine/EventBuffer.hpp @@ -44,8 +44,8 @@ public: bool merge(const EventBuffer& a, const EventBuffer& b); - bool increment() const; - bool is_valid() const; + bool increment() const { return _buf->increment(); } + bool is_valid() const { return _buf->is_valid(); } inline uint32_t latest_frames() const { return _buf->latest_frames(); } inline uint32_t latest_subframes() const { return _buf->latest_subframes(); } diff --git a/src/engine/GraphObjectImpl.cpp b/src/engine/GraphObjectImpl.cpp index b08a9ffc..461ebf0b 100644 --- a/src/engine/GraphObjectImpl.cpp +++ b/src/engine/GraphObjectImpl.cpp @@ -33,7 +33,7 @@ const Atom& GraphObjectImpl::get_variable(const std::string& key) { static const Atom null_atom; - Variables::iterator i = _variables.find(key); + Properties::iterator i = _variables.find(key); return (i != _variables.end()) ? (*i).second : null_atom; } diff --git a/src/engine/GraphObjectImpl.hpp b/src/engine/GraphObjectImpl.hpp index 8cd0d707..5830c618 100644 --- a/src/engine/GraphObjectImpl.hpp +++ b/src/engine/GraphObjectImpl.hpp @@ -74,8 +74,8 @@ public: const Raul::Atom& get_variable(const std::string& key); void set_variable(const std::string& key, const Raul::Atom& value); - const Variables& variables() const { return _variables; } - Variables& variables() { return _variables; } + const Properties& variables() const { return _variables; } + Properties& variables() { return _variables; } /** The Patch this object is a child of. */ virtual PatchImpl* parent_patch() const; @@ -109,7 +109,7 @@ protected: bool _polyphonic; private: - Variables _variables; + Properties _variables; }; diff --git a/src/engine/HTTPEngineReceiver.cpp b/src/engine/HTTPEngineReceiver.cpp index 11803d35..98008a16 100644 --- a/src/engine/HTTPEngineReceiver.cpp +++ b/src/engine/HTTPEngineReceiver.cpp @@ -209,7 +209,7 @@ HTTPEngineReceiver::message_callback(SoupServer* server, SoupMessage* msg, const // Serialise object const string response = serialiser->to_string(start->second, - "http://localhost:16180/patch", GraphObject::Variables()); + "http://localhost:16180/patch", GraphObject::Properties()); soup_message_set_status(msg, SOUP_STATUS_OK); soup_message_set_response(msg, mime_type, SOUP_MEMORY_COPY, diff --git a/src/engine/OSCEngineReceiver.cpp b/src/engine/OSCEngineReceiver.cpp index 7950cdf7..b5505f86 100644 --- a/src/engine/OSCEngineReceiver.cpp +++ b/src/engine/OSCEngineReceiver.cpp @@ -419,40 +419,6 @@ OSCEngineReceiver::_clear_patch_cb(const char* path, const char* types, lo_arg** } -/** \page engine_osc_namespace - * <p> \b /ingen/set_polyphony - Set the polyphony of a patch - * \arg \b response-id (integer) - * \arg \b patch-path - Patch's path - * \arg \b poly (integer) </p> \n \n - */ -int -OSCEngineReceiver::_set_polyphony_cb(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg) -{ - const char* patch_path = &argv[1]->s; - const uint32_t poly = argv[2]->i; - - set_polyphony(patch_path, poly); - return 0; -} - - -/** \page engine_osc_namespace - * <p> \b /ingen/set_polyphonic - Toggle a node's or port's polyphonic mode - * \arg \b response-id (integer) - * \arg \b path - Object's path - * \arg \b polyphonic (bool) </p> \n \n - */ -int -OSCEngineReceiver::_set_polyphonic_cb(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg) -{ - const char* object_path = &argv[1]->s; - bool polyphonic = (types[2] == 'T'); - - set_polyphonic(object_path, polyphonic); - return 0; -} - - // FIXME: add index /** \page engine_osc_namespace * <p> \b /ingen/new_port - Add a port into a given patch (load a plugin by URI) diff --git a/src/engine/ObjectSender.cpp b/src/engine/ObjectSender.cpp index 81759fae..e261bc97 100644 --- a/src/engine/ObjectSender.cpp +++ b/src/engine/ObjectSender.cpp @@ -62,14 +62,14 @@ ObjectSender::send_patch(ClientInterface* client, const PatchImpl* patch, bool r client->transfer_begin(); client->new_patch(patch->path(), patch->internal_polyphony()); - client->set_property(patch->path(), "ingen:polyphonic", patch->polyphonic()); + client->set_variable(patch->path(), "ingen:polyphonic", bool(patch->polyphonic())); // Send variable - const GraphObjectImpl::Variables& data = patch->variables(); - for (GraphObjectImpl::Variables::const_iterator j = data.begin(); j != data.end(); ++j) + const GraphObjectImpl::Properties& data = patch->variables(); + for (GraphObjectImpl::Properties::const_iterator j = data.begin(); j != data.end(); ++j) client->set_variable(patch->path(), (*j).first, (*j).second); - client->set_property(patch->path(), "ingen:enabled", (bool)patch->enabled()); + client->set_variable(patch->path(), "ingen:enabled", (bool)patch->enabled()); if (recursive) { @@ -119,11 +119,11 @@ ObjectSender::send_node(ClientInterface* client, const NodeImpl* node, bool recu client->transfer_begin(); client->new_node(node->path(), node->plugin()->uri()); - client->set_property(node->path(), "ingen:polyphonic", node->polyphonic()); + client->set_variable(node->path(), "ingen:polyphonic", bool(node->polyphonic())); // Send variables - const GraphObjectImpl::Variables& data = node->variables(); - for (GraphObjectImpl::Variables::const_iterator j = data.begin(); j != data.end(); ++j) + const GraphObjectImpl::Properties& data = node->variables(); + for (GraphObjectImpl::Properties::const_iterator j = data.begin(); j != data.end(); ++j) client->set_variable(node->path(), (*j).first, (*j).second); // Send properties @@ -151,11 +151,13 @@ ObjectSender::send_port(ClientInterface* client, const PortImpl* port, bool bund client->bundle_begin(); client->new_port(port->path(), port->type().uri(), port->index(), port->is_output()); - client->set_property(port->path(), "ingen:polyphonic", port->polyphonic()); + PatchImpl* graph_parent = dynamic_cast<PatchImpl*>(port->parent_node()); + if (graph_parent && graph_parent->internal_polyphony() > 1) + client->set_variable(port->path(), "ingen:polyphonic", bool(port->polyphonic())); // Send variable - const GraphObjectImpl::Variables& data = port->variables(); - for (GraphObjectImpl::Variables::const_iterator j = data.begin(); j != data.end(); ++j) + const GraphObjectImpl::Properties& data = port->variables(); + for (GraphObjectImpl::Properties::const_iterator j = data.begin(); j != data.end(); ++j) client->set_variable(port->path(), (*j).first, (*j).second); // Send properties diff --git a/src/engine/QueuedEngineInterface.cpp b/src/engine/QueuedEngineInterface.cpp index fc3d7788..6a322e16 100644 --- a/src/engine/QueuedEngineInterface.cpp +++ b/src/engine/QueuedEngineInterface.cpp @@ -204,20 +204,6 @@ QueuedEngineInterface::clear_patch(const string& patch_path) void -QueuedEngineInterface::set_polyphony(const string& patch_path, uint32_t poly) -{ - push_queued(new SetPolyphonyEvent(_engine, _responder, now(), this, patch_path, poly)); -} - - -void -QueuedEngineInterface::set_polyphonic(const string& path, bool poly) -{ - push_queued(new SetPolyphonicEvent(_engine, _responder, now(), this, path, poly)); -} - - -void QueuedEngineInterface::connect(const string& src_port_path, const string& dst_port_path) { @@ -289,25 +275,7 @@ QueuedEngineInterface::set_property(const string& path, const string& predicate, const Atom& value) { - // FIXME: implement generically - if (predicate == "ingen:enabled") { - if (value.type() == Atom::BOOL) { - push_queued(new EnablePatchEvent(_engine, _responder, now(), path, value.get_bool())); - return; - } - } else if (predicate == "ingen:polyphonic") { - if (value.type() == Atom::BOOL) { - push_queued(new SetPolyphonicEvent(_engine, _responder, now(), this, path, value.get_bool())); - return; - } - } else if (predicate == "ingen:polyphony") { - if (value.type() == Atom::INT) { - push_queued(new SetPolyphonyEvent(_engine, _responder, now(), this, path, value.get_int32())); - return; - } - } else { - push_queued(new SetMetadataEvent(_engine, _responder, now(), true, path, predicate, value)); - } + push_queued(new SetMetadataEvent(_engine, _responder, now(), true, path, predicate, value)); } // Requests // diff --git a/src/engine/QueuedEngineInterface.hpp b/src/engine/QueuedEngineInterface.hpp index 49fe649b..ec5bf602 100644 --- a/src/engine/QueuedEngineInterface.hpp +++ b/src/engine/QueuedEngineInterface.hpp @@ -99,10 +99,6 @@ public: virtual void clear_patch(const string& patch_path); - virtual void set_polyphony(const string& patch_path, uint32_t poly); - - virtual void set_polyphonic(const string& path, bool poly); - virtual void connect(const string& src_port_path, const string& dst_port_path); diff --git a/src/engine/events.hpp b/src/engine/events.hpp index 355c6a3c..b5dcdbc0 100644 --- a/src/engine/events.hpp +++ b/src/engine/events.hpp @@ -30,7 +30,6 @@ #include "events/DestroyEvent.hpp" #include "events/DisconnectAllEvent.hpp" #include "events/DisconnectionEvent.hpp" -#include "events/EnablePatchEvent.hpp" #include "events/LoadPluginsEvent.hpp" #include "events/MidiLearnEvent.hpp" #include "events/NoteEvent.hpp" @@ -44,8 +43,6 @@ #include "events/RequestPluginsEvent.hpp" #include "events/RequestPortValueEvent.hpp" #include "events/SetMetadataEvent.hpp" -#include "events/SetPolyphonicEvent.hpp" -#include "events/SetPolyphonyEvent.hpp" #include "events/SetPortValueEvent.hpp" #include "events/UnregisterClientEvent.hpp" diff --git a/src/engine/events/EnablePatchEvent.cpp b/src/engine/events/EnablePatchEvent.cpp deleted file mode 100644 index 04759cea..00000000 --- a/src/engine/events/EnablePatchEvent.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* This file is part of Ingen. - * Copyright (C) 2007 Dave Robillard <http://drobilla.net> - * - * 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 "EnablePatchEvent.hpp" -#include "Responder.hpp" -#include "Engine.hpp" -#include "PatchImpl.hpp" -#include "util.hpp" -#include "ClientBroadcaster.hpp" -#include "EngineStore.hpp" - -namespace Ingen { - - -EnablePatchEvent::EnablePatchEvent(Engine& engine, SharedPtr<Responder> responder, SampleCount timestamp, const string& patch_path, bool enable) -: QueuedEvent(engine, responder, timestamp), - _patch_path(patch_path), - _patch(NULL), - _compiled_patch(NULL), - _enable(enable) -{ -} - - -void -EnablePatchEvent::pre_process() -{ - _patch = _engine.engine_store()->find_patch(_patch_path); - - if (_enable && _patch) { - /* Any event that requires a new process order will set the patch's - * compiled_patch to NULL if it is executed when the patch is not - * active. So, if the CP is NULL, calculate it here */ - if (_patch->compiled_patch() == NULL) - _compiled_patch = _patch->compile(); - } - - QueuedEvent::pre_process(); -} - - -void -EnablePatchEvent::execute(ProcessContext& context) -{ - QueuedEvent::execute(context); - - if (_patch != NULL) { - if (_enable) - _patch->enable(); - else - _patch->disable(); - - if (_enable && _patch->compiled_patch() == NULL) - _patch->compiled_patch(_compiled_patch); - } -} - - -void -EnablePatchEvent::post_process() -{ - if (_patch != NULL) { - _responder->respond_ok(); - _engine.broadcaster()->send_property_change(_patch_path, "ingen:enabled", (bool)_enable); - } else { - _responder->respond_error(string("Patch ") + _patch_path + " not found"); - } -} - - -} // namespace Ingen - diff --git a/src/engine/events/EnablePatchEvent.hpp b/src/engine/events/EnablePatchEvent.hpp deleted file mode 100644 index dad1803a..00000000 --- a/src/engine/events/EnablePatchEvent.hpp +++ /dev/null @@ -1,63 +0,0 @@ -/* This file is part of Ingen. - * Copyright (C) 2007 Dave Robillard <http://drobilla.net> - * - * 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 ENABLEPATCHEVENT_H -#define ENABLEPATCHEVENT_H - -#include <string> -#include "QueuedEvent.hpp" - -using std::string; - -namespace Raul { template <typename T> class Array; } - -namespace Ingen { - -class PatchImpl; -class NodeImpl; -class CompiledPatch; - - -/** Enables a patch's DSP processing. - * - * \ingroup engine - */ -class EnablePatchEvent : public QueuedEvent -{ -public: - EnablePatchEvent(Engine& engine, - SharedPtr<Responder> responder, - SampleCount timestamp, - const string& patch_path, - bool enable); - - void pre_process(); - void execute(ProcessContext& context); - void post_process(); - -private: - string _patch_path; - PatchImpl* _patch; - CompiledPatch* _compiled_patch; // Patch's new process order - bool _enable; -}; - - -} // namespace Ingen - - -#endif // ENABLEPATCHEVENT_H diff --git a/src/engine/events/SetMetadataEvent.cpp b/src/engine/events/SetMetadataEvent.cpp index 8caede6e..e0b51f2b 100644 --- a/src/engine/events/SetMetadataEvent.cpp +++ b/src/engine/events/SetMetadataEvent.cpp @@ -23,6 +23,7 @@ #include "PortImpl.hpp" #include "ClientBroadcaster.hpp" #include "GraphObjectImpl.hpp" +#include "PatchImpl.hpp" #include "EngineStore.hpp" using std::string; @@ -46,6 +47,8 @@ SetMetadataEvent::SetMetadataEvent( , _key(key) , _value(value) , _object(NULL) + , _patch(NULL) + , _compiled_patch(NULL) { } @@ -61,17 +64,47 @@ SetMetadataEvent::pre_process() _object = _engine.engine_store()->find_object(_path); if (_object == NULL) { + _error = NOT_FOUND; QueuedEvent::pre_process(); return; } + /*cerr << "SET " << _object->path() << (_property ? " PROP " : " VAR ") + << _key << " :: " << _value.type() << endl;*/ + if (_property) _object->set_property(_key, _value); else _object->set_variable(_key, _value); - if (_key == "ingen:broadcast") + _patch = dynamic_cast<PatchImpl*>(_object); + + if (_key == "ingen:broadcast") { _special_type = ENABLE_BROADCAST; + } else if (_patch) { + if (!_property && _key == "ingen:enabled") { + if (_value.type() == Atom::BOOL) { + _special_type = ENABLE; + if (_value.get_bool() && !_patch->compiled_patch()) + _compiled_patch = _patch->compile(); + } else { + _error = BAD_TYPE; + } + } else if (!_property && _key == "ingen:polyphonic") { + if (_value.type() == Atom::BOOL) { + _special_type = POLYPHONIC; + } else { + _error = BAD_TYPE; + } + } else if (_property && _key == "ingen:polyphony") { + if (_value.type() == Atom::INT) { + _special_type = POLYPHONY; + _patch->prepare_internal_poly(_value.get_int32()); + } else { + _error = BAD_TYPE; + } + } + } QueuedEvent::pre_process(); } @@ -80,33 +113,69 @@ SetMetadataEvent::pre_process() void SetMetadataEvent::execute(ProcessContext& context) { - if (_special_type == ENABLE_BROADCAST) { - PortImpl* port = dynamic_cast<PortImpl*>(_object); - if (port) + if (_error != NO_ERROR) + return; + + PortImpl* port = 0; + switch (_special_type) { + case ENABLE_BROADCAST: + if ((port = dynamic_cast<PortImpl*>(_object))) port->broadcast(_value.get_bool()); - } + break; + case ENABLE: + if (_value.get_bool()) { + if (!_patch->compiled_patch()) + _patch->compiled_patch(_compiled_patch); + _patch->enable(); + } else { + _patch->disable(); + } + break; + case POLYPHONIC: + if (!_object->set_polyphonic(*_engine.maid(), _value.get_bool())) + _error = INTERNAL; + break; + case POLYPHONY: + if (!_patch->apply_internal_poly(*_engine.maid(), _value.get_int32())) + _error = INTERNAL; + break; + default: + _success = true; + } QueuedEvent::execute(context); - // Do nothing } void SetMetadataEvent::post_process() { - if (_error == INVALID_PATH) { - _responder->respond_error((boost::format("Invalid path '%1%' setting '%2%'") % _path % _key).str()); - } else if (_object == NULL) { - string msg = (boost::format("Unable to find object '%1%' to set '%2%'") % _path % _key).str(); - _responder->respond_error(msg); - } else { + switch (_error) { + case NO_ERROR: _responder->respond_ok(); if (_property) _engine.broadcaster()->send_property_change(_path, _key, _value); else _engine.broadcaster()->send_variable_change(_path, _key, _value); + break; + case NOT_FOUND: + _responder->respond_error((boost::format( + "Unable to find object '%1%' to set '%2%'") + % _path % _key).str()); + case INTERNAL: + _responder->respond_error("Internal error"); + break; + case INVALID_PATH: + _responder->respond_error((boost::format( + "Invalid path '%1%' setting '%2%'") + % _path % _key).str()); + break; + case BAD_TYPE: + _responder->respond_error((boost::format("Bad type for '%1%'") % _key).str()); + break; } } } // namespace Ingen + diff --git a/src/engine/events/SetMetadataEvent.hpp b/src/engine/events/SetMetadataEvent.hpp index ef1538b7..09774fe9 100644 --- a/src/engine/events/SetMetadataEvent.hpp +++ b/src/engine/events/SetMetadataEvent.hpp @@ -27,6 +27,8 @@ using std::string; namespace Ingen { class GraphObjectImpl; +class PatchImpl; +class CompiledPatch; /** An event to set a piece of variable for an GraphObjectImpl. @@ -49,14 +51,23 @@ public: void post_process(); private: - enum { NO_ERROR, INVALID_PATH } _error; - enum { NONE, ENABLE_BROADCAST } _special_type; + enum { NO_ERROR, NOT_FOUND, INTERNAL, INVALID_PATH, BAD_TYPE } _error; + enum { + NONE, + ENABLE, + ENABLE_BROADCAST, + POLYPHONY, + POLYPHONIC + } _special_type; bool _property; + bool _success; string _path; string _key; Raul::Atom _value; GraphObjectImpl* _object; + PatchImpl* _patch; + CompiledPatch* _compiled_patch; }; diff --git a/src/engine/events/SetPolyphonicEvent.cpp b/src/engine/events/SetPolyphonicEvent.cpp deleted file mode 100644 index 87e03d9e..00000000 --- a/src/engine/events/SetPolyphonicEvent.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* This file is part of Ingen. - * Copyright (C) 2007 Dave Robillard <http://drobilla.net> - * - * 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 "raul/Maid.hpp" -#include "SetPolyphonicEvent.hpp" -#include "Responder.hpp" -#include "Engine.hpp" -#include "PatchImpl.hpp" -#include "ClientBroadcaster.hpp" -#include "util.hpp" -#include "EngineStore.hpp" -#include "PortImpl.hpp" -#include "NodeImpl.hpp" -#include "ConnectionImpl.hpp" -#include "QueuedEventSource.hpp" - -namespace Ingen { - - -SetPolyphonicEvent::SetPolyphonicEvent(Engine& engine, SharedPtr<Responder> responder, FrameTime time, QueuedEventSource* source, const string& path, bool poly) -: QueuedEvent(engine, responder, time, true, source), - _path(path), - _object(NULL), - _poly(poly), - _success(false) -{ -} - - -void -SetPolyphonicEvent::pre_process() -{ - _object = _engine.engine_store()->find_object(_path); - - QueuedEvent::pre_process(); -} - - -void -SetPolyphonicEvent::execute(ProcessContext& context) -{ - QueuedEvent::execute(context); - - if (_object) - _success = _object->set_polyphonic(*_engine.maid(), _poly); - - _source->unblock(); -} - - -void -SetPolyphonicEvent::post_process() -{ - if (_object) { - if (_success) { - _responder->respond_ok(); - _engine.broadcaster()->send_property_change(_path, "ingen:polyphonic", _poly); - } else { - _responder->respond_error("Unable to set object as polyphonic"); - } - } else { - _responder->respond_error("Unable to find object to set polyphonic"); - } -} - - -} // namespace Ingen - diff --git a/src/engine/events/SetPolyphonicEvent.hpp b/src/engine/events/SetPolyphonicEvent.hpp deleted file mode 100644 index 93505cba..00000000 --- a/src/engine/events/SetPolyphonicEvent.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/* This file is part of Ingen. - * Copyright (C) 2007 Dave Robillard <http://drobilla.net> - * - * 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 SETPOLYPHONICEVENT_H -#define SETPOLYPHONICEVENT_H - -#include <string> -#include "raul/Array.hpp" -#include "QueuedEvent.hpp" - -using std::string; - -namespace Ingen { - -class GraphObjectImpl; - - -/** Delete all nodes from a patch. - * - * \ingroup engine - */ -class SetPolyphonicEvent : public QueuedEvent -{ -public: - SetPolyphonicEvent(Engine& engine, SharedPtr<Responder> responder, FrameTime time, QueuedEventSource* source, const string& path, bool poly); - - void pre_process(); - void execute(ProcessContext& context); - void post_process(); - -private: - const string _path; - GraphObjectImpl* _object; - bool _poly; - bool _success; -}; - - -} // namespace Ingen - - -#endif // SETPOLYPHONICEVENT_H diff --git a/src/engine/events/SetPolyphonyEvent.cpp b/src/engine/events/SetPolyphonyEvent.cpp deleted file mode 100644 index 8f48fc41..00000000 --- a/src/engine/events/SetPolyphonyEvent.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* This file is part of Ingen. - * Copyright (C) 2007 Dave Robillard <http://drobilla.net> - * - * 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 "raul/Maid.hpp" -#include "SetPolyphonyEvent.hpp" -#include "Responder.hpp" -#include "Engine.hpp" -#include "PatchImpl.hpp" -#include "ClientBroadcaster.hpp" -#include "util.hpp" -#include "EngineStore.hpp" -#include "PortImpl.hpp" -#include "NodeImpl.hpp" -#include "ConnectionImpl.hpp" -#include "QueuedEventSource.hpp" - -namespace Ingen { - - -SetPolyphonyEvent::SetPolyphonyEvent(Engine& engine, SharedPtr<Responder> responder, FrameTime time, QueuedEventSource* source, const string& patch_path, uint32_t poly) -: QueuedEvent(engine, responder, time, true, source), - _patch_path(patch_path), - _patch(NULL), - _poly(poly) -{ -} - - -void -SetPolyphonyEvent::pre_process() -{ - _patch = _engine.engine_store()->find_patch(_patch_path); - if (_patch && _poly > _patch->internal_polyphony()) - _patch->prepare_internal_poly(_poly); - - QueuedEvent::pre_process(); -} - - -void -SetPolyphonyEvent::execute(ProcessContext& context) -{ - QueuedEvent::execute(context); - - if (_patch) - _patch->apply_internal_poly(*_engine.maid(), _poly); - - _source->unblock(); -} - - -void -SetPolyphonyEvent::post_process() -{ - if (_patch) { - _responder->respond_ok(); - _engine.broadcaster()->send_property_change(_patch_path, "ingen:polyphony", (int32_t)_poly); - } else { - _responder->respond_error("Unable to find patch"); - } -} - - -} // namespace Ingen - diff --git a/src/engine/events/SetPolyphonyEvent.hpp b/src/engine/events/SetPolyphonyEvent.hpp deleted file mode 100644 index f9c5b4f9..00000000 --- a/src/engine/events/SetPolyphonyEvent.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/* This file is part of Ingen. - * Copyright (C) 2007 Dave Robillard <http://drobilla.net> - * - * 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 SETPOLYPHONYEVENT_H -#define SETPOLYPHONYEVENT_H - -#include <string> -#include "raul/Array.hpp" -#include "QueuedEvent.hpp" - -using std::string; - -namespace Ingen { - -class PatchImpl; - - -/** Delete all nodes from a patch. - * - * \ingroup engine - */ -class SetPolyphonyEvent : public QueuedEvent -{ -public: - SetPolyphonyEvent(Engine& engine, SharedPtr<Responder> responder, FrameTime time, QueuedEventSource* source, const string& patch_path, uint32_t poly); - - void pre_process(); - void execute(ProcessContext& context); - void post_process(); - -private: - const string _patch_path; - PatchImpl* _patch; - const uint32_t _poly; - -}; - - -} // namespace Ingen - - -#endif // SETPOLYPHONYEVENT_H diff --git a/src/engine/wscript b/src/engine/wscript index ec22f801..e6f38c0c 100644 --- a/src/engine/wscript +++ b/src/engine/wscript @@ -67,7 +67,6 @@ def build(bld): events/DestroyEvent.cpp events/DisconnectAllEvent.cpp events/DisconnectionEvent.cpp - events/EnablePatchEvent.cpp events/LoadPluginsEvent.cpp events/MidiLearnEvent.cpp events/NoteEvent.cpp @@ -80,8 +79,6 @@ def build(bld): events/RequestPluginsEvent.cpp events/RequestPortValueEvent.cpp events/SetMetadataEvent.cpp - events/SetPolyphonicEvent.cpp - events/SetPolyphonyEvent.cpp events/UnregisterClientEvent.cpp ''' obj.export_incdirs = ['.'] diff --git a/src/gui/ControlPanel.cpp b/src/gui/ControlPanel.cpp index 87167b3f..0d7feafd 100644 --- a/src/gui/ControlPanel.cpp +++ b/src/gui/ControlPanel.cpp @@ -74,12 +74,12 @@ ControlPanel::init(SharedPtr<NodeModel> node, uint32_t poly) add_port(*i); } - node->signal_property.connect(bind( - sigc::mem_fun(this, &ControlPanel::property_changed), false)); + node->signal_property.connect( + sigc::mem_fun(this, &ControlPanel::variable_changed)); if (node->parent()) { - node->signal_property.connect(bind( - sigc::mem_fun(this, &ControlPanel::property_changed), true)); + node->signal_property.connect( + sigc::mem_fun(this, &ControlPanel::parent_property_changed)); } else { cerr << "[ControlPanel] No parent, polyphonic controls disabled" << endl; } @@ -251,15 +251,21 @@ ControlPanel::specific_voice_selected() void -ControlPanel::property_changed(const std::string& predicate, const Raul::Atom& value, bool parent) +ControlPanel::parent_property_changed(const std::string& predicate, const Raul::Atom& value) { - if (!parent && predicate == "ingen:polyphonic" && value.type() == Atom::BOOL) { + if (predicate == "ingen:polyphony" && value.type() == Atom::INT) + _voice_spinbutton->set_range(0, value.get_int32() - 1); +} + + +void +ControlPanel::variable_changed(const std::string& predicate, const Raul::Atom& value) +{ + if (predicate == "ingen:polyphonic" && value.type() == Atom::BOOL) { if (value.get_bool()) _voice_control_box->show(); else _voice_control_box->hide(); - } else if (parent && predicate == "ingen:polyphony" && value.type() == Atom::INT) { - _voice_spinbutton->set_range(0, value.get_int32() - 1); } } diff --git a/src/gui/ControlPanel.hpp b/src/gui/ControlPanel.hpp index c43d59ac..ef73ea16 100644 --- a/src/gui/ControlPanel.hpp +++ b/src/gui/ControlPanel.hpp @@ -72,7 +72,8 @@ private: void all_voices_selected(); void specific_voice_selected(); - void property_changed(const std::string& predicate, const Raul::Atom& value, bool parent); + void variable_changed(const std::string& predicate, const Raul::Atom& value); + void parent_property_changed(const std::string& predicate, const Raul::Atom& value); bool _callback_enabled; diff --git a/src/gui/LoadPatchWindow.cpp b/src/gui/LoadPatchWindow.cpp index 0373ee80..573c6311 100644 --- a/src/gui/LoadPatchWindow.cpp +++ b/src/gui/LoadPatchWindow.cpp @@ -76,7 +76,7 @@ LoadPatchWindow::LoadPatchWindow(BaseObjectType* cobject, const Glib::RefPtr<Gno void -LoadPatchWindow::present(SharedPtr<PatchModel> patch, GraphObject::Variables data) +LoadPatchWindow::present(SharedPtr<PatchModel> patch, GraphObject::Properties data) { set_patch(patch); _initial_data = data; diff --git a/src/gui/LoadPatchWindow.hpp b/src/gui/LoadPatchWindow.hpp index a946275f..2cd9ef9e 100644 --- a/src/gui/LoadPatchWindow.hpp +++ b/src/gui/LoadPatchWindow.hpp @@ -54,7 +54,7 @@ public: void set_replace() { _replace = true; } void set_merge() { _replace = false; } - void present(SharedPtr<PatchModel> patch, GraphObject::Variables data); + void present(SharedPtr<PatchModel> patch, GraphObject::Properties data); protected: void on_show(); @@ -65,7 +65,7 @@ private: void ok_clicked(); void cancel_clicked(); - GraphObject::Variables _initial_data; + GraphObject::Properties _initial_data; SharedPtr<PatchModel> _patch; bool _replace; diff --git a/src/gui/LoadPluginWindow.cpp b/src/gui/LoadPluginWindow.cpp index d8944d28..c0188ba5 100644 --- a/src/gui/LoadPluginWindow.cpp +++ b/src/gui/LoadPluginWindow.cpp @@ -102,7 +102,7 @@ LoadPluginWindow::LoadPluginWindow(BaseObjectType* cobject, const Glib::RefPtr<G void -LoadPluginWindow::present(SharedPtr<PatchModel> patch, GraphObject::Variables data) +LoadPluginWindow::present(SharedPtr<PatchModel> patch, GraphObject::Properties data) { set_patch(patch); _initial_data = data; @@ -334,8 +334,8 @@ LoadPluginWindow::add_clicked() } else { Path path = _patch->path().base() + Path::nameify(name); App::instance().engine()->new_node(path, plugin->uri()); - App::instance().engine()->set_property(path, "ingen:polyphonic", polyphonic); - for (GraphObject::Variables::const_iterator i = _initial_data.begin(); + App::instance().engine()->set_variable(path, "ingen:polyphonic", bool(polyphonic)); + for (GraphObject::Properties::const_iterator i = _initial_data.begin(); i != _initial_data.end(); ++i) App::instance().engine()->set_variable(path, i->first, i->second); _node_name_entry->set_text(generate_module_name(++_plugin_name_offset)); diff --git a/src/gui/LoadPluginWindow.hpp b/src/gui/LoadPluginWindow.hpp index e9be576a..6ed76ded 100644 --- a/src/gui/LoadPluginWindow.hpp +++ b/src/gui/LoadPluginWindow.hpp @@ -98,7 +98,7 @@ public: void add_plugin(SharedPtr<PluginModel> plugin); - void present(SharedPtr<PatchModel> patch, GraphObject::Variables data); + void present(SharedPtr<PatchModel> patch, GraphObject::Properties data); protected: void on_show(); @@ -121,7 +121,7 @@ private: void plugin_selection_changed(); string generate_module_name(int offset = 0); - GraphObject::Variables _initial_data; + GraphObject::Properties _initial_data; SharedPtr<PatchModel> _patch; diff --git a/src/gui/LoadRemotePatchWindow.cpp b/src/gui/LoadRemotePatchWindow.cpp index dab1cd0e..e70c6d3b 100644 --- a/src/gui/LoadRemotePatchWindow.cpp +++ b/src/gui/LoadRemotePatchWindow.cpp @@ -61,7 +61,7 @@ LoadRemotePatchWindow::LoadRemotePatchWindow(BaseObjectType* cobject, const Glib void -LoadRemotePatchWindow::present(SharedPtr<PatchModel> patch, GraphObject::Variables data) +LoadRemotePatchWindow::present(SharedPtr<PatchModel> patch, GraphObject::Properties data) { _liststore->clear(); diff --git a/src/gui/LoadRemotePatchWindow.hpp b/src/gui/LoadRemotePatchWindow.hpp index d6d26725..211924d5 100644 --- a/src/gui/LoadRemotePatchWindow.hpp +++ b/src/gui/LoadRemotePatchWindow.hpp @@ -64,7 +64,7 @@ public: void set_replace() { _replace = true; } void set_merge() { _replace = false; } - void present(SharedPtr<PatchModel> patch, GraphObject::Variables data); + void present(SharedPtr<PatchModel> patch, GraphObject::Properties data); private: void patch_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* col); @@ -73,7 +73,7 @@ private: void open_clicked(); void cancel_clicked(); - GraphObject::Variables _initial_data; + GraphObject::Properties _initial_data; SharedPtr<PatchModel> _patch; bool _replace; diff --git a/src/gui/LoadSubpatchWindow.cpp b/src/gui/LoadSubpatchWindow.cpp index f6ec41d2..3b935f68 100644 --- a/src/gui/LoadSubpatchWindow.cpp +++ b/src/gui/LoadSubpatchWindow.cpp @@ -74,7 +74,7 @@ LoadSubpatchWindow::LoadSubpatchWindow(BaseObjectType* cobject, const Glib::RefP void -LoadSubpatchWindow::present(SharedPtr<PatchModel> patch, GraphObject::Variables data) +LoadSubpatchWindow::present(SharedPtr<PatchModel> patch, GraphObject::Properties data) { set_patch(patch); _initial_data = data; diff --git a/src/gui/LoadSubpatchWindow.hpp b/src/gui/LoadSubpatchWindow.hpp index 559df05c..9e4fda0d 100644 --- a/src/gui/LoadSubpatchWindow.hpp +++ b/src/gui/LoadSubpatchWindow.hpp @@ -45,7 +45,7 @@ public: void set_patch(SharedPtr<PatchModel> patch); - void present(SharedPtr<PatchModel> patch, GraphObject::Variables data); + void present(SharedPtr<PatchModel> patch, GraphObject::Properties data); protected: void on_show(); @@ -59,7 +59,7 @@ private: void ok_clicked(); void cancel_clicked(); - GraphObject::Variables _initial_data; + GraphObject::Properties _initial_data; SharedPtr<PatchModel> _patch; diff --git a/src/gui/NewSubpatchWindow.cpp b/src/gui/NewSubpatchWindow.cpp index a8a13508..6fa2a430 100644 --- a/src/gui/NewSubpatchWindow.cpp +++ b/src/gui/NewSubpatchWindow.cpp @@ -43,7 +43,7 @@ NewSubpatchWindow::NewSubpatchWindow(BaseObjectType* cobject, const Glib::RefPtr } void -NewSubpatchWindow::present(SharedPtr<PatchModel> patch, GraphObject::Variables data) +NewSubpatchWindow::present(SharedPtr<PatchModel> patch, GraphObject::Properties data) { set_patch(patch); _initial_data = data; @@ -92,10 +92,10 @@ NewSubpatchWindow::ok_clicked() const uint32_t poly = _poly_spinbutton->get_value_as_int(); App::instance().engine()->new_patch(path, poly); - for (GraphObject::Variables::const_iterator i = _initial_data.begin(); i != _initial_data.end(); ++i) + for (GraphObject::Properties::const_iterator i = _initial_data.begin(); i != _initial_data.end(); ++i) App::instance().engine()->set_variable(path, i->first, i->second); - App::instance().engine()->set_property(path, "ingen:enabled", (bool)true); + App::instance().engine()->set_variable(path, "ingen:enabled", (bool)true); hide(); } diff --git a/src/gui/NewSubpatchWindow.hpp b/src/gui/NewSubpatchWindow.hpp index 3c685d3f..186e0953 100644 --- a/src/gui/NewSubpatchWindow.hpp +++ b/src/gui/NewSubpatchWindow.hpp @@ -45,14 +45,14 @@ public: void set_patch(SharedPtr<PatchModel> patch); - void present(SharedPtr<PatchModel> patch, GraphObject::Variables data); + void present(SharedPtr<PatchModel> patch, GraphObject::Properties data); private: void name_changed(); void ok_clicked(); void cancel_clicked(); - GraphObject::Variables _initial_data; + GraphObject::Properties _initial_data; SharedPtr<PatchModel> _patch; Gtk::Entry* _name_entry; diff --git a/src/gui/NodeModule.cpp b/src/gui/NodeModule.cpp index d2d2fe24..b137ebc1 100644 --- a/src/gui/NodeModule.cpp +++ b/src/gui/NodeModule.cpp @@ -52,7 +52,6 @@ NodeModule::NodeModule(boost::shared_ptr<PatchCanvas> canvas, SharedPtr<NodeMode node->signal_new_port.connect(sigc::bind(sigc::mem_fun(this, &NodeModule::add_port), true)); node->signal_removed_port.connect(sigc::hide_return(sigc::mem_fun(this, &NodeModule::remove_port))); node->signal_variable.connect(sigc::mem_fun(this, &NodeModule::set_variable)); - node->signal_property.connect(sigc::mem_fun(this, &NodeModule::set_property)); node->signal_renamed.connect(sigc::mem_fun(this, &NodeModule::rename)); } @@ -92,18 +91,19 @@ NodeModule::create(boost::shared_ptr<PatchCanvas> canvas, SharedPtr<NodeModel> n else ret = boost::shared_ptr<NodeModule>(new NodeModule(canvas, node)); - for (GraphObject::Variables::const_iterator m = node->variables().begin(); m != node->variables().end(); ++m) + for (GraphObject::Properties::const_iterator m = node->variables().begin(); m != node->variables().end(); ++m) ret->set_variable(m->first, m->second); for (NodeModel::Ports::const_iterator p = node->ports().begin(); p != node->ports().end(); ++p) { ret->add_port(*p, false); } + + ret->set_stacked_border(node->polyphonic()); if (human) ret->show_human_names(human); // FIXME: double port iteration - - ret->resize(); - ret->set_stacked_border(node->polyphonic()); + else + ret->resize(); return ret; } @@ -372,17 +372,11 @@ NodeModule::store_location() void NodeModule::set_variable(const string& key, const Atom& value) { - if (key == "ingenuity:canvas-x" && value.type() == Atom::FLOAT) + if (key == "ingenuity:canvas-x" && value.type() == Atom::FLOAT) { move_to(value.get_float(), property_y()); - else if (key == "ingenuity:canvas-y" && value.type() == Atom::FLOAT) + } else if (key == "ingenuity:canvas-y" && value.type() == Atom::FLOAT) { move_to(property_x(), value.get_float()); -} - - -void -NodeModule::set_property(const string& key, const Atom& value) -{ - if (key == "ingen:polyphonic" && value.type() == Atom::BOOL) { + } else if (key == "ingen:polyphonic" && value.type() == Atom::BOOL) { set_stacked_border(value.get_bool()); } else if (key == "ingen:selected" && value.type() == Atom::BOOL) { if (value.get_bool() != selected()) { @@ -401,7 +395,7 @@ NodeModule::set_selected(bool b) if (b != selected()) { Module::set_selected(b); if (App::instance().signal()) - App::instance().engine()->set_property(_node->path(), "ingen:selected", b); + App::instance().engine()->set_variable(_node->path(), "ingen:selected", b); } } diff --git a/src/gui/NodeModule.hpp b/src/gui/NodeModule.hpp index d5c9ff79..35691dcc 100644 --- a/src/gui/NodeModule.hpp +++ b/src/gui/NodeModule.hpp @@ -77,8 +77,7 @@ protected: void set_selected(bool b); void rename(); - void set_variable(const std::string& key, const Raul::Atom& value); - void set_property(const std::string& predicate, const Raul::Atom& value); + void set_variable(const std::string& predicate, const Raul::Atom& value); void add_port(SharedPtr<PortModel> port, bool resize=true); diff --git a/src/gui/ObjectMenu.cpp b/src/gui/ObjectMenu.cpp index becbf964..801561e3 100644 --- a/src/gui/ObjectMenu.cpp +++ b/src/gui/ObjectMenu.cpp @@ -68,7 +68,7 @@ ObjectMenu::init(SharedPtr<ObjectModel> object) _properties_menuitem->signal_activate().connect( sigc::mem_fun(this, &ObjectMenu::on_menu_properties)); - object->signal_property.connect(sigc::mem_fun(this, &ObjectMenu::property_changed)); + object->signal_variable.connect(sigc::mem_fun(this, &ObjectMenu::variable_changed)); _enable_signal = true; } @@ -78,13 +78,13 @@ void ObjectMenu::on_menu_polyphonic() { if (_enable_signal) - App::instance().engine()->set_property( - _object->path(), "ingen:polyphonic", _polyphonic_menuitem->get_active()); + App::instance().engine()->set_variable( + _object->path(), "ingen:polyphonic", bool(_polyphonic_menuitem->get_active())); } void -ObjectMenu::property_changed(const std::string& predicate, const Raul::Atom& value) +ObjectMenu::variable_changed(const std::string& predicate, const Raul::Atom& value) { _enable_signal = false; if (predicate == "ingen:polyphonic" && value.type() == Atom::BOOL) diff --git a/src/gui/ObjectMenu.hpp b/src/gui/ObjectMenu.hpp index d1f6b5fe..edd25353 100644 --- a/src/gui/ObjectMenu.hpp +++ b/src/gui/ObjectMenu.hpp @@ -50,7 +50,7 @@ protected: void on_menu_destroy(); void on_menu_properties(); - void property_changed(const std::string& predicate, const Raul::Atom& value); + void variable_changed(const std::string& predicate, const Raul::Atom& value); bool _enable_signal; SharedPtr<ObjectModel> _object; diff --git a/src/gui/PatchCanvas.cpp b/src/gui/PatchCanvas.cpp index e5a92206..ef91e38e 100644 --- a/src/gui/PatchCanvas.cpp +++ b/src/gui/PatchCanvas.cpp @@ -85,22 +85,22 @@ PatchCanvas::PatchCanvas(SharedPtr<PatchModel> patch, int width, int height) // Add port menu items _menu_add_audio_input->signal_activate().connect( sigc::bind(sigc::mem_fun(this, &PatchCanvas::menu_add_port), - "audio_input", "lv2:AudioPort", false)); + "audio_in", "Audio In", "lv2:AudioPort", false)); _menu_add_audio_output->signal_activate().connect( sigc::bind(sigc::mem_fun(this, &PatchCanvas::menu_add_port), - "audio_output", "lv2:AudioPort", true)); + "audio_out", "Audio Out", "lv2:AudioPort", true)); _menu_add_control_input->signal_activate().connect( sigc::bind(sigc::mem_fun(this, &PatchCanvas::menu_add_port), - "control_input", "lv2:ControlPort", false)); + "control_in", "Control In", "lv2:ControlPort", false)); _menu_add_control_output->signal_activate().connect( sigc::bind(sigc::mem_fun(this, &PatchCanvas::menu_add_port), - "control_output", "lv2:ControlPort", true)); + "control_out", "Control Out", "lv2:ControlPort", true)); _menu_add_event_input->signal_activate().connect( sigc::bind(sigc::mem_fun(this, &PatchCanvas::menu_add_port), - "event_input", "lv2ev:EventPort", false)); + "event_in", "Event In", "lv2ev:EventPort", false)); _menu_add_event_output->signal_activate().connect( sigc::bind(sigc::mem_fun(this, &PatchCanvas::menu_add_port), - "event_output", "lv2ev:EventPort", true)); + "event_out", "Event Out", "lv2ev:EventPort", true)); // Add control menu items /*_menu_add_number_control->signal_activate().connect( @@ -284,6 +284,10 @@ PatchCanvas::show_human_names(bool b) boost::shared_ptr<NodeModule> mod = boost::dynamic_pointer_cast<NodeModule>(*m); if (mod) mod->show_human_names(b); + + boost::shared_ptr<PatchPortModule> pmod = boost::dynamic_pointer_cast<PatchPortModule>(*m); + if (pmod) + pmod->show_human_names(b); } } @@ -381,7 +385,7 @@ PatchCanvas::add_port(SharedPtr<PortModel> pm) boost::shared_ptr<PatchCanvas> shared_this = boost::dynamic_pointer_cast<PatchCanvas>(shared_from_this()); - SharedPtr<PatchPortModule> view = PatchPortModule::create(shared_this, pm); + SharedPtr<PatchPortModule> view = PatchPortModule::create(shared_this, pm, _human_names); _views.insert(std::make_pair(pm, view)); add_item(view); view->show(); @@ -690,18 +694,18 @@ PatchCanvas::paste() //cout << "Skipping root" << endl; continue; } - GraphObject::Variables::iterator x = i->second->variables().find("ingenuity:canvas-x"); + GraphObject::Properties::iterator x = i->second->variables().find("ingenuity:canvas-x"); if (x != i->second->variables().end()) x->second = x->second.get_float() + (20.0f * _paste_count); - GraphObject::Variables::iterator y = i->second->variables().find("ingenuity:canvas-y"); + GraphObject::Properties::iterator y = i->second->variables().find("ingenuity:canvas-y"); if (y != i->second->variables().end()) y->second = y->second.get_float() + (20.0f * _paste_count); if (i->first.parent() == "/") { - GraphObject::Properties::iterator s = i->second->properties().find("ingen:selected"); - if (s != i->second->properties().end()) + GraphObject::Properties::iterator s = i->second->variables().find("ingen:selected"); + if (s != i->second->variables().end()) s->second = true; else - i->second->properties().insert(make_pair("ingen:selected", true)); + i->second->variables().insert(make_pair("ingen:selected", true)); } builder.build(i->second); } @@ -723,23 +727,27 @@ PatchCanvas::paste() } -string -PatchCanvas::generate_port_name(const string& base) +void +PatchCanvas::generate_port_name( + const string& sym_base, string& symbol, + const string& name_base, string& name) { - string name = base; + symbol = sym_base; + name = name_base; char num_buf[5]; - for (uint i=1; i < 9999; ++i) { + uint32_t i = 1; + for ( ; i < 9999; ++i) { snprintf(num_buf, 5, "%u", i); - name = base + "_"; - name += num_buf; - if (!_patch->get_port(name)) + symbol = sym_base + "_"; + symbol += num_buf; + if (!_patch->get_port(symbol)) break; } - assert(Path::is_valid(string("/") + name)); + assert(Path::is_valid(string("/") + symbol)); - return name; + name.append(" ").append(num_buf); } void @@ -747,7 +755,7 @@ PatchCanvas::menu_add_control(ControlType type) { // FIXME: bundleify - GraphObject::Variables data = get_initial_data(); + GraphObject::Properties data = get_initial_data(); float x = data["ingenuity:canvas-x"].get_float(); float y = data["ingenuity:canvas-y"].get_float(); @@ -758,14 +766,18 @@ PatchCanvas::menu_add_control(ControlType type) } void -PatchCanvas::menu_add_port(const string& name, const string& type, bool is_output) +PatchCanvas::menu_add_port(const string& sym_base, const string& name_base, + const string& type, bool is_output) { - const Path& path = _patch->path().base() + generate_port_name(name); + string sym, name; + generate_port_name(sym_base, sym, name_base, name); + const Path& path = _patch->path().base() + sym; App::instance().engine()->bundle_begin(); App::instance().engine()->new_port(path, type, _patch->num_ports(), is_output); - GraphObject::Variables data = get_initial_data(); - for (GraphObject::Variables::const_iterator i = data.begin(); i != data.end(); ++i) - App::instance().engine()->set_variable(path, i->first, i->second); + GraphObject::Properties data = get_initial_data(); + App::instance().engine()->set_property(path, "lv2:name", Atom(name.c_str())); + for (GraphObject::Properties::const_iterator i = data.begin(); i != data.end(); ++i) + App::instance().engine()->set_property(path, i->first, i->second); App::instance().engine()->bundle_end(); } @@ -788,8 +800,8 @@ PatchCanvas::load_plugin(WeakPtr<PluginModel> weak_plugin) const Path path = _patch->path().base() + name; // FIXME: polyphony? App::instance().engine()->new_node(path, plugin->uri()); - GraphObject::Variables data = get_initial_data(); - for (GraphObject::Variables::const_iterator i = data.begin(); i != data.end(); ++i) + GraphObject::Properties data = get_initial_data(); + for (GraphObject::Properties::const_iterator i = data.begin(); i != data.end(); ++i) App::instance().engine()->set_variable(path, i->first, i->second); } @@ -807,10 +819,10 @@ PatchCanvas::get_new_module_location(double& x, double& y) } -GraphObject::Variables +GraphObject::Properties PatchCanvas::get_initial_data() { - GraphObject::Variables result; + GraphObject::Properties result; result["ingenuity:canvas-x"] = Atom((float)_last_click_x); result["ingenuity:canvas-y"] = Atom((float)_last_click_y); diff --git a/src/gui/PatchCanvas.hpp b/src/gui/PatchCanvas.hpp index d215817e..b67c4937 100644 --- a/src/gui/PatchCanvas.hpp +++ b/src/gui/PatchCanvas.hpp @@ -89,8 +89,13 @@ private: enum ControlType { NUMBER, BUTTON }; void menu_add_control(ControlType type); - string generate_port_name(const string& base); - void menu_add_port(const string& name, const string& type, bool is_output); + void generate_port_name( + const string& sym_base, string& sym, + const string& name_base, string& name); + + void menu_add_port( + const string& sym_base, const string& name_base, + const string& type, bool is_output); void menu_load_plugin(); void menu_new_patch(); @@ -110,7 +115,7 @@ private: SLV2PluginClasses classes); #endif - GraphObject::Variables get_initial_data(); + GraphObject::Properties get_initial_data(); bool canvas_event(GdkEvent* event); diff --git a/src/gui/PatchPortModule.cpp b/src/gui/PatchPortModule.cpp index ff482fb7..200ce12f 100644 --- a/src/gui/PatchPortModule.cpp +++ b/src/gui/PatchPortModule.cpp @@ -16,6 +16,7 @@ */ #include <cassert> +#include <iostream> #include "PatchPortModule.hpp" #include "interface/EngineInterface.hpp" #include "client/PatchModel.hpp" @@ -33,40 +34,45 @@ namespace Ingen { namespace GUI { -PatchPortModule::PatchPortModule(boost::shared_ptr<PatchCanvas> canvas, SharedPtr<PortModel> port) - : FlowCanvas::Module(canvas, port->path().name(), 0, 0, false) // FIXME: coords? - , _port(port) +PatchPortModule::PatchPortModule(boost::shared_ptr<PatchCanvas> canvas, SharedPtr<PortModel> model) + : FlowCanvas::Module(canvas, model->path().name(), 0, 0, false) // FIXME: coords? + , _model(model) + , _human_name_visible(false) { assert(canvas); - assert(port); + assert(model); - assert(PtrCast<PatchModel>(port->parent())); + assert(PtrCast<PatchModel>(model->parent())); - set_stacked_border(port->polyphonic()); + set_stacked_border(model->polyphonic()); - port->signal_variable.connect(sigc::mem_fun(this, &PatchPortModule::set_variable)); - port->signal_property.connect(sigc::mem_fun(this, &PatchPortModule::set_property)); + model->signal_variable.connect(sigc::mem_fun(this, &PatchPortModule::set_variable)); + model->signal_property.connect(sigc::mem_fun(this, &PatchPortModule::set_property)); } boost::shared_ptr<PatchPortModule> -PatchPortModule::create(boost::shared_ptr<PatchCanvas> canvas, SharedPtr<PortModel> port) +PatchPortModule::create(boost::shared_ptr<PatchCanvas> canvas, SharedPtr<PortModel> model, bool human) { - boost::shared_ptr<PatchPortModule> ret = boost::shared_ptr<PatchPortModule>( - new PatchPortModule(canvas, port)); - assert(ret); + boost::shared_ptr<PatchPortModule> ret(new PatchPortModule(canvas, model)); + boost::shared_ptr<Port> port(new Port(ret, model, model->symbol(), true)); - boost::shared_ptr<Port> view(new Port(ret, port, port->symbol(), true)); - ret->add_port(view); - ret->set_menu(view->menu()); + ret->add_port(port); + ret->set_port(port); + ret->set_menu(port->menu()); - for (GraphObject::Variables::const_iterator m = port->variables().begin(); m != port->variables().end(); ++m) + for (GraphObject::Properties::const_iterator m = model->variables().begin(); + m != model->variables().end(); ++m) ret->set_variable(m->first, m->second); - for (GraphObject::Properties::const_iterator m = port->properties().begin(); m != port->properties().end(); ++m) + for (GraphObject::Properties::const_iterator m = model->properties().begin(); + m != model->properties().end(); ++m) ret->set_property(m->first, m->second); - - ret->resize(); + + if (human) + ret->show_human_names(human); + else + ret->resize(); return ret; } @@ -77,7 +83,7 @@ PatchPortModule::create_menu() { Glib::RefPtr<Gnome::Glade::Xml> xml = GladeFactory::new_glade_reference(); xml->get_widget_derived("object_menu", _menu); - _menu->init(_port, true); + _menu->init(_model, true); set_menu(_menu); } @@ -89,29 +95,42 @@ PatchPortModule::store_location() const float x = static_cast<float>(property_x()); const float y = static_cast<float>(property_y()); - const Atom& existing_x = _port->get_variable("ingenuity:canvas-x"); - const Atom& existing_y = _port->get_variable("ingenuity:canvas-y"); + const Atom& existing_x = _model->get_property("ingenuity:canvas-x"); + const Atom& existing_y = _model->get_property("ingenuity:canvas-y"); if (existing_x.type() != Atom::FLOAT || existing_y.type() != Atom::FLOAT || existing_x.get_float() != x || existing_y.get_float() != y) { - App::instance().engine()->set_variable(_port->path(), "ingenuity:canvas-x", Atom(x)); - App::instance().engine()->set_variable(_port->path(), "ingenuity:canvas-y", Atom(y)); + App::instance().engine()->set_property(_model->path(), "ingenuity:canvas-x", Atom(x)); + App::instance().engine()->set_property(_model->path(), "ingenuity:canvas-y", Atom(y)); } } void -PatchPortModule::set_variable(const string& key, const Atom& value) +PatchPortModule::show_human_names(bool b) { - if (key == "ingenuity:canvas-x" && value.type() == Atom::FLOAT) - move_to(value.get_float(), property_y()); - else if (key == "ingenuity:canvas-y" && value.type() == Atom::FLOAT) - move_to(property_x(), value.get_float()); + using namespace std; + _human_name_visible = b; + const Atom& name = _model->get_property("lv2:name"); + if (b && name.is_valid()) + set_name(name.get_string()); + else + set_name(_model->symbol()); + + resize(); } void -PatchPortModule::set_property(const string& key, const Atom& value) +PatchPortModule::set_name(const std::string& n) +{ + _port->set_name(n); + Module::resize(); +} + + +void +PatchPortModule::set_variable(const string& key, const Atom& value) { if (key == "ingen:polyphonic" && value.type() == Atom::BOOL) { set_stacked_border(value.get_bool()); @@ -127,12 +146,27 @@ PatchPortModule::set_property(const string& key, const Atom& value) void +PatchPortModule::set_property(const string& key, const Atom& value) +{ + if (key == "ingenuity:canvas-x" && value.type() == Atom::FLOAT) { + move_to(value.get_float(), property_y()); + } else if (key == "ingenuity:canvas-y" && value.type() == Atom::FLOAT) { + move_to(property_x(), value.get_float()); + } else if (key == "lv2:name" && value.type() == Atom::STRING && _human_name_visible) { + set_name(value.get_string()); + } else if (key == "lv2:symbol" && value.type() == Atom::STRING && !_human_name_visible) { + set_name(value.get_string()); + } +} + + +void PatchPortModule::set_selected(bool b) { if (b != selected()) { Module::set_selected(b); if (App::instance().signal()) - App::instance().engine()->set_property(_port->path(), "ingen:selected", b); + App::instance().engine()->set_variable(_model->path(), "ingen:selected", b); } } diff --git a/src/gui/PatchPortModule.hpp b/src/gui/PatchPortModule.hpp index 60a50738..62c968ef 100644 --- a/src/gui/PatchPortModule.hpp +++ b/src/gui/PatchPortModule.hpp @@ -50,23 +50,31 @@ class PatchPortModule : public FlowCanvas::Module { public: static boost::shared_ptr<PatchPortModule> create(boost::shared_ptr<PatchCanvas> canvas, - SharedPtr<PortModel> port); + SharedPtr<PortModel> model, + bool human); virtual void store_location(); + void show_human_names(bool b); + + void set_name(const std::string& n); - SharedPtr<PortModel> port() const { return _port; } + SharedPtr<PortModel> port() const { return _model; } protected: - PatchPortModule(boost::shared_ptr<PatchCanvas> canvas, SharedPtr<PortModel> port); + PatchPortModule(boost::shared_ptr<PatchCanvas> canvas, SharedPtr<PortModel> model); void create_menu(); void set_selected(bool b); + + void set_port(SharedPtr<Port> port) { _port = port; } void set_variable(const std::string& predicate, const Raul::Atom& value); void set_property(const std::string& predicate, const Raul::Atom& value); - SharedPtr<PortModel> _port; + SharedPtr<PortModel> _model; + SharedPtr<Port> _port; PortMenu* _menu; + bool _human_name_visible; }; diff --git a/src/gui/PatchTreeWindow.cpp b/src/gui/PatchTreeWindow.cpp index 15c33550..f3a24920 100644 --- a/src/gui/PatchTreeWindow.cpp +++ b/src/gui/PatchTreeWindow.cpp @@ -110,8 +110,8 @@ PatchTreeWindow::add_patch(SharedPtr<PatchModel> pm) } } - pm->signal_property.connect(sigc::bind( - sigc::mem_fun(this, &PatchTreeWindow::patch_property_changed), + pm->signal_variable.connect(sigc::bind( + sigc::mem_fun(this, &PatchTreeWindow::patch_variable_changed), pm->path())); pm->signal_destroyed.connect(sigc::bind( @@ -198,12 +198,12 @@ PatchTreeWindow::event_patch_enabled_toggled(const Glib::ustring& path_str) assert(pm); if (_enable_signal) - App::instance().engine()->set_property(patch_path, "ingen:enabled", (bool)!pm->enabled()); + App::instance().engine()->set_variable(patch_path, "ingen:enabled", (bool)!pm->enabled()); } void -PatchTreeWindow::patch_property_changed(const string& key, const Raul::Atom& value, const Path& path) +PatchTreeWindow::patch_variable_changed(const string& key, const Raul::Atom& value, const Path& path) { _enable_signal = false; if (key == "ingen:enabled" && value.type() == Atom::BOOL) { diff --git a/src/gui/PatchTreeWindow.hpp b/src/gui/PatchTreeWindow.hpp index 6c8794e7..64e20b7c 100644 --- a/src/gui/PatchTreeWindow.hpp +++ b/src/gui/PatchTreeWindow.hpp @@ -49,7 +49,7 @@ public: void new_object(SharedPtr<Client::ObjectModel> object); - void patch_property_changed(const string& key, const Raul::Atom& value, const Path& path); + void patch_variable_changed(const string& key, const Raul::Atom& value, const Path& path); void patch_renamed(const Path& old_path, const Path& new_path); void add_patch(SharedPtr<Client::PatchModel> pm); diff --git a/src/gui/PatchView.cpp b/src/gui/PatchView.cpp index c441a64a..911c7c73 100644 --- a/src/gui/PatchView.cpp +++ b/src/gui/PatchView.cpp @@ -81,8 +81,13 @@ PatchView::set_patch(SharedPtr<PatchModel> patch) for (GraphObject::Properties::const_iterator i = patch->properties().begin(); i != patch->properties().end(); ++i) property_changed(i->first, i->second); + + for (GraphObject::Properties::const_iterator i = patch->variables().begin(); + i != patch->variables().end(); ++i) + variable_changed(i->first, i->second); // Connect model signals to track state + patch->signal_variable.connect(sigc::mem_fun(this, &PatchView::variable_changed)); patch->signal_property.connect(sigc::mem_fun(this, &PatchView::property_changed)); // Connect widget signals to do things @@ -193,7 +198,7 @@ PatchView::process_toggled() if (!_enable_signal) return; - App::instance().engine()->set_property(_patch->path(), "ingen:enabled", + App::instance().engine()->set_variable(_patch->path(), "ingen:enabled", (bool)_process_but->get_active()); } @@ -223,12 +228,18 @@ PatchView::refresh_clicked() void PatchView::property_changed(const std::string& predicate, const Raul::Atom& value) { +} + + +void +PatchView::variable_changed(const std::string& predicate, const Raul::Atom& value) +{ _enable_signal = false; if (predicate == "ingen:enabled") { if (value.type() == Atom::BOOL) _process_but->set_active(value.get_bool()); else - cerr << "WARNING: Bad type for ingen:enabled property: " << value.type() << endl; + cerr << "WARNING: Bad type for ingen:enabled variable: " << value.type() << endl; } _enable_signal = true; } diff --git a/src/gui/PatchView.hpp b/src/gui/PatchView.hpp index 474060f1..488674e5 100644 --- a/src/gui/PatchView.hpp +++ b/src/gui/PatchView.hpp @@ -85,6 +85,7 @@ private: void canvas_item_left(Gnome::Canvas::Item* item); void property_changed(const std::string& predicate, const Raul::Atom& value); + void variable_changed(const std::string& predicate, const Raul::Atom& value); void zoom_full(); diff --git a/src/gui/PatchWindow.cpp b/src/gui/PatchWindow.cpp index 14aab7d9..e8e2d7e0 100644 --- a/src/gui/PatchWindow.cpp +++ b/src/gui/PatchWindow.cpp @@ -394,7 +394,7 @@ PatchWindow::event_import_location() void PatchWindow::event_save() { - GraphObject::Variables::const_iterator doc = _patch->variables().find("ingen:document"); + GraphObject::Properties::const_iterator doc = _patch->variables().find("ingen:document"); if (doc == _patch->variables().end()) { event_save_as(); } else { @@ -410,38 +410,56 @@ PatchWindow::event_save() void PatchWindow::event_save_as() { - Gtk::FileChooserDialog dialog(*this, "Save Patch", Gtk::FILE_CHOOSER_ACTION_SAVE); - - dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - Gtk::Button* save_button = dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); - save_button->property_has_default() = true; - - Gtk::FileFilter filt; - filt.add_pattern("*.ingen.ttl"); - filt.set_name("Ingen patches"); - filt.add_pattern("*.ingen.lv2"); - filt.set_name("Ingen bundles"); - dialog.set_filter(filt); - - // Set current folder to most sensible default - GraphObject::Variables::const_iterator doc = _patch->variables().find("ingen:document"); - if (doc != _patch->variables().end()) - dialog.set_uri(doc->second.get_string()); - else if (App::instance().configuration()->patch_folder().length() > 0) - dialog.set_current_folder(App::instance().configuration()->patch_folder()); - - int result = dialog.run(); - //bool recursive = recursive_checkbutton.get_active(); - - if (result == Gtk::RESPONSE_OK) { + while (true) { + Gtk::FileChooserDialog dialog(*this, "Save Patch", Gtk::FILE_CHOOSER_ACTION_SAVE); + + dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + Gtk::Button* save_button = dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); + save_button->property_has_default() = true; + + Gtk::FileFilter filt; + filt.add_pattern("*.ingen.ttl"); + filt.set_name("Ingen patches"); + filt.add_pattern("*.ingen.lv2"); + filt.set_name("Ingen bundles"); + dialog.set_filter(filt); + + // Set current folder to most sensible default + GraphObject::Properties::const_iterator doc = _patch->variables().find("ingen:document"); + if (doc != _patch->variables().end()) + dialog.set_uri(doc->second.get_string()); + else if (App::instance().configuration()->patch_folder().length() > 0) + dialog.set_current_folder(App::instance().configuration()->patch_folder()); + + if (dialog.run() != Gtk::RESPONSE_OK) + break; + string filename = dialog.get_filename(); + + string base = filename.substr(0, filename.find(".")); + if (base.find("/") != string::npos) + base = base.substr(base.find_last_of("/") + 1); + + if (!Symbol::is_valid(base)) { + Gtk::MessageDialog error_dialog(*this, + "<b>Ingen patch file names must be valid symbols</b>", true, + Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); + error_dialog.set_secondary_text( + "The first character must be _, a-z, or A-Z, and " + "subsequent characters must be _, a-z, A-Z, or 0-9."); + error_dialog.run(); + continue; + } + const bool is_bundle = filename.find(".ingen.lv2") != string::npos; const bool is_patch = filename.find(".ingen.ttl") != string::npos; - + // Save a bundle by default if (!is_bundle && !is_patch) filename += ".ingen.ttl"; + _patch->set_property("lv2:symbol", Atom(base.c_str())); + bool confirm = true; std::fstream fin; fin.open(filename.c_str(), std::ios::in); @@ -449,11 +467,11 @@ PatchWindow::event_save_as() string msg = "File already exists! Are you sure you want to overwrite "; msg += filename + "?"; Gtk::MessageDialog confirm_dialog(*this, - msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_YES_NO, true); + msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_YES_NO, true); confirm = (confirm_dialog.run() == Gtk::RESPONSE_YES); } fin.close(); - + if (confirm) { const Glib::ustring uri = Glib::filename_to_uri(filename); App::instance().loader()->save_patch(_patch, uri); @@ -462,8 +480,10 @@ PatchWindow::event_save_as() (boost::format("Wrote %1% to %2%") % _patch->path() % uri).str(), STATUS_CONTEXT_PATCH); } + + App::instance().configuration()->set_patch_folder(dialog.get_current_folder()); + break; } - App::instance().configuration()->set_patch_folder(dialog.get_current_folder()); } diff --git a/src/gui/ThreadedLoader.cpp b/src/gui/ThreadedLoader.cpp index cf9265db..64a77d0a 100644 --- a/src/gui/ThreadedLoader.cpp +++ b/src/gui/ThreadedLoader.cpp @@ -86,7 +86,7 @@ ThreadedLoader::load_patch(bool merge, optional<Path> data_path, optional<Path> engine_parent, optional<Symbol> engine_symbol, - optional<GraphObject::Variables> engine_data) + optional<GraphObject::Properties> engine_data) { _mutex.lock(); diff --git a/src/gui/ThreadedLoader.hpp b/src/gui/ThreadedLoader.hpp index c0e30a63..ffe7a482 100644 --- a/src/gui/ThreadedLoader.hpp +++ b/src/gui/ThreadedLoader.hpp @@ -61,7 +61,7 @@ public: optional<Path> data_path, optional<Path> engine_parent, optional<Symbol> engine_symbol, - optional<GraphObject::Variables> engine_data); + optional<GraphObject::Properties> engine_data); void save_patch(SharedPtr<PatchModel> model, const string& filename); diff --git a/src/gui/UploadPatchWindow.cpp b/src/gui/UploadPatchWindow.cpp index 874a4b43..96594924 100644 --- a/src/gui/UploadPatchWindow.cpp +++ b/src/gui/UploadPatchWindow.cpp @@ -75,7 +75,7 @@ UploadPatchWindow::on_show() { Gtk::Dialog::on_show(); - Raul::Atom atom = _patch->get_variable("lv2:symbol"); + Raul::Atom atom = _patch->get_property("lv2:symbol"); if (atom.is_valid()) _symbol_entry->set_text(atom.get_string()); @@ -238,7 +238,7 @@ UploadPatchWindow::upload_clicked() Glib::ustring symbol = _symbol_entry->get_text(); Glib::ustring short_name = _short_name_entry->get_text(); - GraphObject::Variables extra_rdf; + GraphObject::Properties extra_rdf; extra_rdf["lv2:symbol"] = Atom(Atom::STRING, symbol); extra_rdf["doap:name"] = Atom(Atom::STRING, short_name); diff --git a/src/gui/WindowFactory.cpp b/src/gui/WindowFactory.cpp index 1e7bf14c..5d05c853 100644 --- a/src/gui/WindowFactory.cpp +++ b/src/gui/WindowFactory.cpp @@ -256,7 +256,7 @@ WindowFactory::remove_control_window(NodeControlWindow* win, GdkEventAny* ignore void -WindowFactory::present_load_plugin(SharedPtr<PatchModel> patch, GraphObject::Variables data) +WindowFactory::present_load_plugin(SharedPtr<PatchModel> patch, GraphObject::Properties data) { PatchWindowMap::iterator w = _patch_windows.find(patch->path()); @@ -269,7 +269,7 @@ WindowFactory::present_load_plugin(SharedPtr<PatchModel> patch, GraphObject::Var void -WindowFactory::present_load_patch(SharedPtr<PatchModel> patch, GraphObject::Variables data) +WindowFactory::present_load_patch(SharedPtr<PatchModel> patch, GraphObject::Properties data) { PatchWindowMap::iterator w = _patch_windows.find(patch->path()); @@ -283,7 +283,7 @@ WindowFactory::present_load_patch(SharedPtr<PatchModel> patch, GraphObject::Vari void -WindowFactory::present_load_remote_patch(SharedPtr<PatchModel> patch, GraphObject::Variables data) +WindowFactory::present_load_remote_patch(SharedPtr<PatchModel> patch, GraphObject::Properties data) { PatchWindowMap::iterator w = _patch_windows.find(patch->path()); @@ -310,7 +310,7 @@ WindowFactory::present_upload_patch(SharedPtr<PatchModel> patch) } void -WindowFactory::present_new_subpatch(SharedPtr<PatchModel> patch, GraphObject::Variables data) +WindowFactory::present_new_subpatch(SharedPtr<PatchModel> patch, GraphObject::Properties data) { PatchWindowMap::iterator w = _patch_windows.find(patch->path()); @@ -322,7 +322,7 @@ WindowFactory::present_new_subpatch(SharedPtr<PatchModel> patch, GraphObject::Va void -WindowFactory::present_load_subpatch(SharedPtr<PatchModel> patch, GraphObject::Variables data) +WindowFactory::present_load_subpatch(SharedPtr<PatchModel> patch, GraphObject::Properties data) { PatchWindowMap::iterator w = _patch_windows.find(patch->path()); diff --git a/src/gui/WindowFactory.hpp b/src/gui/WindowFactory.hpp index 79da3902..60f195f2 100644 --- a/src/gui/WindowFactory.hpp +++ b/src/gui/WindowFactory.hpp @@ -73,12 +73,12 @@ public: void present_controls(SharedPtr<NodeModel> node); - void present_load_plugin(SharedPtr<PatchModel> patch, GraphObject::Variables data=GraphObject::Variables()); - void present_load_patch(SharedPtr<PatchModel> patch, GraphObject::Variables data=GraphObject::Variables()); - void present_load_remote_patch(SharedPtr<PatchModel> patch, GraphObject::Variables data=GraphObject::Variables()); + void present_load_plugin(SharedPtr<PatchModel> patch, GraphObject::Properties data=GraphObject::Properties()); + void present_load_patch(SharedPtr<PatchModel> patch, GraphObject::Properties data=GraphObject::Properties()); + void present_load_remote_patch(SharedPtr<PatchModel> patch, GraphObject::Properties data=GraphObject::Properties()); void present_upload_patch(SharedPtr<PatchModel> patch); - void present_new_subpatch(SharedPtr<PatchModel> patch, GraphObject::Variables data=GraphObject::Variables()); - void present_load_subpatch(SharedPtr<PatchModel> patch, GraphObject::Variables data=GraphObject::Variables()); + void present_new_subpatch(SharedPtr<PatchModel> patch, GraphObject::Properties data=GraphObject::Properties()); + void present_load_subpatch(SharedPtr<PatchModel> patch, GraphObject::Properties data=GraphObject::Properties()); void present_rename(SharedPtr<ObjectModel> object); void present_properties(SharedPtr<ObjectModel> object); diff --git a/src/serialisation/Parser.cpp b/src/serialisation/Parser.cpp index a8938ca4..f64e96ab 100644 --- a/src/serialisation/Parser.cpp +++ b/src/serialisation/Parser.cpp @@ -42,8 +42,24 @@ namespace Serialisation { static Glib::ustring relative_uri(Glib::ustring base, const Glib::ustring uri, bool leading_slash) { - base = base.substr(0, base.find_last_of("/")+1); Glib::ustring ret; + if (uri.substr(0, base.length()) == base) { + ret = (leading_slash ? "/" : "") + uri.substr(base.length()); + while (ret[0] == '#' || ret[0] == '/') + ret = ret.substr(1); + if (leading_slash && ret[0] != '/') + ret = string("/") + ret; + return ret; + } + + size_t last_slash = base.find_last_of("/"); + if (last_slash != string::npos) + base = base.substr(0, last_slash + 1); + + size_t last_hash = base.find_last_of("#"); + if (last_hash != string::npos) + base = base.substr(0, last_hash + 1); + if (uri.length() >= base.length() && uri.substr(0, base.length()) == base) ret = uri.substr(base.length()); else @@ -58,6 +74,7 @@ relative_uri(Glib::ustring base, const Glib::ustring uri, bool leading_slash) } +#if 0 static Glib::ustring chop_uri_scheme(const Glib::ustring in) { @@ -100,6 +117,7 @@ dequote_uri(const Glib::ustring in) out = out.substr(1, out.length()-2); return out; } +#endif static void @@ -116,13 +134,13 @@ normalise_uri(Glib::ustring& uri) */ bool Parser::parse_document( - Ingen::Shared::World* world, - Ingen::Shared::CommonInterface* target, - Glib::ustring document_uri, - boost::optional<Raul::Path> data_path, - boost::optional<Raul::Path> parent, - boost::optional<Raul::Symbol> symbol, - boost::optional<GraphObject::Variables> data) + Ingen::Shared::World* world, + Ingen::Shared::CommonInterface* target, + Glib::ustring document_uri, + boost::optional<Raul::Path> data_path, + boost::optional<Raul::Path> parent, + boost::optional<Raul::Symbol> symbol, + boost::optional<GraphObject::Properties> data) { normalise_uri(document_uri); @@ -151,14 +169,14 @@ Parser::parse_document( bool Parser::parse_string( - Ingen::Shared::World* world, - Ingen::Shared::CommonInterface* target, - const Glib::ustring& str, - const Glib::ustring& base_uri, - boost::optional<Raul::Path> data_path, - boost::optional<Raul::Path> parent, - boost::optional<Raul::Symbol> symbol, - boost::optional<GraphObject::Variables> data) + Ingen::Shared::World* world, + Ingen::Shared::CommonInterface* target, + const Glib::ustring& str, + const Glib::ustring& base_uri, + boost::optional<Raul::Path> data_path, + boost::optional<Raul::Path> parent, + boost::optional<Raul::Symbol> symbol, + boost::optional<GraphObject::Properties> data) { Redland::Model model(*world->rdf_world, str.c_str(), str.length(), base_uri); @@ -177,14 +195,14 @@ Parser::parse_string( bool Parser::parse_update( - Ingen::Shared::World* world, - Shared::CommonInterface* target, - const Glib::ustring& str, - const Glib::ustring& base_uri, - boost::optional<Raul::Path> data_path, - boost::optional<Raul::Path> parent, - boost::optional<Raul::Symbol> symbol, - boost::optional<GraphObject::Variables> data) + Ingen::Shared::World* world, + Shared::CommonInterface* target, + const Glib::ustring& str, + const Glib::ustring& base_uri, + boost::optional<Raul::Path> data_path, + boost::optional<Raul::Path> parent, + boost::optional<Raul::Symbol> symbol, + boost::optional<GraphObject::Properties> data) { Redland::Model model(*world->rdf_world, str.c_str(), str.length(), base_uri); @@ -209,12 +227,11 @@ Parser::parse_update( results = Redland::Query::Results(query.run(*world->rdf_world, model, base_uri)); for (Redland::Query::Results::iterator i = results.begin(); i != results.end(); ++i) { - world->rdf_world->mutex().lock(); + Glib::Mutex::Lock lock(world->rdf_world->mutex()); const string obj_path = (*i)["path"].to_string(); const string key = world->rdf_world->prefixes().qualify((*i)["varkey"].to_string()); const Redland::Node& val_node = (*i)["varval"]; const Atom a(AtomRDF::node_to_atom(val_node)); - world->rdf_world->mutex().unlock(); if (key != "") target->set_variable(obj_path, key, a); } @@ -232,11 +249,10 @@ Parser::parse_update( results = Redland::Query::Results(query.run(*world->rdf_world, model, base_uri)); for (Redland::Query::Results::iterator i = results.begin(); i != results.end(); ++i) { - world->rdf_world->mutex().lock(); + Glib::Mutex::Lock lock(world->rdf_world->mutex()); const string obj_path = (*i)["path"].to_string(); const Redland::Node& val_node = (*i)["value"]; const Atom a(AtomRDF::node_to_atom(val_node)); - world->rdf_world->mutex().unlock(); target->set_port_value(obj_path, a); } @@ -246,14 +262,14 @@ Parser::parse_update( boost::optional<Path> Parser::parse( - Ingen::Shared::World* world, - Ingen::Shared::CommonInterface* target, - Redland::Model& model, - Glib::ustring document_uri, - boost::optional<Raul::Path> data_path, - boost::optional<Raul::Path> parent, - boost::optional<Raul::Symbol> symbol, - boost::optional<GraphObject::Variables> data) + Ingen::Shared::World* world, + Ingen::Shared::CommonInterface* target, + Redland::Model& model, + Glib::ustring document_uri, + boost::optional<Raul::Path> data_path, + boost::optional<Raul::Path> parent, + boost::optional<Raul::Symbol> symbol, + boost::optional<GraphObject::Properties> data) { const Redland::Node::Type res = Redland::Node::RESOURCE; @@ -284,9 +300,6 @@ Parser::parse( const Redland::Node& subject = (data_path ? subject_node : (*i)["s"]); const Redland::Node& rdf_class = (*i)["t"]; - //cout << "SUBJECT: " << subject.to_c_string() << endl; - //cout << "CLASS: " << rdf_class.to_c_string() << endl; - if (!data_path) path_str = relative_uri(document_uri, subject.to_c_string(), true); else if (path_str == "" || path_str[0] != '/') @@ -310,12 +323,9 @@ Parser::parse( if (is_object) { - string path; - if (parent && symbol) { - path = parent->base() + *symbol; - } else { - path = (parent ? parent->base() : "/") + path_str.substr(1); - } + string path = (parent && symbol) + ? parent->base() + *symbol + : (parent ? parent->base() : "/") + path_str.substr(1); if (!Path::is_valid(path)) { cerr << "WARNING: Invalid path '" << path << "' transformed to /" << endl; @@ -351,46 +361,48 @@ Parser::parse( boost::optional<Path> Parser::parse_patch( - Ingen::Shared::World* world, - Ingen::Shared::CommonInterface* target, - Redland::Model& model, - const Redland::Node& subject_node, - boost::optional<Raul::Path> parent, - boost::optional<Raul::Symbol> a_symbol, - boost::optional<GraphObject::Variables> data) + Ingen::Shared::World* world, + Ingen::Shared::CommonInterface* target, + Redland::Model& model, + const Redland::Node& subject_node, + boost::optional<Raul::Path> parent, + boost::optional<Raul::Symbol> a_symbol, + boost::optional<GraphObject::Properties> data) { - std::set<Path> created; - uint32_t patch_poly = 0; + uint32_t patch_poly = 0; + + typedef Redland::Query::Results Results; /* Use parameter overridden polyphony, if given */ if (data) { - GraphObject::Variables::iterator poly_param = data.get().find("ingen:polyphony"); + GraphObject::Properties::iterator poly_param = data.get().find("ingen:polyphony"); if (poly_param != data.get().end() && poly_param->second.type() == Atom::INT) patch_poly = poly_param->second.get_int32(); } const Glib::ustring subject = subject_node.to_turtle_token(); - //cout << "Parse patch " << subject << endl; + //cout << "**** Parse patch " << subject << endl; - /* Get polyphony from file (mandatory if not specified in parameters) */ + /* Load polyphony from file if necessary */ if (patch_poly == 0) { Redland::Query query(*world->rdf_world, Glib::ustring( "SELECT DISTINCT ?poly WHERE { ") + subject + " ingen:polyphony ?poly }"); - Redland::Query::Results results = query.run(*world->rdf_world, model); - - if (results.size() == 0) { - cerr << "[Parser] ERROR: No polyphony found!" << endl; - cerr << "Query was:" << endl << query.string() << endl; - return boost::optional<Path>(); + Results results = query.run(*world->rdf_world, model); + if (results.size() > 0) { + const Redland::Node& poly_node = (*results.begin())["poly"]; + if (poly_node.is_int()) + patch_poly = poly_node.to_int(); + else + cerr << "WARNING: Patch has non-integer polyphony, assuming 1" << endl; } - - const Redland::Node& poly_node = (*results.begin())["poly"]; - assert(poly_node.is_int()); - patch_poly = static_cast<uint32_t>(poly_node.to_int()); } + /* No polyphony value anywhere, 1 it is */ + if (patch_poly == 0) + patch_poly = 1; + const Glib::ustring base_uri = model.base_uri().to_string(); string symbol; @@ -402,183 +414,242 @@ Parser::parse_patch( if (symbol != "") symbol = Path::nameify(symbol); } - - const Path patch_path(parent ? parent->base() + symbol : "/"); + + string patch_path_str = relative_uri(base_uri, subject_node.to_string(), true); + if (!Path::is_valid(patch_path_str)) { + cerr << "ERROR: Patch has invalid path: " << patch_path_str << endl; + return boost::optional<Raul::Path>(); + } + + + /* Create patch */ + Path patch_path(patch_path_str); target->new_patch(patch_path, patch_poly); - /* Plugin nodes */ + /* Find patches in document */ Redland::Query query(*world->rdf_world, Glib::ustring( - "SELECT DISTINCT ?name ?plugin ?varkey ?varval ?poly WHERE {\n") + - subject + " ingen:node ?node .\n" - "?node lv2:symbol ?name ;\n" - " rdf:instanceOf ?plugin ;\n" - " ingen:polyphonic ?poly .\n" - "OPTIONAL { ?node lv2var:variable ?variable .\n" - " ?variable rdf:predicate ?varkey ;\n" - " rdf:value ?varval .\n" - " }" + "SELECT DISTINCT ?patch WHERE {\n") + + "?patch a ingen:Patch .\n" "}"); + set<string> patches; + Results results = query.run(*world->rdf_world, model, base_uri); + for (Results::iterator i = results.begin(); i != results.end(); ++i) { + Glib::Mutex::Lock lock(world->rdf_world->mutex()); + patches.insert((*i)["patch"].to_string()); + } + + typedef multimap<std::string, Redland::Node> Properties; + typedef map<string, Redland::Node> Resources; + typedef map<string, Properties> Objects; + typedef map<string, string> Types; - Redland::Query::Results results = query.run(*world->rdf_world, model, base_uri); - - for (Redland::Query::Results::iterator i = results.begin(); i != results.end(); ++i) { - world->rdf_world->mutex().lock(); - const string node_name = (*i)["name"].to_string(); - const Path node_path = patch_path.base() + node_name; - - if (created.find(node_path) == created.end()) { - const string node_plugin = (*i)["plugin"].to_string(); - bool node_polyphonic = false; - const Redland::Node& poly_node = (*i)["poly"]; - if (poly_node.is_bool() && poly_node.to_bool() == true) - node_polyphonic = true; - - world->rdf_world->mutex().unlock(); - - target->new_node(node_path, node_plugin); - target->set_property(node_path, "ingen:polyphonic", node_polyphonic); - created.insert(node_path); - - world->rdf_world->mutex().lock(); + /* Find nodes on this patch */ + query = Redland::Query(*world->rdf_world, Glib::ustring( + "SELECT DISTINCT ?node ?type WHERE {\n") + + subject + " ingen:node ?node .\n" + "?node rdf:instanceOf ?type .\n" + "}"); + Objects patch_nodes; + Objects plugin_nodes; + Resources resources; + Types types; + results = query.run(*world->rdf_world, model, base_uri); + for (Results::iterator i = results.begin(); i != results.end(); ++i) { + Glib::Mutex::Lock lock(world->rdf_world->mutex()); + Redland::Node& node = (*i)["node"]; + Redland::Node& type = (*i)["type"]; + if (node.type() == Redland::Node::RESOURCE && type.type() == Redland::Node::RESOURCE) { + types.insert(make_pair(node.to_string(), type.to_string())); + if (patches.find(type.to_string()) != patches.end()) { + patch_nodes.insert(make_pair(node.to_string(), Properties())); + resources.insert(make_pair(type.to_string(), type)); + } else { + plugin_nodes.insert(make_pair(node.to_string(), Properties())); + } } - - const string key = world->rdf_world->prefixes().qualify((*i)["varkey"].to_string()); - const Redland::Node& val_node = (*i)["varval"]; - - world->rdf_world->mutex().unlock(); - - if (key != "") - target->set_variable(node_path, key, AtomRDF::node_to_atom(val_node)); } - /* Load subpatches */ + /* Load nodes on this patch */ query = Redland::Query(*world->rdf_world, Glib::ustring( - "SELECT DISTINCT ?subpatch ?symbol WHERE {\n") + - subject + " ingen:node ?subpatch .\n" - "?subpatch a ingen:Patch ;\n" - " lv2:symbol ?symbol .\n" + "SELECT DISTINCT ?node ?predicate ?object WHERE {\n") + + subject + " ingen:node ?node .\n" + "?node ?predicate ?object .\n" "}"); - results = query.run(*world->rdf_world, model, base_uri); - for (Redland::Query::Results::iterator i = results.begin(); i != results.end(); ++i) { - world->rdf_world->mutex().lock(); - const string symbol = (*i)["symbol"].to_string(); - const string subpatch = (*i)["subpatch"].to_string(); - world->rdf_world->mutex().unlock(); - - const Path subpatch_path = patch_path.base() + symbol; - - if (created.find(subpatch_path) == created.end()) { - /*const string subpatch_rel = relative_uri(base_uri, subpatch); - string sub_base = engine_base; - if (sub_base[sub_base.length()-1] == '/') - sub_base = sub_base.substr(sub_base.length()-1); - sub_base.append("/").append(symbol);*/ - created.insert(subpatch_path); - parse_patch(world, target, model, (*i)["subpatch"], patch_path, Symbol(symbol)); + for (Results::iterator i = results.begin(); i != results.end(); ++i) { + Glib::Mutex::Lock lock(world->rdf_world->mutex()); + Redland::Node& node = (*i)["node"]; + Redland::Node& predicate = (*i)["predicate"]; + Redland::Node& object = (*i)["object"]; + Objects::iterator patch_i = patch_nodes.find(node.to_string()); + Objects::iterator plug_i = plugin_nodes.find(node.to_string()); + Types::iterator type_i = types.find(node.to_string()); + if (node.type() == Redland::Node::RESOURCE && type_i != types.end()) { + if (patch_i != patch_nodes.end()) { + patch_i->second.insert(make_pair(predicate.to_string(), object)); + } else if (plug_i != plugin_nodes.end()) { + plug_i->second.insert(make_pair(predicate.to_string(), object)); + } else { + cerr << "WARNING: Unrecognized node: " << node.to_string() << endl; + } } } + /* Create patch nodes */ + for (Objects::iterator i = patch_nodes.begin(); i != patch_nodes.end(); ++i) { + const Path node_path = Path(relative_uri(base_uri, i->first, true)); + Types::iterator type_i = types.find(i->first); + if (type_i == types.end()) + continue; + Resources::iterator res_i = resources.find(type_i->second); + if (res_i == resources.end()) + continue; + parse_patch(world, target, model, res_i->second, patch_path, Symbol(node_path.name())); + Glib::Mutex::Lock lock(world->rdf_world->mutex()); + for (Properties::iterator j = i->second.begin(); j != i->second.end(); ++j) { + const string key = world->rdf_world->prefixes().qualify(j->first); + target->set_variable(node_path, key, AtomRDF::node_to_atom(j->second)); + } + } + + /* Create plugin nodes */ + for (Objects::iterator i = plugin_nodes.begin(); i != plugin_nodes.end(); ++i) { + Types::iterator type_i = types.find(i->first); + if (type_i == types.end()) + continue; + const Path node_path(relative_uri(base_uri, i->first, true)); + target->new_node(node_path, type_i->second); + Glib::Mutex::Lock lock(world->rdf_world->mutex()); + for (Properties::iterator j = i->second.begin(); j != i->second.end(); ++j) { + const string key = world->rdf_world->prefixes().qualify(j->first); + target->set_variable(node_path, key, AtomRDF::node_to_atom(j->second)); + } + } + - /* Set node port control values */ + /* Load node ports */ query = Redland::Query(*world->rdf_world, Glib::ustring( - "SELECT DISTINCT ?nodename ?portname ?portval WHERE {\n") + - subject + " ingen:node ?node .\n" - "?node lv2:symbol ?nodename ;\n" - " lv2:port ?port .\n" - "?port lv2:symbol ?portname ;\n" - " ingen:value ?portval .\n" - "FILTER ( datatype(?portval) = xsd:decimal )\n" + "SELECT DISTINCT ?node ?port ?key ?val WHERE {\n") + + subject + " ingen:node ?node .\n" + "?node lv2:port ?port .\n" + "?port ?key ?val .\n" "}"); - results = query.run(*world->rdf_world, model, base_uri); - for (Redland::Query::Results::iterator i = results.begin(); i != results.end(); ++i) { - world->rdf_world->mutex().lock(); - const string node_name = (*i)["nodename"].to_string(); - const string port_name = (*i)["portname"].to_string(); - world->rdf_world->mutex().unlock(); - - assert(Path::is_valid_name(node_name)); - assert(Path::is_valid_name(port_name)); - const Path port_path = patch_path.base() + node_name + "/" + port_name; + for (Results::iterator i = results.begin(); i != results.end(); ++i) { + Glib::Mutex::Lock lock(world->rdf_world->mutex()); + const string node_uri = (*i)["node"].to_string(); + const string port_uri = (*i)["port"].to_string(); + if (port_uri.length() <= node_uri.length()) { + cerr << "WARNING: Port on " << node_uri << " has bad URI: " << port_uri << endl; + continue; + } - target->set_port_value(port_path, AtomRDF::node_to_atom((*i)["portval"])); + const Path node_path(relative_uri(base_uri, node_uri, true)); + const Symbol port_sym = port_uri.substr(node_uri.length() + 1); + const Path port_path = node_path.base() + port_sym; + const string key = world->rdf_world->prefixes().qualify((*i)["key"].to_string()); + if (key == "ingen:value") { + target->set_port_value(port_path, AtomRDF::node_to_atom((*i)["val"])); + } else { + target->set_variable(port_path, key, AtomRDF::node_to_atom((*i)["val"])); + } } + - - /* Load this patch's ports */ + /* Find ports on this patch */ query = Redland::Query(*world->rdf_world, Glib::ustring( - "SELECT DISTINCT ?port ?type ?name ?datatype ?varkey ?varval ?portval WHERE {\n") + - subject + " lv2:port ?port .\n" - "?port a ?type ;\n" - " a ?datatype ;\n" - " lv2:symbol ?name .\n" - " FILTER (?type != ?datatype && ((?type = lv2:InputPort) || (?type = lv2:OutputPort)))\n" - "OPTIONAL { ?port ingen:value ?portval . \n" - " FILTER ( datatype(?portval) = xsd:decimal ) }\n" - "OPTIONAL { ?port lv2var:variable ?variable .\n" - " ?variable rdf:predicate ?varkey ;\n" - " rdf:value ?varval .\n" - " }" + "SELECT DISTINCT ?port ?type WHERE {\n") + + subject + " lv2:port ?port .\n" + "?port rdf:instanceOf ?type .\n" "}"); - + Objects patch_ports; results = query.run(*world->rdf_world, model, base_uri); - - for (Redland::Query::Results::iterator i = results.begin(); i != results.end(); ++i) { - world->rdf_world->mutex().lock(); - const string name = (*i)["name"].to_string(); - const string type = world->rdf_world->qualify((*i)["type"].to_string()); - const string datatype = world->rdf_world->qualify((*i)["datatype"].to_string()); - world->rdf_world->mutex().unlock(); - - assert(Path::is_valid_name(name)); - const Path port_path = patch_path.base() + name; - - if (created.find(port_path) == created.end()) { - // TODO: read index for plugin wrapper - bool is_output = (type == "lv2:OutputPort"); - target->new_port(port_path, datatype, 0, is_output); - created.insert(port_path); + for (Results::iterator i = results.begin(); i != results.end(); ++i) { + Glib::Mutex::Lock lock(world->rdf_world->mutex()); + Redland::Node& port = (*i)["port"]; + Redland::Node& type = (*i)["type"]; + if (port.type() == Redland::Node::RESOURCE && type.type() == Redland::Node::RESOURCE) { + types.insert(make_pair(port.to_string(), type.to_string())); + patch_ports.insert(make_pair(port.to_string(), Properties())); } + } + - world->rdf_world->mutex().lock(); - const Redland::Node& val_node = (*i)["portval"]; - world->rdf_world->mutex().unlock(); - - target->set_port_value(patch_path.base() + name, AtomRDF::node_to_atom(val_node)); - - world->rdf_world->mutex().lock(); - const string key = world->rdf_world->prefixes().qualify((*i)["varkey"].to_string()); - const Redland::Node& var_val_node = (*i)["varval"]; - world->rdf_world->mutex().unlock(); - - if (key != "") - target->set_variable(patch_path.base() + name, key, AtomRDF::node_to_atom(var_val_node)); + /* Load patch ports */ + query = Redland::Query(*world->rdf_world, Glib::ustring( + "SELECT DISTINCT ?port ?key ?val WHERE {\n") + + subject + " lv2:port ?port .\n" + "?port ?key ?val .\n" + "}"); + results = query.run(*world->rdf_world, model, base_uri); + for (Results::iterator i = results.begin(); i != results.end(); ++i) { + Glib::Mutex::Lock lock(world->rdf_world->mutex()); + const string port_uri = (*i)["port"].to_string(); + const Path port_path(Path(relative_uri(base_uri, port_uri, true))); + const string key = world->rdf_world->prefixes().qualify((*i)["key"].to_string()); + Objects::iterator ports_i = patch_ports.find(port_uri); + if (ports_i == patch_ports.end()) + ports_i = patch_ports.insert(make_pair(port_uri, Properties())).first; + ports_i->second.insert(make_pair(key, (*i)["val"])); } + for (Objects::iterator i = patch_ports.begin(); i != patch_ports.end(); ++i) { + Glib::Mutex::Lock lock(world->rdf_world->mutex()); + const Path port_path(relative_uri(base_uri, i->first, true)); + Properties::iterator types_begin = i->second.find("rdf:type"); + if (types_begin == i->second.end()) { + cerr << "WARNING: Patch port has no types" << endl; + continue; + } + Properties::iterator types_end = i->second.upper_bound("rdf:type"); + bool is_input = false; + bool is_output = false; + Redland::Node* type = 0; + for (Properties::iterator t = types_begin; t != types_end; ++t) { + if (t->second.to_string() == NS_LV2 "InputPort") { + is_input = true; + } else if (t->second.to_string() == NS_LV2 "OutputPort") { + is_output = true; + } else if (!type || type->to_string() == t->second.to_string()) { + type = &t->second; + } else { + cerr << "ERROR: Port has several data types" << endl; + continue; + } + } + if ((is_input && is_output) || !type) { + cerr << "ERROR: Corrupt patch port" << endl; + continue; + } + const string type_str = world->rdf_world->prefixes().qualify(type->to_string()); + target->new_port(port_path, type_str, 0, is_output); + for (Properties::iterator j = i->second.begin(); j != i->second.end(); ++j) { + target->set_property(port_path, j->first, AtomRDF::node_to_atom(j->second)); + } + } - created.clear(); - - parse_connections(world, target, model, subject, patch_path); + parse_connections(world, target, model, subject, "/"); parse_variables(world, target, model, subject_node, patch_path, data); - + + /* Enable */ query = Redland::Query(*world->rdf_world, Glib::ustring( - "SELECT DISTINCT ?enabled WHERE { ") + subject + " ingen:enabled ?enabled }"); + "SELECT DISTINCT ?enabled WHERE {\n") + + subject + " ingen:enabled ?enabled .\n" + "}"); results = query.run(*world->rdf_world, model, base_uri); - for (Redland::Query::Results::iterator i = results.begin(); i != results.end(); ++i) { - world->rdf_world->mutex().lock(); + for (Results::iterator i = results.begin(); i != results.end(); ++i) { + Glib::Mutex::Lock lock(world->rdf_world->mutex()); const Redland::Node& enabled_node = (*i)["enabled"]; - world->rdf_world->mutex().unlock(); if (enabled_node.is_bool() && enabled_node) { - target->set_property(patch_path, "ingen:enabled", (bool)true); + target->set_variable(patch_path, "ingen:enabled", (bool)true); break; } else { - cerr << "WARNING: Unknown type for property ingen:enabled" << endl; + cerr << "WARNING: Unknown type for ingen:enabled" << endl; } } @@ -588,17 +659,18 @@ Parser::parse_patch( boost::optional<Path> Parser::parse_node( - Ingen::Shared::World* world, - Ingen::Shared::CommonInterface* target, - Redland::Model& model, - const Redland::Node& subject, - const Raul::Path& path, - boost::optional<GraphObject::Variables> data) + Ingen::Shared::World* world, + Ingen::Shared::CommonInterface* target, + Redland::Model& model, + const Redland::Node& subject, + const Raul::Path& path, + boost::optional<GraphObject::Properties> data) { /* Get plugin */ Redland::Query query(*world->rdf_world, Glib::ustring( - "SELECT DISTINCT ?plug WHERE { ") + subject.to_turtle_token() - + " rdf:instanceOf ?plug }"); + "SELECT DISTINCT ?plug WHERE {\n") + + subject.to_turtle_token() + " rdf:instanceOf ?plug .\n" + "}"); Redland::Query::Results results = query.run(*world->rdf_world, model); @@ -621,12 +693,12 @@ Parser::parse_node( boost::optional<Path> Parser::parse_port( - Ingen::Shared::World* world, - Ingen::Shared::CommonInterface* target, - Redland::Model& model, - const Redland::Node& subject_node, - const Raul::Path& path, - boost::optional<GraphObject::Variables> data) + Ingen::Shared::World* world, + Ingen::Shared::CommonInterface* target, + Redland::Model& model, + const Redland::Node& subject_node, + const Raul::Path& path, + boost::optional<GraphObject::Properties> data) { const Glib::ustring subject = subject_node.to_turtle_token(); @@ -639,21 +711,20 @@ Parser::parse_port( "}"); Redland::Query::Results results = query.run(*world->rdf_world, model); - world->rdf_world->mutex().lock(); for (Redland::Query::Results::iterator i = results.begin(); i != results.end(); ++i) { - const string type = world->rdf_world->qualify((*i)["type"].to_string()); - const string datatype = world->rdf_world->qualify((*i)["datatype"].to_string()); + Glib::Mutex::Lock lock(world->rdf_world->mutex()); + const string type = world->rdf_world->qualify((*i)["type"].to_string()); + const string datatype = world->rdf_world->qualify((*i)["datatype"].to_string()); + const Redland::Node& val_node = (*i)["value"]; // TODO: read index for plugin wrapper bool is_output = (type == "lv2:OutputPort"); target->new_port(path, datatype, 0, is_output); - - const Redland::Node& val_node = (*i)["value"]; + if (val_node.to_string() != "") target->set_port_value(path, AtomRDF::node_to_atom(val_node)); } - world->rdf_world->mutex().unlock(); parse_variables(world, target, model, subject_node, path, data); return path; @@ -670,36 +741,24 @@ Parser::parse_connections( { Redland::Query query(*world->rdf_world, Glib::ustring( "SELECT DISTINCT ?src ?dst WHERE {\n") - + subject + " ingen:connection ?connection .\n" - "?connection ingen:source ?src ;\n" - " ingen:destination ?dst .\n" + + subject + " ingen:connection ?connection .\n" + "?connection ingen:source ?src ;\n" + " ingen:destination ?dst .\n" "}"); - const Glib::ustring& full_base_uri = model.base_uri().to_string(); - const Glib::ustring& base_uri = full_base_uri.substr(0, full_base_uri.find_last_of("/")); - const Glib::ustring& subject_uri = dequote_uri(subject); - - const Glib::ustring& subject_base = (subject_uri == full_base_uri) - ? "" - : chop_uri_scheme(relative_uri(full_base_uri, subject_uri, false)); - - const Glib::ustring& base = uri_child(base_uri, subject_base, true); + const Glib::ustring& base_uri = model.base_uri().to_string(); Redland::Query::Results results = query.run(*world->rdf_world, model); for (Redland::Query::Results::iterator i = results.begin(); i != results.end(); ++i) { - const string src_path = parent.base() + relative_uri(base, (*i)["src"].to_string(), false); - if (!Path::is_valid(src_path)) { - cerr << "ERROR: Invalid path in connection: " << src_path << endl; - continue; - } - - const string dst_path = parent.base() + relative_uri(base, (*i)["dst"].to_string(), false); - if (!Path::is_valid(dst_path)) { - cerr << "ERROR: Invalid path in connection: " << dst_path << endl; - continue; + Glib::Mutex::Lock lock(world->rdf_world->mutex()); + string src_path = parent.base() + relative_uri(base_uri, (*i)["src"].to_string(), false); + string dst_path = parent.base() + relative_uri(base_uri, (*i)["dst"].to_string(), false); + if (Path::is_valid(src_path) && Path::is_valid(dst_path)) { + target->connect(src_path, dst_path); + } else { + cerr << "ERROR: Invalid path in connection " + << src_path << " => " << dst_path << endl; } - - target->connect(src_path, dst_path); } return true; @@ -708,48 +767,33 @@ Parser::parse_connections( bool Parser::parse_variables( - Ingen::Shared::World* world, - Ingen::Shared::CommonInterface* target, - Redland::Model& model, - const Redland::Node& subject_node, - const Raul::Path& path, - boost::optional<GraphObject::Variables> data) + Ingen::Shared::World* world, + Ingen::Shared::CommonInterface* target, + Redland::Model& model, + const Redland::Node& subject_node, + const Raul::Path& path, + boost::optional<GraphObject::Properties> data) { const Glib::ustring& subject = subject_node.to_turtle_token(); Redland::Query query(*world->rdf_world, Glib::ustring( - "SELECT DISTINCT ?varkey ?varval WHERE {\n") + - subject + " lv2var:variable ?variable .\n" - "?variable rdf:predicate ?varkey ;\n" - " rdf:value ?varval .\n" + "SELECT DISTINCT ?key ?val WHERE {\n") + + subject + " ?key ?val .\n" "}"); Redland::Query::Results results = query.run(*world->rdf_world, model); for (Redland::Query::Results::iterator i = results.begin(); i != results.end(); ++i) { - const string key = world->rdf_world->prefixes().qualify(string((*i)["varkey"])); - const Redland::Node& val_node = (*i)["varval"]; + Glib::Mutex::Lock lock(world->rdf_world->mutex()); + const string key = world->rdf_world->prefixes().qualify(string((*i)["key"])); + const Redland::Node& val = (*i)["val"]; if (key != "") - target->set_variable(path, key, AtomRDF::node_to_atom(val_node)); + target->set_variable(path, key, AtomRDF::node_to_atom(val)); } - query = Redland::Query(*world->rdf_world, Glib::ustring( - "SELECT DISTINCT ?key ?val WHERE {\n") + - subject + " ingen:property ?property .\n" - "?property rdf:predicate ?key ;\n" - " rdf:value ?val .\n" - "}"); - - results = query.run(*world->rdf_world, model); - for (Redland::Query::Results::iterator i = results.begin(); i != results.end(); ++i) { - const string key = world->rdf_world->prefixes().qualify(string((*i)["key"])); - const Redland::Node& val_node = (*i)["val"]; - if (key != "") - target->set_property(path, key, AtomRDF::node_to_atom(val_node)); - } - // Set passed variables last to override any loaded values if (data) - for (GraphObject::Variables::const_iterator i = data.get().begin(); i != data.get().end(); ++i) + for (GraphObject::Properties::const_iterator i = data.get().begin(); + i != data.get().end(); ++i) target->set_variable(path, i->first, i->second); return true; diff --git a/src/serialisation/Parser.hpp b/src/serialisation/Parser.hpp index 7b5acede..6fbb8be6 100644 --- a/src/serialisation/Parser.hpp +++ b/src/serialisation/Parser.hpp @@ -46,7 +46,7 @@ public: boost::optional<Raul::Path> data_path=boost::optional<Raul::Path>(), boost::optional<Raul::Path> parent=boost::optional<Raul::Path>(), boost::optional<Raul::Symbol> symbol=boost::optional<Raul::Symbol>(), - boost::optional<GraphObject::Variables> data=boost::optional<GraphObject::Variables>()); + boost::optional<GraphObject::Properties> data=boost::optional<GraphObject::Properties>()); virtual bool parse_string( Ingen::Shared::World* world, @@ -56,7 +56,7 @@ public: boost::optional<Raul::Path> data_path=boost::optional<Raul::Path>(), boost::optional<Raul::Path> parent=boost::optional<Raul::Path>(), boost::optional<Raul::Symbol> symbol=boost::optional<Raul::Symbol>(), - boost::optional<GraphObject::Variables> data=boost::optional<GraphObject::Variables>()); + boost::optional<GraphObject::Properties> data=boost::optional<GraphObject::Properties>()); virtual bool parse_update( Ingen::Shared::World* world, @@ -66,7 +66,7 @@ public: boost::optional<Raul::Path> data_path=boost::optional<Raul::Path>(), boost::optional<Raul::Path> parent=boost::optional<Raul::Path>(), boost::optional<Raul::Symbol> symbol=boost::optional<Raul::Symbol>(), - boost::optional<GraphObject::Variables> data=boost::optional<GraphObject::Variables>()); + boost::optional<GraphObject::Properties> data=boost::optional<GraphObject::Properties>()); private: boost::optional<Raul::Path> parse( @@ -77,7 +77,7 @@ private: boost::optional<Raul::Path> data_path=boost::optional<Raul::Path>(), boost::optional<Raul::Path> parent=boost::optional<Raul::Path>(), boost::optional<Raul::Symbol> symbol=boost::optional<Raul::Symbol>(), - boost::optional<GraphObject::Variables> data=boost::optional<GraphObject::Variables>()); + boost::optional<GraphObject::Properties> data=boost::optional<GraphObject::Properties>()); boost::optional<Raul::Path> parse_patch( Ingen::Shared::World* world, @@ -86,7 +86,7 @@ private: const Redland::Node& subject, boost::optional<Raul::Path> parent=boost::optional<Raul::Path>(), boost::optional<Raul::Symbol> symbol=boost::optional<Raul::Symbol>(), - boost::optional<GraphObject::Variables> data=boost::optional<GraphObject::Variables>()); + boost::optional<GraphObject::Properties> data=boost::optional<GraphObject::Properties>()); boost::optional<Raul::Path> parse_node( Ingen::Shared::World* world, @@ -94,7 +94,7 @@ private: Redland::Model& model, const Redland::Node& subject, const Raul::Path& path, - boost::optional<GraphObject::Variables> data=boost::optional<GraphObject::Variables>()); + boost::optional<GraphObject::Properties> data=boost::optional<GraphObject::Properties>()); boost::optional<Raul::Path> parse_port( Ingen::Shared::World* world, @@ -102,7 +102,7 @@ private: Redland::Model& model, const Redland::Node& subject, const Raul::Path& path, - boost::optional<GraphObject::Variables> data=boost::optional<GraphObject::Variables>()); + boost::optional<GraphObject::Properties> data=boost::optional<GraphObject::Properties>()); bool parse_variables( Ingen::Shared::World* world, @@ -110,7 +110,7 @@ private: Redland::Model& model, const Redland::Node& subject, const Raul::Path& path, - boost::optional<GraphObject::Variables> data=boost::optional<GraphObject::Variables>()); + boost::optional<GraphObject::Properties> data=boost::optional<GraphObject::Properties>()); bool parse_connections( Ingen::Shared::World* world, diff --git a/src/serialisation/Serialiser.cpp b/src/serialisation/Serialiser.cpp index 4bfa74db..a1f4f902 100644 --- a/src/serialisation/Serialiser.cpp +++ b/src/serialisation/Serialiser.cpp @@ -93,23 +93,19 @@ void Serialiser::write_manifest(const std::string& bundle_uri, const Records& records) { - - cout << "WRITE MANIFEST BUNDLE URI: " << bundle_uri << endl; const string filename = Glib::filename_from_uri(bundle_uri) + "manifest.ttl"; - cout << "FILENAME: " << filename << endl; start_to_filename(filename); _model->set_base_uri(bundle_uri); for (Records::const_iterator i = records.begin(); i != records.end(); ++i) { SharedPtr<Patch> patch = PtrCast<Patch>(i->object); if (patch) { - const Redland::Node subject(_model->world(), Redland::Node::RESOURCE, - uri_to_symbol(i->uri)); + const Redland::Resource subject(_model->world(), uri_to_symbol(i->uri)); _model->add_statement(subject, "rdf:type", - Redland::Node(_model->world(), Redland::Node::RESOURCE, "ingen:Patch")); + Redland::Resource(_model->world(), "ingen:Patch")); _model->add_statement(subject, "rdf:type", - Redland::Node(_model->world(), Redland::Node::RESOURCE, "lv2:Plugin")); + Redland::Resource(_model->world(), "lv2:Plugin")); _model->add_statement(subject, "rdfs:seeAlso", - Redland::Node(_model->world(), Redland::Node::RESOURCE, i->uri)); + Redland::Resource(_model->world(), i->uri)); } } finish(); @@ -139,15 +135,15 @@ Serialiser::write_bundle(const Record& record) string -Serialiser::to_string(SharedPtr<GraphObject> object, - const string& base_uri, - const GraphObject::Variables& extra_rdf) +Serialiser::to_string(SharedPtr<GraphObject> object, + const string& base_uri, + const GraphObject::Properties& extra_rdf) { start_to_string(object->path(), base_uri); serialise(object); - Redland::Node base_rdf_node(_model->world(), Redland::Node::RESOURCE, base_uri); - for (GraphObject::Variables::const_iterator v = extra_rdf.begin(); v != extra_rdf.end(); ++v) { + Redland::Resource base_rdf_node(_model->world(), base_uri); + for (GraphObject::Properties::const_iterator v = extra_rdf.begin(); v != extra_rdf.end(); ++v) { if (v->first.find(":") != string::npos) { _model->add_statement(base_rdf_node, v->first, AtomRDF::atom_to_node(_model->world(), v->second)); @@ -223,111 +219,37 @@ Serialiser::finish() } _base_uri = ""; -#ifdef USE_BLANK_NODES - _node_map.clear(); -#endif return ret; } - -Redland::Node -Serialiser::patch_path_to_rdf_node(const Path& path) -{ -#ifdef USE_BLANK_NODES - if (path == _root_path) { - return Redland::Node(_model->world(), Redland::Node::RESOURCE, _base_uri); - } else { - assert(path.length() > _root_path.length()); - return Redland::Node(_model->world(), Redland::Node::RESOURCE, - _base_uri + string("#") + path.substr(_root_path.length())); - } -#else - return path_to_rdf_node(path); -#endif -} - - -/** Convert a path to an RDF blank node ID for serializing. - */ Redland::Node -Serialiser::path_to_rdf_node(const Path& path) +Serialiser::instance_rdf_node(const Path& path) { -#ifdef USE_BLANK_NODES - NodeMap::iterator i = _node_map.find(path); - if (i != _node_map.end()) { - assert(i->second); - assert(i->second.get_node()); - return i->second; - } else { - Redland::Node id = _world.blank_id(Path::nameify(path.substr(1))); - assert(id); - _node_map[path] = id; - return id; - } -#else assert(_model); assert(path.substr(0, _root_path.length()) == _root_path); if (path == _root_path) - return Redland::Node(_model->world(), Redland::Node::RESOURCE, _base_uri); + return Redland::Resource(_model->world(), _base_uri); else - return Redland::Node(_model->world(), Redland::Node::RESOURCE, + return Redland::Resource(_model->world(), path.substr(_root_path.base().length())); -#endif } -#if 0 -/** Searches for the filename passed in the path, returning the full - * path of the file, or the empty string if not found. - * - * This function tries to be as friendly a black box as possible - if the path - * passed is an absolute path and the file is found there, it will return - * that path, etc. - * - * additional_path is a list (colon delimeted as usual) of additional - * directories to look in. ie the directory the parent patch resides in would - * be a good idea to pass as additional_path, in the case of a subpatch. - */ -string -Serialiser::find_file(const string& filename, const string& additional_path) +Redland::Node +Serialiser::class_rdf_node(const Path& path) { - string search_path = additional_path + ":" + _patch_search_path; - - // Try to open the raw filename first - std::ifstream is(filename.c_str(), std::ios::in); - if (is.good()) { - is.close(); - return filename; - } - - string directory; - string full_patch_path = ""; - - while (search_path != "") { - directory = search_path.substr(0, search_path.find(':')); - if (search_path.find(':') != string::npos) - search_path = search_path.substr(search_path.find(':')+1); - else - search_path = ""; - - full_patch_path = directory +"/"+ filename; - - std::ifstream is; - is.open(full_patch_path.c_str(), std::ios::in); + assert(_model); + assert(path.substr(0, _root_path.length()) == _root_path); - if (is.good()) { - is.close(); - return full_patch_path; - } else { - cerr << "[Serialiser] Could not find patch file " << full_patch_path << endl; - } - } - - return ""; + if (path == _root_path) + return Redland::Resource(_model->world(), _base_uri); + else + return Redland::Resource(_model->world(), + string("#") + path.substr(_root_path.base().length())); } -#endif + void Serialiser::serialise(SharedPtr<GraphObject> object) throw (std::logic_error) @@ -337,19 +259,27 @@ Serialiser::serialise(SharedPtr<GraphObject> object) throw (std::logic_error) SharedPtr<Shared::Patch> patch = PtrCast<Shared::Patch>(object); if (patch) { - serialise_patch(patch); + if (patch->path() == _root_path) { + const Redland::Resource patch_id(_model->world(), _base_uri); + serialise_patch(patch, patch_id); + } else { + const Redland::Resource patch_id(_model->world(), string("#") + patch->path().substr(1)); + serialise_patch(patch, patch_id); + serialise_node(patch, patch_id, instance_rdf_node(patch->path())); + } return; } SharedPtr<Shared::Node> node = PtrCast<Shared::Node>(object); if (node) { - serialise_node(node, path_to_rdf_node(node->path())); + const Redland::Resource plugin_id(_model->world(), node->plugin()->uri()); + serialise_node(node, plugin_id, instance_rdf_node(node->path())); return; } SharedPtr<Shared::Port> port = PtrCast<Shared::Port>(object); if (port) { - serialise_port(port.get(), path_to_rdf_node(port->path())); + serialise_port(port.get(), instance_rdf_node(port->path())); return; } @@ -359,46 +289,30 @@ Serialiser::serialise(SharedPtr<GraphObject> object) throw (std::logic_error) void -Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch) +Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch, const Redland::Node& patch_id) { assert(_model); - - const Redland::Node patch_id = patch_path_to_rdf_node(patch->path()); - _model->add_statement( - patch_id, - "rdf:type", - Redland::Node(_model->world(), Redland::Node::RESOURCE, "http://drobilla.net/ns/ingen#Patch")); + _model->add_statement(patch_id, "rdf:type", + Redland::Resource(_model->world(), "ingen:Patch")); - _model->add_statement( - patch_id, - "rdf:type", - Redland::Node(_model->world(), Redland::Node::RESOURCE, "http://lv2plug.in/ns/lv2core#Plugin")); - - GraphObject::Variables::const_iterator s = patch->variables().find("lv2:symbol"); - // If symbol is stored as a variable, write that - if (s != patch->variables().end()) { + _model->add_statement(patch_id, "rdf:type", + Redland::Resource(_model->world(), "lv2:Plugin")); + + GraphObject::Properties::const_iterator s = patch->properties().find("lv2:symbol"); + // If symbol is stored as a property, write that + if (s != patch->properties().end() && s->second.is_valid()) { _model->add_statement(patch_id, "lv2:symbol", - Redland::Node(_model->world(), Redland::Node::LITERAL, s->second.get_string())); + Redland::Literal(_model->world(), s->second.get_string())); // Otherwise take the one from our path (if possible) } else if (patch->path() != "/") { - _model->add_statement( - patch_id, "lv2:symbol", - Redland::Node(_model->world(), Redland::Node::LITERAL, patch->path().name())); + _model->add_statement(patch_id, "lv2:symbol", + Redland::Literal(_model->world(), patch->path().name())); + } else { + cerr << "WARNING: Patch has no lv2:symbol" << endl; } - _model->add_statement( - patch_id, - "ingen:polyphony", - AtomRDF::atom_to_node(_model->world(), Atom((int)patch->internal_polyphony()))); - - _model->add_statement( - patch_id, - "ingen:enabled", - AtomRDF::atom_to_node(_model->world(), Atom((bool)patch->enabled()))); - serialise_properties(patch_id, patch->properties()); - serialise_variables(patch_id, patch->variables()); for (GraphObject::const_iterator n = _store->children_begin(patch); n != _store->children_end(patch); ++n) { @@ -409,25 +323,33 @@ Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch) SharedPtr<Shared::Patch> patch = PtrCast<Shared::Patch>(n->second); SharedPtr<Shared::Node> node = PtrCast<Shared::Node>(n->second); if (patch) { - _model->add_statement(patch_id, "ingen:node", patch_path_to_rdf_node(patch->path())); - serialise_patch(patch); + const Redland::Resource class_id(_model->world(),string("#") + patch->path().substr(1)); + const Redland::Node node_id(instance_rdf_node(n->second->path())); + _model->add_statement(patch_id, "ingen:node", node_id); + serialise_patch(patch, class_id); + serialise_node(patch, class_id, node_id); } else if (node) { - const Redland::Node node_id = path_to_rdf_node(n->second->path()); + const Redland::Resource class_id(_model->world(), node->plugin()->uri()); + const Redland::Node node_id(instance_rdf_node(n->second->path())); _model->add_statement(patch_id, "ingen:node", node_id); - serialise_node(node, node_id); + serialise_node(node, class_id, node_id); } } + + bool root = (patch->path() == _root_path); for (uint32_t i=0; i < patch->num_ports(); ++i) { Port* p = patch->port(i); - const Redland::Node port_id = path_to_rdf_node(p->path()); + const Redland::Node port_id = root + ? instance_rdf_node(p->path()) + : class_rdf_node(p->path()); // Ensure lv2:name always exists so Patch is a valid LV2 plugin if (p->properties().find("lv2:name") == p->properties().end()) - p->set_property("lv2:name", Atom(Atom::STRING, p->symbol())); // FIXME: use human name + p->set_property("lv2:name", Atom(Atom::STRING, p->symbol())); _model->add_statement(patch_id, "lv2:port", port_id); - serialise_port(p, port_id); + serialise_port_class(p, port_id); } for (Shared::Patch::Connections::const_iterator c = patch->connections().begin(); @@ -442,86 +364,90 @@ Serialiser::serialise_plugin(const Shared::Plugin& plugin) { assert(_model); - const Redland::Node plugin_id = Redland::Node(_model->world(), Redland::Node::RESOURCE, plugin.uri()); + const Redland::Node plugin_id = Redland::Resource(_model->world(), plugin.uri()); - _model->add_statement( - plugin_id, - "rdf:type", - Redland::Node(_model->world(), Redland::Node::RESOURCE, plugin.type_uri())); + _model->add_statement(plugin_id, "rdf:type", + Redland::Resource(_model->world(), plugin.type_uri())); } void -Serialiser::serialise_node(SharedPtr<Shared::Node> node, const Redland::Node& node_id) +Serialiser::serialise_node(SharedPtr<Shared::Node> node, + const Redland::Node& class_id, const Redland::Node& node_id) { - const Redland::Node plugin_id - = Redland::Node(_model->world(), Redland::Node::RESOURCE, node->plugin()->uri()); - - _model->add_statement( - node_id, - "rdf:type", - Redland::Node(_model->world(), Redland::Node::RESOURCE, "ingen:Node")); - - _model->add_statement( - node_id, - "lv2:symbol", - Redland::Node(_model->world(), Redland::Node::LITERAL, node->path().name())); - - _model->add_statement( - node_id, - "rdf:instanceOf", - plugin_id); - - _model->add_statement( - node_id, - "ingen:polyphonic", - AtomRDF::atom_to_node(_model->world(), Atom(node->polyphonic()))); - - //serialise_plugin(node->plugin()); + _model->add_statement(node_id, "rdf:type", + Redland::Resource(_model->world(), "ingen:Node")); + _model->add_statement(node_id, "rdf:instanceOf", + class_id); + _model->add_statement(node_id, "lv2:symbol", + Redland::Literal(_model->world(), node->path().name())); for (uint32_t i=0; i < node->num_ports(); ++i) { Port* p = node->port(i); - assert(p); - const Redland::Node port_id = path_to_rdf_node(p->path()); + const Redland::Node port_id = instance_rdf_node(p->path()); serialise_port(p, port_id); _model->add_statement(node_id, "lv2:port", port_id); } - serialise_properties(node_id, node->properties()); serialise_variables(node_id, node->variables()); } -/** Writes a port subject with various information only if there are some - * predicate/object pairs to go with it (eg if the port has variable, or a value, or..). - * Audio output ports with no variable will not be written, for example. - */ +/** Serialise a port on a Node */ void Serialiser::serialise_port(const Port* port, const Redland::Node& port_id) { if (port->is_input()) _model->add_statement(port_id, "rdf:type", - Redland::Node(_model->world(), Redland::Node::RESOURCE, "lv2:InputPort")); + Redland::Resource(_model->world(), "lv2:InputPort")); else _model->add_statement(port_id, "rdf:type", - Redland::Node(_model->world(), Redland::Node::RESOURCE, "lv2:OutputPort")); + Redland::Resource(_model->world(), "lv2:OutputPort")); + + _model->add_statement(port_id, "rdf:type", + Redland::Resource(_model->world(), port->type().uri())); if (dynamic_cast<Patch*>(port->graph_parent())) - _model->add_statement(port_id, "lv2:index", - AtomRDF::atom_to_node(_model->world(), Atom((int)port->index()))); + _model->add_statement(port_id, "rdf:instanceOf", + class_rdf_node(port->path())); + + if (port->is_input() && port->type() == DataType::CONTROL) + _model->add_statement(port_id, "ingen:value", + AtomRDF::atom_to_node(_model->world(), Atom(port->value()))); - _model->add_statement(port_id, "lv2:symbol", - Redland::Node(_model->world(), Redland::Node::LITERAL, port->path().name())); + serialise_variables(port_id, port->variables()); +} + + +/** Serialise a port on a Patch */ +void +Serialiser::serialise_port_class(const Port* port, const Redland::Node& port_id) +{ + if (port->is_input()) + _model->add_statement(port_id, "rdf:type", + Redland::Resource(_model->world(), "lv2:InputPort")); + else + _model->add_statement(port_id, "rdf:type", + Redland::Resource(_model->world(), "lv2:OutputPort")); _model->add_statement(port_id, "rdf:type", - Redland::Node(_model->world(), Redland::Node::RESOURCE, port->type().uri())); + Redland::Resource(_model->world(), port->type().uri())); - if (port->type() == DataType::CONTROL && port->is_input()) - _model->add_statement(port_id, "ingen:value", - AtomRDF::atom_to_node(_model->world(), Atom(port->value()))); + _model->add_statement(port_id, "lv2:index", + AtomRDF::atom_to_node(_model->world(), Atom((int)port->index()))); + + if (!port->get_property("lv2:default").is_valid()) { + if (port->is_input()) { + if (port->value().is_valid()) { + _model->add_statement(port_id, "lv2:default", + AtomRDF::atom_to_node(_model->world(), Atom(port->value()))); + } else if (port->type() == DataType::CONTROL) { + cerr << "WARNING: Port " << port->path() << " has no lv2:default" << endl; + } + } + } serialise_properties(port_id, port->properties()); - serialise_variables(port_id, port->variables()); } @@ -532,30 +458,26 @@ Serialiser::serialise_connection(SharedPtr<GraphObject> parent, if (!_model) throw std::logic_error("serialise_connection called without serialization in progress"); - const Redland::Node src_node = path_to_rdf_node(connection->src_port_path()); - const Redland::Node dst_node = path_to_rdf_node(connection->dst_port_path()); + const Redland::Node src_node = class_rdf_node(connection->src_port_path()); + const Redland::Node dst_node = class_rdf_node(connection->dst_port_path()); - /* This would allow associating data with the connection... */ const Redland::Node connection_node = _world.blank_id(); _model->add_statement(connection_node, "ingen:source", src_node); _model->add_statement(connection_node, "ingen:destination", dst_node); if (parent) { - const Redland::Node parent_node = path_to_rdf_node(parent->path()); + const Redland::Node parent_node = class_rdf_node(parent->path()); _model->add_statement(parent_node, "ingen:connection", connection_node); } else { _model->add_statement(connection_node, "rdf:type", - Redland::Node(_model->world(), Redland::Node::RESOURCE, "ingen:Connection")); + Redland::Resource(_model->world(), "ingen:Connection")); } - - /* ... but this is cleaner */ - //_model->add_statement(dst_node, "ingen:connectedTo", src_node); } void -Serialiser::serialise_properties(Redland::Node subject, const GraphObject::Variables& properties) +Serialiser::serialise_properties(Redland::Node subject, const GraphObject::Properties& properties) { - for (GraphObject::Variables::const_iterator v = properties.begin(); v != properties.end(); ++v) { + for (GraphObject::Properties::const_iterator v = properties.begin(); v != properties.end(); ++v) { if (v->first.find(":") && v->second.is_valid()) { const Redland::Node value = AtomRDF::atom_to_node(_model->world(), v->second); _model->add_statement(subject, v->first, value); @@ -567,24 +489,21 @@ Serialiser::serialise_properties(Redland::Node subject, const GraphObject::Varia void -Serialiser::serialise_variables(Redland::Node subject, const GraphObject::Variables& variables) +Serialiser::serialise_variables(Redland::Node subject, const GraphObject::Properties& variables) { - for (GraphObject::Variables::const_iterator v = variables.begin(); v != variables.end(); ++v) { + for (GraphObject::Properties::const_iterator v = variables.begin(); v != variables.end(); ++v) { if (v->first.find(":") && v->first != "ingen:document") { if (v->second.is_valid()) { - const Redland::Node var_id = _world.blank_id(); - const Redland::Node key(_model->world(), Redland::Node::RESOURCE, v->first); + const Redland::Resource key(_model->world(), v->first); const Redland::Node value = AtomRDF::atom_to_node(_model->world(), v->second); - if (value) { - _model->add_statement(subject, "lv2var:variable", var_id); - _model->add_statement(var_id, "rdf:predicate", key); - _model->add_statement(var_id, "rdf:value", value); + if (value.is_valid()) { + _model->add_statement(subject, key, value); } else { - cerr << "Warning: can not serialise value: key '" << v->first << "', type " + cerr << "WARNING: can not serialise variable '" << v->first << "' :: " << (int)v->second.type() << endl; } } else { - cerr << "Warning: variable with no value: key '" << v->first << "'" << endl; + cerr << "WARNING: variable '" << v->first << "' has no value" << endl; } } else { cerr << "Not serialising special variable '" << v->first << "'" << endl; diff --git a/src/serialisation/Serialiser.hpp b/src/serialisation/Serialiser.hpp index 8126e350..a2863871 100644 --- a/src/serialisation/Serialiser.hpp +++ b/src/serialisation/Serialiser.hpp @@ -77,7 +77,7 @@ public: std::string to_string(SharedPtr<GraphObject> object, const std::string& base_uri, - const GraphObject::Variables& extra_rdf); + const GraphObject::Properties& extra_rdf); void start_to_string(const Raul::Path& root, const std::string& base_uri); void serialise(SharedPtr<GraphObject> object) throw (std::logic_error); @@ -94,15 +94,17 @@ private: void setup_prefixes(); - void serialise_patch(SharedPtr<Shared::Patch> p); - void serialise_node(SharedPtr<Shared::Node> n, const Redland::Node& id); + void serialise_patch(SharedPtr<Shared::Patch> p, const Redland::Node& id); + void serialise_node(SharedPtr<Shared::Node> n, + const Redland::Node& class_id, const Redland::Node& id); void serialise_port(const Shared::Port* p, const Redland::Node& id); + void serialise_port_class(const Shared::Port* p, const Redland::Node& id); - void serialise_properties(Redland::Node subject, const GraphObject::Variables& properties); - void serialise_variables(Redland::Node subject, const GraphObject::Variables& variables); + void serialise_properties(Redland::Node subject, const GraphObject::Properties& properties); + void serialise_variables(Redland::Node subject, const GraphObject::Properties& variables); - Redland::Node path_to_rdf_node(const Path& path); - Redland::Node patch_path_to_rdf_node(const Path& path); + Redland::Node instance_rdf_node(const Path& path); + Redland::Node class_rdf_node(const Path& path); Raul::Path _root_path; SharedPtr<Shared::Store> _store; diff --git a/src/shared/Builder.cpp b/src/shared/Builder.cpp index f73b0e11..9da71a09 100644 --- a/src/shared/Builder.cpp +++ b/src/shared/Builder.cpp @@ -89,7 +89,7 @@ Builder::connect(SharedPtr<const GraphObject> object) void Builder::build_object(SharedPtr<const GraphObject> object) { - for (GraphObject::Variables::const_iterator i = object->variables().begin(); + for (GraphObject::Properties::const_iterator i = object->variables().begin(); i != object->variables().end(); ++i) _interface.set_variable(object->path(), i->first, i->second); diff --git a/src/shared/ResourceImpl.cpp b/src/shared/ResourceImpl.cpp index 4dd25602..10c57fbe 100644 --- a/src/shared/ResourceImpl.cpp +++ b/src/shared/ResourceImpl.cpp @@ -34,10 +34,7 @@ ResourceImpl::get_property(const std::string& uri) const { static const Raul::Atom nil; Properties::const_iterator i = _properties.find(uri); - if (i == _properties.end()) - return nil; - else - return i->second; + return (i != _properties.end()) ? i->second : nil; } |