diff options
author | David Robillard <d@drobilla.net> | 2012-08-19 02:24:38 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-08-19 02:24:38 +0000 |
commit | 800c329a0b77f9044923885abe0728028eca8350 (patch) | |
tree | f2d4a9d06fd6978e193de95ba60bfffe3d15a998 /src/serialisation | |
parent | 317627ef40f7654c298aa1ac707851c852259e3a (diff) | |
download | ingen-800c329a0b77f9044923885abe0728028eca8350.tar.gz ingen-800c329a0b77f9044923885abe0728028eca8350.tar.bz2 ingen-800c329a0b77f9044923885abe0728028eca8350.zip |
Patch => Graph
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4721 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/serialisation')
-rw-r--r-- | src/serialisation/Parser.cpp | 58 | ||||
-rw-r--r-- | src/serialisation/Serialiser.cpp | 108 |
2 files changed, 83 insertions, 83 deletions
diff --git a/src/serialisation/Parser.cpp b/src/serialisation/Parser.cpp index 900aba02..9a5c52ed 100644 --- a/src/serialisation/Parser.cpp +++ b/src/serialisation/Parser.cpp @@ -179,7 +179,7 @@ parse( boost::optional<Resource::Properties> data = boost::optional<Resource::Properties>()); static boost::optional<Raul::Path> -parse_patch( +parse_graph( World* world, Interface* target, Sord::Model& model, @@ -212,7 +212,7 @@ parse_edges( Interface* target, Sord::Model& model, const Sord::Node& subject, - const Raul::Path& patch); + const Raul::Path& graph); static boost::optional<Raul::Path> parse_block(Ingen::World* world, @@ -263,10 +263,10 @@ parse_block(Ingen::World* world, serd_env_free(env); Sord::URI sub_node(*world->rdf_world(), sub_file); - parse_patch(world, target, sub_model, sub_node, + parse_graph(world, target, sub_model, sub_node, path.parent(), Raul::Symbol(path.symbol())); - parse_patch(world, target, model, subject, + parse_graph(world, target, model, subject, path.parent(), Raul::Symbol(path.symbol())); } else { Resource::Properties props = get_properties(world, model, subject); @@ -278,7 +278,7 @@ parse_block(Ingen::World* world, } static boost::optional<Raul::Path> -parse_patch(Ingen::World* world, +parse_graph(Ingen::World* world, Ingen::Interface* target, Sord::Model& model, const Sord::Node& subject_node, @@ -292,7 +292,7 @@ parse_patch(Ingen::World* world, const Sord::URI ingen_polyphony(*world->rdf_world(), uris.ingen_polyphony); const Sord::URI lv2_port(*world->rdf_world(), LV2_CORE__port); - const Sord::Node& patch = subject_node; + const Sord::Node& graph = subject_node; const Sord::Node nil; const Glib::ustring base_uri = model.base_uri().to_string(); @@ -304,25 +304,25 @@ parse_patch(Ingen::World* world, const std::string basename = get_basename(base_uri); } - string patch_path_str = relative_uri(base_uri, subject_node.to_string(), true); + string graph_path_str = relative_uri(base_uri, subject_node.to_string(), true); if (parent && a_symbol) - patch_path_str = parent->child(*a_symbol); + graph_path_str = parent->child(*a_symbol); - if (!Raul::Path::is_valid(patch_path_str)) { - world->log().error(Raul::fmt("Patch %1% has invalid path\n") - % patch_path_str); + if (!Raul::Path::is_valid(graph_path_str)) { + world->log().error(Raul::fmt("Graph %1% has invalid path\n") + % graph_path_str); return boost::optional<Raul::Path>(); } - // Create patch - Raul::Path patch_path(patch_path_str); + // Create graph + Raul::Path graph_path(graph_path_str); Resource::Properties props = get_properties(world, model, subject_node); - target->put(GraphObject::path_to_uri(patch_path), props); + target->put(GraphObject::path_to_uri(graph_path), props); - // For each block in this patch + // For each block in this graph for (Sord::Iter n = model.find(subject_node, ingen_block, nil); !n.end(); ++n) { Sord::Node node = n.get_object(); - const Raul::Path block_path = patch_path.child( + const Raul::Path block_path = graph_path.child( Raul::Symbol(get_basename(node.to_string()))); // Parse and create block @@ -348,16 +348,16 @@ parse_patch(Ingen::World* world, } } - // For each port on this patch + // For each port on this graph typedef std::map<uint32_t, PortRecord> PortRecords; PortRecords ports; - for (Sord::Iter p = model.find(patch, lv2_port, nil); !p.end(); ++p) { + for (Sord::Iter p = model.find(graph, lv2_port, nil); !p.end(); ++p) { Sord::Node port = p.get_object(); // Get all properties uint32_t index = 0; boost::optional<PortRecord> port_record = get_port( - world, model, port, patch_path, index); + world, model, port, graph_path, index); if (!port_record) { world->log().error(Raul::fmt("Invalid port %1%\n") % port); return boost::optional<Raul::Path>(); @@ -373,9 +373,9 @@ parse_patch(Ingen::World* world, i->second.second); } - parse_edges(world, target, model, subject_node, patch_path); + parse_edges(world, target, model, subject_node, graph_path); - return patch_path; + return graph_path; } static bool @@ -479,7 +479,7 @@ parse(Ingen::World* world, { URIs& uris = world->uris(); - const Sord::URI patch_class (*world->rdf_world(), uris.ingen_Patch); + const Sord::URI graph_class (*world->rdf_world(), uris.ingen_Graph); const Sord::URI block_class (*world->rdf_world(), uris.ingen_Block); const Sord::URI edge_class (*world->rdf_world(), uris.ingen_Edge); const Sord::URI internal_class(*world->rdf_world(), uris.ingen_Internal); @@ -489,9 +489,9 @@ parse(Ingen::World* world, const Sord::URI rdf_type (*world->rdf_world(), uris.rdf_type); const Sord::Node nil; - // Parse explicit subject patch + // Parse explicit subject graph if (subject.is_valid()) { - return parse_patch(world, target, model, subject, parent, symbol, data); + return parse_graph(world, target, model, subject, parent, symbol, data); } // Get all subjects and their types (?subject a ?type) @@ -519,8 +519,8 @@ parse(Ingen::World* world, boost::optional<Raul::Path> ret; const Raul::Path path( relative_uri( model.base_uri().to_string(), s.to_string(), true)); - if (types.find(patch_class) != types.end()) { - ret = parse_patch(world, target, model, s, parent, symbol, data); + if (types.find(graph_class) != types.end()) { + ret = parse_graph(world, target, model, s, parent, symbol, data); } else if (types.find(block_class) != types.end()) { ret = parse_block(world, target, model, s, path, data); } else if (types.find(in_port_class) != types.end() || @@ -539,7 +539,7 @@ parse(Ingen::World* world, return boost::optional<Raul::Path>(); } -/** Parse a patch from RDF into a Interface (engine or client). +/** Parse a graph from RDF into a Interface (engine or client). * @return whether or not load was successful. */ bool @@ -551,7 +551,7 @@ Parser::parse_file(Ingen::World* world, boost::optional<GraphObject::Properties> data) { if (Glib::file_test(path, Glib::FILE_TEST_IS_DIR)) { - // This is a bundle, append "/name.ttl" to get patch file path + // This is a bundle, append "/name.ttl" to get graph file path path = Glib::build_filename(path, get_basename(path) + ".ttl"); } @@ -572,7 +572,7 @@ Parser::parse_file(Ingen::World* world, SerdNode base_node = serd_node_from_string(SERD_URI, uri_c_str); SerdEnv* env = serd_env_new(&base_node); - // Load patch file into model + // Load graph file into model Sord::Model model(*world->rdf_world(), uri, SORD_SPO|SORD_PSO, false); model.load_file(env, SERD_TURTLE, uri); diff --git a/src/serialisation/Serialiser.cpp b/src/serialisation/Serialiser.cpp index a9d49fe3..e1b1548d 100644 --- a/src/serialisation/Serialiser.cpp +++ b/src/serialisation/Serialiser.cpp @@ -66,7 +66,7 @@ struct Serialiser::Impl { void start_to_filename(const std::string& filename); - void serialise_patch(SharedPtr<const GraphObject> p, + void serialise_graph(SharedPtr<const GraphObject> p, const Sord::Node& id); void serialise_block(SharedPtr<const GraphObject> n, @@ -80,14 +80,14 @@ struct Serialiser::Impl { void serialise_properties(Sord::Node id, const Resource::Properties& props); - void write_bundle(SharedPtr<const GraphObject> patch, + void write_bundle(SharedPtr<const GraphObject> graph, const std::string& uri); Sord::Node path_rdf_node(const Raul::Path& path); void write_manifest(const std::string& bundle_path, - SharedPtr<const GraphObject> patch, - const std::string& patch_symbol); + SharedPtr<const GraphObject> graph, + const std::string& graph_symbol); void serialise_edge(const Sord::Node& parent, SharedPtr<const Edge> c) @@ -124,8 +124,8 @@ Serialiser::to_file(SharedPtr<const GraphObject> object, void Serialiser::Impl::write_manifest(const std::string& bundle_path, - SharedPtr<const GraphObject> patch, - const std::string& patch_symbol) + SharedPtr<const GraphObject> graph, + const std::string& graph_symbol) { const string manifest_path(Glib::build_filename(bundle_path, "manifest.ttl")); const string binary_path(Glib::Module::build_path("", "ingen_lv2")); @@ -135,12 +135,12 @@ Serialiser::Impl::write_manifest(const std::string& bundle_path, Sord::World& world = _model->world(); const URIs& uris = _world.uris(); - const string filename(patch_symbol + ".ttl"); + const string filename(graph_symbol + ".ttl"); const Sord::URI subject(world, filename, _base_uri); _model->add_statement(subject, Sord::URI(world, uris.rdf_type), - Sord::URI(world, uris.ingen_Patch)); + Sord::URI(world, uris.ingen_Graph)); _model->add_statement(subject, Sord::URI(world, uris.rdf_type), Sord::URI(world, uris.lv2_Plugin)); @@ -158,14 +158,14 @@ Serialiser::Impl::write_manifest(const std::string& bundle_path, } void -Serialiser::write_bundle(SharedPtr<const GraphObject> patch, +Serialiser::write_bundle(SharedPtr<const GraphObject> graph, const std::string& path) { - me->write_bundle(patch, path); + me->write_bundle(graph, path); } void -Serialiser::Impl::write_bundle(SharedPtr<const GraphObject> patch, +Serialiser::Impl::write_bundle(SharedPtr<const GraphObject> graph, const std::string& a_path) { std::string path = Glib::filename_from_uri(a_path); @@ -186,12 +186,12 @@ Serialiser::Impl::write_bundle(SharedPtr<const GraphObject> patch, start_to_filename(root_file); const Raul::Path old_root_path = _root_path; - _root_path = patch->path(); - serialise_patch(patch, Sord::URI(_model->world(), root_file, _base_uri)); + _root_path = graph->path(); + serialise_graph(graph, Sord::URI(_model->world(), root_file, _base_uri)); _root_path = old_root_path; finish(); - write_manifest(path, patch, symbol); + write_manifest(path, graph, symbol); } string @@ -284,8 +284,8 @@ Serialiser::serialise(SharedPtr<const GraphObject> object) throw (std::logic_err if (!me->_model) throw std::logic_error("serialise called without serialisation in progress"); - if (object->graph_type() == GraphObject::PATCH) { - me->serialise_patch(object, me->path_rdf_node(object->path())); + if (object->graph_type() == GraphObject::GRAPH) { + me->serialise_graph(object, me->path_rdf_node(object->path())); } else if (object->graph_type() == GraphObject::BLOCK) { const Sord::URI plugin_id(me->_model->world(), object->plugin()->uri()); me->serialise_block(object, plugin_id, me->path_rdf_node(object->path())); @@ -300,122 +300,122 @@ Serialiser::serialise(SharedPtr<const GraphObject> object) throw (std::logic_err } void -Serialiser::Impl::serialise_patch(SharedPtr<const GraphObject> patch, - const Sord::Node& patch_id) +Serialiser::Impl::serialise_graph(SharedPtr<const GraphObject> graph, + const Sord::Node& graph_id) { Sord::World& world = _model->world(); const URIs& uris = _world.uris(); - _model->add_statement(patch_id, + _model->add_statement(graph_id, Sord::URI(world, uris.rdf_type), - Sord::URI(world, uris.ingen_Patch)); + Sord::URI(world, uris.ingen_Graph)); - _model->add_statement(patch_id, + _model->add_statement(graph_id, Sord::URI(world, uris.rdf_type), Sord::URI(world, uris.lv2_Plugin)); - _model->add_statement(patch_id, + _model->add_statement(graph_id, Sord::URI(world, uris.lv2_extensionData), Sord::URI(world, LV2_STATE__interface)); - _model->add_statement(patch_id, + _model->add_statement(graph_id, Sord::URI(world, LV2_UI__ui), - Sord::URI(world, "http://drobilla.net/ns/ingen#PatchUIGtk2")); + Sord::URI(world, "http://drobilla.net/ns/ingen#GraphUIGtk2")); // Always write a symbol (required by Ingen) Raul::Symbol symbol("_"); - GraphObject::Properties::const_iterator s = patch->properties().find(uris.lv2_symbol); - if (s == patch->properties().end() + GraphObject::Properties::const_iterator s = graph->properties().find(uris.lv2_symbol); + if (s == graph->properties().end() || !s->second.type() == _world.forge().String || !Raul::Symbol::is_valid(s->second.get_string())) { const std::string base = Glib::path_get_basename( _model->base_uri().to_c_string()); symbol = Raul::Symbol::symbolify(base.substr(0, base.find('.'))); _model->add_statement( - patch_id, + graph_id, Sord::URI(world, uris.lv2_symbol), Sord::Literal(world, symbol.c_str())); } else { symbol = Raul::Symbol::symbolify(s->second.get_string()); } - // If the patch has no doap:name (required by LV2), use the symbol - if (patch->properties().find(uris.doap_name) == patch->properties().end()) - _model->add_statement(patch_id, + // If the graph has no doap:name (required by LV2), use the symbol + if (graph->properties().find(uris.doap_name) == graph->properties().end()) + _model->add_statement(graph_id, Sord::URI(world, uris.doap_name), Sord::Literal(world, symbol.c_str())); - const GraphObject::Properties props = patch->properties(Resource::INTERNAL); - serialise_properties(patch_id, props); + const GraphObject::Properties props = graph->properties(Resource::INTERNAL); + serialise_properties(graph_id, props); - const Store::const_range kids = _world.store()->children_range(patch); + const Store::const_range kids = _world.store()->children_range(graph); for (Store::const_iterator n = kids.first; n != kids.second; ++n) { - if (n->first.parent() != patch->path()) + if (n->first.parent() != graph->path()) continue; - if (n->second->graph_type() == GraphObject::PATCH) { - SharedPtr<GraphObject> subpatch = n->second; + if (n->second->graph_type() == GraphObject::GRAPH) { + SharedPtr<GraphObject> subgraph = n->second; SerdURI base_uri; serd_uri_parse((const uint8_t*)_base_uri.c_str(), &base_uri); - const string sub_bundle_path = subpatch->path().substr(1) + ".ingen"; + const string sub_bundle_path = subgraph->path().substr(1) + ".ingen"; - SerdURI subpatch_uri; - SerdNode subpatch_node = serd_node_new_uri_from_string( + SerdURI subgraph_uri; + SerdNode subgraph_node = serd_node_new_uri_from_string( (const uint8_t*)sub_bundle_path.c_str(), &base_uri, - &subpatch_uri); + &subgraph_uri); - const Sord::URI subpatch_id(world, (const char*)subpatch_node.buf); + const Sord::URI subgraph_id(world, (const char*)subgraph_node.buf); // Save our state std::string my_base_uri = _base_uri; Sord::Model* my_model = _model; // Write child bundle within this bundle - write_bundle(subpatch, subpatch_id.to_string()); + write_bundle(subgraph, subgraph_id.to_string()); // Restore our state _base_uri = my_base_uri; _model = my_model; - // Serialise reference to patch block - const Sord::Node block_id(path_rdf_node(subpatch->path())); - _model->add_statement(patch_id, + // Serialise reference to graph block + const Sord::Node block_id(path_rdf_node(subgraph->path())); + _model->add_statement(graph_id, Sord::URI(world, uris.ingen_block), block_id); - serialise_block(subpatch, subpatch_id, block_id); + serialise_block(subgraph, subgraph_id, block_id); } else if (n->second->graph_type() == GraphObject::BLOCK) { SharedPtr<const GraphObject> block = n->second; const Sord::URI class_id(world, block->plugin()->uri()); const Sord::Node block_id(path_rdf_node(n->second->path())); - _model->add_statement(patch_id, + _model->add_statement(graph_id, Sord::URI(world, uris.ingen_block), block_id); serialise_block(block, class_id, block_id); } } - for (uint32_t i = 0; i < patch->num_ports(); ++i) { - GraphObject* p = patch->port(i); + for (uint32_t i = 0; i < graph->num_ports(); ++i) { + GraphObject* p = graph->port(i); const Sord::Node port_id = path_rdf_node(p->path()); - // Ensure lv2:name always exists so Patch is a valid LV2 plugin + // Ensure lv2:name always exists so Graph is a valid LV2 plugin if (p->properties().find(uris.lv2_name) == p->properties().end()) p->set_property(uris.lv2_name, _world.forge().alloc(p->symbol().c_str())); - _model->add_statement(patch_id, + _model->add_statement(graph_id, Sord::URI(world, LV2_CORE__port), port_id); serialise_port(p, Resource::INTERNAL, port_id); } - for (GraphObject::Edges::const_iterator c = patch->edges().begin(); - c != patch->edges().end(); ++c) { - serialise_edge(patch_id, c->second); + for (GraphObject::Edges::const_iterator c = graph->edges().begin(); + c != graph->edges().end(); ++c) { + serialise_edge(graph_id, c->second); } } |