summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-11-27 21:02:35 +0100
committerDavid Robillard <d@drobilla.net>2020-11-27 21:52:29 +0100
commitf6a72b69f8660ec1aaa6fb00ee9907e798835a25 (patch)
treebb795dfd30c383deaa76aa792c709cf8f0218f68
parent2e7a3b3bc94f8d68475883c845f31ee42cba115c (diff)
downloadpatchage-f6a72b69f8660ec1aaa6fb00ee9907e798835a25.tar.gz
patchage-f6a72b69f8660ec1aaa6fb00ee9907e798835a25.tar.bz2
patchage-f6a72b69f8660ec1aaa6fb00ee9907e798835a25.zip
Ensure that modules always have an ID
-rw-r--r--src/AlsaDriver.cpp4
-rw-r--r--src/ClientID.hpp108
-rw-r--r--src/JackDbusDriver.cpp2
-rw-r--r--src/JackDriver.cpp7
-rw-r--r--src/PatchageModule.cpp2
-rw-r--r--src/PatchageModule.hpp4
6 files changed, 123 insertions, 4 deletions
diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp
index 65a2a64..9487d87 100644
--- a/src/AlsaDriver.cpp
+++ b/src/AlsaDriver.cpp
@@ -16,6 +16,7 @@
#include "AlsaDriver.hpp"
+#include "ClientID.hpp"
#include "Patchage.hpp"
#include "PatchageCanvas.hpp"
#include "PatchageModule.hpp"
@@ -222,7 +223,8 @@ AlsaDriver::find_or_create_module(Patchage* patchage,
{
PatchageModule* m = find_module(client_id, type);
if (!m) {
- m = new PatchageModule(patchage, client_name, type);
+ m = new PatchageModule(
+ patchage, client_name, type, ClientID::alsa(client_id));
m->load_location();
_app->canvas()->add_module(client_name, m);
_modules.insert(std::make_pair(client_id, m));
diff --git a/src/ClientID.hpp b/src/ClientID.hpp
new file mode 100644
index 0000000..665c237
--- /dev/null
+++ b/src/ClientID.hpp
@@ -0,0 +1,108 @@
+/* This file is part of Patchage.
+ * Copyright 2020 David Robillard <d@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 3 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 Patchage. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PATCHAGE_CLIENTID_HPP
+#define PATCHAGE_CLIENTID_HPP
+
+#include <cassert>
+#include <cstdint>
+#include <ostream>
+#include <string>
+#include <utility>
+
+/// An ID for some client (program) that has ports
+struct ClientID
+{
+ enum class Type
+ {
+ jack,
+ alsa,
+ };
+
+ ClientID(const ClientID& copy) = default;
+ ClientID& operator=(const ClientID& copy) = default;
+
+ ClientID(ClientID&& id) = default;
+ ClientID& operator=(ClientID&& id) = default;
+
+ ~ClientID() = default;
+
+ /// Return an ID for a JACK client by name
+ static ClientID jack(std::string name)
+ {
+ return ClientID{Type::jack, std::move(name)};
+ }
+
+ /// Return an ID for an ALSA Sequencer client by ID
+ static ClientID alsa(const uint8_t id) { return ClientID{Type::alsa, id}; }
+
+ Type type() const { return _type; }
+ const std::string& jack_name() const { return _jack_name; }
+ uint8_t alsa_id() const { return _alsa_id; }
+
+private:
+ ClientID(const Type type, std::string jack_name)
+ : _type{type}
+ , _jack_name{std::move(jack_name)}
+ {
+ assert(_type == Type::jack);
+ }
+
+ ClientID(const Type type, uint8_t alsa_id)
+ : _type{type}
+ , _alsa_id{alsa_id}
+ {
+ assert(_type == Type::alsa);
+ }
+
+ Type _type; ///< Type that determines which field is active
+ std::string _jack_name{}; ///< Client name for Type::jack
+ uint8_t _alsa_id{}; ///< Client ID for Type::alsa
+};
+
+static inline std::ostream&
+operator<<(std::ostream& os, const ClientID& id)
+{
+ switch (id.type()) {
+ case ClientID::Type::jack:
+ return os << "jack:" << id.jack_name();
+ case ClientID::Type::alsa:
+ return os << "alsa:" << int(id.alsa_id());
+ }
+
+ assert(false);
+ return os;
+}
+
+static inline bool
+operator<(const ClientID& lhs, const ClientID& rhs)
+{
+ if (lhs.type() != rhs.type()) {
+ return lhs.type() < rhs.type();
+ }
+
+ switch (lhs.type()) {
+ case ClientID::Type::jack:
+ return lhs.jack_name() < rhs.jack_name();
+ case ClientID::Type::alsa:
+ return lhs.alsa_id() < rhs.alsa_id();
+ }
+
+ assert(false);
+ return false;
+}
+
+#endif // PATCHAGE_CLIENTID_HPP
diff --git a/src/JackDbusDriver.cpp b/src/JackDbusDriver.cpp
index fbd8bf4..073d54b 100644
--- a/src/JackDbusDriver.cpp
+++ b/src/JackDbusDriver.cpp
@@ -684,7 +684,7 @@ JackDriver::find_or_create_module(ModuleType type, const std::string& name)
PatchageModule* module = _app->canvas()->find_module(name, type);
if (!module) {
- module = new PatchageModule(_app, name, type);
+ module = new PatchageModule(_app, name, type, ClientID::jack(name));
module->load_location();
_app->canvas()->add_module(name, module);
}
diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp
index b3f4be0..2807791 100644
--- a/src/JackDriver.cpp
+++ b/src/JackDriver.cpp
@@ -16,6 +16,7 @@
#include "JackDriver.hpp"
+#include "ClientID.hpp"
#include "ILog.hpp"
#include "Patchage.hpp"
#include "PatchageCanvas.hpp"
@@ -166,7 +167,8 @@ JackDriver::create_port_view(Patchage* patchage, const PortID& id)
PatchageModule* parent = _app->canvas()->find_module(module_name, type);
if (!parent) {
- parent = new PatchageModule(patchage, module_name, type);
+ parent = new PatchageModule(
+ patchage, module_name, type, ClientID::jack(module_name));
parent->load_location();
patchage->canvas()->add_module(module_name, parent);
}
@@ -326,7 +328,8 @@ JackDriver::refresh()
PatchageModule* m = _app->canvas()->find_module(client1_name, type);
if (!m) {
- m = new PatchageModule(_app, client1_name, type);
+ m = new PatchageModule(
+ _app, client1_name, type, ClientID::jack(client1_name));
m->load_location();
_app->canvas()->add_module(client1_name, m);
}
diff --git a/src/PatchageModule.cpp b/src/PatchageModule.cpp
index 31c30a8..574757f 100644
--- a/src/PatchageModule.cpp
+++ b/src/PatchageModule.cpp
@@ -23,6 +23,7 @@
PatchageModule::PatchageModule(Patchage* app,
const std::string& name,
ModuleType type,
+ ClientID id,
double x,
double y)
: Module(*app->canvas(), name, x, y)
@@ -30,6 +31,7 @@ PatchageModule::PatchageModule(Patchage* app,
, _menu(nullptr)
, _name(name)
, _type(type)
+ , _id(std::move(id))
{
signal_event().connect(sigc::mem_fun(this, &PatchageModule::on_event));
diff --git a/src/PatchageModule.hpp b/src/PatchageModule.hpp
index aa25546..e5abe43 100644
--- a/src/PatchageModule.hpp
+++ b/src/PatchageModule.hpp
@@ -17,6 +17,7 @@
#ifndef PATCHAGE_PATCHAGEMODULE_HPP
#define PATCHAGE_PATCHAGEMODULE_HPP
+#include "ClientID.hpp"
#include "Configuration.hpp"
#include "warnings.hpp"
@@ -38,6 +39,7 @@ public:
PatchageModule(Patchage* app,
const std::string& name,
ModuleType type,
+ ClientID id,
double x = 0,
double y = 0);
@@ -63,6 +65,7 @@ public:
void store_location(double x, double y);
ModuleType type() const { return _type; }
+ ClientID id() const { return _id; }
const std::string& name() const { return _name; }
protected:
@@ -72,6 +75,7 @@ protected:
Gtk::Menu* _menu;
std::string _name;
ModuleType _type;
+ ClientID _id;
};
#endif // PATCHAGE_PATCHAGEMODULE_HPP