Monitor refactor; link_nodes PW utility
This commit is contained in:
@@ -99,57 +99,43 @@ Soundboard::~Soundboard()
|
||||
|
||||
void Soundboard::on_app_selected(int index)
|
||||
{
|
||||
if (index < 0 || index >= m_apps.size() || !m_sink) {
|
||||
if (!m_sink) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_graph.refresh();
|
||||
|
||||
int target_app_id = m_apps[index].id;
|
||||
int sink_id = m_sink->get_id();
|
||||
|
||||
// Destroy old output links from our sink
|
||||
auto existing_links = m_graph.get_links_from_node(sink_id);
|
||||
auto existing_links = m_graph.get_links_from_node(m_sink->get_id());
|
||||
for (const auto& link : existing_links) {
|
||||
Pipewire::destroy_link(link.id);
|
||||
}
|
||||
|
||||
auto sink_out_ports = m_graph.get_ports_for_node(sink_id, "out");
|
||||
auto target_in_ports = m_graph.get_ports_for_node(target_app_id, "in");
|
||||
|
||||
// Link sink to target app
|
||||
// TODO(1): create a wrapper function to link all channels
|
||||
for (const auto& out_port : sink_out_ports) {
|
||||
for (const auto& in_port : target_in_ports) {
|
||||
if (out_port.channel == in_port.channel &&
|
||||
!Pipewire::link_ports(out_port.id, in_port.id)) {
|
||||
std::cerr << "[ERROR] Failed to link sink with target node" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Link to monitor only if checked
|
||||
// Recover monitor state
|
||||
if (m_monitor_toggle->isChecked()) {
|
||||
int sink_id = m_sink->get_id();
|
||||
auto sinks = m_graph.get_all_sinks();
|
||||
|
||||
for (const auto& system_sink : sinks) {
|
||||
// Skip our own virtual sink
|
||||
if (system_sink.id == sink_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto output_ids = m_graph.get_ports_for_node(system_sink.id, "in");
|
||||
// TODO(1): create a wrapper function to link all channels
|
||||
for (const auto& out_port : sink_out_ports) {
|
||||
for (const auto& in_port : output_ids) {
|
||||
if (out_port.channel == in_port.channel) {
|
||||
Pipewire::link_ports(out_port.id, in_port.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Pipewire::link_nodes(sink_id, system_sink.id, m_graph);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "[INFO] Monitor: " << m_monitor_toggle->isChecked() << std::endl;
|
||||
|
||||
if (index < 0 || index >= m_apps.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Link sink to target app
|
||||
int target_app_id = m_apps[index].id;
|
||||
Pipewire::link_nodes(m_sink->get_id(), target_app_id, m_graph);
|
||||
|
||||
std::cout << "[INFO] Updated routing" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user