summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Metadata.cpp73
-rw-r--r--src/Metadata.hpp53
-rw-r--r--src/Patchage.hpp3
-rw-r--r--src/handle_event.cpp6
4 files changed, 134 insertions, 1 deletions
diff --git a/src/Metadata.cpp b/src/Metadata.cpp
new file mode 100644
index 0000000..d717387
--- /dev/null
+++ b/src/Metadata.cpp
@@ -0,0 +1,73 @@
+/* This file is part of Patchage.
+ * Copyright 2014-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/>.
+ */
+
+#include "Metadata.hpp"
+
+boost::optional<ClientInfo>
+Metadata::client(const ClientID& id)
+{
+ const auto i = _client_data.find(id);
+ if (i == _client_data.end()) {
+ return {};
+ }
+
+ return i->second;
+}
+
+boost::optional<PortInfo>
+Metadata::port(const PortID& id)
+{
+ const auto i = _port_data.find(id);
+ if (i == _port_data.end()) {
+ return {};
+ }
+
+ return i->second;
+}
+
+void
+Metadata::set_client(const ClientID& id, const ClientInfo& info)
+{
+ const auto i = _client_data.find(id);
+ if (i == _client_data.end()) {
+ _client_data.emplace(id, info);
+ } else {
+ i->second = info;
+ }
+}
+
+void
+Metadata::set_port(const PortID& id, const PortInfo& info)
+{
+ const auto i = _port_data.find(id);
+ if (i == _port_data.end()) {
+ _port_data.emplace(id, info);
+ } else {
+ i->second = info;
+ }
+}
+
+void
+Metadata::erase_client(const ClientID& id)
+{
+ _client_data.erase(id);
+}
+
+void
+Metadata::erase_port(const PortID& id)
+{
+ _port_data.erase(id);
+}
diff --git a/src/Metadata.hpp b/src/Metadata.hpp
new file mode 100644
index 0000000..4e4a946
--- /dev/null
+++ b/src/Metadata.hpp
@@ -0,0 +1,53 @@
+/* This file is part of Patchage.
+ * Copyright 2007-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_METADATA_HPP
+#define PATCHAGE_METADATA_HPP
+
+#include "ClientID.hpp"
+#include "ClientInfo.hpp"
+#include "PortID.hpp"
+#include "PortInfo.hpp"
+
+#include <boost/optional.hpp>
+
+#include <map>
+#include <string>
+
+/// Cache of metadata about clients and ports beyond their IDs
+class Metadata
+{
+public:
+ Metadata() = default;
+
+ boost::optional<ClientInfo> client(const ClientID& id);
+ boost::optional<PortInfo> port(const PortID& id);
+
+ void set_client(const ClientID& id, const ClientInfo& info);
+ void set_port(const PortID& id, const PortInfo& info);
+
+ void erase_client(const ClientID& id);
+ void erase_port(const PortID& id);
+
+private:
+ using ClientData = std::map<ClientID, ClientInfo>;
+ using PortData = std::map<PortID, PortInfo>;
+
+ ClientData _client_data;
+ PortData _port_data;
+};
+
+#endif // PATCHAGE_METADATA_HPP
diff --git a/src/Patchage.hpp b/src/Patchage.hpp
index 19b2e9f..daae7c7 100644
--- a/src/Patchage.hpp
+++ b/src/Patchage.hpp
@@ -41,6 +41,7 @@
#include "Connector.hpp"
#include "ILog.hpp"
#include "Legend.hpp"
+#include "Metadata.hpp"
#include "TextViewLog.hpp"
#include "Widget.hpp"
#include "patchage_config.h"
@@ -74,6 +75,7 @@ public:
Gtk::Window* window() { return _main_win.get(); }
ILog& log() { return _log; }
+ Metadata& metadata() { return _metadata; }
Configuration* conf() const { return _conf; }
JackDriver* jack_driver() const { return _jack_driver; }
@@ -212,6 +214,7 @@ protected:
Legend* _legend;
TextViewLog _log;
Connector _connector;
+ Metadata _metadata;
Glib::RefPtr<Gtk::TextTag> _error_tag;
Glib::RefPtr<Gtk::TextTag> _warning_tag;
diff --git a/src/handle_event.cpp b/src/handle_event.cpp
index 47b2557..2bd3609 100644
--- a/src/handle_event.cpp
+++ b/src/handle_event.cpp
@@ -51,14 +51,16 @@ public:
: _patchage{patchage}
{}
- void operator()(const ClientCreationEvent&)
+ void operator()(const ClientCreationEvent& event)
{
// Don't create empty modules, they will be created when ports are added
+ _patchage.metadata().set_client(event.id, event.info);
}
void operator()(const ClientDestructionEvent& event)
{
_patchage.canvas()->remove_module(event.id);
+ _patchage.metadata().erase_client(event.id);
}
void operator()(const PortCreationEvent& event)
@@ -73,6 +75,7 @@ public:
driver = _patchage.alsa_driver();
#endif
}
+ _patchage.metadata().set_port(event.id, event.info);
if (driver) {
PatchagePort* port = driver->create_port_view(&_patchage, event.id);
@@ -89,6 +92,7 @@ public:
void operator()(const PortDestructionEvent& event)
{
_patchage.canvas()->remove_port(event.id);
+ _patchage.metadata().erase_port(event.id);
}
void operator()(const ConnectionEvent& event)