diff options
Diffstat (limited to 'src/serialisation')
-rw-r--r-- | src/serialisation/Parser.cpp | 80 | ||||
-rw-r--r-- | src/serialisation/Parser.hpp | 16 | ||||
-rw-r--r-- | src/serialisation/Serialiser.cpp | 48 | ||||
-rw-r--r-- | src/serialisation/Serialiser.hpp | 20 | ||||
-rw-r--r-- | src/serialisation/serialisation.cpp | 8 | ||||
-rw-r--r-- | src/serialisation/serialisation.hpp | 6 |
6 files changed, 89 insertions, 89 deletions
diff --git a/src/serialisation/Parser.cpp b/src/serialisation/Parser.cpp index c68d6ccf..36d1a422 100644 --- a/src/serialisation/Parser.cpp +++ b/src/serialisation/Parser.cpp @@ -1,15 +1,15 @@ /* 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 @@ -55,7 +55,7 @@ relative_uri(Glib::ustring base, const Glib::ustring uri, bool leading_slash) 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); @@ -99,12 +99,12 @@ uri_child(const Glib::ustring base, const Glib::ustring child, bool trailing_sla Glib::ustring ret = (base[base.length()-1] == '/' || child[0] == '/') ? base + child : base + '/' + child; - + if (trailing_slash && (ret == "" || ret[ret.length()-1] != '/')) ret = ret + "/"; else if (!trailing_slash && ret != "" && ret[ret.length()-1] == '/') ret = ret.substr(0, ret.length()-1); - + return ret; } @@ -143,7 +143,7 @@ Parser::parse_document( boost::optional<GraphObject::Properties> data) { normalise_uri(document_uri); - + Redland::Model model(*world->rdf_world, document_uri, document_uri); cout << "[Parser] Parsing document " << document_uri << endl; @@ -156,13 +156,13 @@ Parser::parse_document( boost::optional<Path> parsed_path = parse(world, target, model, document_uri, data_path, parent, symbol, data); - + if (parsed_path) { target->set_variable(*parsed_path, "ingen:document", Atom(document_uri.c_str())); } else { cerr << "WARNING: document URI lost" << endl; } - + return parsed_path; } @@ -179,12 +179,12 @@ Parser::parse_string( boost::optional<GraphObject::Properties> data) { Redland::Model model(*world->rdf_world, str.c_str(), str.length(), base_uri); - + cout << "Parsing " << (data_path ? data_path->str() : "*") << " from string"; if (base_uri != "") cout << "(base " << base_uri << ")"; cout << endl; - + bool ret = parse(world, target, model, base_uri, data_path, parent, symbol, data); const Glib::ustring subject = Glib::ustring("<") + base_uri + Glib::ustring(">"); parse_connections(world, target, model, subject, parent ? *parent : "/"); @@ -210,12 +210,12 @@ Parser::parse_update( Glib::ustring query_str = Glib::ustring("SELECT DISTINCT ?o WHERE { ?o a owl:Nothing }"); Redland::Query query(*world->rdf_world, query_str); Redland::Query::Results results = query.run(*world->rdf_world, model, base_uri); - + for (Redland::Query::Results::iterator i = results.begin(); i != results.end(); ++i) { const Redland::Node& object = (*i)["o"]; target->destroy(object.to_string()); } - + // Variable settings query = Redland::Query(*world->rdf_world, "SELECT DISTINCT ?path ?varkey ?varval WHERE {\n" @@ -223,7 +223,7 @@ Parser::parse_update( "?variable rdf:predicate ?varkey ;\n" " rdf:value ?varval .\n" "}"); - + results = Redland::Query::Results(query.run(*world->rdf_world, model, base_uri)); for (Redland::Query::Results::iterator i = results.begin(); i != results.end(); ++i) { @@ -239,13 +239,13 @@ Parser::parse_update( // Connections parse_connections(world, target, model, base_uri, "/"); - + // Port values query = Redland::Query(*world->rdf_world, "SELECT DISTINCT ?path ?value WHERE {\n" "?path ingen:value ?value .\n" "}"); - + results = Redland::Query::Results(query.run(*world->rdf_world, model, base_uri)); for (Redland::Query::Results::iterator i = results.begin(); i != results.end(); ++i) { @@ -272,14 +272,14 @@ Parser::parse( boost::optional<GraphObject::Properties> data) { const Redland::Node::Type res = Redland::Node::RESOURCE; - + const Glib::ustring query_str = data_path ? Glib::ustring("SELECT DISTINCT ?t WHERE { <") + data_path->chop_start("/") + "> a ?t . }" : Glib::ustring("SELECT DISTINCT ?s ?t WHERE { ?s a ?t . }"); Redland::Query query(*world->rdf_world, query_str); Redland::Query::Results results(query.run(*world->rdf_world, model, document_uri)); - + const Redland::Node patch_class (*world->rdf_world, res, NS_INGEN "Patch"); const Redland::Node node_class (*world->rdf_world, res, NS_INGEN "Node"); const Redland::Node internal_class (*world->rdf_world, res, NS_INGEN "Internal"); @@ -287,7 +287,7 @@ Parser::parse( const Redland::Node in_port_class (*world->rdf_world, res, NS_LV2 "InputPort"); const Redland::Node out_port_class (*world->rdf_world, res, NS_LV2 "OutputPort"); const Redland::Node lv2_class (*world->rdf_world, res, NS_LV2 "Plugin"); - + const Redland::Node subject_node = (data_path && !data_path->is_root()) ? Redland::Node(*world->rdf_world, res, data_path->chop_start("/")) : model.base_uri(); @@ -304,21 +304,21 @@ Parser::parse( path_str = relative_uri(document_uri, subject.to_c_string(), true); else if (path_str == "" || path_str[0] != '/') path_str = "/" + path_str; - + if (!Path::is_valid(path_str)) { cerr << "WARNING: Invalid path '" << path_str << "', object skipped" << endl; continue; } - + const bool is_plugin = (rdf_class == ladspa_class) || (rdf_class == lv2_class) || (rdf_class == internal_class); - + const bool is_object = (rdf_class == patch_class) || (rdf_class == node_class) || (rdf_class == in_port_class) || (rdf_class == out_port_class); - + const Glib::ustring subject_uri_tok = Glib::ustring("<").append(subject).append(">"); if (is_object) { @@ -331,7 +331,7 @@ Parser::parse( cerr << "WARNING: Invalid path '" << path << "' transformed to /" << endl; path = "/"; } - + if (rdf_class == patch_class) { ret = parse_patch(world, target, model, subject, parent, symbol, data); } else if (rdf_class == node_class) { @@ -344,7 +344,7 @@ Parser::parse( cerr << "Failed to parse object " << path << endl; return boost::optional<Path>(); } - + if (data_path && subject.to_string() == data_path->str()) root_path = ret; @@ -354,7 +354,7 @@ Parser::parse( } } - + return root_path; } @@ -379,7 +379,7 @@ Parser::parse_patch( 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; @@ -398,11 +398,11 @@ Parser::parse_patch( cerr << "WARNING: Patch has non-integer polyphony, assuming 1" << endl; } } - + /* 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; @@ -425,7 +425,7 @@ Parser::parse_patch( /* Create patch */ Path patch_path(patch_path_str); target->new_patch(patch_path, patch_poly); - + /* Find patches in document */ Redland::Query query(*world->rdf_world, Glib::ustring( @@ -438,7 +438,7 @@ Parser::parse_patch( 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; @@ -514,7 +514,7 @@ Parser::parse_patch( 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); @@ -528,7 +528,7 @@ Parser::parse_patch( target->set_variable(node_path, key, AtomRDF::node_to_atom(j->second)); } } - + /* Load node ports */ query = Redland::Query(*world->rdf_world, Glib::ustring( @@ -557,7 +557,7 @@ Parser::parse_patch( target->set_variable(port_path, key, AtomRDF::node_to_atom((*i)["val"])); } } - + /* Find ports on this patch */ query = Redland::Query(*world->rdf_world, Glib::ustring( @@ -576,7 +576,7 @@ Parser::parse_patch( patch_ports.insert(make_pair(port.to_string(), Properties())); } } - + /* Load patch ports */ query = Redland::Query(*world->rdf_world, Glib::ustring( @@ -633,8 +633,8 @@ Parser::parse_patch( 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 {\n") @@ -678,7 +678,7 @@ Parser::parse_node( cerr << "[Parser] ERROR: Node missing mandatory rdf:instanceOf property" << endl; return boost::optional<Path>(); } - + const Redland::Node& plugin_node = (*results.begin())["plug"]; if (plugin_node.type() != Redland::Node::RESOURCE) { cerr << "[Parser] ERROR: node's rdf:instanceOf property is not a resource" << endl; @@ -725,7 +725,7 @@ Parser::parse_port( if (val_node.to_string() != "") target->set_port_value(path, AtomRDF::node_to_atom(val_node)); } - + parse_variables(world, target, model, subject_node, path, data); return path; } @@ -789,7 +789,7 @@ Parser::parse_variables( if (key != "") target->set_variable(path, key, AtomRDF::node_to_atom(val)); } - + // Set passed variables last to override any loaded values if (data) for (GraphObject::Properties::const_iterator i = data.get().begin(); diff --git a/src/serialisation/Parser.hpp b/src/serialisation/Parser.hpp index eea5ca9b..87fbddd0 100644 --- a/src/serialisation/Parser.hpp +++ b/src/serialisation/Parser.hpp @@ -1,15 +1,15 @@ /* 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 @@ -37,7 +37,7 @@ public: virtual ~Parser() {} typedef Shared::GraphObject::Properties Properties; - + virtual bool parse_document( Ingen::Shared::World* world, Shared::CommonInterface* target, @@ -46,7 +46,7 @@ public: boost::optional<Raul::Path> parent=boost::optional<Raul::Path>(), boost::optional<Raul::Symbol> symbol=boost::optional<Raul::Symbol>(), boost::optional<Properties> data=boost::optional<Properties>()); - + virtual bool parse_string( Ingen::Shared::World* world, Shared::CommonInterface* target, @@ -56,7 +56,7 @@ public: boost::optional<Raul::Path> parent=boost::optional<Raul::Path>(), boost::optional<Raul::Symbol> symbol=boost::optional<Raul::Symbol>(), boost::optional<Properties> data=boost::optional<Properties>()); - + virtual bool parse_update( Ingen::Shared::World* world, Shared::CommonInterface* target, @@ -86,7 +86,7 @@ private: boost::optional<Raul::Path> parent=boost::optional<Raul::Path>(), boost::optional<Raul::Symbol> symbol=boost::optional<Raul::Symbol>(), boost::optional<Properties> data=boost::optional<Properties>()); - + boost::optional<Raul::Path> parse_node( Ingen::Shared::World* world, Ingen::Shared::CommonInterface* target, @@ -102,7 +102,7 @@ private: const Redland::Node& subject, const Raul::Path& path, boost::optional<Properties> data=boost::optional<Properties>()); - + bool parse_variables( Ingen::Shared::World* world, Ingen::Shared::CommonInterface* target, diff --git a/src/serialisation/Serialiser.cpp b/src/serialisation/Serialiser.cpp index cb598eb7..d64cf684 100644 --- a/src/serialisation/Serialiser.cpp +++ b/src/serialisation/Serialiser.cpp @@ -1,15 +1,15 @@ /* 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 @@ -62,7 +62,7 @@ Serialiser::Serialiser(Shared::World& world, SharedPtr<Shared::Store> store) , _world(*world.rdf_world) { } - + void Serialiser::to_file(const Record& record) @@ -133,7 +133,7 @@ Serialiser::write_bundle(const Record& record) write_manifest(bundle_uri, records); } - + string Serialiser::to_string(SharedPtr<GraphObject> object, const string& base_uri, @@ -141,7 +141,7 @@ Serialiser::to_string(SharedPtr<GraphObject> object, { start_to_string(object->path(), base_uri); serialise(object); - + 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) { @@ -228,7 +228,7 @@ Serialiser::instance_rdf_node(const Path& path) { assert(_model); assert(path.is_child_of(_root_path)); - + if (path == _root_path) return Redland::Resource(_model->world(), _base_uri); else @@ -242,7 +242,7 @@ Serialiser::class_rdf_node(const Path& path) { assert(_model); assert(path.is_child_of(_root_path)); - + if (path == _root_path) return Redland::Resource(_model->world(), _base_uri); else @@ -269,14 +269,14 @@ Serialiser::serialise(SharedPtr<GraphObject> object) throw (std::logic_error) } return; } - + SharedPtr<Shared::Node> node = PtrCast<Shared::Node>(object); if (node) { const Redland::Resource plugin_id(_model->world(), node->plugin()->uri().str()); 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(), instance_rdf_node(port->path())); @@ -292,10 +292,10 @@ void Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch, const Redland::Node& patch_id) { assert(_model); - + _model->add_statement(patch_id, "rdf:type", Redland::Resource(_model->world(), "ingen:Patch")); - + _model->add_statement(patch_id, "rdf:type", Redland::Resource(_model->world(), "lv2:Plugin")); @@ -316,7 +316,7 @@ Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch, const Redland::Node& for (GraphObject::const_iterator n = _store->children_begin(patch); n != _store->children_end(patch); ++n) { - + if (n->second->graph_parent() != patch.get()) continue; @@ -337,13 +337,13 @@ Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch, const Redland::Node& } 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 = 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())); @@ -368,7 +368,7 @@ Serialiser::serialise_plugin(const Shared::Plugin& plugin) _model->add_statement(plugin_id, "rdf:type", Redland::Resource(_model->world(), plugin.type_uri())); -} +} void @@ -381,7 +381,7 @@ Serialiser::serialise_node(SharedPtr<Shared::Node> node, 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); const Redland::Node port_id = instance_rdf_node(p->path()); @@ -403,14 +403,14 @@ Serialiser::serialise_port(const Port* port, const Redland::Node& port_id) else _model->add_statement(port_id, "rdf:type", 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, "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()))); @@ -429,13 +429,13 @@ Serialiser::serialise_port_class(const Port* port, const Redland::Node& port_id) else _model->add_statement(port_id, "rdf:type", Redland::Resource(_model->world(), "lv2:OutputPort")); - + _model->add_statement(port_id, "rdf:type", Redland::Resource(_model->world(), port->type().uri())); - + _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()) { @@ -486,7 +486,7 @@ Serialiser::serialise_properties(Redland::Node subject, const GraphObject::Prope } } } - + void Serialiser::serialise_variables(Redland::Node subject, const GraphObject::Properties& variables) diff --git a/src/serialisation/Serialiser.hpp b/src/serialisation/Serialiser.hpp index 95425bad..7c0710d8 100644 --- a/src/serialisation/Serialiser.hpp +++ b/src/serialisation/Serialiser.hpp @@ -1,15 +1,15 @@ /* 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 @@ -53,7 +53,7 @@ class Serialiser { public: Serialiser(Shared::World& world, SharedPtr<Shared::Store> store); - + typedef Shared::GraphObject::Properties Properties; struct Record { @@ -68,7 +68,7 @@ public: typedef std::list<Record> Records; void to_file(const Record& record); - + void write_bundle(const Record& record); void write_manifest(const std::string& bundle_uri, @@ -77,18 +77,18 @@ public: std::string to_string(SharedPtr<Shared::GraphObject> object, const std::string& base_uri, const Properties& extra_rdf); - + void start_to_string(const Raul::Path& root, const std::string& base_uri); void serialise(SharedPtr<Shared::GraphObject> object) throw (std::logic_error); void serialise_plugin(const Shared::Plugin& p); void serialise_connection(SharedPtr<Shared::GraphObject> parent, SharedPtr<Shared::Connection> c) throw (std::logic_error); - + std::string finish(); - + private: enum Mode { TO_FILE, TO_STRING }; - + void start_to_filename(const std::string& filename); void setup_prefixes(); @@ -101,7 +101,7 @@ private: void serialise_properties(Redland::Node subject, const Properties& properties); void serialise_variables(Redland::Node subject, const Properties& variables); - + Redland::Node instance_rdf_node(const Raul::Path& path); Redland::Node class_rdf_node(const Raul::Path& path); diff --git a/src/serialisation/serialisation.cpp b/src/serialisation/serialisation.cpp index 172db2a1..ad125d4f 100644 --- a/src/serialisation/serialisation.cpp +++ b/src/serialisation/serialisation.cpp @@ -1,15 +1,15 @@ /* 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 @@ -31,7 +31,7 @@ new_parser() return new Parser(); } - + Ingen::Serialisation::Serialiser* new_serialiser(Ingen::Shared::World* world, SharedPtr<Shared::Store> store) { diff --git a/src/serialisation/serialisation.hpp b/src/serialisation/serialisation.hpp index a250945b..5778d34b 100644 --- a/src/serialisation/serialisation.hpp +++ b/src/serialisation/serialisation.hpp @@ -1,15 +1,15 @@ /* 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 |