audio: replace reactive reduce with imperative node categorisation
This commit is contained in:
parent
9464c72f7a
commit
c14db315f6
1 changed files with 28 additions and 20 deletions
|
|
@ -13,26 +13,9 @@ Singleton {
|
||||||
property string previousSinkName: ""
|
property string previousSinkName: ""
|
||||||
property string previousSourceName: ""
|
property string previousSourceName: ""
|
||||||
|
|
||||||
readonly property var nodes: Pipewire.nodes.values.reduce((acc, node) => {
|
property list<PwNode> sinks: []
|
||||||
if (!node.isStream) {
|
property list<PwNode> sources: []
|
||||||
if (node.isSink)
|
property list<PwNode> streams: []
|
||||||
acc.sinks.push(node);
|
|
||||||
else if (node.audio)
|
|
||||||
acc.sources.push(node);
|
|
||||||
} else if (node.isStream && node.audio) {
|
|
||||||
// Application streams (output streams)
|
|
||||||
acc.streams.push(node);
|
|
||||||
}
|
|
||||||
return acc;
|
|
||||||
}, {
|
|
||||||
sources: [],
|
|
||||||
sinks: [],
|
|
||||||
streams: []
|
|
||||||
})
|
|
||||||
|
|
||||||
readonly property list<PwNode> sinks: nodes.sinks
|
|
||||||
readonly property list<PwNode> sources: nodes.sources
|
|
||||||
readonly property list<PwNode> streams: nodes.streams
|
|
||||||
|
|
||||||
readonly property PwNode sink: Pipewire.defaultAudioSink
|
readonly property PwNode sink: Pipewire.defaultAudioSink
|
||||||
readonly property PwNode source: Pipewire.defaultAudioSource
|
readonly property PwNode source: Pipewire.defaultAudioSource
|
||||||
|
|
@ -141,6 +124,31 @@ Singleton {
|
||||||
previousSourceName = source?.description || source?.name || qsTr("Unknown Device");
|
previousSourceName = source?.description || source?.name || qsTr("Unknown Device");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: Pipewire.nodes
|
||||||
|
|
||||||
|
function onValuesChanged(): void {
|
||||||
|
const newSinks = [];
|
||||||
|
const newSources = [];
|
||||||
|
const newStreams = [];
|
||||||
|
|
||||||
|
for (const node of Pipewire.nodes.values) {
|
||||||
|
if (!node.isStream) {
|
||||||
|
if (node.isSink)
|
||||||
|
newSinks.push(node);
|
||||||
|
else if (node.audio)
|
||||||
|
newSources.push(node);
|
||||||
|
} else if (node.audio) {
|
||||||
|
newStreams.push(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
root.sinks = newSinks;
|
||||||
|
root.sources = newSources;
|
||||||
|
root.streams = newStreams;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PwObjectTracker {
|
PwObjectTracker {
|
||||||
objects: [...root.sinks, ...root.sources, ...root.streams]
|
objects: [...root.sinks, ...root.sources, ...root.streams]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue