From ce4f43343f7554d550e71ca16d9b5ce1ce5fcc13 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 28 Nov 2020 21:11:58 +0100 Subject: Add separate store for client and port metadata --- src/Metadata.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/Metadata.hpp | 53 ++++++++++++++++++++++++++++++++++++++ src/Patchage.hpp | 3 +++ src/handle_event.cpp | 6 ++++- wscript | 1 + 5 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 src/Metadata.cpp create mode 100644 src/Metadata.hpp 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 + * + * 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 . + */ + +#include "Metadata.hpp" + +boost::optional +Metadata::client(const ClientID& id) +{ + const auto i = _client_data.find(id); + if (i == _client_data.end()) { + return {}; + } + + return i->second; +} + +boost::optional +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 + * + * 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 . + */ + +#ifndef PATCHAGE_METADATA_HPP +#define PATCHAGE_METADATA_HPP + +#include "ClientID.hpp" +#include "ClientInfo.hpp" +#include "PortID.hpp" +#include "PortInfo.hpp" + +#include + +#include +#include + +/// Cache of metadata about clients and ports beyond their IDs +class Metadata +{ +public: + Metadata() = default; + + boost::optional client(const ClientID& id); + boost::optional 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; + using PortData = std::map; + + 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 _error_tag; Glib::RefPtr _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) diff --git a/wscript b/wscript index 2072907..3aa7c2f 100644 --- a/wscript +++ b/wscript @@ -244,6 +244,7 @@ def build(bld): src/Configuration.cpp src/Connector.cpp src/Legend.cpp + src/Metadata.cpp src/Patchage.cpp src/PatchageCanvas.cpp src/PatchageModule.cpp -- cgit v1.2.1