From c449044cd4c8178afca187bab823f580d517b813 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 4 Jul 2006 18:49:56 +0000 Subject: Partial support for loading old patches git-svn-id: http://svn.drobilla.net/lad/ingen@84 a436a847-0d15-0410-975c-d299462d15a1 --- src/common/util/CountedPtr.h | 2 +- src/libs/client/PatchLibrarian.cpp | 1 + src/libs/client/PatchModel.cpp | 2 +- src/libs/engine/NodeFactory.cpp | 127 ++++++++++++++---------------- src/libs/engine/NodeFactory.h | 16 ++-- src/libs/engine/OSCReceiver.cpp | 23 +----- src/libs/engine/Plugin.h | 11 ++- src/libs/engine/QueuedEngineInterface.cpp | 21 ++++- src/libs/engine/QueuedEngineInterface.h | 7 ++ 9 files changed, 107 insertions(+), 103 deletions(-) (limited to 'src') diff --git a/src/common/util/CountedPtr.h b/src/common/util/CountedPtr.h index 6b9847eb..d6cc46bb 100644 --- a/src/common/util/CountedPtr.h +++ b/src/common/util/CountedPtr.h @@ -107,7 +107,7 @@ public: CountedPtr& operator=(const CountedPtr& copy) { if (this != ©) { - assert(_counter != copy._counter); + assert(_counter == NULL || _counter != copy._counter); release(); retain(copy._counter); } diff --git a/src/libs/client/PatchLibrarian.cpp b/src/libs/client/PatchLibrarian.cpp index f80ba90b..add95625 100644 --- a/src/libs/client/PatchLibrarian.cpp +++ b/src/libs/client/PatchLibrarian.cpp @@ -600,6 +600,7 @@ PatchLibrarian::parse_node(const PatchModel* parent, xmlDocPtr doc, const xmlNod PortModel* pm = new PortModel(path, PortModel::CONTROL, PortModel::INPUT, PortModel::NONE, 0.0, user_min, user_max); + pm->set_parent(nm); nm->add_port(pm); // DSSI hacks. Stored in the patch files as special elements, but sent to diff --git a/src/libs/client/PatchModel.cpp b/src/libs/client/PatchModel.cpp index 27f0361a..c6b4c46b 100644 --- a/src/libs/client/PatchModel.cpp +++ b/src/libs/client/PatchModel.cpp @@ -209,7 +209,7 @@ PatchModel::add_connection(CountedPtr cm) void PatchModel::remove_connection(const string& src_port_path, const string& dst_port_path) { - cerr << path() << " PatchModel::remove_connection: " << cm->src_port_path() << " -> " << cm->dst_port_path() << endl; + cerr << path() << " PatchModel::remove_connection: " << src_port_path << " -> " << dst_port_path << endl; for (list >::iterator i = m_connections.begin(); i != m_connections.end(); ++i) { CountedPtr cm = (*i); if (cm->src_port_path() == src_port_path && cm->dst_port_path() == dst_port_path) { diff --git a/src/libs/engine/NodeFactory.cpp b/src/libs/engine/NodeFactory.cpp index db721f8e..3b5d09a9 100644 --- a/src/libs/engine/NodeFactory.cpp +++ b/src/libs/engine/NodeFactory.cpp @@ -65,48 +65,27 @@ namespace Om { NodeFactory::NodeFactory() -: m_has_loaded(false) +: _has_loaded(false) { - pthread_mutex_init(&m_plugin_list_mutex, NULL); + pthread_mutex_init(&_plugin_list_mutex, NULL); - // Add builtin plugin types to m_internal_plugins list + // Add builtin plugin types to _internal_plugins list // FIXME: ewwww, definitely a better way to do this! - //Plugin* pi = NULL; Patch* parent = new Patch("dummy", 1, NULL, 1, 1, 1); Node* n = NULL; -#if 0 - n = new AudioInputNode("foo", 1, parent, 1, 1); - m_internal_plugins.push_back(new Plugin(n->plugin())); - delete n; - n = new AudioOutputNode("foo", 1, parent, 1, 1); - m_internal_plugins.push_back(new Plugin(n->plugin())); - delete n; - n = new ControlInputNode("foo", 1, parent, 1, 1); - m_internal_plugins.push_back(new Plugin(n->plugin())); - delete n; - n = new ControlOutputNode("foo", 1, parent, 1, 1); - m_internal_plugins.push_back(new Plugin(n->plugin())); - delete n; - n = new MidiInputNode("foo", 1, parent, 1, 1); - m_internal_plugins.push_back(new Plugin(n->plugin())); - delete n; - n = new MidiOutputNode("foo", 1, parent, 1, 1); - m_internal_plugins.push_back(new Plugin(n->plugin())); - delete n; -#endif n = new MidiNoteNode("foo", 1, parent, 1, 1); - m_internal_plugins.push_back(new Plugin(n->plugin())); + _internal_plugins.push_back(new Plugin(n->plugin())); delete n; n = new MidiTriggerNode("foo", 1, parent, 1, 1); - m_internal_plugins.push_back(new Plugin(n->plugin())); + _internal_plugins.push_back(new Plugin(n->plugin())); delete n; n = new MidiControlNode("foo", 1, parent, 1, 1); - m_internal_plugins.push_back(new Plugin(n->plugin())); + _internal_plugins.push_back(new Plugin(n->plugin())); delete n; n = new TransportNode("foo", 1, parent, 1, 1); - m_internal_plugins.push_back(new Plugin(n->plugin())); + _internal_plugins.push_back(new Plugin(n->plugin())); delete n; @@ -116,10 +95,10 @@ NodeFactory::NodeFactory() NodeFactory::~NodeFactory() { - for (list::iterator i = m_plugins.begin(); i != m_plugins.end(); ++i) + for (list::iterator i = _plugins.begin(); i != _plugins.end(); ++i) delete (*i); - for (list::iterator i = m_libraries.begin(); i != m_libraries.end(); ++i) { + for (list::iterator i = _libraries.begin(); i != _libraries.end(); ++i) { (*i)->close(); delete (*i); } @@ -132,11 +111,11 @@ NodeFactory::load_plugins() // Only load if we havn't already, so every client connecting doesn't cause // this (expensive!) stuff to happen. Not the best solution - would be nice // if clients could refresh plugins list for whatever reason :/ - if (!m_has_loaded) { - pthread_mutex_lock(&m_plugin_list_mutex); + if (!_has_loaded) { + pthread_mutex_lock(&_plugin_list_mutex); - m_plugins.clear(); - m_plugins = m_internal_plugins; + _plugins.clear(); + _plugins = _internal_plugins; #if HAVE_SLV2 load_lv2_plugins(); @@ -148,9 +127,9 @@ NodeFactory::load_plugins() load_ladspa_plugins(); #endif - m_has_loaded = true; + _has_loaded = true; - pthread_mutex_unlock(&m_plugin_list_mutex); + pthread_mutex_unlock(&_plugin_list_mutex); } } @@ -166,23 +145,31 @@ NodeFactory::load_plugin(const Plugin* a_plugin, const string& name, size_t poly assert(poly == 1 || poly == parent->internal_poly()); assert(a_plugin); - pthread_mutex_lock(&m_plugin_list_mutex); + pthread_mutex_lock(&_plugin_list_mutex); Node* r = NULL; Plugin* plugin = NULL; + // FIXME FIXME FIXME: double lookup + // Attempt to find the plugin in loaded DB if (a_plugin->type() != Plugin::Internal) { - list::iterator i; - if (a_plugin->plug_label().length() == 0) { - for (i = m_plugins.begin(); i != m_plugins.end(); ++i) { - if (a_plugin->uri() == (*i)->uri()) { + + // DEPRECATED: Search by lib name / plug label + if (a_plugin->uri().length() == 0) { + assert(a_plugin->lib_name().length() > 0 && a_plugin->plug_label().length() > 0); + cerr << "Searching for: " << a_plugin->lib_name() << " : " << a_plugin->plug_label() << endl; + for (list::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { + cerr << (*i)->lib_name() << " : " << (*i)->plug_label() << endl; + if (a_plugin->lib_name() == (*i)->lib_name() && a_plugin->plug_label() == (*i)->plug_label()) { plugin = *i; break; } } } else { - for (i = m_plugins.begin(); i != m_plugins.end(); ++i) { + // Search by URI + cerr << "Searching for " << name << " by URI" << endl; + for (list::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { if (a_plugin->uri() == (*i)->uri()) { plugin = *i; break; @@ -190,8 +177,10 @@ NodeFactory::load_plugin(const Plugin* a_plugin, const string& name, size_t poly } } - if (plugin == NULL) + if (plugin == NULL) { + cerr << "DID NOT FIND PLUGIN " << name << endl; return NULL; + } } switch (a_plugin->type()) { @@ -217,7 +206,7 @@ NodeFactory::load_plugin(const Plugin* a_plugin, const string& name, size_t poly cerr << "[NodeFactory] WARNING: Unknown plugin type." << endl; } - pthread_mutex_unlock(&m_plugin_list_mutex); + pthread_mutex_unlock(&_plugin_list_mutex); return r; } @@ -228,14 +217,16 @@ NodeFactory::load_plugin(const Plugin* a_plugin, const string& name, size_t poly Node* NodeFactory::load_internal_plugin(const string& uri, const string& name, size_t poly, Patch* parent) { + return NULL; + cerr << "FIXME: Internal plugin" << endl; +#if 0 assert(parent != NULL); assert(poly == 1 || poly == parent->internal_poly()); assert(uri.length() > 3); assert(uri.substr(0, 3) == "om:"); string plug_label = uri.substr(3); -#if 0 - if (plug_label == "midi_input") { + /*if (plug_label == "midi_input") { MidiInputNode* tn = new MidiInputNode(name, 1, parent, om->audio_driver()->sample_rate(), om->audio_driver()->buffer_size()); return tn; } else if (plug_label == "midi_output") { @@ -258,7 +249,7 @@ NodeFactory::load_internal_plugin(const string& uri, const string& name, size_t om->audio_driver()->sample_rate(), om->audio_driver()->buffer_size()); return on; } else -#endif + */ if (plug_label == "note_in" || plug_label == "midi_note_in") { MidiNoteNode* mn = new MidiNoteNode(name, poly, parent, om->audio_driver()->sample_rate(), om->audio_driver()->buffer_size()); return mn; @@ -276,6 +267,7 @@ NodeFactory::load_internal_plugin(const string& uri, const string& name, size_t } return NULL; +#endif } @@ -302,7 +294,7 @@ NodeFactory::load_lv2_plugins() //cerr << "LV2 plugin: " << uri << endl; bool found = false; - for (list::const_iterator i = m_plugins.begin(); i != m_plugins.end(); ++i) { + for (list::const_iterator i = _plugins.begin(); i != _plugins.end(); ++i) { if (!strcmp((*i)->uri().c_str(), uri)) { cerr << "Warning: Duplicate LV2 plugin (" << uri << ").\nUsing " << (*i)->lib_path() << " version." << endl; @@ -312,19 +304,17 @@ NodeFactory::load_lv2_plugins() } if (!found) { //printf("[NodeFactory] Found LV2 plugin %s\n", uri); - Plugin* om_plug = new Plugin(); - om_plug->type(Plugin::LV2); + Plugin* om_plug = new Plugin(Plugin::LV2, uri); om_plug->slv2_plugin(lv2_plug); - om_plug->uri(uri); // FIXME FIXME FIXME temporary hack om_plug->library(NULL); - om_plug->lib_path("FIXMEpath"); + om_plug->lib_path("FIXME/Some/path"); om_plug->plug_label("FIXMElabel"); unsigned char* name = slv2_plugin_get_name(lv2_plug); om_plug->name((char*)name); free(name); om_plug->type(Plugin::LV2); - m_plugins.push_back(om_plug); + _plugins.push_back(om_plug); } } @@ -344,7 +334,7 @@ NodeFactory::load_lv2_plugin(const string& plug_uri, // Find (Om) Plugin Plugin* plugin = NULL; list::iterator i; - for (i = m_plugins.begin(); i != m_plugins.end(); ++i) { + for (i = _plugins.begin(); i != _plugins.end(); ++i) { plugin = (*i); if ((*i)->uri() == plug_uri) break; } @@ -428,14 +418,15 @@ NodeFactory::load_dssi_plugins() } PluginLibrary* plugin_library = new PluginLibrary(full_lib_name); - m_libraries.push_back(plugin_library); + _libraries.push_back(plugin_library); const LADSPA_Descriptor* ld = NULL; for (unsigned long i=0; (descriptor = (DSSI_Descriptor*)df(i)) != NULL; ++i) { ld = descriptor->LADSPA_Plugin; assert(ld != NULL); - Plugin* plugin = new Plugin(); + string uri = string("dssi:") + pfile->d_name +":"+ ld->Label; + Plugin* plugin = new Plugin(Plugin::DSSI, uri); assert(plugin_library != NULL); plugin->library(plugin_library); plugin->lib_path(dir + "/" + pfile->d_name); @@ -445,7 +436,7 @@ NodeFactory::load_dssi_plugins() plugin->id(ld->UniqueID); bool found = false; - for (list::const_iterator i = m_plugins.begin(); i != m_plugins.end(); ++i) { + for (list::const_iterator i = _plugins.begin(); i != _plugins.end(); ++i) { if ((*i)->uri() == plugin->uri()) { cerr << "Warning: Duplicate DSSI plugin (" << plugin->lib_name() << ":" << plugin->plug_label() << ")" << " found.\nUsing " << (*i)->lib_path() @@ -455,7 +446,7 @@ NodeFactory::load_dssi_plugins() } } if (!found) - m_plugins.push_back(plugin); + _plugins.push_back(plugin); else delete plugin; } @@ -488,14 +479,14 @@ NodeFactory::load_dssi_plugin(const string& uri, // Attempt to find the lib list::iterator i; - for (i = m_plugins.begin(); i != m_plugins.end(); ++i) { + for (i = _plugins.begin(); i != _plugins.end(); ++i) { plugin = (*i); if (plugin->uri() == uri) break; } assert(plugin->id() != 0); - if (i == m_plugins.end()) { + if (i == _plugins.end()) { cerr << "Did not find DSSI plugin " << uri << " in database." << endl; return NULL; } else { @@ -597,10 +588,14 @@ NodeFactory::load_ladspa_plugins() } PluginLibrary* plugin_library = new PluginLibrary(full_lib_name); - m_libraries.push_back(plugin_library); + _libraries.push_back(plugin_library); for (unsigned long i=0; (descriptor = (LADSPA_Descriptor*)df(i)) != NULL; ++i) { - Plugin* plugin = new Plugin(); + char id_str[11]; + snprintf(id_str, 11, "%lu", descriptor->UniqueID); + string uri = string("ladspa:").append(id_str); + Plugin* plugin = new Plugin(Plugin::LADSPA, uri); + assert(plugin_library != NULL); plugin->library(plugin_library); plugin->lib_path(dir + "/" + pfile->d_name); @@ -610,7 +605,7 @@ NodeFactory::load_ladspa_plugins() plugin->id(descriptor->UniqueID); bool found = false; - for (list::const_iterator i = m_plugins.begin(); i != m_plugins.end(); ++i) { + for (list::const_iterator i = _plugins.begin(); i != _plugins.end(); ++i) { if ((*i)->uri() == plugin->uri()) { cerr << "Warning: Duplicate LADSPA plugin " << plugin->uri() << " found.\nChoosing " << (*i)->lib_path() @@ -620,7 +615,7 @@ NodeFactory::load_ladspa_plugins() } } if (!found) - m_plugins.push_back(plugin); + _plugins.push_back(plugin); else delete plugin; } @@ -652,14 +647,14 @@ NodeFactory::load_ladspa_plugin(const string& uri, // Attempt to find the lib list::iterator i; - for (i = m_plugins.begin(); i != m_plugins.end(); ++i) { + for (i = _plugins.begin(); i != _plugins.end(); ++i) { plugin = (*i); if (plugin->uri() == uri) break; } assert(plugin->id() != 0); - if (i == m_plugins.end()) { + if (i == _plugins.end()) { cerr << "Did not find LADSPA plugin " << uri << " in database." << endl; return NULL; } else { diff --git a/src/libs/engine/NodeFactory.h b/src/libs/engine/NodeFactory.h index 9f29644d..e183bab5 100644 --- a/src/libs/engine/NodeFactory.h +++ b/src/libs/engine/NodeFactory.h @@ -53,10 +53,10 @@ public: void load_plugins(); Node* load_plugin(const Plugin* info, const string& name, size_t poly, Patch* parent); - const list& plugins() { return m_plugins; } + const list& plugins() { return _plugins; } - void lock_plugin_list() { pthread_mutex_lock(&m_plugin_list_mutex); } - void unlock_plugin_list() { pthread_mutex_unlock(&m_plugin_list_mutex); } + void lock_plugin_list() { pthread_mutex_lock(&_plugin_list_mutex); } + void unlock_plugin_list() { pthread_mutex_unlock(&_plugin_list_mutex); } private: #ifdef HAVE_LADSPA @@ -76,14 +76,14 @@ private: Node* load_internal_plugin(const string& plug_label, const string& name, size_t poly, Patch* parent); - list m_libraries; - list m_internal_plugins; - list m_plugins; + list _libraries; + list _internal_plugins; + list _plugins; /** Used to protect the list while load_plugins is building it. */ - pthread_mutex_t m_plugin_list_mutex; + pthread_mutex_t _plugin_list_mutex; - bool m_has_loaded; + bool _has_loaded; }; diff --git a/src/libs/engine/OSCReceiver.cpp b/src/libs/engine/OSCReceiver.cpp index eb9db6e7..206cd3da 100644 --- a/src/libs/engine/OSCReceiver.cpp +++ b/src/libs/engine/OSCReceiver.cpp @@ -30,7 +30,6 @@ #include "OSCClient.h" #include "OSCResponder.h" #include "ClientBroadcaster.h" -#include "Plugin.h" using std::cerr; using std::cout; using std::endl; @@ -514,39 +513,21 @@ OSCReceiver::m_create_node_by_uri_cb(const char* path, const char* types, lo_arg * \arg \b poly (integer-boolean) - Whether node is polyphonic (0 = false, 1 = true) * * \li This is only here to provide backwards compatibility for old patches that store LADSPA plugin - * references as libname, label. It is to be removed, don't use it. + * references as libname, label. It is to be removed ASAP, don't use it. *

\n \n */ int OSCReceiver::m_create_node_cb(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg) { - /* - const char* node_path = &argv[1]->s; const char* type = &argv[2]->s; const char* lib_name = &argv[3]->s; const char* plug_label = &argv[4]->s; const int poly = argv[5]->i; - */ - cerr << "LOAD NODE BY LIB LABEL\n"; - return 0; - #if 0 - // FIXME Event-ize - Plugin* plugin = new Plugin(); - plugin->set_type(type); - plugin->lib_name(lib_name); - plugin->plug_label(plug_label); - - if (poly != 0 && poly != 1) { - OSCResponder(addr).respond_error("Invalid poly parameter in create_node"); - return 0; - } - - add_node(node_path, plugin, (poly == 1)); + create_node(node_path, type, lib_name, plug_label, (poly == 1)); return 0; - #endif } diff --git a/src/libs/engine/Plugin.h b/src/libs/engine/Plugin.h index 65b65735..a5b70b22 100644 --- a/src/libs/engine/Plugin.h +++ b/src/libs/engine/Plugin.h @@ -76,8 +76,9 @@ public: Type type() const { return m_type; } void type(Type t) { m_type = t; } const string& lib_path() const { return m_lib_path; } - void lib_path(const string& s) { m_lib_path = s; } - string lib_name() const { return m_lib_path.substr(m_lib_path.find_last_of("/")); } + void lib_path(const string& s) { m_lib_path = s; m_lib_name = m_lib_path.substr(m_lib_path.find_last_of("/")+1); } + string lib_name() const { return m_lib_name; } + void lib_name(const string& s) { m_lib_name = s; } const string& plug_label() const { return m_plug_label; } void plug_label(const string& s) { m_plug_label = s; } const string& name() const { return m_name; } @@ -87,7 +88,7 @@ public: void uri(const string& s) { m_uri = s; } const string uri() const { - char id_str[11]; + /* char id_str[11]; snprintf(id_str, 11, "%lu", m_id); if (m_uri.length() > 0) { @@ -100,7 +101,8 @@ public: return string("dssi:") + lib_name() +":"+ m_plug_label; } else { return ""; - } + }*/ + return m_uri; } PluginLibrary* library() const { return m_library; } @@ -137,6 +139,7 @@ private: Type m_type; string m_uri; ///< LV2 only string m_lib_path; ///< LADSPA/DSSI only + string m_lib_name; ///< LADSPA/DSSI only string m_plug_label; ///< LADSPA/DSSI only string m_name; ///< LADSPA/DSSI only unsigned long m_id; ///< LADSPA/DSSI only diff --git a/src/libs/engine/QueuedEngineInterface.cpp b/src/libs/engine/QueuedEngineInterface.cpp index b2b02112..0546b8a2 100644 --- a/src/libs/engine/QueuedEngineInterface.cpp +++ b/src/libs/engine/QueuedEngineInterface.cpp @@ -140,12 +140,29 @@ QueuedEngineInterface::create_node(const string& path, plugin->set_type(plugin_type); plugin->uri(plugin_uri); - AddNodeEvent* ev = new AddNodeEvent(_responder, - path, plugin, polyphonic); + AddNodeEvent* ev = new AddNodeEvent(_responder, path, plugin, polyphonic); push(ev); } +void +QueuedEngineInterface::create_node(const string& path, + const string& plugin_type, + const string& plugin_lib, + const string& plugin_label, + bool polyphonic) +{ + // FIXME: ew + + Plugin* plugin = new Plugin(); + plugin->set_type(plugin_type); + plugin->lib_name(plugin_lib); + plugin->plug_label(plugin_label); + + AddNodeEvent* ev = new AddNodeEvent(_responder, path, plugin, polyphonic); + push(ev); +} + void QueuedEngineInterface::rename(const string& old_path, const string& new_name) diff --git a/src/libs/engine/QueuedEngineInterface.h b/src/libs/engine/QueuedEngineInterface.h index 12e5540f..12afcb65 100644 --- a/src/libs/engine/QueuedEngineInterface.h +++ b/src/libs/engine/QueuedEngineInterface.h @@ -86,6 +86,13 @@ public: const string& plugin_type, const string& plugin_uri, bool polyphonic); + + /** FIXME: DEPRECATED, REMOVE */ + virtual void create_node(const string& path, + const string& plugin_type, + const string& lib_path, + const string& plug_label, + bool polyphonic); virtual void rename(const string& old_path, const string& new_name); -- cgit v1.2.1