From 91d5cb109563c67bdad5f3ebeaafc8e1e8f7e14a Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 3 Oct 2006 22:24:22 +0000 Subject: shared_ptr bugfixes. Updated Ingen to work with new FlowCanvas. Updated Patchage to work with new(er) FlowCanvas. git-svn-id: http://svn.drobilla.net/lad/ingen@152 a436a847-0d15-0410-975c-d299462d15a1 --- src/common/util/CountedPtr.h | 4 +- src/common/util/RedlandAtom.h | 47 +++++--- src/libs/client/Makefile.am | 4 +- src/libs/client/PluginModel.h | 2 +- src/libs/client/Serializer.cpp | 205 ++++++++++++++++++-------------- src/libs/client/Serializer.h | 36 +++--- src/progs/ingenuity/DSSIModule.cpp | 2 +- src/progs/ingenuity/DSSIModule.h | 2 +- src/progs/ingenuity/Loader.cpp | 14 ++- src/progs/ingenuity/Loader.h | 2 + src/progs/ingenuity/NodeModule.cpp | 54 ++++----- src/progs/ingenuity/NodeModule.h | 28 +++-- src/progs/ingenuity/PatchCanvas.cpp | 74 +++++++----- src/progs/ingenuity/PatchCanvas.h | 22 +++- src/progs/ingenuity/PatchPortModule.cpp | 29 +++-- src/progs/ingenuity/PatchPortModule.h | 13 +- src/progs/ingenuity/PatchView.cpp | 10 +- src/progs/ingenuity/PatchView.h | 10 +- src/progs/ingenuity/Port.cpp | 2 +- src/progs/ingenuity/Port.h | 2 +- src/progs/ingenuity/SubpatchModule.cpp | 2 +- src/progs/ingenuity/SubpatchModule.h | 2 +- 22 files changed, 329 insertions(+), 237 deletions(-) (limited to 'src') diff --git a/src/common/util/CountedPtr.h b/src/common/util/CountedPtr.h index 0f00be87..63b2bdf4 100644 --- a/src/common/util/CountedPtr.h +++ b/src/common/util/CountedPtr.h @@ -31,7 +31,7 @@ static std::list counted_ptr_counters; // Use debug hooks to ensure 2 shared_ptrs never point to the same thing namespace boost { - static void sp_scalar_constructor_hook(void* object, unsigned long cnt, void* ptr) { + inline void sp_scalar_constructor_hook(void* object, unsigned long cnt, void* ptr) { assert(std::find(counted_ptr_counters.begin(), counted_ptr_counters.end(), (void*)object) == counted_ptr_counters.end()); counted_ptr_counters.push_back(object); @@ -39,7 +39,7 @@ namespace boost { // << object << ", count = " << cnt << std::endl; } - static void sp_scalar_destructor_hook(void* object, unsigned long cnt, void* ptr) { + inline void sp_scalar_destructor_hook(void* object, unsigned long cnt, void* ptr) { counted_ptr_counters.remove(object); //std::cerr << "Destroying CountedPtr to " // << object << ", count = " << cnt << std::endl; diff --git a/src/common/util/RedlandAtom.h b/src/common/util/RedlandAtom.h index 6b5658cf..df55affb 100644 --- a/src/common/util/RedlandAtom.h +++ b/src/common/util/RedlandAtom.h @@ -17,7 +17,8 @@ #ifndef REDLAND_ATOM_H #define REDLAND_ATOM_H -#include +#include +#include #include "util/Atom.h" #define U(x) ((const unsigned char*)(x)) @@ -28,31 +29,46 @@ */ class RedlandAtom { public: - static librdf_node* atom_to_node(librdf_world* world, const Atom& atom) { - char tmp_buf[32]; + /** Set this atom's value to the object (value) portion of an RDF triple. + * + * Caller is responsible for calling free(triple->object). + */ + static void atom_to_triple_object(raptor_statement* triple, const Atom& atom) { + static const size_t STR_LENGTH = 32; // FIXME ? + char* str = (char*)malloc(sizeof(char) * STR_LENGTH); switch (atom.type()) { - //case NIL: - // (see below) - //break; case Atom::INT: - snprintf(tmp_buf, 32, "%d", atom.get_int32()); - return librdf_new_node_from_typed_literal(world, U(tmp_buf), NULL, librdf_new_uri(world, U("http://www.w3.org/2001/XMLSchema#integer"))); - break; + snprintf(str, 32, "%d", atom.get_int32()); + triple->object = (unsigned char*)str; + triple->object_type = RAPTOR_IDENTIFIER_TYPE_LITERAL; + triple->object_literal_datatype = raptor_new_uri( + U("http://www.w3.org/2001/XMLSchema#integer")); + break; case Atom::FLOAT: - snprintf(tmp_buf, 32, "%f", atom.get_float()); - return librdf_new_node_from_typed_literal(world, U(tmp_buf), NULL, librdf_new_uri(world, U("http://www.w3.org/2001/XMLSchema#float"))); + snprintf(str, 32, "%f", atom.get_float()); + triple->object = (unsigned char*)str; + triple->object_type = RAPTOR_IDENTIFIER_TYPE_LITERAL; + triple->object_literal_datatype = raptor_new_uri( + U("http://www.w3.org/2001/XMLSchema#float")); break; case Atom::STRING: - return librdf_new_node_from_literal(world, U(atom.get_string()), NULL, 0); + snprintf(str, 32, "%f", atom.get_float()); + triple->object = (unsigned char*)str; + triple->object_type = RAPTOR_IDENTIFIER_TYPE_LITERAL; + break; case Atom::BLOB: + case Atom::NIL: + default: cerr << "WARNING: Unserializable atom!" << endl; - return NULL; - default: // This catches Atom::Type::NIL too - return librdf_new_node(world); // blank node + // FIXME: what to do? + triple->object = NULL; + triple->object_type = RAPTOR_IDENTIFIER_TYPE_UNKNOWN; + free(str); // FIXME: ew } } +#if 0 static Atom node_to_atom(librdf_node* node) { /*switch (type) { case 'i': @@ -70,6 +86,7 @@ public: cerr << "FIXME: node_to_atom\n"; return Atom(); } +#endif }; diff --git a/src/libs/client/Makefile.am b/src/libs/client/Makefile.am index 47e675c2..126b07fa 100644 --- a/src/libs/client/Makefile.am +++ b/src/libs/client/Makefile.am @@ -3,8 +3,8 @@ AM_CXXFLAGS = -I$(top_srcdir)/src/common if BUILD_CLIENT_LIB noinst_LTLIBRARIES = libingenclient.la -libingenclient_la_CXXFLAGS = -I$(top_srcdir)/src/common -DPKGDATADIR=\"$(pkgdatadir)\" @LXML2_CFLAGS@ @REDLAND_CFLAGS@ @LSIGCPP_CFLAGS@ -libingenclient_la_LIBADD = @LXML2_LIBS@ @LOSC_LIBS@ @REDLAND_LIBS@ @LSIGCPP_LIBS@ +libingenclient_la_CXXFLAGS = -I$(top_srcdir)/src/common -DPKGDATADIR=\"$(pkgdatadir)\" @LXML2_CFLAGS@ @RAPTOR_CFLAGS@ @LSIGCPP_CFLAGS@ +libingenclient_la_LIBADD = @LXML2_LIBS@ @LOSC_LIBS@ @RAPTOR_LIBS@ @LSIGCPP_LIBS@ libingenclient_la_SOURCES = \ ClientInterface.h \ diff --git a/src/libs/client/PluginModel.h b/src/libs/client/PluginModel.h index 74eee7cb..42548f64 100644 --- a/src/libs/client/PluginModel.h +++ b/src/libs/client/PluginModel.h @@ -39,7 +39,7 @@ public: : m_uri(uri), m_name(name) { - cerr << "FIXME: plugin type" << endl; + //cerr << "FIXME: plugin type" << endl; } Type type() const { return m_type; } diff --git a/src/libs/client/Serializer.cpp b/src/libs/client/Serializer.cpp index e82389d4..d7c1a153 100644 --- a/src/libs/client/Serializer.cpp +++ b/src/libs/client/Serializer.cpp @@ -20,11 +20,12 @@ #include #include #include // pair, make_pair +#include #include #include #include // atof #include -#include +#include #include "Serializer.h" #include "PatchModel.h" #include "NodeModel.h" @@ -47,13 +48,11 @@ namespace Client { Serializer::Serializer(CountedPtr engine) - : _world(librdf_new_world()) - , _serializer(0) + : _serializer(NULL) + , _string_output(NULL) , _patch_search_path(".") , _engine(engine) { - librdf_world_open(_world); - //_prefixes["xsd"] = "http://www.w3.org/2001/XMLSchema#"; _prefixes["rdf"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; _prefixes["ingen"] = "http://codeson.net/ns/ingen#"; @@ -63,24 +62,67 @@ Serializer::Serializer(CountedPtr engine) Serializer::~Serializer() { - - librdf_free_world(_world); } +/** Begin a serialization to a file. + * + * This must be called before any serializing methods. + */ void -Serializer::create() +Serializer::start_to_filename(const string& filename) { - _serializer = librdf_new_serializer(_world, "rdfxml-abbrev", NULL, librdf_new_uri(_world, U(NS_INGEN()))); - + raptor_init(); + _serializer = raptor_new_serializer("rdfxml-abbrev"); setup_prefixes(); + raptor_serialize_start_to_filename(_serializer, filename.c_str()); } + +/** Begin a serialization to a string. + * + * 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. + */ void -Serializer::destroy() +Serializer::start_to_string() { - librdf_free_serializer(_serializer); + _serializer = raptor_new_serializer("rdfxml-abbrev"); + setup_prefixes(); + raptor_serialize_start_to_string(_serializer, + NULL /*base_uri*/, + (void**)&_string_output, + NULL /*size*/); +} + + +/** Finish a serialization. + * + * If this was a serialization to a string, the serialization output + * will be returned, otherwise the empty string is returned. + */ +string +Serializer::finish() throw(std::logic_error) +{ + string ret = ""; + + if (!_serializer) + throw std::logic_error("finish() called with no serialization in progress"); + + raptor_serialize_end(_serializer); + + if (_string_output) { + ret = string((char*)_string_output); + free(_string_output); + _string_output = NULL; + } + + raptor_free_serializer(_serializer); _serializer = NULL; + + return ret; } @@ -88,8 +130,8 @@ void Serializer::setup_prefixes() { for (map::const_iterator i = _prefixes.begin(); i != _prefixes.end(); ++i) { - librdf_serializer_set_namespace(_serializer, - librdf_new_uri(_world, U(i->second.c_str())), i->first.c_str()); + raptor_serialize_set_namespace(_serializer, + raptor_new_uri(U(i->second.c_str())), U(i->first.c_str())); } } @@ -106,11 +148,6 @@ Serializer::expand_uri(const string& uri) if (uri.substr(0, i->first.length()+1) == i->first + ":") return i->second + uri.substr(i->first.length()+1); - /*librdf_uri* redland_uri = librdf_new_uri(_world, U(uri.c_str())); - string ret = (redland_uri) ? uri : ""; - librdf_free_uri(redland_uri); - return ret;*/ - // FIXME: find a correct way to validate a URI if (uri.find(":") == string::npos && uri.find("/") == string::npos) return ""; @@ -169,110 +206,97 @@ Serializer::find_file(const string& filename, const string& additional_path) } -/** Save a patch from a PatchModel to a filename. - * - * The filename passed is the true filename the patch will be saved to (with no prefixing or anything - * like that), and the patch_model's filename member will be set accordingly. - * - * FIXME: make this take a URI. network loading for free. - * - * This will break if: - * - The filename does not have an extension (ie contain a ".") - * - The patch_model has no (Ingen) path - */ -void -Serializer::save_patch(CountedPtr patch_model, const string& filename, bool recursive) -{ - librdf_storage* storage = librdf_new_storage(_world, "hashes", NULL, "hash-type='memory'"); - - librdf_model* model = librdf_new_model(_world, storage, NULL); - assert(model); - - const string uri = string("file://") + filename; - add_patch_to_rdf(model, patch_model, uri); - - create(); - - //librdf_serializer_serialize_model_to_file_handle(serializer, stdout, NULL, model); - librdf_serializer_serialize_model_to_file(_serializer, - filename.c_str(), NULL, model); - - destroy(); - - librdf_storage_close(storage); - librdf_free_storage(storage); - librdf_free_model(model); -} - - void -Serializer::add_resource_to_rdf(librdf_model* rdf, +Serializer::add_resource_to_rdf(raptor_serializer* rdf, const string& subject_uri, const string& predicate_uri, const string& object_uri) { - - librdf_node* subject = librdf_new_node_from_uri_string(_world, U(subject_uri.c_str())); - add_resource_to_rdf(rdf, subject, predicate_uri, object_uri); + raptor_statement triple; + triple.subject = (void*)raptor_new_uri((const unsigned char*)subject_uri.c_str()); + triple.subject_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE; + triple.predicate = (void*)raptor_new_uri((const unsigned char*)predicate_uri.c_str()); + triple.predicate_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE; + triple.object = (void*)raptor_new_uri((const unsigned char*)object_uri.c_str()); + triple.object_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE; + raptor_serialize_statement(rdf, &triple); } +#if 0 void -Serializer::add_resource_to_rdf(librdf_model* rdf, +Serializer::add_resource_to_rdf(raptor_serializer* rdf librdf_node* subject, const string& predicate_uri, const string& object_uri) { + cerr << "FIXME: serialize blank node\n"; + /* + raptor_statement triple; + triple.subject = (void*)raptor_new_uri((const unsigned char*)subject_uri.c_str()); + triple.subject_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE; + triple.predicate = (void*)raptor_new_uri((const unsigned char*)predicate_uri.c_str()); + triple.predicate_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE; + triple.object = (void*)raptor_new_uri((const unsigned char*)object_uri.c_str()); + triple.object_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE; + raptor_serialize_statement(rdf, triple); librdf_node* predicate = librdf_new_node_from_uri_string(_world, U(predicate_uri.c_str())); librdf_node* object = librdf_new_node_from_uri_string(_world, U(object_uri.c_str())); librdf_model_add(rdf, subject, predicate, object); + */ } - +#endif void -Serializer::add_atom_to_rdf(librdf_model* rdf, +Serializer::add_atom_to_rdf(raptor_serializer* rdf, const string& subject_uri, const string& predicate_uri, const Atom& atom) { - librdf_node* subject = librdf_new_node_from_uri_string(_world, U(subject_uri.c_str())); - librdf_node* predicate = librdf_new_node_from_uri_string(_world, U(predicate_uri.c_str())); - librdf_node* object = RedlandAtom::atom_to_node(_world, atom); + raptor_statement triple; + triple.subject = (void*)raptor_new_uri((const unsigned char*)subject_uri.c_str()); + triple.subject_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE; + triple.predicate = (void*)raptor_new_uri((const unsigned char*)predicate_uri.c_str()); + triple.predicate_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE; - librdf_model_add(rdf, subject, predicate, object); + RedlandAtom::atom_to_triple_object(&triple, atom); + + raptor_serialize_statement(rdf, &triple); } void -Serializer::add_patch_to_rdf(librdf_model* rdf, - CountedPtr patch, const string& uri_unused) +Serializer::serialize_patch(CountedPtr patch) throw (std::logic_error) { + if (!_serializer) + throw std::logic_error("serialize_patch called without serialization in progress"); + const string uri = "#"; - add_resource_to_rdf(rdf, + add_resource_to_rdf(_serializer, uri.c_str(), NS_RDF("type"), NS_INGEN("Patch")); if (patch->path().name().length() > 0) { - add_atom_to_rdf(rdf, + add_atom_to_rdf(_serializer, uri.c_str(), NS_INGEN("name"), Atom(patch->path().name().c_str())); } - add_atom_to_rdf(rdf, + add_atom_to_rdf(_serializer, uri.c_str(), NS_INGEN("polyphony"), Atom((int)patch->poly())); for (NodeModelMap::const_iterator n = patch->nodes().begin(); n != patch->nodes().end(); ++n) { - add_node_to_rdf(rdf, n->second, "#"); - add_resource_to_rdf(rdf, "#", NS_INGEN("node"), uri + n->second->path().name()); + add_node_to_rdf(_serializer, n->second, "#"); + add_resource_to_rdf(_serializer, "#", NS_INGEN("node"), uri + n->second->path().name()); } for (PortModelList::const_iterator p = patch->ports().begin(); p != patch->ports().end(); ++p) { - add_port_to_rdf(rdf, *p, uri); - add_resource_to_rdf(rdf, "#", NS_INGEN("port"), uri + (*p)->path().name()); + add_port_to_rdf(_serializer, *p, uri); + add_resource_to_rdf(_serializer, "#", NS_INGEN("port"), uri + (*p)->path().name()); } for (ConnectionList::const_iterator c = patch->connections().begin(); c != patch->connections().end(); ++c) { - add_connection_to_rdf(rdf, *c, uri); + add_connection_to_rdf(_serializer, *c, uri); } //_engine->set_metadata(patch->path(), "uri", uri); @@ -280,29 +304,29 @@ Serializer::add_patch_to_rdf(librdf_model* rdf, void -Serializer::add_node_to_rdf(librdf_model* rdf, +Serializer::add_node_to_rdf(raptor_serializer* rdf, CountedPtr node, const string ns_prefix) { const string node_uri = ns_prefix + node->path().name(); - add_resource_to_rdf(rdf, + add_resource_to_rdf(_serializer, node_uri.c_str(), NS_RDF("type"), NS_INGEN("Node")); - /*add_atom_to_rdf(rdf, + /*add_atom_to_rdf(_serializer, node_uri_ref.c_str(), NS_INGEN("name"), Atom(node->path().name()));*/ for (PortModelList::const_iterator p = node->ports().begin(); p != node->ports().end(); ++p) { - add_port_to_rdf(rdf, *p, node_uri + "/"); - add_resource_to_rdf(rdf, node_uri, NS_INGEN("port"), node_uri + "/" + (*p)->path().name()); + add_port_to_rdf(_serializer, *p, node_uri + "/"); + add_resource_to_rdf(_serializer, node_uri, NS_INGEN("port"), node_uri + "/" + (*p)->path().name()); } for (MetadataMap::const_iterator m = node->metadata().begin(); m != node->metadata().end(); ++m) { if (expand_uri(m->first) != "") { - add_atom_to_rdf(rdf, + add_atom_to_rdf(_serializer, node_uri.c_str(), expand_uri(m->first.c_str()).c_str(), m->second); @@ -312,19 +336,19 @@ Serializer::add_node_to_rdf(librdf_model* rdf, void -Serializer::add_port_to_rdf(librdf_model* rdf, +Serializer::add_port_to_rdf(raptor_serializer* rdf, CountedPtr port, const string ns_prefix) { const string port_uri_ref = ns_prefix + port->path().name(); - add_resource_to_rdf(rdf, + add_resource_to_rdf(_serializer, port_uri_ref.c_str(), NS_RDF("type"), NS_INGEN("Port")); for (MetadataMap::const_iterator m = port->metadata().begin(); m != port->metadata().end(); ++m) { if (expand_uri(m->first) != "") { - add_atom_to_rdf(rdf, + add_atom_to_rdf(_serializer, port_uri_ref.c_str(), expand_uri(m->first).c_str(), m->second); @@ -334,9 +358,11 @@ Serializer::add_port_to_rdf(librdf_model* rdf, void -Serializer::add_connection_to_rdf(librdf_model* rdf, +Serializer::add_connection_to_rdf(raptor_serializer* rdf, CountedPtr connection, const string ns_prefix) { + cerr << "FIXME: serialize connection\n"; +#if 0 librdf_node* c = librdf_new_node(_world); const string src_port_rel_path = connection->src_port_path().substr(connection->patch_path().length()); @@ -345,14 +371,15 @@ Serializer::add_connection_to_rdf(librdf_model* rdf, librdf_statement* s = librdf_new_statement_from_nodes(_world, c, librdf_new_node_from_uri_string(_world, U(NS_INGEN("source"))), librdf_new_node_from_uri_string(_world, U((ns_prefix + src_port_rel_path).c_str()))); - librdf_model_add_statement(rdf, s); + librdf_model_add_statement(_serializer, s); librdf_statement* d = librdf_new_statement_from_nodes(_world, c, librdf_new_node_from_uri_string(_world, U(NS_INGEN("destination"))), librdf_new_node_from_uri_string(_world, U((ns_prefix + dst_port_rel_path).c_str()))); - librdf_model_add_statement(rdf, d); + librdf_model_add_statement(_serializer, d); - add_resource_to_rdf(rdf, c, NS_RDF("type"), NS_INGEN("Connection")); + add_resource_to_rdf(_serializer, c, NS_RDF("type"), NS_INGEN("Connection")); +#endif } diff --git a/src/libs/client/Serializer.h b/src/libs/client/Serializer.h index b2dbf000..a563dbb8 100644 --- a/src/libs/client/Serializer.h +++ b/src/libs/client/Serializer.h @@ -20,7 +20,8 @@ #include #include #include -#include +#include +#include #include #include "util/CountedPtr.h" #include "util/Path.h" @@ -60,52 +61,51 @@ public: string find_file(const string& filename, const string& additional_path = ""); - void save_patch(CountedPtr patch_model, const string& filename, bool recursive); - string load_patch(const string& filename, const string& parent_path, const string& name, size_t poly, MetadataMap initial_data, bool existing = false); + + void start_to_filename(const string& filename); + void start_to_string(); + + void serialize_patch(CountedPtr patch) throw(std::logic_error); + + string finish() throw(std::logic_error); private: // Model -> RDF - void add_patch_to_rdf(librdf_model* rdf, - CountedPtr patch, const string& uri); - - void add_node_to_rdf(librdf_model* rdf, + void add_node_to_rdf(raptor_serializer* rdf, CountedPtr node, const string ns_prefix=""); - void add_port_to_rdf(librdf_model* rdf, + void add_port_to_rdf(raptor_serializer* rdf, CountedPtr port, const string ns_prefix=""); - void add_connection_to_rdf(librdf_model* rdf, + void add_connection_to_rdf(raptor_serializer* rdf, CountedPtr connection, const string port_ns_prefix=""); // Triple -> RDF - void add_resource_to_rdf(librdf_model* model, + void add_resource_to_rdf(raptor_serializer* rdf, const string& subject_uri, const string& predicate_uri, const string& object_uri); - void add_resource_to_rdf(librdf_model* model, - librdf_node* subject, const string& predicate_uri, const string& object_uri); + //void add_resource_to_rdf(raptor_serializer* rdf + // librdf_node* subject, const string& predicate_uri, const string& object_uri); - void add_atom_to_rdf(librdf_model* model, + void add_atom_to_rdf(raptor_serializer* rdf, const string& subject_uri, const string& predicate_uri, const Atom& atom); - - void create(); - void destroy(); void setup_prefixes(); string expand_uri(const string& uri); - librdf_world* _world; - librdf_serializer* _serializer; + raptor_serializer* _serializer; + unsigned char* _string_output; string _patch_search_path; map _prefixes; CountedPtr _engine; diff --git a/src/progs/ingenuity/DSSIModule.cpp b/src/progs/ingenuity/DSSIModule.cpp index 670c8efb..9506897d 100644 --- a/src/progs/ingenuity/DSSIModule.cpp +++ b/src/progs/ingenuity/DSSIModule.cpp @@ -20,7 +20,7 @@ namespace Ingenuity { -DSSIModule::DSSIModule(PatchCanvas* canvas, CountedPtr node) +DSSIModule::DSSIModule(boost::shared_ptr canvas, CountedPtr node) : NodeModule(canvas, node) { } diff --git a/src/progs/ingenuity/DSSIModule.h b/src/progs/ingenuity/DSSIModule.h index e281a2b7..342d5f7b 100644 --- a/src/progs/ingenuity/DSSIModule.h +++ b/src/progs/ingenuity/DSSIModule.h @@ -30,7 +30,7 @@ class DSSIController; class DSSIModule : public Ingenuity::NodeModule { public: - DSSIModule(PatchCanvas* canvas, CountedPtr node); + DSSIModule(boost::shared_ptr canvas, CountedPtr node); virtual ~DSSIModule() {} void on_double_click(GdkEventButton* ev); diff --git a/src/progs/ingenuity/Loader.cpp b/src/progs/ingenuity/Loader.cpp index 485e450d..c07d99bf 100644 --- a/src/progs/ingenuity/Loader.cpp +++ b/src/progs/ingenuity/Loader.cpp @@ -81,7 +81,7 @@ Loader::save_patch(CountedPtr model, const string& filename, bool re _mutex.lock(); _events.push_back(sigc::hide_return(sigc::bind( - sigc::mem_fun(_serializer, &Serializer::save_patch), + sigc::mem_fun(this, &Loader::save_patch_event), model, filename, recursive))); _mutex.unlock(); @@ -90,4 +90,16 @@ Loader::save_patch(CountedPtr model, const string& filename, bool re } +void +Loader::save_patch_event(CountedPtr model, const string& filename, bool recursive) +{ + if (recursive) + cerr << "FIXME: Recursive save." << endl; + + _serializer->start_to_filename(filename); + _serializer->serialize_patch(model); + _serializer->finish(); +} + + } // namespace Ingenuity diff --git a/src/progs/ingenuity/Loader.h b/src/progs/ingenuity/Loader.h index 7459378e..3a043c59 100644 --- a/src/progs/ingenuity/Loader.h +++ b/src/progs/ingenuity/Loader.h @@ -69,6 +69,8 @@ public: private: + void save_patch_event(CountedPtr model, const string& filename, bool recursive); + /** Returns nothing and takes no parameters (because they have all been bound) */ typedef sigc::slot Closure; diff --git a/src/progs/ingenuity/NodeModule.cpp b/src/progs/ingenuity/NodeModule.cpp index 29af857e..6d4e54de 100644 --- a/src/progs/ingenuity/NodeModule.cpp +++ b/src/progs/ingenuity/NodeModule.cpp @@ -31,7 +31,7 @@ namespace Ingenuity { -NodeModule::NodeModule(PatchCanvas* canvas, CountedPtr node) +NodeModule::NodeModule(boost::shared_ptr canvas, CountedPtr node) : LibFlowCanvas::Module(canvas, node->path().name()), m_node(node), m_menu(node) @@ -39,55 +39,39 @@ NodeModule::NodeModule(PatchCanvas* canvas, CountedPtr node) assert(m_node); if (node->polyphonic()) { - border_width(2.0); + set_border_width(2.0); } - create_all_ports(); - set_all_metadata(); - - node->new_port_sig.connect(sigc::mem_fun(this, &NodeModule::add_port)); + node->new_port_sig.connect(sigc::bind(sigc::mem_fun(this, &NodeModule::add_port), true)); node->removed_port_sig.connect(sigc::mem_fun(this, &NodeModule::remove_port)); node->metadata_update_sig.connect(sigc::mem_fun(this, &NodeModule::metadata_update)); } -void -NodeModule::create_all_ports() +boost::shared_ptr +NodeModule::create(boost::shared_ptr canvas, CountedPtr node) { - for (PortModelList::const_iterator i = m_node->ports().begin(); - i != m_node->ports().end(); ++i) { - add_port(*i); - } - - resize(); - - // FIXME - //if (has_control_inputs()) - // enable_controls_menuitem(); -} + boost::shared_ptr ret = boost::shared_ptr( + new NodeModule(canvas, node)); + for (MetadataMap::const_iterator m = node->metadata().begin(); m != node->metadata().end(); ++m) + ret->metadata_update(m->first, m->second); -void -NodeModule::set_all_metadata() -{ - for (MetadataMap::const_iterator i = m_node->metadata().begin(); i != m_node->metadata().end(); ++i) - metadata_update(i->first, i->second); -} + for (PortModelList::const_iterator p = node->ports().begin(); p != node->ports().end(); ++p) + ret->add_port(*p, false); + ret->resize(); -void -NodeModule::add_port(CountedPtr port) -{ - manage(new Port(this, port)); - resize(); + return ret; } void -NodeModule::remove_port(CountedPtr port) +NodeModule::add_port(CountedPtr port, bool resize_to_fit) { - LibFlowCanvas::Port* canvas_port = get_port(port->path().name()); - delete canvas_port; + Module::add_port(boost::shared_ptr(new Port(shared_from_this(), port))); + if (resize_to_fit) + resize(); } @@ -101,6 +85,8 @@ NodeModule::show_control_window() void NodeModule::store_location() { + cerr << "FIXME: store_location\n"; +#if 0 const float x = static_cast(property_x()); const float y = static_cast(property_y()); @@ -112,7 +98,7 @@ NodeModule::store_location() App::instance().engine()->set_metadata(m_node->path(), "ingenuity:canvas-x", Atom(x)); App::instance().engine()->set_metadata(m_node->path(), "ingenuity:canvas-y", Atom(y)); } - +#endif } diff --git a/src/progs/ingenuity/NodeModule.h b/src/progs/ingenuity/NodeModule.h index 6f7460bf..cbdfc6d2 100644 --- a/src/progs/ingenuity/NodeModule.h +++ b/src/progs/ingenuity/NodeModule.h @@ -18,10 +18,12 @@ #define OMMODULE_H #include +#include #include #include -#include "NodeMenu.h" #include "util/CountedPtr.h" +#include "Port.h" +#include "NodeMenu.h" using std::string; class Atom; @@ -46,14 +48,16 @@ class Port; * * \ingroup Ingenuity */ -class NodeModule : public LibFlowCanvas::Module +class NodeModule : public boost::enable_shared_from_this, public LibFlowCanvas::Module { public: - NodeModule(PatchCanvas* canvas, CountedPtr node); + static boost::shared_ptr create (boost::shared_ptr canvas, CountedPtr node); + virtual ~NodeModule() {} - - virtual Ingenuity::Port* port(const string& port_name) { - return (Ingenuity::Port*)Module::get_port(port_name); + + boost::shared_ptr port(const string& port_name) { + return boost::dynamic_pointer_cast( + Module::get_port(port_name)); } virtual void store_location(); @@ -65,16 +69,16 @@ public: CountedPtr node() const { return m_node; } protected: + NodeModule(boost::shared_ptr canvas, CountedPtr node); + virtual void on_double_click(GdkEventButton* ev) { show_control_window(); } virtual void on_middle_click(GdkEventButton* ev) { show_control_window(); } - void set_all_metadata(); void metadata_update(const string& key, const Atom& value); - - void create_all_ports(); - void add_port(CountedPtr port); - void remove_port(CountedPtr port); - + + void add_port(CountedPtr port, bool resize=true); + void remove_port(CountedPtr port) { Module::remove_port(port->path().name()); } + CountedPtr m_node; NodeMenu m_menu; }; diff --git a/src/progs/ingenuity/PatchCanvas.cpp b/src/progs/ingenuity/PatchCanvas.cpp index 707b8856..6d8403eb 100644 --- a/src/progs/ingenuity/PatchCanvas.cpp +++ b/src/progs/ingenuity/PatchCanvas.cpp @@ -54,8 +54,6 @@ PatchCanvas::PatchCanvas(CountedPtr patch, int width, int height) xml->get_widget("canvas_menu_load_patch", m_menu_load_patch); xml->get_widget("canvas_menu_new_patch", m_menu_new_patch); - build_canvas(); - // Add port menu items m_menu_add_audio_input->signal_activate().connect( sigc::bind(sigc::mem_fun(this, &PatchCanvas::menu_add_port), @@ -92,7 +90,10 @@ PatchCanvas::PatchCanvas(CountedPtr patch, int width, int height) void -PatchCanvas::build_canvas() { +PatchCanvas::build() +{ + boost::shared_ptr shared_this = + boost::dynamic_pointer_cast(shared_from_this()); // Create modules for nodes for (NodeModelMap::const_iterator i = m_patch->nodes().begin(); @@ -103,7 +104,7 @@ PatchCanvas::build_canvas() { // Create pseudo modules for ports (ports on this canvas, not on our module) for (PortModelList::const_iterator i = m_patch->ports().begin(); i != m_patch->ports().end(); ++i) { - manage(new PatchPortModule(this, *i)); + add_module(PatchPortModule::create(shared_this, *i)); } // Create connections @@ -117,26 +118,31 @@ PatchCanvas::build_canvas() { void PatchCanvas::add_node(CountedPtr nm) { + boost::shared_ptr shared_this = + boost::dynamic_pointer_cast(shared_from_this()); + CountedPtr pm = PtrCast(nm); if (pm) - manage(new SubpatchModule(this, pm)); + add_module(SubpatchModule::create(shared_this, pm)); else - manage(new NodeModule(this, nm)); + add_module(NodeModule::create(shared_this, nm)); } void PatchCanvas::remove_node(CountedPtr nm) { - LibFlowCanvas::Module* module = get_module(nm->path().name()); - delete module; + remove_module(nm->path().name()); // should cut all references } void PatchCanvas::add_port(CountedPtr pm) { - manage(new PatchPortModule(this, pm)); + boost::shared_ptr shared_this = + boost::dynamic_pointer_cast(shared_from_this()); + + add_module(PatchPortModule::create(shared_this, pm)); } @@ -161,11 +167,13 @@ PatchCanvas::connection(CountedPtr cm) const string& dst_parent_name = (dst_parent_path == m_patch->path()) ? "" : dst_parent_path.name(); - LibFlowCanvas::Port* src_port = get_port(src_parent_name, cm->src_port_path().name()); - LibFlowCanvas::Port* dst_port = get_port(dst_parent_name, cm->dst_port_path().name()); - assert(src_port && dst_port); - - add_connection(src_port, dst_port); + boost::shared_ptr src = get_port(src_parent_name, cm->src_port_path().name()); + boost::shared_ptr dst = get_port(dst_parent_name, cm->dst_port_path().name()); + + if (src && dst) + add_connection(src, dst); + else + cerr << "[Canvas] ERROR: Unable to find ports to create connection." << endl; } @@ -177,8 +185,8 @@ PatchCanvas::disconnection(const Path& src_port_path, const Path& dst_port_path) const string& dst_node_name = dst_port_path.parent().name(); const string& dst_port_name = dst_port_path.name(); - LibFlowCanvas::Port* src_port = get_port(src_node_name, src_port_name); - LibFlowCanvas::Port* dst_port = get_port(dst_node_name, dst_port_name); + boost::shared_ptr src_port = get_port(src_node_name, src_port_name); + boost::shared_ptr dst_port = get_port(dst_node_name, dst_port_name); if (src_port && dst_port) { remove_connection(src_port, dst_port); @@ -199,14 +207,16 @@ PatchCanvas::disconnection(const Path& src_port_path, const Path& dst_port_path) void -PatchCanvas::connect(const LibFlowCanvas::Port* src_port, const LibFlowCanvas::Port* dst_port) +PatchCanvas::connect(boost::shared_ptr src_port, boost::shared_ptr dst_port) { - assert(src_port != NULL); - assert(dst_port != NULL); + const boost::shared_ptr src + = boost::dynamic_pointer_cast(src_port); + + const boost::shared_ptr dst + = boost::dynamic_pointer_cast(dst_port); - const Ingenuity::Port* const src = dynamic_cast(src_port); - const Ingenuity::Port* const dst = dynamic_cast(dst_port); - assert(src && dst); + if (!src || !dst) + return; // Midi binding/learn shortcut if (src->model()->type() == PortModel::MIDI && @@ -240,13 +250,16 @@ PatchCanvas::connect(const LibFlowCanvas::Port* src_port, const LibFlowCanvas::P void -PatchCanvas::disconnect(const LibFlowCanvas::Port* src_port, const LibFlowCanvas::Port* dst_port) +PatchCanvas::disconnect(boost::shared_ptr src_port, boost::shared_ptr dst_port) { - assert(src_port != NULL); - assert(dst_port != NULL); + const boost::shared_ptr src + = boost::dynamic_pointer_cast(src_port); + + const boost::shared_ptr dst + = boost::dynamic_pointer_cast(dst_port); - App::instance().engine()->disconnect(((Ingenuity::Port*)src_port)->model()->path(), - ((Ingenuity::Port*)dst_port)->model()->path()); + App::instance().engine()->disconnect(src->model()->path(), + dst->model()->path()); } @@ -282,8 +295,11 @@ PatchCanvas::canvas_event(GdkEvent* event) void PatchCanvas::destroy_selected() { - for (list::iterator m = m_selected_modules.begin(); m != m_selected_modules.end(); ++m) - App::instance().engine()->destroy(((NodeModule*)(*m))->node()->path()); + for (list >::iterator m = m_selected_modules.begin(); m != m_selected_modules.end(); ++m) { + boost::shared_ptr module = boost::dynamic_pointer_cast(*m); + App::instance().engine()->destroy(module->node()->path()); + } + } diff --git a/src/progs/ingenuity/PatchCanvas.h b/src/progs/ingenuity/PatchCanvas.h index c6abeeb0..15312367 100644 --- a/src/progs/ingenuity/PatchCanvas.h +++ b/src/progs/ingenuity/PatchCanvas.h @@ -18,11 +18,14 @@ #define OMPATCHBAYAREA_H #include +#include #include +#include #include "util/CountedPtr.h" #include "util/Path.h" #include "ConnectionModel.h" #include "PatchModel.h" +#include "NodeModule.h" using std::string; using namespace LibFlowCanvas; @@ -48,8 +51,14 @@ class PatchCanvas : public LibFlowCanvas::FlowCanvas public: PatchCanvas(CountedPtr patch, int width, int height); - NodeModule* find_module(const string& name) - { return (NodeModule*)FlowCanvas::get_module(name); } + virtual ~PatchCanvas() {} + + boost::shared_ptr find_module(const string& name) { + return boost::dynamic_pointer_cast( + FlowCanvas::get_module(name)); + } + + void build(); void add_node(CountedPtr nm); void remove_node(CountedPtr nm); @@ -74,12 +83,13 @@ private: MetadataMap get_initial_data(); - void build_canvas(); - bool canvas_event(GdkEvent* event); - void connect(const LibFlowCanvas::Port* src_port, const LibFlowCanvas::Port* dst_port); - void disconnect(const LibFlowCanvas::Port* src_port, const LibFlowCanvas::Port* dst_port); + void connect(boost::shared_ptr src, + boost::shared_ptr dst); + + void disconnect(boost::shared_ptr src, + boost::shared_ptr dst); CountedPtr m_patch; diff --git a/src/progs/ingenuity/PatchPortModule.cpp b/src/progs/ingenuity/PatchPortModule.cpp index 8843882b..2804a6a6 100644 --- a/src/progs/ingenuity/PatchPortModule.cpp +++ b/src/progs/ingenuity/PatchPortModule.cpp @@ -29,10 +29,9 @@ namespace Ingenuity { -PatchPortModule::PatchPortModule(PatchCanvas* canvas, CountedPtr port) +PatchPortModule::PatchPortModule(boost::shared_ptr canvas, CountedPtr port) : LibFlowCanvas::Module(canvas, "", 0, 0), // FIXME: coords? - m_port(port), - m_patch_port(NULL) + m_port(port) { /*if (port_model()->polyphonic() && port_model()->parent() != NULL && port_model()->parent_patch()->poly() > 1) { @@ -42,12 +41,9 @@ PatchPortModule::PatchPortModule(PatchCanvas* canvas, CountedPtr port assert(canvas); assert(port); - if (PtrCast(port->parent())) { - if (m_patch_port) - delete m_patch_port; - - m_patch_port = new Port(this, port, true); - } + //if (PtrCast(port->parent())) { + // m_patch_port = boost::shared_ptr(new Port(shared_from_this(), port, true)); + //} resize(); @@ -67,6 +63,21 @@ PatchPortModule::PatchPortModule(PatchCanvas* canvas, CountedPtr port } +boost::shared_ptr +PatchPortModule::create(boost::shared_ptr canvas, CountedPtr port) +{ + boost::shared_ptr ret = boost::shared_ptr( + new PatchPortModule(canvas, port)); + + for (MetadataMap::const_iterator m = port->metadata().begin(); m != port->metadata().end(); ++m) + ret->metadata_update(m->first, m->second); + + ret->resize(); + + return ret; +} + + void PatchPortModule::store_location() { diff --git a/src/progs/ingenuity/PatchPortModule.h b/src/progs/ingenuity/PatchPortModule.h index 98bc1b1d..3cf55192 100644 --- a/src/progs/ingenuity/PatchPortModule.h +++ b/src/progs/ingenuity/PatchPortModule.h @@ -18,6 +18,7 @@ #define OMPORTMODULE_H #include +#include #include #include #include "util/Atom.h" @@ -43,10 +44,12 @@ class Port; * * \ingroup Ingenuity */ -class PatchPortModule : public LibFlowCanvas::Module +class PatchPortModule : public LibFlowCanvas::Module//, public boost::enable_shared_from_this { public: - PatchPortModule(PatchCanvas* canvas, CountedPtr port); + static boost::shared_ptr create (boost::shared_ptr canvas, + CountedPtr port); + virtual ~PatchPortModule() {} virtual void store_location(); @@ -56,13 +59,15 @@ public: CountedPtr port() const { return m_port; } protected: + PatchPortModule(boost::shared_ptr canvas, CountedPtr port); + //virtual void on_double_click(GdkEventButton* ev) { show_control_window(); } //virtual void on_middle_click(GdkEventButton* ev) { show_control_window(); } void metadata_update(const string& key, const Atom& value); - CountedPtr m_port; - Port* m_patch_port; ///< Port on this 'anonymous' module + CountedPtr m_port; + boost::shared_ptr m_patch_port; ///< Port on this 'anonymous' module }; diff --git a/src/progs/ingenuity/PatchView.cpp b/src/progs/ingenuity/PatchView.cpp index fbebd886..69dcf0b8 100644 --- a/src/progs/ingenuity/PatchView.cpp +++ b/src/progs/ingenuity/PatchView.cpp @@ -35,7 +35,6 @@ namespace Ingenuity { PatchView::PatchView(BaseObjectType* cobject, const Glib::RefPtr& xml) : Gtk::Box(cobject), - _canvas(NULL), _breadcrumb_container(NULL), _enable_signal(true) { @@ -57,12 +56,15 @@ PatchView::PatchView(BaseObjectType* cobject, const Glib::RefPtr patch) { + assert(!_canvas); // FIXME: remove + cerr << "Creating view for " << patch->path() << endl; assert(_breadcrumb_container); // ensure created _patch = patch; - _canvas = new PatchCanvas(patch, 1600*2, 1200*2); + _canvas = CountedPtr(new PatchCanvas(patch, 1600*2, 1200*2)); + _canvas->build(); _canvas_scrolledwindow->add(*_canvas); @@ -80,10 +82,10 @@ PatchView::set_patch(CountedPtr patch) _refresh_but->signal_clicked().connect(sigc::mem_fun(this, &PatchView::refresh_clicked)); _zoom_normal_but->signal_clicked().connect(sigc::bind(sigc::mem_fun( - static_cast(_canvas), &FlowCanvas::set_zoom), 1.0)); + _canvas.get(), &FlowCanvas::set_zoom), 1.0)); _zoom_full_but->signal_clicked().connect( - sigc::mem_fun(static_cast(_canvas), &FlowCanvas::zoom_full)); + sigc::mem_fun(_canvas.get(), &FlowCanvas::zoom_full)); } diff --git a/src/progs/ingenuity/PatchView.h b/src/progs/ingenuity/PatchView.h index a0225bda..0a445baa 100644 --- a/src/progs/ingenuity/PatchView.h +++ b/src/progs/ingenuity/PatchView.h @@ -57,9 +57,9 @@ public: PatchView(BaseObjectType* cobject, const Glib::RefPtr& glade_xml); ~PatchView(); - PatchCanvas* canvas() const { return _canvas; } - CountedPtr patch() const { return _patch; } - Gtk::Viewport* breadcrumb_container() const { return _breadcrumb_container; } + CountedPtr canvas() const { return _canvas; } + CountedPtr patch() const { return _patch; } + Gtk::Viewport* breadcrumb_container() const { return _breadcrumb_container; } static CountedPtr create(CountedPtr patch); @@ -75,8 +75,8 @@ private: void zoom_full(); - CountedPtr _patch; - PatchCanvas* _canvas; + CountedPtr _patch; + CountedPtr _canvas; Gtk::ScrolledWindow* _canvas_scrolledwindow; diff --git a/src/progs/ingenuity/Port.cpp b/src/progs/ingenuity/Port.cpp index 863e8a1a..560be981 100644 --- a/src/progs/ingenuity/Port.cpp +++ b/src/progs/ingenuity/Port.cpp @@ -31,7 +31,7 @@ namespace Ingenuity { /** @param flip Make an input port appear as an output port, and vice versa. */ -Port::Port(LibFlowCanvas::Module* module, CountedPtr pm, bool flip) +Port::Port(boost::shared_ptr module, CountedPtr pm, bool flip) : LibFlowCanvas::Port(module, pm->path().name(), flip ? (!pm->is_input()) : pm->is_input(), diff --git a/src/progs/ingenuity/Port.h b/src/progs/ingenuity/Port.h index c2344aef..84e50e7d 100644 --- a/src/progs/ingenuity/Port.h +++ b/src/progs/ingenuity/Port.h @@ -35,7 +35,7 @@ namespace Ingenuity { class Port : public LibFlowCanvas::Port { public: - Port(LibFlowCanvas::Module* module, CountedPtr pm, bool flip = false); + Port(boost::shared_ptr module, CountedPtr pm, bool flip = false); virtual ~Port() {} diff --git a/src/progs/ingenuity/SubpatchModule.cpp b/src/progs/ingenuity/SubpatchModule.cpp index 585ccee3..566248f9 100644 --- a/src/progs/ingenuity/SubpatchModule.cpp +++ b/src/progs/ingenuity/SubpatchModule.cpp @@ -31,7 +31,7 @@ using std::cerr; using std::cout; using std::endl; namespace Ingenuity { -SubpatchModule::SubpatchModule(PatchCanvas* canvas, CountedPtr patch) +SubpatchModule::SubpatchModule(boost::shared_ptr canvas, CountedPtr patch) : NodeModule(canvas, patch), m_patch(patch) { diff --git a/src/progs/ingenuity/SubpatchModule.h b/src/progs/ingenuity/SubpatchModule.h index 571ae0fd..6d5d3e35 100644 --- a/src/progs/ingenuity/SubpatchModule.h +++ b/src/progs/ingenuity/SubpatchModule.h @@ -47,7 +47,7 @@ class NodeControlWindow; class SubpatchModule : public NodeModule { public: - SubpatchModule(PatchCanvas* canvas, CountedPtr controller); + SubpatchModule(boost::shared_ptr canvas, CountedPtr controller); virtual ~SubpatchModule() {} void on_double_click(GdkEventButton* ev); -- cgit v1.2.1