diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b38144..800cda8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,7 +81,7 @@ include("cmake/cpm.cmake") CPMFindPackage( NAME rohrkabel - VERSION 3.1 + VERSION 4.1 GIT_REPOSITORY "https://github.com/Curve/rohrkabel" ) @@ -105,7 +105,7 @@ CPMFindPackage( CPMFindPackage( NAME glaze - VERSION 2.4.0 + VERSION 2.4.5 GIT_REPOSITORY "https://github.com/stephenberry/glaze" ) diff --git a/private/patchbay.impl.hpp b/private/patchbay.impl.hpp index b6d33ac..63de144 100644 --- a/private/patchbay.impl.hpp +++ b/private/patchbay.impl.hpp @@ -6,12 +6,18 @@ #include #include #include +#include + +#include #include #include #include +#include #include + +#include #include namespace vencord @@ -40,8 +46,11 @@ namespace vencord link_options options; private: - std::unique_ptr virt_mic; std::optional speaker; + std::unique_ptr listener; + + private: + std::unique_ptr virt_mic; std::multimap created; private: @@ -68,8 +77,14 @@ namespace vencord private: void create_mic(); void cleanup(bool); + + private: + void relink_all(); void relink(std::uint32_t); + private: + void meta_update(std::string_view, pw::metadata_property); + private: template void bind(const pw::global &); diff --git a/src/patchbay.impl.cpp b/src/patchbay.impl.cpp index 8a60118..6950b1c 100644 --- a/src/patchbay.impl.cpp +++ b/src/patchbay.impl.cpp @@ -87,6 +87,23 @@ namespace vencord virt_mic.reset(); } + void patchbay::impl::relink_all() + { + cleanup(false); + + for (const auto &[id, info] : nodes) + { + on_node(id); + } + + for (const auto &[id, info] : links) + { + on_link(id); + } + + logger::get()->debug("[patchbay] (relink_all) relinked all targets"); + } + void patchbay::impl::relink(std::uint32_t id) { created.erase(id); @@ -177,6 +194,29 @@ namespace vencord } } + void patchbay::impl::meta_update(std::string_view key, pw::metadata_property prop) + { + logger::get()->debug(R"([patchbay] (meta_update) metadata property changed: "{}" (value: "{}"))", key, + prop.value); + + if (key != "default.audio.sink") + { + return; + } + + auto parsed = glz::read_json(prop.value); + + if (!parsed.has_value()) + { + logger::get()->warn("[patchbay] (meta_update) failed to parse speaker"); + return; + } + + speaker.emplace(parsed->name); + + relink_all(); + } + template <> void patchbay::impl::add_global(pw::node &node) { @@ -265,13 +305,15 @@ namespace vencord auto props = data.properties(); const auto name = data.props()["metadata.name"]; + logger::get()->trace(R"([patchbay] (add_global) new metadata: {} (name: "{}"))", data.id(), name); + if (name != "default") { return; } metadata = std::make_unique(std::move(data)); - logger::get()->info("[patchbay] (add_global) found metadata: {}", metadata->id()); + logger::get()->info("[patchbay] (add_global) found default metadata: {}", metadata->id()); auto parsed = glz::read_json(props["default.audio.sink"].value); @@ -281,10 +323,18 @@ namespace vencord return; } - logger::get()->debug("[patchbay] (add_global) speakers name: \"{}\"", parsed->name); + listener = std::make_unique(metadata->listen()); + logger::get()->debug("[patchbay] (add_global) speaker name: \"{}\"", parsed->name); speaker.emplace(parsed->name); + listener->on( + [this](auto... args) + { + meta_update(args...); + return 0; + }); + for (const auto &[id, info] : nodes) { on_node(id); @@ -309,6 +359,8 @@ namespace vencord template <> void patchbay::impl::add_global(const pw::global &global) { + logger::get()->trace(R"([patchbay] (add_global) new global: {} (type: "{}"))", global.id, global.type); + if (global.type == pw::node::type) { bind(global); @@ -461,19 +513,9 @@ namespace vencord create_mic(); } - cleanup(false); - options = std::move(req); - for (const auto &[id, info] : nodes) - { - on_node(id); - } - - for (const auto &[id, info] : links) - { - on_link(id); - } + relink_all(); } template <>