summaryrefslogtreecommitdiffstats
path: root/src/Canvas.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Canvas.cpp')
-rw-r--r--src/Canvas.cpp120
1 files changed, 57 insertions, 63 deletions
diff --git a/src/Canvas.cpp b/src/Canvas.cpp
index d86049d..3624933 100644
--- a/src/Canvas.cpp
+++ b/src/Canvas.cpp
@@ -1,29 +1,20 @@
-/* This file is part of Patchage.
- * Copyright 2007-2021 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/>.
- */
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: GPL-3.0-or-later
#include "Canvas.hpp"
#include "Action.hpp"
+#include "ActionSink.hpp"
#include "CanvasModule.hpp"
#include "CanvasPort.hpp"
+#include "ClientID.hpp"
#include "ClientInfo.hpp"
+#include "ClientType.hpp"
#include "Configuration.hpp"
#include "Coord.hpp"
#include "ILog.hpp"
#include "Metadata.hpp"
+#include "PortID.hpp"
#include "PortInfo.hpp"
#include "PortNames.hpp"
#include "Setting.hpp"
@@ -31,19 +22,19 @@
#include "warnings.hpp"
PATCHAGE_DISABLE_GANV_WARNINGS
+#include "ganv/Canvas.hpp"
#include "ganv/Edge.hpp"
#include "ganv/Module.hpp"
#include "ganv/Node.hpp"
#include "ganv/Port.hpp"
#include "ganv/module.h"
+#include "ganv/types.h"
PATCHAGE_RESTORE_WARNINGS
PATCHAGE_DISABLE_FMT_WARNINGS
#include <fmt/core.h>
-#include <fmt/ostream.h>
PATCHAGE_RESTORE_WARNINGS
-#include <boost/optional/optional.hpp>
#include <gdk/gdkkeysyms.h>
#include <sigc++/functors/mem_fun.h>
#include <sigc++/signal.h>
@@ -51,12 +42,58 @@ PATCHAGE_RESTORE_WARNINGS
#include <cassert>
#include <cstdlib>
#include <functional>
-#include <iosfwd>
+#include <optional>
#include <set>
#include <string>
#include <utility>
namespace patchage {
+namespace {
+
+struct RemovePortsData {
+ using Predicate = bool (*)(const CanvasPort*);
+
+ explicit RemovePortsData(Predicate p)
+ : pred(p)
+ {}
+
+ Predicate pred;
+ std::set<ClientID> empty_clients;
+};
+
+void
+delete_port_if_matches(GanvPort* port, void* cdata)
+{
+ auto* data = static_cast<RemovePortsData*>(cdata);
+ auto* pport = dynamic_cast<CanvasPort*>(Glib::wrap(port));
+ if (pport && data->pred(pport)) {
+ delete pport;
+ }
+}
+
+void
+remove_ports_matching(GanvNode* node, void* cdata)
+{
+ if (!GANV_IS_MODULE(node)) {
+ return;
+ }
+
+ Ganv::Module* cmodule = Glib::wrap(GANV_MODULE(node));
+ auto* pmodule = dynamic_cast<CanvasModule*>(cmodule);
+ if (!pmodule) {
+ return;
+ }
+
+ auto* data = static_cast<RemovePortsData*>(cdata);
+
+ pmodule->for_each_port(delete_port_if_matches, data);
+
+ if (pmodule->num_ports() == 0) {
+ data->empty_clients.insert(pmodule->id());
+ }
+}
+
+} // namespace
Canvas::Canvas(ILog& log, ActionSink& action_sink, int width, int height)
: Ganv::Canvas(width, height)
@@ -85,7 +122,7 @@ Canvas::create_port(Configuration& conf,
const auto client_info = metadata.client(client_id);
if (!client_info) {
_log.error(fmt::format(
- R"(Unable to add port "{}", client "{}" is unknown)", id, client_id));
+ u8"(Unable to add port “{}”, client “{}” is unknown)", id, client_id));
return nullptr;
}
@@ -123,7 +160,7 @@ Canvas::create_port(Configuration& conf,
if (parent->get_port(id)) {
// TODO: Update existing port?
_log.error(fmt::format(
- R"(Module "{}" already has port "{}")", client_name, port_name));
+ u8"(Module “{}” already has port “{}”)", client_name, port_name));
return nullptr;
}
@@ -192,49 +229,6 @@ Canvas::remove_port(const PortID& id)
delete port;
}
-struct RemovePortsData {
- using Predicate = bool (*)(const CanvasPort*);
-
- explicit RemovePortsData(Predicate p)
- : pred(p)
- {}
-
- Predicate pred;
- std::set<ClientID> empty_clients;
-};
-
-static void
-delete_port_if_matches(GanvPort* port, void* cdata)
-{
- auto* data = static_cast<RemovePortsData*>(cdata);
- auto* pport = dynamic_cast<CanvasPort*>(Glib::wrap(port));
- if (pport && data->pred(pport)) {
- delete pport;
- }
-}
-
-static void
-remove_ports_matching(GanvNode* node, void* cdata)
-{
- if (!GANV_IS_MODULE(node)) {
- return;
- }
-
- Ganv::Module* cmodule = Glib::wrap(GANV_MODULE(node));
- auto* pmodule = dynamic_cast<CanvasModule*>(cmodule);
- if (!pmodule) {
- return;
- }
-
- auto* data = static_cast<RemovePortsData*>(cdata);
-
- pmodule->for_each_port(delete_port_if_matches, data);
-
- if (pmodule->num_ports() == 0) {
- data->empty_clients.insert(pmodule->id());
- }
-}
-
void
Canvas::remove_ports(bool (*pred)(const CanvasPort*))
{