From 88cff5320290010b5f35b8dcbd40c63317956d62 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 8 Oct 2007 18:17:47 +0000 Subject: Added missing interface/Patch.hpp. Serialize variables in a sane way for a change. git-svn-id: http://svn.drobilla.net/lad/ingen@853 a436a847-0d15-0410-975c-d299462d15a1 --- src/common/interface/Patch.hpp | 50 +++++++++++++++++++ src/libs/engine/ObjectSender.hpp | 2 +- src/libs/gui/PatchCanvas.cpp | 6 +-- src/libs/gui/UploadPatchWindow.cpp | 2 +- src/libs/serialisation/Serialiser.cpp | 94 ++++++++++++++++------------------- src/libs/serialisation/Serialiser.hpp | 15 +++--- 6 files changed, 106 insertions(+), 63 deletions(-) create mode 100644 src/common/interface/Patch.hpp (limited to 'src') diff --git a/src/common/interface/Patch.hpp b/src/common/interface/Patch.hpp new file mode 100644 index 00000000..87165a4e --- /dev/null +++ b/src/common/interface/Patch.hpp @@ -0,0 +1,50 @@ +/* This file is part of Ingen. + * Copyright (C) 2007 Dave Robillard + * + * Ingen is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PATCH_H +#define PATCH_H + +#include +#include +#include "interface/Node.hpp" + +namespace Ingen { +namespace Shared { + +class Connection; + + +/** A Path (graph of Nodes/Connections) + * + * \ingroup interface + */ +class Patch : virtual public Node +{ +public: + typedef Raul::List< SharedPtr > Connections; + + virtual const Connections& connections() const = 0; + + virtual bool enabled() const = 0; + virtual uint32_t internal_polyphony() const = 0; +}; + + +} // namespace Shared +} // namespace Ingen + +#endif // PATCH_H diff --git a/src/libs/engine/ObjectSender.hpp b/src/libs/engine/ObjectSender.hpp index 7176dcaa..9b6eb000 100644 --- a/src/libs/engine/ObjectSender.hpp +++ b/src/libs/engine/ObjectSender.hpp @@ -38,7 +38,7 @@ class PluginImpl; * (protocol), this is used from the engine to easily send proper Objects * with these messages (which is done in a few different parts of the code). * - * Basically a serializer, except to calls on ClientInterface rather than + * Basically a serialiser, except to calls on ClientInterface rather than * eg a byte stream. */ class ObjectSender { diff --git a/src/libs/gui/PatchCanvas.cpp b/src/libs/gui/PatchCanvas.cpp index 3f0e2716..74000b79 100644 --- a/src/libs/gui/PatchCanvas.cpp +++ b/src/libs/gui/PatchCanvas.cpp @@ -465,11 +465,11 @@ PatchCanvas::copy_selection() for (list >::iterator m = _selected_items.begin(); m != _selected_items.end(); ++m) { boost::shared_ptr module = boost::dynamic_pointer_cast(*m); if (module) { - serialiser.serialize(module->node()); + serialiser.serialise(module->node()); } else { boost::shared_ptr port_module = boost::dynamic_pointer_cast(*m); if (port_module) - serialiser.serialize(port_module->port()); + serialiser.serialise(port_module->port()); } } @@ -477,7 +477,7 @@ PatchCanvas::copy_selection() c != _selected_connections.end(); ++c) { boost::shared_ptr connection = boost::dynamic_pointer_cast(*c); if (connection) - serialiser.serialize_connection(connection->model()); + serialiser.serialise_connection(connection->model()); } string result = serialiser.finish(); diff --git a/src/libs/gui/UploadPatchWindow.cpp b/src/libs/gui/UploadPatchWindow.cpp index 57045a91..959bb1ae 100644 --- a/src/libs/gui/UploadPatchWindow.cpp +++ b/src/libs/gui/UploadPatchWindow.cpp @@ -251,7 +251,7 @@ UploadPatchWindow::upload_clicked() Serialiser s(*App::instance().world()->rdf_world); s.start_to_string(); - s.serialize(_patch); + s.serialise(_patch); const string str = s.finish(); istringstream stream(str); diff --git a/src/libs/serialisation/Serialiser.cpp b/src/libs/serialisation/Serialiser.cpp index b21b7c6d..f0008b64 100644 --- a/src/libs/serialisation/Serialiser.cpp +++ b/src/libs/serialisation/Serialiser.cpp @@ -62,7 +62,7 @@ Serialiser::to_file(SharedPtr object, const string& filename) { _root_object = object; start_to_filename(filename); - serialize(object); + serialise(object); finish(); } @@ -72,7 +72,7 @@ Serialiser::to_string(SharedPtr object) { _root_object = object; start_to_string(); - serialize(object); + serialise(object); return finish(); } @@ -97,7 +97,7 @@ Serialiser::start_to_filename(const string& filename) * This must be called before any serializing methods. * * The results of the serialization will be returned by the finish() method after - * the desired objects have been serialized. + * the desired objects have been serialised. */ void Serialiser::start_to_string() @@ -121,9 +121,9 @@ Serialiser::finish() string ret = ""; if (_mode == TO_FILE) - _model->serialize_to_file(_base_uri); + _model->serialise_to_file(_base_uri); else - ret = _model->serialize_to_string(); + ret = _model->serialise_to_string(); _base_uri = ""; _node_map.clear(); @@ -214,31 +214,31 @@ Serialiser::find_file(const string& filename, const string& additional_path) #endif void -Serialiser::serialize(SharedPtr object) throw (std::logic_error) +Serialiser::serialise(SharedPtr object) throw (std::logic_error) { if (!_model) - throw std::logic_error("serialize called without serialization in progress"); + throw std::logic_error("serialise called without serialization in progress"); SharedPtr patch = PtrCast(object); if (patch) { - serialize_patch(patch); + serialise_patch(patch); return; } SharedPtr node = PtrCast(object); if (node) { - serialize_node(node, path_to_node_id(node->path())); + serialise_node(node, path_to_node_id(node->path())); return; } SharedPtr port = PtrCast(object); if (port) { - serialize_port(port.get(), path_to_node_id(port->path())); + serialise_port(port.get(), path_to_node_id(port->path())); return; } cerr << "[Serialiser] WARNING: Unsupported object type, " - << object->path() << " not serialized." << endl; + << object->path() << " not serialised." << endl; } @@ -256,7 +256,7 @@ Serialiser::patch_path_to_rdf_id(const Path& path) void -Serialiser::serialize_patch(SharedPtr patch) +Serialiser::serialise_patch(SharedPtr patch) { assert(_model); @@ -283,26 +283,18 @@ Serialiser::serialize_patch(SharedPtr patch) "ingen:enabled", Atom(patch->enabled())); - for (GraphObject::Variables::const_iterator m = patch->variables().begin(); - m != patch->variables().end(); ++m) { - if (m->first.find(":") != string::npos) { - _model->add_statement( - patch_id, - m->first.c_str(), - m->second); - } - } + serialise_variables(patch_id, patch->variables()); for (GraphObject::const_iterator n = patch->children_begin(); n != patch->children_end(); ++n) { SharedPtr patch = PtrCast(n->second); SharedPtr node = PtrCast(n->second); if (patch) { _model->add_statement(patch_id, "ingen:node", patch_path_to_rdf_id(patch->path())); - serialize_patch(patch); + serialise_patch(patch); } else if (node) { const RDF::Node node_id = path_to_node_id(n->second->path()); _model->add_statement(patch_id, "ingen:node", node_id); - serialize_node(node, node_id); + serialise_node(node, node_id); } } @@ -310,18 +302,18 @@ Serialiser::serialize_patch(SharedPtr patch) Port* p = patch->port(i); const RDF::Node port_id = path_to_node_id(p->path()); _model->add_statement(patch_id, "ingen:port", port_id); - serialize_port(p, port_id); + serialise_port(p, port_id); } for (Shared::Patch::Connections::const_iterator c = patch->connections().begin(); c != patch->connections().end(); ++c) { - serialize_connection(*c); + serialise_connection(*c); } } void -Serialiser::serialize_plugin(SharedPtr plugin) +Serialiser::serialise_plugin(SharedPtr plugin) { assert(_model); @@ -335,7 +327,7 @@ Serialiser::serialize_plugin(SharedPtr plugin) void -Serialiser::serialize_node(SharedPtr node, const RDF::Node& node_id) +Serialiser::serialise_node(SharedPtr node, const RDF::Node& node_id) { const RDF::Node plugin_id = RDF::Node(_model->world(), RDF::Node::RESOURCE, node->plugin()->uri()); @@ -360,33 +352,26 @@ Serialiser::serialize_node(SharedPtr node, const RDF::Node& node_i "ingen:polyphonic", node->polyphonic()); - //serialize_plugin(node->plugin()); + //serialise_plugin(node->plugin()); for (uint32_t i=0; i < node->num_ports(); ++i) { Port* p = node->port(i); assert(p); const RDF::Node port_id = path_to_node_id(p->path()); - serialize_port(p, port_id); + serialise_port(p, port_id); _model->add_statement(node_id, "ingen:port", port_id); } - for (GraphObject::Variables::const_iterator m = node->variables().begin(); - m != node->variables().end(); ++m) { - if (m->first.find(":") != string::npos) { - _model->add_statement( - node_id, - m->first, - m->second); - } - } + 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. */ void -Serialiser::serialize_port(const Port* port, const RDF::Node& port_id) +Serialiser::serialise_port(const Port* port, const RDF::Node& port_id) { if (port->is_input()) _model->add_statement(port_id, "rdf:type", @@ -403,31 +388,36 @@ Serialiser::serialize_port(const Port* port, const RDF::Node& port_id) if (port->type() == DataType::CONTROL && port->is_input()) _model->add_statement(port_id, "ingen:value", port->value()); - if (port->variables().size() > 0) { - for (GraphObject::Variables::const_iterator m = port->variables().begin(); - m != port->variables().end(); ++m) { - if (m->first.find(":") != string::npos) { - _model->add_statement( - port_id, - m->first, - m->second); - } - } - } + serialise_variables(port_id, port->variables()); } void -Serialiser::serialize_connection(SharedPtr connection) throw (std::logic_error) +Serialiser::serialise_connection(SharedPtr connection) throw (std::logic_error) { if (!_model) - throw std::logic_error("serialize_connection called without serialization in progress"); + throw std::logic_error("serialise_connection called without serialization in progress"); const RDF::Node src_node = path_to_node_id(connection->src_port_path()); const RDF::Node dst_node = path_to_node_id(connection->dst_port_path()); _model->add_statement(dst_node, "ingen:connectedTo", src_node); } + + +void +Serialiser::serialise_variables(RDF::Node subject, const GraphObject::Variables& variables) +{ + for (GraphObject::Variables::const_iterator v = variables.begin(); v != variables.end(); ++v) { + if (v->first.find(":") != string::npos) { + RDF::Node var_id = _world.blank_id(); + _model->add_statement(subject, "ingen:variable", var_id); + _model->add_statement(var_id, "ingen:value", v->second); + } else { + cerr << "Warning: not serialising variable with key '" << v->first << "'" << endl; + } + } +} } // namespace Serialisation diff --git a/src/libs/serialisation/Serialiser.hpp b/src/libs/serialisation/Serialiser.hpp index fb1df5d0..041bbb69 100644 --- a/src/libs/serialisation/Serialiser.hpp +++ b/src/libs/serialisation/Serialiser.hpp @@ -28,6 +28,7 @@ #include #include #include +#include "interface/GraphObject.hpp" using namespace Raul; using namespace Ingen::Shared; @@ -59,8 +60,8 @@ public: string to_string(SharedPtr object); void start_to_string(); - void serialize(SharedPtr object) throw (std::logic_error); - void serialize_connection(SharedPtr c) throw (std::logic_error); + void serialise(SharedPtr object) throw (std::logic_error); + void serialise_connection(SharedPtr c) throw (std::logic_error); string finish(); private: @@ -70,11 +71,13 @@ private: void setup_prefixes(); - void serialize_plugin(SharedPtr p); + void serialise_plugin(SharedPtr p); - void serialize_patch(SharedPtr p); - void serialize_node(SharedPtr n, const Raul::RDF::Node& id); - void serialize_port(const Shared::Port* p, const Raul::RDF::Node& id); + void serialise_patch(SharedPtr p); + void serialise_node(SharedPtr n, const Raul::RDF::Node& id); + void serialise_port(const Shared::Port* p, const Raul::RDF::Node& id); + + void serialise_variables(RDF::Node subject, const GraphObject::Variables& variables); Raul::RDF::Node path_to_node_id(const Path& path); Raul::RDF::Node patch_path_to_rdf_id(const Path& path); -- cgit v1.2.1