diff options
-rw-r--r-- | src/AlsaDriver.cpp | 9 | ||||
-rw-r--r-- | src/Driver.h | 2 | ||||
-rw-r--r-- | src/JackDriver.cpp | 23 | ||||
-rw-r--r-- | src/LashDriver.cpp | 5 | ||||
-rw-r--r-- | src/Patchage.cpp | 4 | ||||
-rw-r--r-- | src/Patchage.h | 12 | ||||
-rw-r--r-- | src/PatchageCanvas.h | 2 | ||||
-rw-r--r-- | src/PatchageEvent.cpp | 40 | ||||
-rw-r--r-- | src/PatchageEvent.h | 33 |
9 files changed, 61 insertions, 69 deletions
diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp index 7ed05bb..6a07487 100644 --- a/src/AlsaDriver.cpp +++ b/src/AlsaDriver.cpp @@ -30,8 +30,9 @@ using std::string; using namespace FlowCanvas; AlsaDriver::AlsaDriver(Patchage* app) -: _app(app), - _seq(NULL) + : Driver(128) + , _app(app) + , _seq(NULL) { } @@ -504,11 +505,11 @@ AlsaDriver::_refresh_main() switch (ev->type) { case SND_SEQ_EVENT_PORT_SUBSCRIBED: - _events.push(PatchageEvent(_app, PatchageEvent::CONNECTION, + _events.push(PatchageEvent(PatchageEvent::CONNECTION, ev->data.connect.sender, ev->data.connect.dest)); break; case SND_SEQ_EVENT_PORT_UNSUBSCRIBED: - _events.push(PatchageEvent(_app, PatchageEvent::DISCONNECTION, + _events.push(PatchageEvent(PatchageEvent::DISCONNECTION, ev->data.connect.sender, ev->data.connect.dest)); break; case SND_SEQ_EVENT_RESET: diff --git a/src/Driver.h b/src/Driver.h index d7f3fbc..7feb8ca 100644 --- a/src/Driver.h +++ b/src/Driver.h @@ -48,7 +48,7 @@ public: sigc::signal<void> signal_detached; protected: - Driver() : _events(128) {} + Driver(size_t event_queue_size) : _events(event_queue_size) {} Raul::SRSWQueue<PatchageEvent> _events; }; diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp index 3428eb6..4513830 100644 --- a/src/JackDriver.cpp +++ b/src/JackDriver.cpp @@ -37,11 +37,12 @@ using namespace FlowCanvas; JackDriver::JackDriver(Patchage* app) -: _app(app) -, _client(NULL) -, _is_activated(false) -, _xruns(0) -, _xrun_delay(0) + : Driver(128) + , _app(app) + , _client(NULL) + , _is_activated(false) + , _xruns(0) + , _xrun_delay(0) { _last_pos.frame = 0; _last_pos.valid = (jack_position_bits_t)0; @@ -401,11 +402,9 @@ JackDriver::jack_port_registration_cb(jack_port_id_t port_id, int registered, vo jack_reset_max_delayed_usecs(me->_client); if (registered) { - me->_events.push(PatchageEvent(me->_app, - PatchageEvent::PORT_CREATION, port_id)); + me->_events.push(PatchageEvent(PatchageEvent::PORT_CREATION, port_id)); } else { - me->_events.push(PatchageEvent(me->_app, - PatchageEvent::PORT_DESTRUCTION, port_id)); + me->_events.push(PatchageEvent(PatchageEvent::PORT_DESTRUCTION, port_id)); } } @@ -420,11 +419,9 @@ JackDriver::jack_port_connect_cb(jack_port_id_t src, jack_port_id_t dst, int con jack_reset_max_delayed_usecs(me->_client); if (connect) { - me->_events.push(PatchageEvent(me->_app, - PatchageEvent::CONNECTION, src, dst)); + me->_events.push(PatchageEvent(PatchageEvent::CONNECTION, src, dst)); } else { - me->_events.push(PatchageEvent(me->_app, - PatchageEvent::DISCONNECTION, src, dst)); + me->_events.push(PatchageEvent(PatchageEvent::DISCONNECTION, src, dst)); } } diff --git a/src/LashDriver.cpp b/src/LashDriver.cpp index db8a51d..114748b 100644 --- a/src/LashDriver.cpp +++ b/src/LashDriver.cpp @@ -27,8 +27,9 @@ using std::string; LashDriver::LashDriver(Patchage* app, int argc, char** argv) -: _app(app), - _args(NULL) + : Driver(2) + , _app(app) + , _args(NULL) { _args = lash_extract_args(&argc, &argv); } diff --git a/src/Patchage.cpp b/src/Patchage.cpp index 693d4ac..8e2dd3a 100644 --- a/src/Patchage.cpp +++ b/src/Patchage.cpp @@ -298,7 +298,7 @@ Patchage::idle_callback() while (!_jack_driver->events().empty()) { PatchageEvent& ev = _jack_driver->events().front(); _jack_driver->events().pop(); - ev.execute(); + ev.execute(this); } } @@ -308,7 +308,7 @@ Patchage::idle_callback() while (!_alsa_driver->events().empty()) { PatchageEvent& ev = _alsa_driver->events().front(); _alsa_driver->events().pop(); - ev.execute(); + ev.execute(this); } } #endif diff --git a/src/Patchage.h b/src/Patchage.h index 288c8ee..e4112ff 100644 --- a/src/Patchage.h +++ b/src/Patchage.h @@ -39,16 +39,16 @@ public: Patchage(int argc, char** argv); ~Patchage(); - boost::shared_ptr<PatchageCanvas> canvas() { return _canvas; } + boost::shared_ptr<PatchageCanvas> canvas() const { return _canvas; } - StateManager* state_manager() { return _state_manager; } - Gtk::Window* window() { return _main_window; } - JackDriver* jack_driver() { return _jack_driver; } + StateManager* state_manager() const { return _state_manager; } + Gtk::Window* window() const { return _main_window; } + JackDriver* jack_driver() const { return _jack_driver; } #ifdef HAVE_ALSA - AlsaDriver* alsa_driver() { return _alsa_driver; } + AlsaDriver* alsa_driver() const { return _alsa_driver; } #endif #ifdef HAVE_LASH - LashDriver* lash_driver() { return _lash_driver; } + LashDriver* lash_driver() const { return _lash_driver; } #endif void attach(); diff --git a/src/PatchageCanvas.h b/src/PatchageCanvas.h index ab9b92e..fe91a34 100644 --- a/src/PatchageCanvas.h +++ b/src/PatchageCanvas.h @@ -39,7 +39,7 @@ public: boost::shared_ptr<PatchageModule> find_module(const string& name, ModuleType type); #ifdef HAVE_ALSA - boost::shared_ptr<PatchagePort> find_port(const snd_seq_addr_t* alsa_addr); + boost::shared_ptr<PatchagePort> find_port(const snd_seq_addr_t* alsa_addr); #endif void connect(boost::shared_ptr<Connectable> port1, boost::shared_ptr<Connectable> port2); void disconnect(boost::shared_ptr<Connectable> port1, boost::shared_ptr<Connectable> port2); diff --git a/src/PatchageEvent.cpp b/src/PatchageEvent.cpp index 775f030..0d46c41 100644 --- a/src/PatchageEvent.cpp +++ b/src/PatchageEvent.cpp @@ -24,15 +24,15 @@ SharedPtr<PatchagePort> -PatchageEvent::find_port(const PortRef& ref) +PatchageEvent::find_port(const Patchage* patchage, const PortRef& ref) { if (ref.type == PortRef::NULL_PORT_REF) return boost::shared_ptr<PatchagePort>(); if (ref.type == PortRef::ALSA_ADDR) { - return _patchage->canvas()->find_port(&ref.id.alsa_addr); + return patchage->canvas()->find_port(&ref.id.alsa_addr); } else { - if (!_patchage->jack_driver()->client()) + if (!patchage->jack_driver()->client()) return boost::shared_ptr<PatchagePort>(); jack_port_t* jack_port = NULL; @@ -40,7 +40,7 @@ PatchageEvent::find_port(const PortRef& ref) if (ref.type == PortRef::JACK_PORT) jack_port = ref.id.jack_port; else if (ref.type == PortRef::JACK_ID) - jack_port = jack_port_by_id(_patchage->jack_driver()->client(), ref.id.jack_id); + jack_port = jack_port_by_id(patchage->jack_driver()->client(), ref.id.jack_id); if (!jack_port) return boost::shared_ptr<PatchagePort>(); @@ -49,7 +49,7 @@ PatchageEvent::find_port(const PortRef& ref) const string module_name = full_name.substr(0, full_name.find(":")); const string port_name = full_name.substr(full_name.find(":")+1); - SharedPtr<PatchageModule> module = _patchage->canvas()->find_module(module_name, + SharedPtr<PatchageModule> module = patchage->canvas()->find_module(module_name, (jack_port_flags(jack_port) & JackPortIsInput) ? Input : Output); if (module) @@ -63,14 +63,14 @@ PatchageEvent::find_port(const PortRef& ref) void -PatchageEvent::execute() +PatchageEvent::execute(Patchage* patchage) { //cerr << "{ EXECUTING EVENT" << endl; if (_type == PORT_CREATION) { jack_port_t* jack_port = NULL; - if (_patchage->jack_driver()->client()) - jack_port = jack_port_by_id(_patchage->jack_driver()->client(), _port_1.id.jack_id); + if (patchage->jack_driver()->client()) + jack_port = jack_port_by_id(patchage->jack_driver()->client(), _port_1.id.jack_id); if (!jack_port) return; @@ -79,29 +79,29 @@ PatchageEvent::execute() const string module_name = full_name.substr(0, full_name.find(":")); const string port_name = full_name.substr(full_name.find(":")+1); - SharedPtr<PatchageModule> module = _patchage->canvas()->find_module(module_name, + SharedPtr<PatchageModule> module = patchage->canvas()->find_module(module_name, (jack_port_flags(jack_port) & JackPortIsInput) ? Input : Output); if (!module) { module = SharedPtr<PatchageModule>( - new PatchageModule(_patchage, module_name, InputOutput)); + new PatchageModule(patchage, module_name, InputOutput)); module->load_location(); module->store_location(); - _patchage->canvas()->add_item(module); + patchage->canvas()->add_item(module); module->show(); } boost::shared_ptr<PatchagePort> port = PtrCast<PatchagePort>( module->get_port(port_name)); if (!port) { - port = _patchage->jack_driver()->create_port(module, jack_port); + port = patchage->jack_driver()->create_port(module, jack_port); module->add_port(port); module->resize(); } } else if (_type == PORT_DESTRUCTION) { - SharedPtr<PatchagePort> port = find_port(_port_1); + SharedPtr<PatchagePort> port = find_port(patchage, _port_1); if (port) { SharedPtr<PatchageModule> module = PtrCast<PatchageModule>(port->module().lock()); @@ -111,7 +111,7 @@ PatchageEvent::execute() module->remove_port(port); //assert(removed_port == port); if (module->num_ports() == 0) { - _patchage->canvas()->remove_item(module); + patchage->canvas()->remove_item(module); module.reset(); } } else { @@ -120,21 +120,21 @@ PatchageEvent::execute() } else if (_type == CONNECTION) { - SharedPtr<PatchagePort> port_1 = find_port(_port_1); - SharedPtr<PatchagePort> port_2 = find_port(_port_2); + SharedPtr<PatchagePort> port_1 = find_port(patchage, _port_1); + SharedPtr<PatchagePort> port_2 = find_port(patchage, _port_2); if (port_1 && port_2) - _patchage->canvas()->add_connection(port_1, port_2, port_1->color() + 0x22222200); + patchage->canvas()->add_connection(port_1, port_2, port_1->color() + 0x22222200); else cerr << "Unable to find port to connect" << endl; } else if (_type == DISCONNECTION) { - SharedPtr<PatchagePort> port_1 = find_port(_port_1); - SharedPtr<PatchagePort> port_2 = find_port(_port_2); + SharedPtr<PatchagePort> port_1 = find_port(patchage, _port_1); + SharedPtr<PatchagePort> port_2 = find_port(patchage, _port_2); if (port_1 && port_2) - _patchage->canvas()->remove_connection(port_1, port_2); + patchage->canvas()->remove_connection(port_1, port_2); else cerr << "Unable to find port to disconnect" << endl; } diff --git a/src/PatchageEvent.h b/src/PatchageEvent.h index c249613..79fb711 100644 --- a/src/PatchageEvent.h +++ b/src/PatchageEvent.h @@ -34,49 +34,42 @@ class Patchage; class PatchageEvent { public: enum Type { - NULL_EVENT, + NULL_EVENT = 0, PORT_CREATION, PORT_DESTRUCTION, CONNECTION, DISCONNECTION }; - PatchageEvent(Patchage* patchage) - : _patchage(patchage) - , _type(NULL_EVENT) + PatchageEvent() + : _type(NULL_EVENT) {} - PatchageEvent(Patchage* patchage, Type type, jack_port_id_t port) - : _patchage(patchage) - , _type(type) + PatchageEvent(Type type, jack_port_id_t port) + : _type(type) , _port_1(port) {} - PatchageEvent(Patchage* patchage, Type type, - jack_port_id_t port_1, jack_port_id_t port_2) - : _patchage(patchage) - , _type(type) + PatchageEvent(Type type, jack_port_id_t port_1, jack_port_id_t port_2) + : _type(type) , _port_1(port_1) , _port_2(port_2) {} #ifdef HAVE_ALSA - PatchageEvent(Patchage* patchage, Type type, - snd_seq_addr_t port_1, snd_seq_addr_t port_2) - : _patchage(patchage) - , _type(type) + PatchageEvent(Type type, snd_seq_addr_t port_1, snd_seq_addr_t port_2) + : _type(type) , _port_1(port_1) , _port_2(port_2) {} #endif - void execute(); + void execute(Patchage* patchage); - Type type() { return _type; } + inline Type type() const { return (Type)_type; } private: - Patchage* _patchage; - Type _type; + uint8_t _type; struct PortRef { PortRef() : type(NULL_PORT_REF) { id.jack_id = 0; } @@ -102,7 +95,7 @@ private: PortRef _port_1; PortRef _port_2; - boost::shared_ptr<PatchagePort> find_port(const PortRef& ref); + boost::shared_ptr<PatchagePort> find_port(const Patchage* patchage, const PortRef& ref); }; |