summaryrefslogtreecommitdiffstats
path: root/src/PatchageEvent.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-01-14 04:22:16 +0000
committerDavid Robillard <d@drobilla.net>2007-01-14 04:22:16 +0000
commitf9a66347152ad4459a564d5f92fdeabb6d8b4019 (patch)
tree8ab4ed5436a83bbad634773d5b3b96428f77d85e /src/PatchageEvent.cpp
parent8e946da143030272b1bb325aba1ea52e67792254 (diff)
downloadpatchage-f9a66347152ad4459a564d5f92fdeabb6d8b4019.tar.gz
patchage-f9a66347152ad4459a564d5f92fdeabb6d8b4019.tar.bz2
patchage-f9a66347152ad4459a564d5f92fdeabb6d8b4019.zip
Follow Jack port creation/destruction.
git-svn-id: http://svn.drobilla.net/lad/patchage@257 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/PatchageEvent.cpp')
-rw-r--r--src/PatchageEvent.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/PatchageEvent.cpp b/src/PatchageEvent.cpp
new file mode 100644
index 0000000..456756c
--- /dev/null
+++ b/src/PatchageEvent.cpp
@@ -0,0 +1,83 @@
+/* This file is part of Patchage. Copyright (C) 2005 Dave Robillard.
+ *
+ * Patchage 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.
+ *
+ * Patchage 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.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "raul/SharedPtr.h"
+#include "Patchage.h"
+#include "PatchageFlowCanvas.h"
+#include "PatchageModule.h"
+#include "PatchageEvent.h"
+#include "JackDriver.h"
+
+void
+PatchageEvent::execute()
+{
+ //cerr << "{ EXECUTING EVENT" << endl;
+
+ jack_port_t* const 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);
+
+ SharedPtr<PatchageModule> module = PtrCast<PatchageModule>(
+ _patchage->canvas()->get_module(module_name));
+
+ if (_type == PORT_CREATION) {
+
+ if (!module) {
+ module = boost::shared_ptr<PatchageModule>(
+ new PatchageModule(_patchage, module_name, InputOutput));
+ module->load_location();
+ module->store_location();
+ _patchage->canvas()->add_module(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);
+ module->add_port(port);
+ module->resize();
+ }
+
+ } else if (_type == PORT_DESTRUCTION) {
+
+ if (!module) {
+ cerr << "Unable to find module for port " << full_name << endl;
+ return;
+ }
+
+ boost::shared_ptr<PatchagePort> port = PtrCast<PatchagePort>(
+ 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 (module->num_ports() == 0) {
+ _patchage->canvas()->remove_module(module->name()); // FIXME: slow
+ module->hide();
+ module.reset();
+ }
+
+ //cerr << "}" << endl << endl;
+}