summaryrefslogtreecommitdiffstats
path: root/src/PatchageCanvas.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-11-28 21:41:26 +0100
committerDavid Robillard <d@drobilla.net>2020-11-28 22:49:10 +0100
commit5128bfab7ddb9504abf17375e910e5bc94af291e (patch)
tree79cc0953718e1f79ed47282b9f11f9f087edc3bc /src/PatchageCanvas.cpp
parent0f25dd575f9c74cc34a54e64468f07e6c631750d (diff)
downloadpatchage-5128bfab7ddb9504abf17375e910e5bc94af291e.tar.gz
patchage-5128bfab7ddb9504abf17375e910e5bc94af291e.tar.bz2
patchage-5128bfab7ddb9504abf17375e910e5bc94af291e.zip
Refresh by emitting events
This decouples drivers from the rest of the application, in particular the horrible situation where they were working with the canvas directly, by having them always communicate changes by emitting events.
Diffstat (limited to 'src/PatchageCanvas.cpp')
-rw-r--r--src/PatchageCanvas.cpp87
1 files changed, 86 insertions, 1 deletions
diff --git a/src/PatchageCanvas.cpp b/src/PatchageCanvas.cpp
index b94806d..bb9c484 100644
--- a/src/PatchageCanvas.cpp
+++ b/src/PatchageCanvas.cpp
@@ -19,8 +19,10 @@
#include "patchage_config.h"
#include "Connector.hpp"
+#include "Patchage.hpp"
#include "PatchageModule.hpp"
#include "PatchagePort.hpp"
+#include "PortNames.hpp"
#include "SignalDirection.hpp"
#include "warnings.hpp"
@@ -30,6 +32,11 @@ PATCHAGE_DISABLE_GANV_WARNINGS
#include "ganv/Edge.hpp"
PATCHAGE_RESTORE_WARNINGS
+PATCHAGE_DISABLE_FMT_WARNINGS
+#include <fmt/core.h>
+#include <fmt/ostream.h>
+PATCHAGE_RESTORE_WARNINGS
+
PatchageCanvas::PatchageCanvas(Connector& connector, int width, int height)
: Ganv::Canvas(width, height)
, _connector(connector)
@@ -41,6 +48,84 @@ PatchageCanvas::PatchageCanvas(Connector& connector, int width, int height)
}
PatchageModule*
+PatchageCanvas::create_module(Patchage& patchage,
+ const ClientID& id,
+ const ClientInfo& info)
+{
+ (void)patchage;
+ (void)id;
+ (void)info;
+ return nullptr;
+}
+
+PatchagePort*
+PatchageCanvas::create_port(Patchage& patchage,
+ const PortID& id,
+ const PortInfo& info)
+{
+ const auto client_id = id.client();
+
+ const auto port_name =
+ ((id.type() == PortID::Type::alsa) ? info.label : PortNames(id).port());
+
+ // Figure out the client name, for ALSA we need the metadata cache
+ std::string client_name;
+ if (id.type() == PortID::Type::alsa) {
+ const auto client_info = patchage.metadata().client(client_id);
+ if (!client_info.has_value()) {
+ patchage.log().error(fmt::format(
+ "Unable to add port \"{}\", client \"{}\" is unknown",
+ id,
+ client_id));
+
+ return nullptr;
+ }
+
+ client_name = client_info->label;
+ } else {
+ client_name = PortNames(id).client();
+ }
+
+ // Determine the module type to place the port on in case of splitting
+ SignalDirection module_type = SignalDirection::duplex;
+ if (patchage.conf()->get_module_split(client_name, info.is_terminal)) {
+ module_type = info.direction;
+ }
+
+ // Find or create parent module
+ PatchageModule* parent = find_module(client_id, module_type);
+ if (!parent) {
+ parent =
+ new PatchageModule(&patchage, client_name, module_type, client_id);
+
+ parent->load_location();
+ add_module(client_id, parent);
+ }
+
+ if (parent->get_port(id)) {
+ // TODO: Update existing port?
+ patchage.log().error(fmt::format(
+ "Module \"{}\" already has port \"{}\"", client_name, port_name));
+ return nullptr;
+ }
+
+ auto* const port =
+ new PatchagePort(*parent,
+ info.type,
+ id,
+ port_name,
+ info.label,
+ info.direction == SignalDirection::input,
+ patchage.conf()->get_port_color(info.type),
+ patchage.show_human_names(),
+ info.order);
+
+ index_port(id, port);
+
+ return port;
+}
+
+PatchageModule*
PatchageCanvas::find_module(const ClientID& id, const SignalDirection type)
{
auto i = _module_index.find(id);
@@ -199,7 +284,7 @@ PatchageCanvas::add_module(const ClientID& id, PatchageModule* module)
in_module = module;
out_module = find_module(id, SignalDirection::output);
} else if (module->type() == SignalDirection::output) {
- in_module = find_module(id, SignalDirection::output);
+ in_module = find_module(id, SignalDirection::input);
out_module = module;
}