From d82dcd232f201b531a0be165ee44aede1bc8a1df Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 19 Sep 2006 18:11:19 +0000 Subject: Alsa MIDI fixes. git-svn-id: http://svn.drobilla.net/lad/ingen@144 a436a847-0d15-0410-975c-d299462d15a1 --- src/progs/demolition/DemolitionClientInterface.cpp | 109 --------- src/progs/demolition/DemolitionClientInterface.h | 79 ------- src/progs/demolition/DemolitionModel.cpp | 246 --------------------- src/progs/demolition/DemolitionModel.h | 59 ----- src/progs/demolition/Makefile.am | 4 - src/progs/demolition/demolition.cpp | 166 ++++++++------ 6 files changed, 98 insertions(+), 565 deletions(-) delete mode 100644 src/progs/demolition/DemolitionClientInterface.cpp delete mode 100644 src/progs/demolition/DemolitionClientInterface.h delete mode 100644 src/progs/demolition/DemolitionModel.cpp delete mode 100644 src/progs/demolition/DemolitionModel.h (limited to 'src/progs/demolition') diff --git a/src/progs/demolition/DemolitionClientInterface.cpp b/src/progs/demolition/DemolitionClientInterface.cpp deleted file mode 100644 index 23f5733f..00000000 --- a/src/progs/demolition/DemolitionClientInterface.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* This file is part of Ingen. Copyright (C) 2006 Dave Robillard. - * - * Ingen is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "DemolitionClientInterface.h" -#include "DemolitionModel.h" - - -DemolitionClientInterface::DemolitionClientInterface(DemolitionModel* model) -: m_model(model) -{ -} - - -DemolitionClientInterface::~DemolitionClientInterface() -{ -} - - -void -DemolitionClientInterface::error(string msg) -{ -} - - -void -DemolitionClientInterface::new_patch_model(CountedPtr pm) -{ - m_model->add_patch(pm); -} - - -void -DemolitionClientInterface::new_port_model(PortModel* port_model) -{ - m_model->add_port(port_model); -} - - -void -DemolitionClientInterface::object_destroyed(string path) -{ - m_model->remove_object(path); -} - -void -DemolitionClientInterface::patch_enabled(string path) -{ -} - - -void -DemolitionClientInterface::patch_disabled(string path) -{ -} - - -void -DemolitionClientInterface::new_node_model(CountedPtr nm) -{ - m_model->add_node(nm); -} - - -void -DemolitionClientInterface::object_renamed(string old_path, string new_path) -{ - m_model->object_renamed(old_path, new_path); -} - - -void -DemolitionClientInterface::connection_model(ConnectionModel* cm) -{ - m_model->add_connection(cm); -} - - -void -DemolitionClientInterface::disconnection(string src_port_path, string dst_port_path) -{ - m_model->remove_connection(src_port_path, dst_port_path); -} - - -void -DemolitionClientInterface::control_change(string port_path, float value) -{ -} - - -void -DemolitionClientInterface::new_plugin_model(PluginModel* pi) -{ - m_model->add_plugin(pi); -} - diff --git a/src/progs/demolition/DemolitionClientInterface.h b/src/progs/demolition/DemolitionClientInterface.h deleted file mode 100644 index 809857cf..00000000 --- a/src/progs/demolition/DemolitionClientInterface.h +++ /dev/null @@ -1,79 +0,0 @@ -/* This file is part of Ingen. Copyright (C) 2006 Dave Robillard. - * - * Ingen is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef DEMOLITIONCLIENTHOOKS_H -#define DEMOLITIONCLIENTHOOKS_H - -#include -#include -#include "ModelClientInterface.h" -#include "DemolitionModel.h" -#include "PluginModel.h" -using std::string; - -using namespace Ingen::Client; - - -/** ModelClientInterface implementation for the Gtk client. - * - * These are the hooks into the GUI for the Comm class. - * - * \ingroup OmGtk - */ -class DemolitionClientInterface : public ModelClientInterface -{ -public: - DemolitionClientInterface(DemolitionModel* model); - virtual ~DemolitionClientInterface(); - - void bundle_begin() {} - void bundle_end() {} - - void transfer_begin() {} - void transfer_end() {} - - void num_plugins(uint32_t num) {} - - void response(int32_t id, bool success, string msg) {} - - // OSC thread functions - void error(string msg); - - void new_plugin(string type, - string uri, - string name) {} - void new_patch_model(CountedPtr pm); - void new_port_model(CountedPtr port_model); - void object_destroyed(string path); - void patch_enabled(string path); - void patch_disabled(string path); - void patch_cleared(string path) { throw; } - void new_node_model(CountedPtr nm); - void object_renamed(string old_path, string new_path); - void connection_model(CountedPtr cm); - void disconnection(string src_port_path, string dst_port_path); - void metadata_update(string path, string key, string value) {} - void control_change(string port_path, float value); - void new_plugin_model(CountedPtr pi); - void program_add(string path, uint32_t bank, uint32_t program, string name) {}; - void program_remove(string path, uint32_t bank, uint32_t program) {}; - -private: - DemolitionModel* m_model; -}; - - -#endif // DEMOLITIONCLIENTHOOKS_H diff --git a/src/progs/demolition/DemolitionModel.cpp b/src/progs/demolition/DemolitionModel.cpp deleted file mode 100644 index 8ac10195..00000000 --- a/src/progs/demolition/DemolitionModel.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/* This file is part of Ingen. Copyright (C) 2006 Dave Robillard. - * - * Ingen is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "DemolitionModel.h" -#include "util/Path.h" -#include "PluginModel.h" -#include -#include -using std::cout; using std::cerr; using std::endl; - - -DemolitionModel::~DemolitionModel() -{ - for (vector::iterator i = m_plugins.begin(); i != m_plugins.end(); ++i) - delete *i; - - for (vector::iterator i = m_patches.begin(); i != m_patches.end(); ++i) - delete *i; -} - - -PatchModel* -DemolitionModel::random_patch() -{ - if (m_patches.size() == 0) - return NULL; - else - return m_patches.at(rand() % m_patches.size()); -} - - -NodeModel* -DemolitionModel::random_node() -{ - int max_attempts = m_patches.size()*4; - int attempts = 0; - - while (attempts++ < max_attempts) { - PatchModel* pm = random_patch(); - - if (pm == NULL) { - return NULL; - } else { - int size = pm->nodes().size(); - if (size == 0) - continue; - int index = rand() % size; - NodeModelMap::const_iterator i = pm->nodes().begin(); - for (int j=0; j < index; ++j) { - ++i; - if (i == pm->nodes().end()) - return NULL; - } - return (*i).second.get(); - } - } - //cout << "***************************** Not returning node *********" << endl; - return NULL; -} - - -NodeModel* -DemolitionModel::random_node_in_patch(PatchModel* pm) -{ - if (pm == NULL) - return NULL; - - int size = pm->nodes().size(); - if (size == 0) - return NULL; - - int index = rand() % size; - NodeModelMap::const_iterator i = pm->nodes().begin(); - for (int j=0; j < index; ++j) { - ++i; - if (i == pm->nodes().end()) - return NULL; - } - return (*i).second.get(); -} - - -PortModel* -DemolitionModel::random_port() -{ - NodeModel* node = random_node(); - - if (node == NULL) return NULL; - - PortModelList ports = node->ports(); - - int num_ports = ports.size(); - int index = rand() % num_ports; - int i = 0; - - for (PortModelList::iterator p = ports.begin(); p != ports.end(); ++p, ++i) - if (i == index) - return (*p).get(); - - return NULL; // shouldn't happen -} - - -PortModel* -DemolitionModel::random_port_in_node(NodeModel* node) -{ - if (node == NULL) - return NULL; - - PortModelList ports = node->ports(); - - int num_ports = ports.size(); - int index = rand() % num_ports; - int i = 0; - - for (PortModelList::iterator p = ports.begin(); p != ports.end(); ++p, ++i) - if (i == index) - return (*p).get(); - - return NULL; // shouldn't happen -} - - -PluginModel* -DemolitionModel::random_plugin() -{ - if (m_plugins.size() == 0) - return NULL; - else - return m_plugins.at(rand() % m_plugins.size()); -} - - -PatchModel* -DemolitionModel::patch(const Path& path) -{ - for (vector::iterator i = m_patches.begin(); i != m_patches.end(); ++i) { - if ((*i)->path() == path) - return (*i); - } - return NULL; -} - - -NodeModel* -DemolitionModel::node(const Path& path) -{ - NodeModel* ret = NULL; - - for (vector::iterator i = m_patches.begin(); i != m_patches.end(); ++i) { - ret = (*i)->get_node(path.name()).get(); - if (ret != NULL) - break; - } - return ret; -} - - -void -DemolitionModel::remove_object(const Path& path) -{ - // Patch - for (vector::iterator i = m_patches.begin(); i != m_patches.end(); ++i) { - if ((*i)->path() == path) { - delete (*i); - m_patches.erase(i); - break; - } - } - - // Node - PatchModel* parent = patch(path.parent()); - if (parent != NULL) - parent->remove_node(path.name()); -} - - -void -DemolitionModel::add_node(CountedPtr nm) -{ - PatchModel* parent = patch(nm->path().parent()); - if (parent == NULL) { - cout << "**** ERROR: Parent for new Node does not exist." << endl; - } else { - parent->add_node(nm); - } -} - - -void -DemolitionModel::add_port(PortModel* pm) -{ -} - - -void -DemolitionModel::add_connection(ConnectionModel* cm) -{ -} - - -void -DemolitionModel::remove_connection(const Path& src_port_path, const Path& dst_port_path) -{ -} - -void -DemolitionModel::object_renamed(const Path& old_path, const Path& new_path) -{ - /* FIXME: broken, does not rename children - assert(Path::parent(old_path) == Path::parent(new_path)); - - // Rename node - NodeModel* nm = get_node(old_path); - if (nm != NULL) { - if (nm->parent() != NULL) { - nm->parent()->remove_node(Path::name(old_path)); - nm->path(new_path); - nm->parent()->add_node(Path::name(new_path)); - } - } - - // Rename patch - for (vector::iterator i = m_patches.begin(); i != m_patches.end(); ++i) { - if ((*i)->path() == path) { - delete (*i); - m_patches.erase(i); - return; - } - } - */ -} - diff --git a/src/progs/demolition/DemolitionModel.h b/src/progs/demolition/DemolitionModel.h deleted file mode 100644 index 6ae8c0ec..00000000 --- a/src/progs/demolition/DemolitionModel.h +++ /dev/null @@ -1,59 +0,0 @@ -/* This file is part of Ingen. Copyright (C) 2006 Dave Robillard. - * - * Ingen is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef DEMOLITIONMODEL_H -#define DEMOLITIONMODEL_H - -#include -#include "PatchModel.h" -#include "util/Path.h" -using std::vector; - -using namespace Ingen::Client; - -class DemolitionModel { -public: - ~DemolitionModel(); - - PatchModel* random_patch(); - NodeModel* random_node(); - NodeModel* random_node_in_patch(PatchModel* patch); - PortModel* random_port(); - PortModel* random_port_in_node(NodeModel* node); - PluginModel* random_plugin(); - - PatchModel* patch(const Path& path); - NodeModel* node(const Path& path); - - void add_patch(PatchModel* pm) { m_patches.push_back(pm); } - void add_node(CountedPtr nm); - void add_port(PortModel* pm); - void remove_object(const Path& path); - void add_connection(ConnectionModel* cm); - void remove_connection(const Path& src_port_path, const Path& dst_port_path); - void add_plugin(PluginModel* pi) { m_plugins.push_back(pi); } - - void object_renamed(const Path& old_path, const Path& new_path); - - int num_patches() { return m_patches.size(); } - -private: - vector m_plugins; - vector m_patches; -}; - - -#endif // DEMOLITIONMODEL_H diff --git a/src/progs/demolition/Makefile.am b/src/progs/demolition/Makefile.am index 07caff5b..b01b062b 100644 --- a/src/progs/demolition/Makefile.am +++ b/src/progs/demolition/Makefile.am @@ -8,10 +8,6 @@ bin_PROGRAMS = om_demolition om_demolition_DEPENDENCIES = ../../libs/client/libomclient.la om_demolition_SOURCES = \ - DemolitionClientInterface.h \ - DemolitionClientInterface.cpp \ - DemolitionModel.h \ - DemolitionModel.cpp \ demolition.cpp \ cmdline.h \ cmdline.c diff --git a/src/progs/demolition/demolition.cpp b/src/progs/demolition/demolition.cpp index 27da5dd9..3015200e 100644 --- a/src/progs/demolition/demolition.cpp +++ b/src/progs/demolition/demolition.cpp @@ -17,8 +17,11 @@ #include "interface/ClientInterface.h" #include "interface/ClientKey.h" #include "OSCModelEngineInterface.h" +#include "OSCClientReceiver.h" +#include "SigClientInterface.h" +#include "Store.h" #include "PatchLibrarian.h" -#include "DemolitionClientInterface.h" +#include "PluginModel.h" #include "util/CountedPtr.h" #include #include @@ -46,9 +49,21 @@ void rename_object(); // Yay globals! -DemolitionModel* model; -OSCModelEngineInterface* engine; - +CountedPtr engine; +CountedPtr store; + + +// OSC listening non-threaded signal emitter +struct OSCSigEmitter : public OSCClientReceiver, public SigClientInterface { +public: + OSCSigEmitter(int listen_port) + : Ingen::Shared::ClientInterface() + , OSCClientReceiver(listen_port) + , SigClientInterface() + { + } +}; + int main(int argc, char** argv) @@ -73,18 +88,16 @@ main(int argc, char** argv) else client_port = 0; // will choose a free port automatically - model = new DemolitionModel(); + engine = CountedPtr(new OSCModelEngineInterface(engine_url)); + CountedPtr emitter(new OSCSigEmitter(16182)); - // Create this first so engine interface (liblo) uses the port - CountedPtr client - = CountedPtr(new DemolitionClientInterface(model)); - - engine = new OSCModelEngineInterface(engine_url); + store = CountedPtr(new Store(engine, emitter)); + engine->activate(); /* Connect to engine */ //engine->attach(engine_url); - engine->register_client(ClientKey(), (CountedPtr)client); + engine->register_client(ClientKey(), emitter); engine->load_plugins(); engine->request_plugins(); @@ -106,9 +119,6 @@ main(int argc, char** argv) engine->unregister_client(ClientKey()); //engine->detach(); - delete engine; - delete model; - return 0; } @@ -157,36 +167,70 @@ random_name() } +Path +random_object() +{ + typedef map > ObjectMap; + + const ObjectMap& objects = store->objects(); + + // Return a crap path every once in a while + if (rand() % 30) + return "/DEAD/BEEF"; + + // "random" is a bit of a generous label... + for (ObjectMap::const_iterator i = objects.begin(); i != objects.end(); ++i) + if (rand() % objects.size()) + return i->second->path(); + + return "/"; +} + + +string +random_plugin() +{ + typedef map > PluginMap; + + const PluginMap& plugins = store->plugins(); + + // Return a crap path every once in a while + if (rand() % 30) + return "DEAD:BEEF"; + + // "random" is a bit of a generous label... + for (PluginMap::const_iterator i = plugins.begin(); i != plugins.end(); ++i) + if (rand() % plugins.size()) + return i->second->uri(); + + return "DEAD:BEEF2"; +} + + void create_patch() { // Make the probability of this happening inversely proportionate to the number - // of patches to keep the # in a sane range - //if (model->num_patches() > 0 && (rand() % model->num_patches())) - // return; + // of objects to keep the # in a sane range + if (store->objects().size() > 0 && (rand() % store->objects().size())) + return; bool subpatch = rand()%2; - PatchModel* parent = NULL; + Path parent = "/"; string name = random_name(); - PatchModel* pm = NULL; if (subpatch) - parent = model->random_patch(); + parent = random_object(); // very likely invalid parent error - if (parent != NULL) - pm = new PatchModel(parent->path() +"/"+ name, (rand()%8)+1); - else - pm = new PatchModel(string("/") + name, (rand()%8)+1); + const Path path = parent.base() + name; - cout << "Creating patch " << pm->path() << endl; + cout << "Creating patch " << path << endl; - engine->create_patch_from_model(pm); + engine->create_patch(path, (rand()%8)+1); // Spread them out a bit for easier monitoring with ingenuity - engine->set_metadata(pm->path(), "module-x", 1600 + rand()%800 - 400); - engine->set_metadata(pm->path(), "module-y", 1200 + rand()%700 - 350); - - delete pm; + engine->set_metadata(path, "module-x", 1600 + rand()%800 - 400); + engine->set_metadata(path, "module-y", 1200 + rand()%700 - 350); } @@ -195,38 +239,24 @@ destroy() { // Make the probability of this happening proportionate to the number // of patches to keep the # in a sane range - if (model->num_patches() == 0 || !(rand() % model->num_patches())) + if (store->objects().size() > 0 && !(rand() % store->objects().size())) return; - NodeModel* nm = NULL; - - if (rand()%2) - nm = model->random_patch(); - else - nm = model->random_node(); - - if (nm != NULL) { - cout << "Destroying " << nm->path() << endl; - engine->destroy(nm->path()); - } + engine->destroy(random_object()); } void add_node() { - PatchModel* parent = model->random_patch(); - PluginModel* plugin = model->random_plugin(); - - if (parent != NULL && plugin != NULL) { - NodeModel* nm = new NodeModel(plugin, parent->path() +"/"+ random_name()); - cout << "Adding node " << nm->path() << endl; - engine->create_node_from_model(nm); - - // Spread them out a bit for easier monitoring with ingenuity - engine->set_metadata(pm->path(), "module-x", 1600 + rand()%800 - 400); - engine->set_metadata(pm->path(), "module-y", 1200 + rand()%700 - 350); - } + const Path path = random_object().base() + random_name(); + + cout << "Adding node " << path << endl; + engine->create_node(path, random_plugin(), rand()%2); + + // Spread them out a bit for easier monitoring with ingenuity + engine->set_metadata(path, "module-x", 1600 + rand()%800 - 400); + engine->set_metadata(path, "module-y", 1200 + rand()%700 - 350); } @@ -234,11 +264,11 @@ void connect() { if (!(rand() % 10)) { // Attempt a connection between two nodes in the same patch - PatchModel* parent = model->random_patch(); - NodeModel* n1 = model->random_node_in_patch(parent); - NodeModel* n2 = model->random_node_in_patch(parent); - PortModel* p1 = model->random_port_in_node(n1); - PortModel* p2 = model->random_port_in_node(n2); + PatchModel* parent = store->random_patch(); + NodeModel* n1 = store->random_node_in_patch(parent); + NodeModel* n2 = store->random_node_in_patch(parent); + PortModel* p1 = store->random_port_in_node(n1); + PortModel* p2 = store->random_port_in_node(n2); if (p1 != NULL && p2 != NULL) { cout << "Connecting " << p1->path() << " -> " << p2->path() << endl; @@ -246,8 +276,8 @@ connect() } } else { // Attempt a connection between two truly random nodes - PortModel* p1 = model->random_port(); - PortModel* p2 = model->random_port(); + PortModel* p1 = store->random_port(); + PortModel* p2 = store->random_port(); if (p1 != NULL && p2 != NULL) { cout << "Connecting " << p1->path() << " -> " << p2->path() << endl; @@ -260,8 +290,8 @@ connect() void disconnect() { - PortModel* p1 = model->random_port(); - PortModel* p2 = model->random_port(); + PortModel* p1 = store->random_port(); + PortModel* p2 = store->random_port(); if (p1 != NULL && p2 != NULL) { cout << "Disconnecting " << p1->path() << " -> " << p2->path() << endl; @@ -273,7 +303,7 @@ disconnect() void disconnect_all() { - PortModel* p = model->random_port(); + PortModel* p = store->random_port(); if (p != NULL) { cout << "Disconnecting all from" << p->path() << endl; @@ -285,7 +315,7 @@ disconnect_all() void set_port_value() { - PortModel* pm = model->random_port(); + PortModel* pm = store->random_port(); float val = (float)rand() / (float)RAND_MAX; if (pm != NULL) { @@ -298,7 +328,7 @@ set_port_value() void set_port_value_queued() { - PortModel* pm = model->random_port(); + PortModel* pm = store->random_port(); float val = (float)rand() / (float)RAND_MAX; if (pm != NULL) { @@ -315,11 +345,11 @@ rename_object() /*int type = rand()%6; if (type == 0) { - NodeModel* n = model->random_node(); + NodeModel* n = store->random_node(); if (n != NULL) engine->rename(n->path(), random_name()); } else { - PatchModel* p = model->random_patch(); + PatchModel* p = store->random_patch(); if (p != NULL) engine->rename(p->path(), random_name()); }*/ -- cgit v1.2.1