Skip to content

Commit

Permalink
porting the backend classes to Qt
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmm committed Oct 1, 2024
1 parent 8eb31d3 commit d2d5247
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 129 deletions.
13 changes: 13 additions & 0 deletions src/pw_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#include <thread>
#include <vector>
#include "config.h"
#include "db_manager.hpp"
#include "pw_model_clients.hpp"
#include "pw_model_modules.hpp"
#include "pw_model_nodes.hpp"
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
36 changes: 18 additions & 18 deletions src/pw_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
96 changes: 43 additions & 53 deletions src/stream_input_effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<StreamInputEffects*>(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<StreamInputEffects*>(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() {
Expand Down
107 changes: 49 additions & 58 deletions src/stream_output_effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<StreamOutputEffects*>(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<StreamOutputEffects*>(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() {
Expand Down Expand Up @@ -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<int>(id));
Expand Down

0 comments on commit d2d5247

Please sign in to comment.