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/common/util/Atom.h | 2 +- src/libs/client/SigClientInterface.h | 63 ++++++ src/libs/client/Store.cpp | 72 +++--- src/libs/client/Store.h | 17 +- src/libs/engine/AlsaMidiDriver.cpp | 7 +- src/libs/engine/AlsaMidiDriver.h | 6 +- src/libs/engine/Engine.cpp | 2 +- src/progs/Makefile.am | 2 +- 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 ++++++++------ src/progs/ingenuity/ConnectWindow.cpp | 13 +- 15 files changed, 224 insertions(+), 623 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') diff --git a/src/common/util/Atom.h b/src/common/util/Atom.h index 6cb001e1..f28b9339 100644 --- a/src/common/util/Atom.h +++ b/src/common/util/Atom.h @@ -17,9 +17,9 @@ #ifndef ATOM_H #define ATOM_H +#include #include #include -#include /** An OSC atom (fundamental data types OSC messages are composed of). diff --git a/src/libs/client/SigClientInterface.h b/src/libs/client/SigClientInterface.h index 1f24ad40..4639bdc7 100644 --- a/src/libs/client/SigClientInterface.h +++ b/src/libs/client/SigClientInterface.h @@ -63,6 +63,69 @@ public: sigc::signal program_add_sig; sigc::signal program_remove_sig; +protected: + + // ClientInterface hooks that fire the above signals + + void bundle_begin() {} + void bundle_end() {} + + void transfer_begin() {} + void transfer_end() {} + + void num_plugins(uint32_t num) { num_plugins_sig.emit(num); } + + void response(int32_t id, bool success, string msg) + { response_sig.emit(id, success, msg); } + + void error(string msg) + { error_sig.emit(msg); } + + void new_plugin(string uri, string name) + { new_plugin_sig.emit(uri, name); } + + void new_patch(string path, uint32_t poly) + { new_patch_sig.emit(path, poly); } + + void new_node(string plugin_uri, string node_path, bool is_polyphonic, uint32_t num_ports) + { new_node_sig.emit(plugin_uri, node_path, is_polyphonic, num_ports); } + + void new_port(string path, string data_type, bool is_output) + { new_port_sig.emit(path, data_type, is_output); } + + void connection(string src_port_path, string dst_port_path) + { connection_sig.emit(src_port_path, dst_port_path); } + + void object_destroyed(string path) + { object_destroyed_sig.emit(path); } + + void patch_enabled(string path) + { patch_enabled_sig.emit(path); } + + void patch_disabled(string path) + { patch_disabled_sig.emit(path); } + + void patch_cleared(string path) + { patch_cleared_sig.emit(path); } + + void object_renamed(string old_path, string new_path) + { object_renamed_sig.emit(old_path, new_path); } + + void disconnection(string src_port_path, string dst_port_path) + { disconnection_sig.emit(src_port_path, dst_port_path); } + + void metadata_update(string path, string key, Atom value) + { metadata_update_sig.emit(path, key, value); } + + void control_change(string port_path, float value) + { control_change_sig.emit(port_path, value); } + + void program_add(string path, uint32_t bank, uint32_t program, string name) + { program_add_sig.emit(path, bank, program, name); } + + void program_remove(string path, uint32_t bank, uint32_t program) + { program_remove_sig.emit(path, bank, program); } + protected: SigClientInterface() {} }; diff --git a/src/libs/client/Store.cpp b/src/libs/client/Store.cpp index 3b7e9768..f9b3f17a 100644 --- a/src/libs/client/Store.cpp +++ b/src/libs/client/Store.cpp @@ -50,8 +50,8 @@ Store::Store(CountedPtr engine, CountedPtr void Store::clear() { - m_objects.clear(); - m_plugins.clear(); + _objects.clear(); + _plugins.clear(); } @@ -63,16 +63,16 @@ Store::add_plugin_orphan(CountedPtr node) << node->plugin_uri() << " unknown." << endl; map > >::iterator spawn - = m_plugin_orphans.find(node->plugin_uri()); + = _plugin_orphans.find(node->plugin_uri()); _engine->request_plugin(node->plugin_uri()); - if (spawn != m_plugin_orphans.end()) { + if (spawn != _plugin_orphans.end()) { spawn->second.push_back(node); } else { list > l; l.push_back(node); - m_plugin_orphans[node->plugin_uri()] = l; + _plugin_orphans[node->plugin_uri()] = l; } } @@ -81,13 +81,13 @@ void Store::resolve_plugin_orphans(CountedPtr plugin) { map > >::iterator n - = m_plugin_orphans.find(plugin->uri()); + = _plugin_orphans.find(plugin->uri()); - if (n != m_plugin_orphans.end()) { + if (n != _plugin_orphans.end()) { list > spawn = n->second; // take a copy - m_plugin_orphans.erase(plugin->uri()); // prevent infinite recursion + _plugin_orphans.erase(plugin->uri()); // prevent infinite recursion for (list >::iterator i = spawn.begin(); i != spawn.end(); ++i) { @@ -103,7 +103,7 @@ Store::add_connection_orphan(CountedPtr connection) cerr << "WARNING: Orphan connection " << connection->src_port_path() << " -> " << connection->dst_port_path() << " received." << endl; - m_connection_orphans.push_back(connection); + _connection_orphans.push_back(connection); } @@ -112,8 +112,8 @@ Store::resolve_connection_orphans(CountedPtr port) { assert(port->parent()); - for (list >::iterator c = m_connection_orphans.begin(); - c != m_connection_orphans.end(); ) { + for (list >::iterator c = _connection_orphans.begin(); + c != _connection_orphans.end(); ) { if ((*c)->src_port_path() == port->path()) (*c)->set_src_port(port); @@ -130,7 +130,7 @@ Store::resolve_connection_orphans(CountedPtr port) cerr << "Resolved orphan connection " << (*c)->src_port_path() << (*c)->dst_port_path() << endl; patch->add_connection(*c); - m_connection_orphans.erase(c); + _connection_orphans.erase(c); } } @@ -145,16 +145,16 @@ Store::add_orphan(CountedPtr child) cerr << "WARNING: Orphan object " << child->path() << " received." << endl; map > >::iterator children - = m_orphans.find(child->path().parent()); + = _orphans.find(child->path().parent()); _engine->request_object(child->path().parent()); - if (children != m_orphans.end()) { + if (children != _orphans.end()) { children->second.push_back(child); } else { list > l; l.push_back(child); - m_orphans[child->path().parent()] = l; + _orphans[child->path().parent()] = l; } } @@ -163,16 +163,16 @@ void Store::add_metadata_orphan(const Path& subject_path, const string& predicate, const Atom& value) { map > >::iterator orphans - = m_metadata_orphans.find(subject_path); + = _metadata_orphans.find(subject_path); _engine->request_object(subject_path); - if (orphans != m_metadata_orphans.end()) { + if (orphans != _metadata_orphans.end()) { orphans->second.push_back(std::pair(predicate, value)); } else { list > l; l.push_back(std::pair(predicate, value)); - m_metadata_orphans[subject_path] = l; + _metadata_orphans[subject_path] = l; } } @@ -181,13 +181,13 @@ void Store::resolve_metadata_orphans(CountedPtr subject) { map > >::iterator v - = m_metadata_orphans.find(subject->path()); + = _metadata_orphans.find(subject->path()); - if (v != m_metadata_orphans.end()) { + if (v != _metadata_orphans.end()) { list > values = v->second; // take a copy - m_metadata_orphans.erase(subject->path()); + _metadata_orphans.erase(subject->path()); for (list >::iterator i = values.begin(); i != values.end(); ++i) { @@ -201,13 +201,13 @@ void Store::resolve_orphans(CountedPtr parent) { map > >::iterator c - = m_orphans.find(parent->path()); + = _orphans.find(parent->path()); - if (c != m_orphans.end()) { + if (c != _orphans.end()) { list > children = c->second; // take a copy - m_orphans.erase(parent->path()); // prevent infinite recursion + _orphans.erase(parent->path()); // prevent infinite recursion for (list >::iterator i = children.begin(); i != children.end(); ++i) { @@ -222,8 +222,8 @@ Store::add_object(CountedPtr object) { // If we already have "this" object, merge the existing one into the new // one (with precedence to the new values). - ObjectMap::iterator existing = m_objects.find(object->path()); - if (existing != m_objects.end()) { + ObjectMap::iterator existing = _objects.find(object->path()); + if (existing != _objects.end()) { existing->second->set(object); } else { @@ -235,7 +235,7 @@ Store::add_object(CountedPtr object) parent->add_child(object); assert(parent && (object->parent() == parent)); - m_objects[object->path()] = object; + _objects[object->path()] = object; new_object_sig.emit(object); resolve_metadata_orphans(parent); @@ -249,7 +249,7 @@ Store::add_object(CountedPtr object) add_orphan(object); } } else { - m_objects[object->path()] = object; + _objects[object->path()] = object; new_object_sig.emit(object); } @@ -262,12 +262,12 @@ Store::add_object(CountedPtr object) CountedPtr Store::remove_object(const Path& path) { - map >::iterator i = m_objects.find(path); + map >::iterator i = _objects.find(path); - if (i != m_objects.end()) { + if (i != _objects.end()) { assert((*i).second->path() == path); CountedPtr result = (*i).second; - m_objects.erase(i); + _objects.erase(i); //cout << "[Store] Removed " << path << endl; if (result) @@ -297,8 +297,8 @@ CountedPtr Store::plugin(const string& uri) { assert(uri.length() > 0); - map >::iterator i = m_plugins.find(uri); - if (i == m_plugins.end()) + map >::iterator i = _plugins.find(uri); + if (i == _plugins.end()) return CountedPtr(); else return (*i).second; @@ -309,8 +309,8 @@ CountedPtr Store::object(const Path& path) { assert(path.length() > 0); - map >::iterator i = m_objects.find(path); - if (i == m_objects.end()) { + map >::iterator i = _objects.find(path); + if (i == _objects.end()) { return CountedPtr(); } else { assert(i->second->path() == "/" || i->second->parent()); @@ -323,7 +323,7 @@ Store::add_plugin(CountedPtr pm) { // FIXME: dupes? merge, like with objects? - m_plugins[pm->uri()] = pm; + _plugins[pm->uri()] = pm; } diff --git a/src/libs/client/Store.h b/src/libs/client/Store.h index a2083ba2..6a8700f9 100644 --- a/src/libs/client/Store.h +++ b/src/libs/client/Store.h @@ -54,9 +54,10 @@ public: void clear(); - size_t num_objects() { return m_objects.size(); } + size_t num_object() { return _objects.size(); } - const map >& plugins() const { return m_plugins; } + const map >& plugins() const { return _plugins; } + const map >& objects() const { return _objects; } sigc::signal > new_object_sig; private: @@ -98,23 +99,23 @@ private: CountedPtr _emitter; typedef map > ObjectMap; - ObjectMap m_objects; ///< Keyed by Ingen path + ObjectMap _objects; ///< Keyed by Ingen path - map > m_plugins; ///< Keyed by URI + map > _plugins; ///< Keyed by URI /** Objects we've received, but depend on the existance of another unknown object. * Keyed by the path of the depended-on object (for tolerance of orderless comms) */ - map > > m_orphans; + map > > _orphans; /** Same idea, except with plugins instead of parents. * It's unfortunate everything doesn't just have a URI and this was the same.. ahem.. */ - map > > m_plugin_orphans; + map > > _plugin_orphans; /** Not orphans OF metadata like the above, but orphans which are metadata */ - map > > m_metadata_orphans; + map > > _metadata_orphans; /** Ditto */ - list > m_connection_orphans; + list > _connection_orphans; }; diff --git a/src/libs/engine/AlsaMidiDriver.cpp b/src/libs/engine/AlsaMidiDriver.cpp index 78d032be..3f6b060d 100644 --- a/src/libs/engine/AlsaMidiDriver.cpp +++ b/src/libs/engine/AlsaMidiDriver.cpp @@ -118,7 +118,7 @@ void AlsaMidiPort::event(snd_seq_event_t* const ev) { // Abuse the tick field to hold the timestamp - ev->time.tick = _driver->clock()->time_stamp(); + ev->time.tick = _driver->audio_driver()->frame_time(); // Fix noteons with velocity 0 (required for DSSI spec) if (ev->type == SND_SEQ_EVENT_NOTEON && ev->data.note.velocity == 0) @@ -187,8 +187,9 @@ AlsaMidiPort::prepare_block(const SampleCount block_start, const SampleCount blo bool AlsaMidiDriver::_midi_thread_exit_flag = true; -AlsaMidiDriver::AlsaMidiDriver() -: _seq_handle(NULL), +AlsaMidiDriver::AlsaMidiDriver(AudioDriver* audio_driver) +: _audio_driver(audio_driver), + _seq_handle(NULL), _event_coder(NULL), _is_activated(false) { diff --git a/src/libs/engine/AlsaMidiDriver.h b/src/libs/engine/AlsaMidiDriver.h index ad40ed17..bc5e6203 100644 --- a/src/libs/engine/AlsaMidiDriver.h +++ b/src/libs/engine/AlsaMidiDriver.h @@ -27,6 +27,7 @@ namespace Ingen { class Node; class SetPortValueEvent; class AlsaMidiDriver; +class AudioDriver; template class DuplexPort; static const int MAX_MIDI_EVENT_SIZE = 3; @@ -76,7 +77,7 @@ private: class AlsaMidiDriver : public MidiDriver { public: - AlsaMidiDriver(); + AlsaMidiDriver(AudioDriver* audio_driver); ~AlsaMidiDriver(); void activate(); @@ -86,6 +87,8 @@ public: void prepare_block(const SampleCount block_start, const SampleCount block_end); + AudioDriver* audio_driver() { return _audio_driver; } + DriverPort* create_port(DuplexPort* patch_port) { return new AlsaMidiPort(this, patch_port); } @@ -113,6 +116,7 @@ private: // MIDI thread static void* process_midi_in(void* me); + AudioDriver* _audio_driver; snd_seq_t* _seq_handle; snd_midi_event_t* _event_coder; pthread_t _process_thread; diff --git a/src/libs/engine/Engine.cpp b/src/libs/engine/Engine.cpp index 94f964dc..5d064d49 100644 --- a/src/libs/engine/Engine.cpp +++ b/src/libs/engine/Engine.cpp @@ -54,7 +54,7 @@ Engine::Engine(AudioDriver* audio_driver) #ifdef HAVE_JACK_MIDI m_midi_driver(new JackMidiDriver(((JackAudioDriver*)m_audio_driver)->jack_client())), #elif HAVE_ALSA_MIDI - m_midi_driver(new AlsaMidiDriver()), + m_midi_driver(new AlsaMidiDriver(m_audio_driver)), #else m_midi_driver(new DummyMidiDriver()), #endif diff --git a/src/progs/Makefile.am b/src/progs/Makefile.am index 01791a1b..f37c8af0 100644 --- a/src/progs/Makefile.am +++ b/src/progs/Makefile.am @@ -5,7 +5,7 @@ DIST_SUBDIRS = python supercollider SUBDIRS = server if BUILD_CONSOLE_CLIENTS -SUBDIRS += patch_loader #demolition +SUBDIRS += patch_loader # demolition endif if BUILD_GTK_CLIENT 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()); }*/ diff --git a/src/progs/ingenuity/ConnectWindow.cpp b/src/progs/ingenuity/ConnectWindow.cpp index 64d611e2..256be92f 100644 --- a/src/progs/ingenuity/ConnectWindow.cpp +++ b/src/progs/ingenuity/ConnectWindow.cpp @@ -44,11 +44,10 @@ namespace Ingenuity { struct OSCSigEmitter : public OSCClientReceiver, public ThreadedSigClientInterface { -public: OSCSigEmitter(size_t queue_size, int listen_port) - : Ingen::Shared::ClientInterface() - , OSCClientReceiver(listen_port) - , ThreadedSigClientInterface(queue_size) + : Ingen::Shared::ClientInterface() + , OSCClientReceiver(listen_port) + , ThreadedSigClientInterface(queue_size) { } }; @@ -56,8 +55,8 @@ public: struct QueuedModelEngineInterface : public QueuedEngineInterface, public ModelEngineInterface { QueuedModelEngineInterface(CountedPtr engine) - : Ingen::Shared::EngineInterface() - , Ingen::QueuedEngineInterface(engine, Ingen::event_queue_size, Ingen::event_queue_size) + : Ingen::Shared::EngineInterface() + , Ingen::QueuedEngineInterface(engine, Ingen::event_queue_size, Ingen::event_queue_size) { QueuedEventSource::start(); } @@ -348,7 +347,7 @@ ConnectWindow::gtk_callback() App::instance().engine()->request_all_objects(); ++stage; } else if (stage == 7) { - if (App::instance().store()->num_objects() > 0) { + if (App::instance().store()->objects().size() > 0) { CountedPtr root = PtrCast(App::instance().store()->object("/")); assert(root); App::instance().window_factory()->present_patch(root); -- cgit v1.2.1