mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-24 21:42:51 -05:00
audio: optimize visualizations
This commit is contained in:
@@ -26,6 +26,7 @@ Item {
|
||||
readonly property real maxBarHeight: Theme.iconSize - 2
|
||||
readonly property real minBarHeight: 3
|
||||
readonly property real heightRange: maxBarHeight - minBarHeight
|
||||
property var barHeights: [minBarHeight, minBarHeight, minBarHeight, minBarHeight, minBarHeight, minBarHeight]
|
||||
|
||||
Timer {
|
||||
id: fallbackTimer
|
||||
@@ -38,6 +39,34 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: CavaService
|
||||
function onValuesChanged() {
|
||||
if (!root.isPlaying) {
|
||||
root.barHeights = [root.minBarHeight, root.minBarHeight, root.minBarHeight, root.minBarHeight, root.minBarHeight, root.minBarHeight];
|
||||
return;
|
||||
}
|
||||
|
||||
const newHeights = [];
|
||||
for (let i = 0; i < 6; i++) {
|
||||
if (CavaService.values.length <= i) {
|
||||
newHeights.push(root.minBarHeight);
|
||||
continue;
|
||||
}
|
||||
|
||||
const rawLevel = CavaService.values[i];
|
||||
if (rawLevel <= 0) {
|
||||
newHeights.push(root.minBarHeight);
|
||||
} else if (rawLevel >= 100) {
|
||||
newHeights.push(root.maxBarHeight);
|
||||
} else {
|
||||
newHeights.push(root.minBarHeight + Math.sqrt(rawLevel * 0.01) * root.heightRange);
|
||||
}
|
||||
}
|
||||
root.barHeights = newHeights;
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
anchors.centerIn: parent
|
||||
spacing: 1.5
|
||||
@@ -46,27 +75,17 @@ Item {
|
||||
model: 6
|
||||
|
||||
Rectangle {
|
||||
readonly property real targetHeight: {
|
||||
if (!root.isPlaying || CavaService.values.length <= index)
|
||||
return root.minBarHeight;
|
||||
|
||||
const rawLevel = CavaService.values[index];
|
||||
const clampedLevel = rawLevel < 0 ? 0 : (rawLevel > 100 ? 100 : rawLevel);
|
||||
const scaledLevel = Math.sqrt(clampedLevel * 0.01);
|
||||
return root.minBarHeight + scaledLevel * root.heightRange;
|
||||
}
|
||||
|
||||
width: 2
|
||||
height: targetHeight
|
||||
height: root.barHeights[index]
|
||||
radius: 1.5
|
||||
color: Theme.primary
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
Behavior on height {
|
||||
enabled: root.isPlaying && !CavaService.cavaAvailable
|
||||
NumberAnimation {
|
||||
duration: Anims.durShort
|
||||
easing.type: Easing.BezierSpline
|
||||
easing.bezierCurve: Anims.standardDecel
|
||||
duration: 100
|
||||
easing.type: Easing.Linear
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,9 +101,24 @@ BasePill {
|
||||
anchors.centerIn: parent
|
||||
spacing: Theme.spacingXS
|
||||
|
||||
AudioVisualization {
|
||||
Item {
|
||||
width: 20
|
||||
height: 20
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
||||
AudioVisualization {
|
||||
anchors.fill: parent
|
||||
visible: CavaService.cavaAvailable
|
||||
}
|
||||
|
||||
DankIcon {
|
||||
anchors.fill: parent
|
||||
name: "music_note"
|
||||
size: 20
|
||||
color: Theme.primary
|
||||
visible: !CavaService.cavaAvailable
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
@@ -165,28 +180,38 @@ BasePill {
|
||||
id: mediaInfo
|
||||
spacing: Theme.spacingXS
|
||||
|
||||
AudioVisualization {
|
||||
Item {
|
||||
width: 20
|
||||
height: 20
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
AudioVisualization {
|
||||
anchors.fill: parent
|
||||
visible: CavaService.cavaAvailable
|
||||
}
|
||||
|
||||
DankIcon {
|
||||
anchors.fill: parent
|
||||
name: "music_note"
|
||||
size: 20
|
||||
color: Theme.primary
|
||||
visible: !CavaService.cavaAvailable
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: textContainer
|
||||
readonly property string cachedIdentity: activePlayer ? (activePlayer.identity || "") : ""
|
||||
readonly property string lowerIdentity: cachedIdentity.toLowerCase()
|
||||
readonly property bool isWebMedia: lowerIdentity.includes("firefox") || lowerIdentity.includes("chrome") || lowerIdentity.includes("chromium") || lowerIdentity.includes("edge") || lowerIdentity.includes("safari")
|
||||
|
||||
property string displayText: {
|
||||
if (!activePlayer || !activePlayer.trackTitle) {
|
||||
return "";
|
||||
}
|
||||
|
||||
let identity = activePlayer.identity || "";
|
||||
let isWebMedia = identity.toLowerCase().includes("firefox") || identity.toLowerCase().includes("chrome") || identity.toLowerCase().includes("chromium") || identity.toLowerCase().includes("edge") || identity.toLowerCase().includes("safari");
|
||||
let title = "";
|
||||
let subtitle = "";
|
||||
if (isWebMedia && activePlayer.trackTitle) {
|
||||
title = activePlayer.trackTitle;
|
||||
subtitle = activePlayer.trackArtist || identity;
|
||||
} else {
|
||||
title = activePlayer.trackTitle || "Unknown Track";
|
||||
subtitle = activePlayer.trackArtist || "";
|
||||
}
|
||||
const title = isWebMedia ? activePlayer.trackTitle : (activePlayer.trackTitle || "Unknown Track");
|
||||
const subtitle = isWebMedia ? (activePlayer.trackArtist || cachedIdentity) : (activePlayer.trackArtist || "");
|
||||
return subtitle.length > 0 ? title + " • " + subtitle : title;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user