Audio Service: more abstraction
This commit is contained in:
parent
ee326a72ae
commit
ade52f5013
3 changed files with 39 additions and 35 deletions
|
|
@ -10,10 +10,6 @@ Item {
|
||||||
width: pill.width
|
width: pill.width
|
||||||
height: pill.height
|
height: pill.height
|
||||||
|
|
||||||
Component.onCompleted: {
|
|
||||||
console.log("[Volume] settingsPanel received:", !!settingsPanel)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Used to avoid opening the pill on Quickshell startup
|
// Used to avoid opening the pill on Quickshell startup
|
||||||
property bool firstVolumeReceived: false
|
property bool firstVolumeReceived: false
|
||||||
|
|
||||||
|
|
@ -50,9 +46,9 @@ Item {
|
||||||
|
|
||||||
onWheel: function (angle) {
|
onWheel: function (angle) {
|
||||||
if (angle > 0) {
|
if (angle > 0) {
|
||||||
Audio.volumeIncrement()
|
Audio.increaseVolume()
|
||||||
} else if (angle < 0) {
|
} else if (angle < 0) {
|
||||||
Audio.volumeDecrement()
|
Audio.decreaseVolume()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onClicked: {
|
onClicked: {
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ ColumnLayout {
|
||||||
repeat: true
|
repeat: true
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
if (Math.abs(localVolume - Audio.volume) >= 0.01) {
|
if (Math.abs(localVolume - Audio.volume) >= 0.01) {
|
||||||
Audio.volumeSet(localVolume)
|
Audio.setVolume(localVolume)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,34 +34,7 @@ Singleton {
|
||||||
readonly property alias muted: root._muted
|
readonly property alias muted: root._muted
|
||||||
property bool _muted: !!sink?.audio?.muted
|
property bool _muted: !!sink?.audio?.muted
|
||||||
|
|
||||||
readonly property real step: 0.05
|
readonly property real stepVolume: 0.05
|
||||||
|
|
||||||
function volumeIncrement() {
|
|
||||||
volumeSet(volume + step)
|
|
||||||
}
|
|
||||||
|
|
||||||
function volumeDecrement() {
|
|
||||||
volumeSet(volume - step)
|
|
||||||
}
|
|
||||||
|
|
||||||
function volumeSet(newVolume) {
|
|
||||||
if (sink?.ready && sink?.audio) {
|
|
||||||
// Clamp it accordingly
|
|
||||||
sink.audio.muted = false
|
|
||||||
sink.audio.volume = Math.max(0, Math.min(1, newVolume))
|
|
||||||
//console.log("[Audio] volumeSet", sink.audio.volume);
|
|
||||||
} else {
|
|
||||||
console.warn("[Audio] No sink available")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function setAudioSink(newSink: PwNode): void {
|
|
||||||
Pipewire.preferredDefaultAudioSink = newSink
|
|
||||||
}
|
|
||||||
|
|
||||||
function setAudioSource(newSource: PwNode): void {
|
|
||||||
Pipewire.preferredDefaultAudioSource = newSource
|
|
||||||
}
|
|
||||||
|
|
||||||
PwObjectTracker {
|
PwObjectTracker {
|
||||||
objects: [...root.sinks, ...root.sources]
|
objects: [...root.sinks, ...root.sources]
|
||||||
|
|
@ -83,4 +56,39 @@ Singleton {
|
||||||
console.log("[Audio] onMuteChanged:", root._muted)
|
console.log("[Audio] onMuteChanged:", root._muted)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function increaseVolume() {
|
||||||
|
setVolume(volume + stepVolume)
|
||||||
|
}
|
||||||
|
|
||||||
|
function decreaseVolume() {
|
||||||
|
setVolume(volume - stepVolume)
|
||||||
|
}
|
||||||
|
|
||||||
|
function setVolume(newVolume: real) {
|
||||||
|
if (sink?.ready && sink?.audio) {
|
||||||
|
// Clamp it accordingly
|
||||||
|
sink.audio.muted = false
|
||||||
|
sink.audio.volume = Math.max(0, Math.min(1, newVolume))
|
||||||
|
//console.log("[Audio] setVolume", sink.audio.volume);
|
||||||
|
} else {
|
||||||
|
console.warn("[Audio] No sink available")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setMuted(muted: bool) {
|
||||||
|
if (sink?.ready && sink?.audio) {
|
||||||
|
sink.audio.muted = muted
|
||||||
|
} else {
|
||||||
|
console.warn("[Audio] No sink available")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setAudioSink(newSink: PwNode): void {
|
||||||
|
Pipewire.preferredDefaultAudioSink = newSink
|
||||||
|
}
|
||||||
|
|
||||||
|
function setAudioSource(newSource: PwNode): void {
|
||||||
|
Pipewire.preferredDefaultAudioSource = newSource
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue