fix: tweak cava settings + improve the cava code to be more reliable

This commit is contained in:
ferreo 2025-07-15 13:05:47 +01:00
parent d6d206ea12
commit 4dacc2143d

View file

@ -1,63 +1,77 @@
import QtQuick import QtQuick
import Quickshell import Quickshell
import Quickshell.Io import Quickshell.Io
import qs.Components
import qs.Services import qs.Services
Scope { Scope {
id: root id: root
property int count: 32 property int count: 32
property int noiseReduction: 60 property int noiseReduction: 60
property string channels: "mono" // or stereo property string channels: "mono"
property string monoOption: "average" // or left or right property string monoOption: "average"
property var config: ({
general: { bars: count },
smoothing: { noise_reduction: noiseReduction },
output: {
method: "raw",
bit_format: 8,
channels: channels,
mono_option: monoOption,
}
})
property var values: Array(count).fill(0) // 0 <= value <= 1 property var config: ({
general: {
bars: count,
framerate: 30,
autosens: 1
},
smoothing: {
monstercat: 1,
gravity: 1000000,
noise_reduction: noiseReduction
},
output: {
method: "raw",
bit_format: 8,
channels: channels,
mono_option: monoOption
}
})
Process { property var values: Array(count).fill(0)
property int index: 0
id: process Process {
stdinEnabled: true id: process
running: MusicManager.isPlaying property int index: 0
command: ["cava", "-p", "/dev/stdin"] stdinEnabled: true
onExited: { stdinEnabled = true; index = 0; values = []; } running: MusicManager.isPlaying
onStarted: { command: ["cava", "-p", "/dev/stdin"]
const iniParts = [] onExited: {
for (const k in config) { stdinEnabled = true;
if (typeof config[k] !== "object") { index = 0;
write(k + "=" + config[k] + "\n") values = Array(count).fill(0);
continue }
} onStarted: {
write("[" + k + "]\n") for (const k in config) {
const obj = config[k] if (typeof config[k] !== "object") {
for (const k2 in obj) { write(k + "=" + config[k] + "\n");
write(k2 + "=" + obj[k2] + "\n") continue;
} }
} write("[" + k + "]\n");
stdinEnabled = false const obj = config[k];
} for (const k2 in obj) {
stdout: SplitParser { write(k2 + "=" + obj[k2] + "\n");
property var newValues: Array(count).fill(0) }
splitMarker: "" }
onRead: data => { stdinEnabled = false;
if (process.index + data.length > config.general.bars) { }
process.index = 0 stdout: SplitParser {
} splitMarker: ""
for (let i = 0; i < data.length; i += 1) { onRead: data => {
newValues[i + process.index] = Math.min(data.charCodeAt(i), 128) / 128 const newValues = Array(count).fill(0);
} for (let i = 0; i < values.length; i++) {
process.index += data.length newValues[i] = values[i];
values = newValues }
} if (process.index + data.length > count) {
} process.index = 0;
} }
for (let i = 0; i < data.length; i += 1) {
newValues[i + process.index] = Math.min(data.charCodeAt(i), 128) / 128;
}
process.index += data.length;
values = newValues;
}
}
}
} }