diff options
-rw-r--r-- | src/AlsaDriver.cpp | 8 | ||||
-rw-r--r-- | src/AlsaDriver.hpp | 4 | ||||
-rw-r--r-- | src/Driver.hpp | 4 | ||||
-rw-r--r-- | src/JackDbusDriver.cpp | 4 | ||||
-rw-r--r-- | src/JackDbusDriver.hpp | 8 | ||||
-rw-r--r-- | src/JackDriver.cpp | 20 | ||||
-rw-r--r-- | src/JackDriver.hpp | 10 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/PatchageCanvas.cpp | 18 | ||||
-rw-r--r-- | src/PatchageCanvas.hpp | 2 | ||||
-rw-r--r-- | src/PatchageEvent.cpp | 4 | ||||
-rw-r--r-- | src/PatchageEvent.hpp | 32 | ||||
-rw-r--r-- | src/PortID.hpp | 61 |
13 files changed, 106 insertions, 70 deletions
diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp index 1662471..cb58c6a 100644 --- a/src/AlsaDriver.cpp +++ b/src/AlsaDriver.cpp @@ -103,8 +103,8 @@ AlsaDriver::refresh() boost::shared_ptr<PatchagePort> -AlsaDriver::create_port_view(Patchage* patchage, - const PatchageEvent::PortRef& ref) +AlsaDriver::create_port_view(Patchage* patchage, + const PortID& id) { return boost::shared_ptr<PatchagePort>(); } @@ -348,8 +348,8 @@ AlsaDriver::add_connections(boost::shared_ptr<PatchagePort> port) if (!connected_addr) continue; - PatchageEvent::PortRef ref(*connected_addr, true); - connected_port = _app->canvas()->find_port(ref); + PortID id(*connected_addr, true); + connected_port = _app->canvas()->find_port(id); if (connected_port && !port->is_connected_to(connected_port)) _app->canvas()->add_connection(port, connected_port, port->color() + 0x22222200); diff --git a/src/AlsaDriver.hpp b/src/AlsaDriver.hpp index fb919eb..c39f8c4 100644 --- a/src/AlsaDriver.hpp +++ b/src/AlsaDriver.hpp @@ -43,8 +43,8 @@ public: void refresh(); boost::shared_ptr<PatchagePort> create_port_view( - Patchage* patchage, - const PatchageEvent::PortRef& ref); + Patchage* patchage, + const PortID& id); bool connect(boost::shared_ptr<PatchagePort> src_port, boost::shared_ptr<PatchagePort> dst_port); diff --git a/src/Driver.hpp b/src/Driver.hpp index 678fdbe..49db805 100644 --- a/src/Driver.hpp +++ b/src/Driver.hpp @@ -46,8 +46,8 @@ public: virtual void refresh() = 0; virtual boost::shared_ptr<PatchagePort> create_port_view( - Patchage* patchage, - const PatchageEvent::PortRef& ref) = 0; + Patchage* patchage, + const PortID& id) = 0; virtual bool connect(boost::shared_ptr<PatchagePort> src_port, boost::shared_ptr<PatchagePort> dst_port) = 0; diff --git a/src/JackDbusDriver.cpp b/src/JackDbusDriver.cpp index f775b8f..1f96647 100644 --- a/src/JackDbusDriver.cpp +++ b/src/JackDbusDriver.cpp @@ -1128,7 +1128,7 @@ JackDriver::rewind_transport() boost::shared_ptr<PatchagePort> -JackDriver::find_port_view(Patchage* patchage, const PatchageEvent::PortRef& ref) +JackDriver::find_port_view(Patchage* patchage, const PortID& id) { assert(false); // we dont use events at all } @@ -1137,7 +1137,7 @@ JackDriver::find_port_view(Patchage* patchage, const PatchageEvent::PortRef& ref boost::shared_ptr<PatchagePort> JackDriver::create_port_view( Patchage * patchage, - const PatchageEvent::PortRef& ref) + const PortID& id) { assert(false); // we dont use events at all } diff --git a/src/JackDbusDriver.hpp b/src/JackDbusDriver.hpp index 9f01c01..0deaef0 100644 --- a/src/JackDbusDriver.hpp +++ b/src/JackDbusDriver.hpp @@ -75,13 +75,13 @@ public: boost::shared_ptr<PatchagePort> find_port_view( - Patchage * patchage, - const PatchageEvent::PortRef& ref); + Patchage* patchage, + const PortID& ref); boost::shared_ptr<PatchagePort> create_port_view( - Patchage * patchage, - const PatchageEvent::PortRef& ref); + Patchage* patchage, + const PortID& ref); private: void error_msg(const std::string& msg) const; diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp index d31d499..609842e 100644 --- a/src/JackDriver.cpp +++ b/src/JackDriver.cpp @@ -141,16 +141,16 @@ JackDriver::destroy_all_ports() boost::shared_ptr<PatchagePort> -JackDriver::create_port_view(Patchage* patchage, - const PatchageEvent::PortRef& ref) +JackDriver::create_port_view(Patchage* patchage, + const PortID& id) { jack_port_t* jack_port = NULL; - if (ref.type == PatchageEvent::PortRef::JACK_ID) - jack_port = jack_port_by_id(_client, ref.id.jack_id); + if (id.type == PortID::JACK_ID) + jack_port = jack_port_by_id(_client, id.id.jack_id); string module_name, port_name; - port_names(ref, module_name, port_name); + port_names(id, module_name, port_name); ModuleType type = InputOutput; if (_app->state_manager()->get_module_split(module_name, @@ -351,14 +351,14 @@ JackDriver::refresh() bool -JackDriver::port_names(const PatchageEvent::PortRef& ref, - string& module_name, - string& port_name) +JackDriver::port_names(const PortID& id, + string& module_name, + string& port_name) { jack_port_t* jack_port = NULL; - if (ref.type == PatchageEvent::PortRef::JACK_ID) - jack_port = jack_port_by_id(_client, ref.id.jack_id); + if (id.type == PortID::JACK_ID) + jack_port = jack_port_by_id(_client, id.id.jack_id); if (!jack_port) { module_name = ""; diff --git a/src/JackDriver.hpp b/src/JackDriver.hpp index 2ea7066..6bbb8db 100644 --- a/src/JackDriver.hpp +++ b/src/JackDriver.hpp @@ -51,13 +51,13 @@ public: void refresh(); - bool port_names(const PatchageEvent::PortRef& ref, - std::string& module_name, - std::string& port_name); + bool port_names(const PortID& id, + std::string& module_name, + std::string& port_name); boost::shared_ptr<PatchagePort> create_port_view( - Patchage* patchage, - const PatchageEvent::PortRef& ref); + Patchage* patchage, + const PortID& id); bool connect(boost::shared_ptr<PatchagePort> src, boost::shared_ptr<PatchagePort> dst); diff --git a/src/Makefile.am b/src/Makefile.am index 389bd15..bfa417b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,6 +18,7 @@ patchage_SOURCES = \ PatchageEvent.hpp \ PatchageModule.hpp \ PatchagePort.hpp \ + PortID.hpp \ StateManager.cpp \ StateManager.hpp \ Widget.hpp \ diff --git a/src/PatchageCanvas.cpp b/src/PatchageCanvas.cpp index e6f348b..6b610e4 100644 --- a/src/PatchageCanvas.cpp +++ b/src/PatchageCanvas.cpp @@ -65,7 +65,7 @@ PatchageCanvas::find_module(const string& name, ModuleType type) boost::shared_ptr<PatchagePort> -PatchageCanvas::find_port(const PatchageEvent::PortRef& ref) +PatchageCanvas::find_port(const PortID& id) { string module_name; string port_name; @@ -78,14 +78,14 @@ PatchageCanvas::find_port(const PatchageEvent::PortRef& ref) boost::shared_ptr<PatchagePort> pp; // TODO: filthy. keep a port map and make this O(log(n)) - switch (ref.type) { + switch (id.type) { #if defined(HAVE_JACK) && !defined(HAVE_JACK_DBUS) - case PatchageEvent::PortRef::JACK_ID: - jack_port = jack_port_by_id(_app->jack_driver()->client(), ref.id.jack_id); + case PortID::JACK_ID: + jack_port = jack_port_by_id(_app->jack_driver()->client(), id.id.jack_id); if (!jack_port) return boost::shared_ptr<PatchagePort>(); - _app->jack_driver()->port_names(ref, module_name, port_name); + _app->jack_driver()->port_names(id, module_name, port_name); module = find_module(module_name, (jack_port_flags(jack_port) & JackPortIsInput) ? Input : Output); @@ -99,7 +99,7 @@ PatchageCanvas::find_port(const PatchageEvent::PortRef& ref) #endif #ifdef HAVE_ALSA - case PatchageEvent::PortRef::ALSA_ADDR: + case PortID::ALSA_ADDR: for (ItemList::iterator m = _items.begin(); m != _items.end(); ++m) { SharedPtr<PatchageModule> module = PtrCast<PatchageModule>(*m); if (!module) @@ -115,9 +115,9 @@ PatchageCanvas::find_port(const PatchageEvent::PortRef& ref) << (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) { + && pp->alsa_addr()->client == id.id.alsa_addr.client + && pp->alsa_addr()->port == id.id.alsa_addr.port) { + if (!id.is_input && module->type() == Input) { //cerr << "WRONG DIRECTION, SKIPPED PORT" << endl; } else { return pp; diff --git a/src/PatchageCanvas.hpp b/src/PatchageCanvas.hpp index 8831414..d0a44fd 100644 --- a/src/PatchageCanvas.hpp +++ b/src/PatchageCanvas.hpp @@ -39,7 +39,7 @@ public: PatchageCanvas(Patchage* _app, int width, int height); boost::shared_ptr<PatchageModule> find_module(const string& name, ModuleType type); - boost::shared_ptr<PatchagePort> find_port(const PatchageEvent::PortRef& ref); + boost::shared_ptr<PatchagePort> find_port(const PortID& id); 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 a7a84be..06e85d5 100644 --- a/src/PatchageEvent.cpp +++ b/src/PatchageEvent.cpp @@ -58,12 +58,12 @@ PatchageEvent::execute(Patchage* patchage) } else if (_type == PORT_CREATION) { Driver* driver = NULL; - if (_port_1.type == PatchageEvent::PortRef::JACK_ID) { + if (_port_1.type == PortID::JACK_ID) { #if defined(HAVE_JACK) || defined(HAVE_JACK_DBUS) driver = patchage->jack_driver(); #endif #ifdef HAVE_ALSA - } else if (_port_1.type == PatchageEvent::PortRef::ALSA_ADDR) { + } else if (_port_1.type == PortID::ALSA_ADDR) { driver = patchage->alsa_driver(); #endif } diff --git a/src/PatchageEvent.hpp b/src/PatchageEvent.hpp index 4167146..4f39dd3 100644 --- a/src/PatchageEvent.hpp +++ b/src/PatchageEvent.hpp @@ -27,6 +27,7 @@ #include <alsa/asoundlib.h> #endif #include "PatchagePort.hpp" +#include "PortID.hpp" class Patchage; @@ -74,37 +75,10 @@ public: inline Type type() const { return (Type)_type; } - struct PortRef { - PortRef() : type(NULL_PORT_REF) { memset(&id, 0, sizeof(id)); } - -#ifdef HAVE_JACK - PortRef(jack_port_id_t jack_id, bool ign=false) - : type(JACK_ID) { id.jack_id = jack_id; } -#endif - -#ifdef HAVE_ALSA - PortRef(snd_seq_addr_t addr, bool in) - : type(ALSA_ADDR) { id.alsa_addr = addr; is_input = in; } - - bool is_input; -#endif - - enum { NULL_PORT_REF, JACK_ID, ALSA_ADDR } type; - - union { -#ifdef HAVE_JACK - jack_port_id_t jack_id; -#endif -#ifdef HAVE_ALSA - snd_seq_addr_t alsa_addr; -#endif - } id; - }; - private: char* _str; - PortRef _port_1; - PortRef _port_2; + PortID _port_1; + PortID _port_2; uint8_t _type; }; diff --git a/src/PortID.hpp b/src/PortID.hpp new file mode 100644 index 0000000..330e6c0 --- /dev/null +++ b/src/PortID.hpp @@ -0,0 +1,61 @@ +/* This file is part of Patchage. + * Copyright (C) 2008 Dave Robillard <http://drobilla.net> + * + * 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., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef PATCHAGE_PORTID_HPP +#define PATCHAGE_PORTID_HPP + +#include CONFIG_H_PATH + +#include <cstring> +#ifdef HAVE_JACK +#include <jack/jack.h> +#endif +#ifdef HAVE_ALSA +#include <alsa/asoundlib.h> +#endif + +#include "PatchagePort.hpp" + +struct PortID { + PortID() : type(NULL_PORT_ID) { memset(&id, 0, sizeof(id)); } + + enum { NULL_PORT_ID, JACK_ID, ALSA_ADDR } type; + +#ifdef HAVE_JACK + PortID(jack_port_id_t jack_id, bool ign=false) + : type(JACK_ID) { id.jack_id = jack_id; } +#endif + +#ifdef HAVE_ALSA + PortID(snd_seq_addr_t addr, bool in) + : type(ALSA_ADDR) { id.alsa_addr = addr; is_input = in; } + + bool is_input; +#endif + + union { +#ifdef HAVE_JACK + jack_port_id_t jack_id; +#endif +#ifdef HAVE_ALSA + snd_seq_addr_t alsa_addr; +#endif + } id; +}; + +#endif // PATCHAGE_PORTID_HPP + |