1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-05 21:15:38 -05:00

audio: optimize non-cava fallback

This commit is contained in:
bbedward
2025-11-24 11:08:03 -05:00
parent ee03853901
commit f618df46d8

View File

@@ -20,19 +20,21 @@ Item {
Ref { Ref {
service: CavaService service: CavaService
} }
} }
} }
readonly property real maxBarHeight: Theme.iconSize - 2
readonly property real minBarHeight: 3
readonly property real heightRange: maxBarHeight - minBarHeight
Timer { Timer {
id: fallbackTimer id: fallbackTimer
running: !CavaService.cavaAvailable && isPlaying running: !CavaService.cavaAvailable && isPlaying
interval: 256 interval: 500
repeat: true repeat: true
onTriggered: { onTriggered: {
CavaService.values = [Math.random() * 40 + 10, Math.random() * 60 + 20, Math.random() * 50 + 15, Math.random() * 35 + 20, Math.random() * 45 + 15, Math.random() * 55 + 25]; 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];
} }
} }
@@ -44,17 +46,18 @@ Item {
model: 6 model: 6
Rectangle { Rectangle {
width: 2 readonly property real targetHeight: {
height: { if (!root.isPlaying || CavaService.values.length <= index)
if (root.isPlaying && CavaService.values.length > index) { return root.minBarHeight;
const rawLevel = CavaService.values[index] || 0;
const scaledLevel = Math.sqrt(Math.min(Math.max(rawLevel, 0), 100) / 100) * 100; const rawLevel = CavaService.values[index];
const maxHeight = Theme.iconSize - 2; const clampedLevel = rawLevel < 0 ? 0 : (rawLevel > 100 ? 100 : rawLevel);
const minHeight = 3; const scaledLevel = Math.sqrt(clampedLevel * 0.01);
return minHeight + (scaledLevel / 100) * (maxHeight - minHeight); return root.minBarHeight + scaledLevel * root.heightRange;
}
return 3;
} }
width: 2
height: targetHeight
radius: 1.5 radius: 1.5
color: Theme.primary color: Theme.primary
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
@@ -65,13 +68,8 @@ Item {
easing.type: Easing.BezierSpline easing.type: Easing.BezierSpline
easing.bezierCurve: Anims.standardDecel easing.bezierCurve: Anims.standardDecel
} }
} }
} }
} }
} }
} }