diff options
author | David Robillard <d@drobilla.net> | 2008-02-23 18:48:59 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2008-02-23 18:48:59 +0000 |
commit | 52c970b2d32cce2090efbbaaed6ff50de80958df (patch) | |
tree | 8e69392e8054c8349ce6dad9a4b4028d08e1ae7c | |
parent | 8efff32d97b1b578f8c42fe2db7b30cfc44ecf2f (diff) | |
download | patchage-52c970b2d32cce2090efbbaaed6ff50de80958df.tar.gz patchage-52c970b2d32cce2090efbbaaed6ff50de80958df.tar.bz2 patchage-52c970b2d32cce2090efbbaaed6ff50de80958df.zip |
Rearrange event port referencing stuff to make a bit more sense.
git-svn-id: http://svn.drobilla.net/lad/patchage@1159 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r-- | src/AlsaDriver.cpp | 25 | ||||
-rw-r--r-- | src/AlsaDriver.hpp | 4 | ||||
-rw-r--r-- | src/Driver.hpp | 4 | ||||
-rw-r--r-- | src/JackDriver.cpp | 52 | ||||
-rw-r--r-- | src/JackDriver.hpp | 4 | ||||
-rw-r--r-- | src/PatchageCanvas.cpp | 74 | ||||
-rw-r--r-- | src/PatchageCanvas.hpp | 6 | ||||
-rw-r--r-- | src/PatchageEvent.cpp | 29 | ||||
-rw-r--r-- | src/PatchageEvent.hpp | 29 |
9 files changed, 99 insertions, 128 deletions
diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp index 6fa90fc..22d1924 100644 --- a/src/AlsaDriver.cpp +++ b/src/AlsaDriver.cpp @@ -316,7 +316,8 @@ AlsaDriver::add_connections(boost::shared_ptr<PatchagePort> port) if (!connected_addr) continue; - connected_port = _app->canvas()->find_port(*connected_addr, true); + PatchageEvent::PortRef ref(*connected_addr, true); + connected_port = _app->canvas()->find_port(ref); if (connected_port && !port->is_connected_to(connected_port)) _app->canvas()->add_connection(port, connected_port, port->color() + 0x22222200); @@ -327,22 +328,6 @@ AlsaDriver::add_connections(boost::shared_ptr<PatchagePort> port) } -/** Find the PatchagePort that corresponds to an Alsa Sequencer port. - * - * This function is not realtime safe, but safe to call from the GUI thread - * (e.g. in PatchageEvent::execute). - */ -boost::shared_ptr<PatchagePort> -AlsaDriver::find_port_view(Patchage* patchage, - const PatchageEvent::PortRef& ref) -{ - if (ref.type == PatchageEvent::PortRef::ALSA_ADDR) - return patchage->canvas()->find_port(ref.id.alsa_addr, ref.is_input); - else - return boost::shared_ptr<PatchagePort>(); -} - - /** Connects two Alsa Midi ports. * * \return Whether connection succeeded. @@ -521,11 +506,11 @@ AlsaDriver::_refresh_main() switch (ev->type) { case SND_SEQ_EVENT_PORT_SUBSCRIBED: - _events.push(PatchageEvent(this, 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(this, PatchageEvent::DISCONNECTION, + _events.push(PatchageEvent(PatchageEvent::DISCONNECTION, ev->data.connect.sender, ev->data.connect.dest)); break; case SND_SEQ_EVENT_PORT_START: @@ -537,7 +522,7 @@ AlsaDriver::_refresh_main() case SND_SEQ_EVENT_RESET: default: // FIXME: Ultra slow kludge, use proper find-grained events - _events.push(PatchageEvent(this, PatchageEvent::REFRESH)); + _events.push(PatchageEvent(PatchageEvent::REFRESH)); } } } diff --git a/src/AlsaDriver.hpp b/src/AlsaDriver.hpp index 8caf911..5f97d47 100644 --- a/src/AlsaDriver.hpp +++ b/src/AlsaDriver.hpp @@ -42,10 +42,6 @@ public: void refresh(); - boost::shared_ptr<PatchagePort> find_port_view( - Patchage* patchage, - const PatchageEvent::PortRef& ref); - boost::shared_ptr<PatchagePort> create_port_view( Patchage* patchage, const PatchageEvent::PortRef& ref); diff --git a/src/Driver.hpp b/src/Driver.hpp index 820e7eb..5c4c35d 100644 --- a/src/Driver.hpp +++ b/src/Driver.hpp @@ -41,10 +41,6 @@ public: Patchage* patchage, const PatchageEvent::PortRef& ref) = 0; - virtual boost::shared_ptr<PatchagePort> find_port_view( - Patchage* patchage, - const PatchageEvent::PortRef& ref) = 0; - virtual bool connect(boost::shared_ptr<PatchagePort> src_port, boost::shared_ptr<PatchagePort> dst_port) = 0; diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp index 8fccde6..f77fd32 100644 --- a/src/JackDriver.cpp +++ b/src/JackDriver.cpp @@ -146,9 +146,7 @@ JackDriver::create_port_view(Patchage* patchage, { jack_port_t* jack_port = NULL; - if (ref.type == PatchageEvent::PortRef::JACK_PORT) - jack_port = ref.id.jack_port; - else if (ref.type == PatchageEvent::PortRef::JACK_ID) + if (ref.type == PatchageEvent::PortRef::JACK_ID) jack_port = jack_port_by_id(_client, ref.id.jack_id); string module_name, port_name; @@ -348,9 +346,7 @@ JackDriver::port_names(const PatchageEvent::PortRef& ref, { jack_port_t* jack_port = NULL; - if (ref.type == PatchageEvent::PortRef::JACK_PORT) - jack_port = ref.id.jack_port; - else if (ref.type == PatchageEvent::PortRef::JACK_ID) + if (ref.type == PatchageEvent::PortRef::JACK_ID) jack_port = jack_port_by_id(_client, ref.id.jack_id); if (!jack_port) { @@ -368,38 +364,6 @@ JackDriver::port_names(const PatchageEvent::PortRef& ref, } -/** Find the PatchagePort that corresponds to a JACK port. - * - * This function is not realtime safe, but safe to call from the GUI thread - * (e.g. in PatchageEvent::execute). - */ -boost::shared_ptr<PatchagePort> -JackDriver::find_port_view(Patchage* patchage, - const PatchageEvent::PortRef& ref) -{ - jack_port_t* jack_port = NULL; - - if (ref.type == PatchageEvent::PortRef::JACK_PORT) - jack_port = ref.id.jack_port; - else if (ref.type == PatchageEvent::PortRef::JACK_ID) - jack_port = jack_port_by_id(_client, ref.id.jack_id); - - if (!jack_port) - return boost::shared_ptr<PatchagePort>(); - - string module_name, port_name; - port_names(ref, module_name, port_name); - - SharedPtr<PatchageModule> module = patchage->canvas()->find_module(module_name, - (jack_port_flags(jack_port) & JackPortIsInput) ? Input : Output); - - if (module) - return PtrCast<PatchagePort>(module->get_port(port_name)); - else - return boost::shared_ptr<PatchagePort>(); -} - - /** Connects two Jack audio ports. * To be called from GTK thread only. * \return Whether connection succeeded. @@ -457,9 +421,9 @@ JackDriver::jack_client_registration_cb(const char* name, int registered, void* // FIXME: This sucks, not realtime :( if (registered) { - me->_events.push(PatchageEvent(me, PatchageEvent::CLIENT_CREATION, name)); + me->_events.push(PatchageEvent(PatchageEvent::CLIENT_CREATION, name)); } else { - me->_events.push(PatchageEvent(me, PatchageEvent::CLIENT_DESTRUCTION, name)); + me->_events.push(PatchageEvent(PatchageEvent::CLIENT_DESTRUCTION, name)); } } @@ -477,9 +441,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, PatchageEvent::PORT_CREATION, port_id)); + me->_events.push(PatchageEvent(PatchageEvent::PORT_CREATION, port_id)); } else { - me->_events.push(PatchageEvent(me, PatchageEvent::PORT_DESTRUCTION, port_id)); + me->_events.push(PatchageEvent(PatchageEvent::PORT_DESTRUCTION, port_id)); } } @@ -494,9 +458,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, PatchageEvent::CONNECTION, src, dst)); + me->_events.push(PatchageEvent(PatchageEvent::CONNECTION, src, dst)); } else { - me->_events.push(PatchageEvent(me, PatchageEvent::DISCONNECTION, src, dst)); + me->_events.push(PatchageEvent(PatchageEvent::DISCONNECTION, src, dst)); } } diff --git a/src/JackDriver.hpp b/src/JackDriver.hpp index 2b0e79b..b75c826 100644 --- a/src/JackDriver.hpp +++ b/src/JackDriver.hpp @@ -55,10 +55,6 @@ public: std::string& module_name, std::string& port_name); - boost::shared_ptr<PatchagePort> find_port_view( - Patchage* patchage, - const PatchageEvent::PortRef& ref); - boost::shared_ptr<PatchagePort> create_port_view( Patchage* patchage, const PatchageEvent::PortRef& ref); diff --git a/src/PatchageCanvas.cpp b/src/PatchageCanvas.cpp index b32ca6e..ffc5627 100644 --- a/src/PatchageCanvas.cpp +++ b/src/PatchageCanvas.cpp @@ -60,41 +60,71 @@ PatchageCanvas::find_module(const string& name, ModuleType type) } -#ifdef HAVE_ALSA boost::shared_ptr<PatchagePort> -PatchageCanvas::find_port(snd_seq_addr_t alsa_addr, bool input) +PatchageCanvas::find_port(const PatchageEvent::PortRef& ref) { + jack_port_t* jack_port = NULL; + string module_name; + string port_name; + + SharedPtr<PatchageModule> module; boost::shared_ptr<PatchagePort> pp; - for (ItemList::iterator m = _items.begin(); m != _items.end(); ++m) { - SharedPtr<PatchageModule> module = PtrCast<PatchageModule>(*m); - if (!module) - continue; - for (PortVector::const_iterator p = module->ports().begin(); p != module->ports().end(); ++p) { - pp = boost::dynamic_pointer_cast<PatchagePort>(*p); - if (!pp) + // TODO: filthy. keep a port map and make this O(log(n)) + switch (ref.type) { + case PatchageEvent::PortRef::JACK_ID: + jack_port = jack_port_by_id(_app->jack_driver()->client(), ref.id.jack_id); + if (!jack_port) + return boost::shared_ptr<PatchagePort>(); + + _app->jack_driver()->port_names(ref, module_name, port_name); + + module = find_module(module_name, + (jack_port_flags(jack_port) & JackPortIsInput) ? Input : Output); + + if (module) + return PtrCast<PatchagePort>(module->get_port(port_name)); + else + return boost::shared_ptr<PatchagePort>(); + + break; + +#ifdef HAVE_ALSA + case PatchageEvent::PortRef::ALSA_ADDR: + for (ItemList::iterator m = _items.begin(); m != _items.end(); ++m) { + SharedPtr<PatchageModule> module = PtrCast<PatchageModule>(*m); + if (!module) continue; - - if (pp->type() == ALSA_MIDI) { - /*cerr << "ALSA PORT: " << (int)pp->alsa_addr()->client << ":" - << (int)pp->alsa_addr()->port << endl;*/ - - if (pp->alsa_addr() - && pp->alsa_addr()->client == alsa_addr.client - && pp->alsa_addr()->port == alsa_addr.port) { - if (!input && module->type() == Input) { - //cerr << "WRONG DIRECTION, SKIPPED PORT" << endl; - } else { - return pp; + + for (PortVector::const_iterator p = module->ports().begin(); p != module->ports().end(); ++p) { + pp = boost::dynamic_pointer_cast<PatchagePort>(*p); + if (!pp) + continue; + + if (pp->type() == ALSA_MIDI) { + /*cerr << "ALSA PORT: " << (int)pp->alsa_addr()->client << ":" + << (int)pp->alsa_addr()->port << endl;*/ + + if (pp->alsa_addr() + && pp->alsa_addr()->client == ref.id.alsa_addr.client + && pp->alsa_addr()->port == ref.id.alsa_addr.port) { + if (!ref.is_input && module->type() == Input) { + //cerr << "WRONG DIRECTION, SKIPPED PORT" << endl; + } else { + return pp; + } } } } } + default: + break; } +#endif // HAVE_ALSA return boost::shared_ptr<PatchagePort>(); } -#endif + void PatchageCanvas::connect(boost::shared_ptr<Connectable> port1, boost::shared_ptr<Connectable> port2) diff --git a/src/PatchageCanvas.hpp b/src/PatchageCanvas.hpp index d904581..c4ed127 100644 --- a/src/PatchageCanvas.hpp +++ b/src/PatchageCanvas.hpp @@ -25,6 +25,7 @@ #endif #include <flowcanvas/Canvas.hpp> #include "StateManager.hpp" +#include "PatchageEvent.hpp" class Patchage; class PatchageModule; @@ -38,9 +39,8 @@ public: PatchageCanvas(Patchage* _app, int width, int height); boost::shared_ptr<PatchageModule> find_module(const string& name, ModuleType type); -#ifdef HAVE_ALSA - boost::shared_ptr<PatchagePort> find_port(snd_seq_addr_t alsa_addr, bool input); -#endif + boost::shared_ptr<PatchagePort> find_port(const PatchageEvent::PortRef& ref); + 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 3f03208..d123188 100644 --- a/src/PatchageEvent.cpp +++ b/src/PatchageEvent.cpp @@ -22,6 +22,10 @@ #include "PatchageModule.hpp" #include "PatchageEvent.hpp" #include "Driver.hpp" +#include "JackDriver.hpp" +#ifdef HAVE_ALSA +#include "AlsaDriver.hpp" +#endif using namespace std; @@ -49,13 +53,24 @@ PatchageEvent::execute(Patchage* patchage) } else if (_type == PORT_CREATION) { - if ( ! _driver->create_port_view(patchage, _port_1)) { - cerr << "Unable to create port view (already exists?" << endl; + Driver* driver; + if (_port_1.type == PatchageEvent::PortRef::JACK_ID) + driver = patchage->jack_driver(); +#ifdef HAVE_ALSA + else if (_port_1.type == PatchageEvent::PortRef::ALSA_ADDR) + driver = patchage->alsa_driver(); +#endif + + if (driver) { + if ( ! driver->create_port_view(patchage, _port_1)) + cerr << "Unable to create port view (already exists?" << endl; + } else { + cerr << "ERROR: Create port with unknown port type" << endl; } } else if (_type == PORT_DESTRUCTION) { - SharedPtr<PatchagePort> port = _driver->find_port_view(patchage, _port_1); + SharedPtr<PatchagePort> port = patchage->canvas()->find_port(_port_1); if (port) { SharedPtr<PatchageModule> module = PtrCast<PatchageModule>(port->module().lock()); @@ -78,8 +93,8 @@ PatchageEvent::execute(Patchage* patchage) } else if (_type == CONNECTION) { - SharedPtr<PatchagePort> port_1 = _driver->find_port_view(patchage, _port_1); - SharedPtr<PatchagePort> port_2 = _driver->find_port_view(patchage, _port_2); + SharedPtr<PatchagePort> port_1 = patchage->canvas()->find_port(_port_1); + SharedPtr<PatchagePort> port_2 = patchage->canvas()->find_port(_port_2); if (port_1 && port_2) patchage->canvas()->add_connection(port_1, port_2, port_1->color() + 0x22222200); @@ -88,8 +103,8 @@ PatchageEvent::execute(Patchage* patchage) } else if (_type == DISCONNECTION) { - SharedPtr<PatchagePort> port_1 = _driver->find_port_view(patchage, _port_1); - SharedPtr<PatchagePort> port_2 = _driver->find_port_view(patchage, _port_2); + SharedPtr<PatchagePort> port_1 = patchage->canvas()->find_port(_port_1); + SharedPtr<PatchagePort> port_2 = patchage->canvas()->find_port(_port_2); if (port_1 && port_2) patchage->canvas()->remove_connection(port_1, port_2); diff --git a/src/PatchageEvent.hpp b/src/PatchageEvent.hpp index 1f15543..e9357ba 100644 --- a/src/PatchageEvent.hpp +++ b/src/PatchageEvent.hpp @@ -26,8 +26,6 @@ #include "PatchagePort.hpp" class Patchage; -class Driver; - /** A Driver event to be processed by the GUI thread. */ @@ -44,30 +42,26 @@ public: DISCONNECTION }; - PatchageEvent(Driver* d = NULL, Type type=NULL_EVENT) - : _driver(d) - , _str(NULL) + PatchageEvent(Type type=NULL_EVENT) + : _str(NULL) , _type(type) {} - PatchageEvent(Driver* driver, Type type, const char* str) - : _driver(driver) - , _str(strdup(str)) // FIXME: not realtime (jack) :( + PatchageEvent(Type type, const char* str) + : _str(strdup(str)) // FIXME: not realtime (jack) :( , _type(type) {} template <typename P> - PatchageEvent(Driver* driver, Type type, P port) - : _driver(driver) - , _str(NULL) + PatchageEvent(Type type, P port) + : _str(NULL) , _port_1(port) , _type(type) {} template <typename P> - PatchageEvent(Driver* driver, Type type, P port_1, P port_2) - : _driver(driver) - , _str(NULL) + PatchageEvent(Type type, P port_1, P port_2) + : _str(NULL) , _port_1(port_1, false) , _port_2(port_2, true) , _type(type) @@ -83,9 +77,6 @@ public: PortRef(jack_port_id_t jack_id, bool ign=false) : type(JACK_ID) { id.jack_id = jack_id; } - PortRef(jack_port_t* jack_port, bool ign=false) - : type(JACK_PORT) { id.jack_port = jack_port; } - #ifdef HAVE_ALSA PortRef(snd_seq_addr_t addr, bool in) : type(ALSA_ADDR) { id.alsa_addr = addr; is_input = in; } @@ -93,10 +84,9 @@ public: bool is_input; #endif - enum { NULL_PORT_REF, JACK_ID, JACK_PORT, ALSA_ADDR } type; + enum { NULL_PORT_REF, JACK_ID, ALSA_ADDR } type; union { - jack_port_t* jack_port; jack_port_id_t jack_id; #ifdef HAVE_ALSA snd_seq_addr_t alsa_addr; @@ -105,7 +95,6 @@ public: }; private: - Driver* _driver; char* _str; PortRef _port_1; PortRef _port_2; |