diff --git a/src/pw_manager.cpp b/src/pw_manager.cpp index 0802799d1..085129988 100644 --- a/src/pw_manager.cpp +++ b/src/pw_manager.cpp @@ -69,6 +69,7 @@ #include #include #include "config.h" +#include "db_manager.hpp" #include "pw_model_clients.hpp" #include "pw_model_modules.hpp" #include "pw_model_nodes.hpp" @@ -900,6 +901,12 @@ auto on_metadata_property(void* data, uint32_t id, const char* key, const char* pm->defaultOutputDeviceName = v.data(); + util::debug("new default output device: " + pm->defaultOutputDeviceName.toStdString()); + + if (db::StreamOutputs::useDefaultOutputDevice()) { + db::StreamOutputs::setOutputDevice(pm->defaultOutputDeviceName); + } + Q_EMIT pm->new_default_sink_name(pm->defaultOutputDeviceName); } @@ -914,6 +921,12 @@ auto on_metadata_property(void* data, uint32_t id, const char* key, const char* pm->defaultInputDeviceName = v.data(); + util::debug("new default input device: " + pm->defaultInputDeviceName.toStdString()); + + if (db::StreamInputs::useDefaultInputDevice()) { + db::StreamInputs::setInputDevice(pm->defaultInputDeviceName); + } + Q_EMIT pm->new_default_source_name(pm->defaultInputDeviceName); } diff --git a/src/pw_manager.hpp b/src/pw_manager.hpp index e919a44bf..97c8c66a4 100644 --- a/src/pw_manager.hpp +++ b/src/pw_manager.hpp @@ -173,29 +173,29 @@ class Manager : public QObject { void defaultInputDeviceNameChanged(); void defaultOutputDeviceNameChanged(); - void stream_input_added(NodeInfo); - void stream_output_added(NodeInfo); - void stream_input_changed(NodeInfo); - void stream_output_changed(NodeInfo); - void stream_input_removed(uint64_t); - void stream_output_removed(uint64_t); + void stream_input_added(NodeInfo node); + void stream_output_added(NodeInfo node); + void stream_input_changed(NodeInfo node); + void stream_output_changed(NodeInfo node); + void stream_input_removed(uint64_t serial); + void stream_output_removed(uint64_t serial); /* Do not pass NodeInfo by reference. Sometimes it dies before we use it and a segmentation fault happens. */ - void source_added(NodeInfo); - void source_changed(NodeInfo); - void source_removed(NodeInfo); - void sink_added(NodeInfo); - void sink_changed(NodeInfo); - void sink_removed(NodeInfo); - void new_default_sink_name(QString); - void new_default_source_name(QString); - void device_input_route_changed(DeviceInfo); - void device_output_route_changed(DeviceInfo); - - void link_changed(LinkInfo); + void source_added(NodeInfo node); + void source_changed(NodeInfo node); + void source_removed(NodeInfo node); + void sink_added(NodeInfo node); + void sink_changed(NodeInfo node); + void sink_removed(NodeInfo node); + void new_default_sink_name(QString name); + void new_default_source_name(QString name); + void device_input_route_changed(DeviceInfo device); + void device_output_route_changed(DeviceInfo device); + + void link_changed(LinkInfo link); private: pw_context* context = nullptr; diff --git a/src/stream_input_effects.cpp b/src/stream_input_effects.cpp index a696d1a59..fcb9046fd 100644 --- a/src/stream_input_effects.cpp +++ b/src/stream_input_effects.cpp @@ -54,75 +54,65 @@ StreamInputEffects::StreamInputEffects(pw::Manager* pipe_manager) : EffectsBase( } } - // connections.push_back(pm->source_added.connect([this](const NodeInfo node) { - // if (node.name == util::gsettings_get_string(settings, "input-device")) { - // pm->input_device = node; - - // if (g_settings_get_boolean(global_settings, "bypass") != 0) { - // g_settings_set_boolean(global_settings, "bypass", 0); + connect(pm, &pw::Manager::source_added, [&](pw::NodeInfo node) { + if (node.name == db::StreamInputs::inputDevice()) { + pm->input_device = node; - // return; // filter connected through update_bypass_state - // } + if (db::Main::bypass()) { + db::Main::setBypass(false); - // set_bypass(false); - // } - // })); - - // connections.push_back(pm->source_removed.connect([this](const NodeInfo node) { - // if (g_settings_get_boolean(settings, "use-default-input-device") == 0) { - // if (node.name == util::gsettings_get_string(settings, "input-device")) { - // pm->input_device.id = SPA_ID_INVALID; - // pm->input_device.serial = SPA_ID_INVALID; - // } - // } - // })); + return; // filter connected through update_bypass_state + } - // connections.push_back(pm->stream_input_added.connect(sigc::mem_fun(*this, &StreamInputEffects::on_app_added))); - // connections.push_back(pm->link_changed.connect(sigc::mem_fun(*this, &StreamInputEffects::on_link_changed))); + set_bypass(false); + } + }); - connect_filters(); + connect(pm, &pw::Manager::source_removed, [&](pw::NodeInfo node) { + if (db::StreamInputs::useDefaultInputDevice() && node.name == db::StreamInputs::inputDevice()) { + pm->input_device.id = SPA_ID_INVALID; + pm->input_device.serial = SPA_ID_INVALID; + } + }); - // gconnections.push_back(g_signal_connect(settings, "changed::input-device", - // G_CALLBACK(+[](GSettings* settings, char* key, gpointer user_data) { - // auto* self = static_cast(user_data); + connect(pm, &pw::Manager::stream_input_added, this, &StreamInputEffects::on_app_added); + connect(pm, &pw::Manager::link_changed, this, &StreamInputEffects::on_link_changed); - // const auto name = util::gsettings_get_string(settings, key); + connect_filters(); - // if (name.empty()) { - // return; - // } + connect(db::StreamInputs::self(), &db::StreamInputs::inputDeviceChanged, [&]() { + const auto name = db::StreamInputs::inputDevice(); - // for (const auto& [serial, node] : self->pm->node_map) { - // if (node.name == name) { - // self->pm->input_device = node; + if (name.isEmpty()) { + return; + } - // if (g_settings_get_boolean(self->global_settings, "bypass") != 0) { - // g_settings_set_boolean(self->global_settings, "bypass", 0); + for (const auto& [serial, node] : pm->node_map) { + if (node.name == name) { + pm->input_device = node; - // return; // filter connected through update_bypass_state - // } + if (db::Main::bypass()) { + db::Main::setBypass(false); - // self->set_bypass(false); + return; // filter connected through update_bypass_state + } - // break; - // } - // } - // }), - // this)); + set_bypass(false); - // gconnections.push_back(g_signal_connect(settings, "changed::plugins", - // G_CALLBACK(+[](GSettings* settings, char* key, gpointer user_data) { - // auto* self = static_cast(user_data); + break; + } + } + }); - // if (g_settings_get_boolean(self->global_settings, "bypass") != 0) { - // g_settings_set_boolean(self->global_settings, "bypass", 0); + connect(db::StreamInputs::self(), &db::StreamInputs::pluginsChanged, [&]() { + if (db::Main::bypass()) { + db::Main::setBypass(false); - // return; // filter connected through update_bypass_state - // } + return; // filter connected through update_bypass_state + } - // self->set_bypass(false); - // }), - // this)); + set_bypass(false); + }); } StreamInputEffects::~StreamInputEffects() { diff --git a/src/stream_output_effects.cpp b/src/stream_output_effects.cpp index 910570fa2..0abd06db5 100644 --- a/src/stream_output_effects.cpp +++ b/src/stream_output_effects.cpp @@ -55,74 +55,64 @@ StreamOutputEffects::StreamOutputEffects(pw::Manager* pipe_manager) : EffectsBas } } - // connections.push_back(pm->sink_added.connect([this](const NodeInfo node) { - // if (node.name == util::gsettings_get_string(settings, "output-device")) { - // pm->output_device = node; - - // if (g_settings_get_boolean(global_settings, "bypass") != 0) { - // g_settings_set_boolean(global_settings, "bypass", 0); + connect(pm, &pw::Manager::sink_added, [&](pw::NodeInfo node) { + if (node.name == db::StreamOutputs::outputDevice()) { + pm->output_device = node; - // return; // filter connected through update_bypass_state - // } + if (db::Main::bypass()) { + db::Main::setBypass(false); - // set_bypass(false); - // } - // })); - - // connections.push_back(pm->sink_removed.connect([this](const NodeInfo node) { - // if (g_settings_get_boolean(settings, "use-default-output-device") == 0) { - // if (node.name == util::gsettings_get_string(settings, "output-device")) { - // pm->output_device.id = SPA_ID_INVALID; - // pm->output_device.serial = SPA_ID_INVALID; - // } - // } - // })); + return; // filter connected through update_bypass_state + } - // connections.push_back(pm->stream_output_added.connect(sigc::mem_fun(*this, &StreamOutputEffects::on_app_added))); + set_bypass(false); + } + }); - connect_filters(); + connect(pm, &pw::Manager::sink_removed, [&](pw::NodeInfo node) { + if (db::StreamOutputs::useDefaultOutputDevice() && node.name == db::StreamOutputs::outputDevice()) { + pm->output_device.id = SPA_ID_INVALID; + pm->output_device.serial = SPA_ID_INVALID; + } + }); - // gconnections.push_back(g_signal_connect(settings, "changed::output-device", - // G_CALLBACK(+[](GSettings* settings, char* key, gpointer user_data) { - // auto* self = static_cast(user_data); + connect(pm, &pw::Manager::stream_output_added, this, &StreamOutputEffects::on_app_added); - // const auto name = util::gsettings_get_string(settings, key); + connect_filters(); - // if (name.empty()) { - // return; - // } + connect(db::StreamOutputs::self(), &db::StreamOutputs::outputDeviceChanged, [&]() { + const auto name = db::StreamOutputs::outputDevice(); - // for (const auto& [serial, node] : self->pm->node_map) { - // if (node.name == name) { - // self->pm->output_device = node; + if (name.isEmpty()) { + return; + } - // if (g_settings_get_boolean(self->global_settings, "bypass") != 0) { - // g_settings_set_boolean(self->global_settings, "bypass", 0); + for (const auto& [serial, node] : pm->node_map) { + if (node.name == name) { + pm->output_device = node; - // return; // filter connected through update_bypass_state - // } + if (db::Main::bypass()) { + db::Main::setBypass(false); - // self->set_bypass(false); + return; // filter connected through update_bypass_state + } - // break; - // } - // } - // }), - // this)); + set_bypass(false); - // gconnections.push_back(g_signal_connect(settings, "changed::plugins", - // G_CALLBACK(+[](GSettings* settings, char* key, gpointer user_data) { - // auto* self = static_cast(user_data); + break; + } + } + }); - // if (g_settings_get_boolean(self->global_settings, "bypass") != 0) { - // g_settings_set_boolean(self->global_settings, "bypass", 0); + connect(db::StreamOutputs::self(), &db::StreamOutputs::pluginsChanged, [&]() { + if (db::Main::bypass()) { + db::Main::setBypass(false); - // return; // filter connected through update_bypass_state - // } + return; // filter connected through update_bypass_state + } - // self->set_bypass(false); - // }), - // this)); + set_bypass(false); + }); } StreamOutputEffects::~StreamOutputEffects() { @@ -303,12 +293,13 @@ void StreamOutputEffects::disconnect_filters() { } } - // for (const auto& link : pm->list_links) { - // if (link.input_node_id == spectrum->get_node_id() || link.output_node_id == spectrum->get_node_id() || - // link.input_node_id == output_level->get_node_id() || link.output_node_id == output_level->get_node_id()) { - // link_id_list.insert(link.id); - // } - // } + for (const auto& link : pm->list_links) { + // if (link.input_node_id == spectrum->get_node_id() || link.output_node_id == spectrum->get_node_id() || + // link.input_node_id == output_level->get_node_id() || link.output_node_id == output_level->get_node_id()) + // { + // link_id_list.insert(link.id); + // } + } for (const auto& id : link_id_list) { pm->destroy_object(static_cast(id));