1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-08-02 11:38:30 -04:00
Files
DankMaterialShell/quickshell/Modules/DankBar/Widgets/AudioVisualization.qml
T
bbedward 0511cd19df qs: numerous performance optimizations
- ClippingRectangle usages
- Asynchronous loader usages
- Replace cava visualizers with shaders
2026-07-07 16:11:11 -04:00

75 lines
2.1 KiB
QML

import QtQuick
import Quickshell.Services.Mpris
import qs.Common
import qs.Services
Item {
id: root
readonly property MprisPlayer activePlayer: MprisController.activePlayer
readonly property bool isPlaying: activePlayer !== null && activePlayer.playbackState === MprisPlaybackState.Playing
readonly property bool live: visible && isPlaying
width: 20
height: Theme.iconSize
readonly property real maxBarHeight: Theme.iconSize - 2
readonly property real minBarHeight: 3
onLiveChanged: {
if (!live) {
bars.bandsA = Qt.vector4d(0, 0, 0, 0);
bars.bandsB = Qt.vector2d(0, 0);
}
}
Loader {
active: root.live
sourceComponent: Component {
Ref {
service: CavaService
}
}
}
Timer {
running: !CavaService.cavaAvailable && root.live
interval: 500
repeat: true
onTriggered: {
CavaService.values = [Math.random() * 20 + 5, Math.random() * 25 + 8, Math.random() * 22 + 6, Math.random() * 20 + 5, Math.random() * 22 + 6, Math.random() * 25 + 8];
}
}
Connections {
target: CavaService
enabled: root.live
function onValuesChanged() {
const v = CavaService.values;
if (v.length < 6)
return;
const n = i => {
const x = v[i];
return x <= 0 ? 0 : x >= 100 ? 1 : Math.sqrt(x * 0.01);
};
bars.bandsA = Qt.vector4d(n(0), n(1), n(2), n(3));
bars.bandsB = Qt.vector2d(n(4), n(5));
}
}
ShaderEffect {
id: bars
anchors.fill: parent
property real widthPx: width
property real heightPx: height
property real minH: root.minBarHeight
property real maxH: root.maxBarHeight
property vector4d bandsA: Qt.vector4d(0, 0, 0, 0)
property vector2d bandsB: Qt.vector2d(0, 0)
property vector4d fillColor: Qt.vector4d(Theme.primary.r, Theme.primary.g, Theme.primary.b, Theme.primary.a)
fragmentShader: Qt.resolvedUrl("../../../Shaders/qsb/viz_bars.frag.qsb")
}
}