From c335e2b88b051a1a14b0806ffabb257c2a0d0e74 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 8 Jun 2007 02:17:40 +0000 Subject: Monitor/change ALSA connections without refreshing entire canvas (much faster). Waiting on JACK to provide the notification to do the same.... git-svn-id: http://svn.drobilla.net/lad/patchage@531 a436a847-0d15-0410-975c-d299462d15a1 --- src/PatchageEvent.cpp | 112 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 78 insertions(+), 34 deletions(-) (limited to 'src/PatchageEvent.cpp') diff --git a/src/PatchageEvent.cpp b/src/PatchageEvent.cpp index 70d1c43..aaec3dc 100644 --- a/src/PatchageEvent.cpp +++ b/src/PatchageEvent.cpp @@ -22,38 +22,68 @@ #include "PatchageEvent.h" #include "JackDriver.h" -void -PatchageEvent::execute() + +SharedPtr +PatchageEvent::find_port(const PortRef& ref) { - //cerr << "{ EXECUTING EVENT" << endl; + if (ref.type == ALSA_MIDI) { + return _patchage->canvas()->find_port(&ref.id.alsa); + } else { + jack_port_t* jack_port = NULL; + if (_patchage->jack_driver()->client()) + jack_port = jack_port_by_id(_patchage->jack_driver()->client(), ref.id.jack); + + if (!jack_port) + return boost::shared_ptr(); - jack_port_t* jack_port = NULL; - if (_patchage->jack_driver()->client()) - jack_port = jack_port_by_id(_patchage->jack_driver()->client(), _port_id); + const string full_name = jack_port_name(jack_port); + const string module_name = full_name.substr(0, full_name.find(":")); + const string port_name = full_name.substr(full_name.find(":")+1); - if (!jack_port) - return; + SharedPtr module = PtrCast( + _patchage->canvas()->get_item(module_name)); + + if (module) + return PtrCast(module->get_port(port_name)); + else + return boost::shared_ptr(); + } + + return boost::shared_ptr(); +} - const string full_name = jack_port_name(jack_port); - const string module_name = full_name.substr(0, full_name.find(":")); - const string port_name = full_name.substr(full_name.find(":")+1); - SharedPtr module = PtrCast( - _patchage->canvas()->get_item(module_name)); +void +PatchageEvent::execute() +{ + //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); + if (!jack_port) + return; + + const string full_name = jack_port_name(jack_port); + const string module_name = full_name.substr(0, full_name.find(":")); + const string port_name = full_name.substr(full_name.find(":")+1); + + SharedPtr module = _patchage->canvas()->find_module(module_name, + (jack_port_flags(jack_port) & JackPortIsInput) ? Input : Output); + if (!module) { - module = boost::shared_ptr( + module = SharedPtr( new PatchageModule(_patchage, module_name, InputOutput)); module->load_location(); module->store_location(); _patchage->canvas()->add_item(module); module->show(); } - + boost::shared_ptr port = PtrCast( - module->get_port(port_name)); + module->get_port(port_name)); if (!port) { port = _patchage->jack_driver()->create_port(module, jack_port); module->add_port(port); @@ -62,28 +92,42 @@ PatchageEvent::execute() } else if (_type == PORT_DESTRUCTION) { - if (!module) { - cerr << "Unable to find module for port " << full_name << endl; - return; - } + SharedPtr port = find_port(_port_1); - boost::shared_ptr port = PtrCast( - module->remove_port(full_name.substr(full_name.find(":")+1))); - - if (!port) - cerr << "Destroy port: Unable to find port " << full_name << endl; - else { - //cerr << "Destroyed port " << full_name << endl; - port->hide(); - port.reset(); // FIXME: leak? + if (port) { + SharedPtr module = PtrCast(port->module().lock()); + assert(module); + + //SharedPtr removed_port = PtrCast( + module->remove_port(port); + //assert(removed_port == port); + if (module->num_ports() == 0) { + _patchage->canvas()->remove_item(module); + module.reset(); + } + } else { + cerr << "Unable to find port to destroy" << endl; } - } + } else if (_type == CONNECTION) { + + SharedPtr port_1 = find_port(_port_1); + SharedPtr port_2 = find_port(_port_2); + + if (port_1 && port_2) + _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 port_1 = find_port(_port_1); + SharedPtr port_2 = find_port(_port_2); - if (module->num_ports() == 0) { - _patchage->canvas()->remove_item(module); - module->hide(); - module.reset(); + if (port_1 && port_2) + _patchage->canvas()->remove_connection(port_1, port_2); + else + cerr << "Unable to find port to disconnect" << endl; } //cerr << "}" << endl << endl; -- cgit v1.2.1