pragma Singleton import QtQuick import Quickshell import Quickshell.Io // EasyEffects 10-band equalizer (serpantinum-style presets). Band edits stay // local and "pending" until applied; presets apply immediately. Singleton { id: root property bool installed: false property bool running: false property bool bypass: false property var bands: Array(10).fill(0) property var saved: Array(10).fill(0) property string preset: "Flat" property var frequencies: [32, 63, 125, 250, 500, 1000, 2000, 4000, 8000, 16000] property string error: "" property bool known: false readonly property bool busy: job.running readonly property bool pending: bands.some((b, i) => b !== saved[i]) readonly property var presets: ({ Flat: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], Bass: [5, 7, 5, 2, 1, 0, 0, 0, 1, 2], Treble: [-2, -1, 0, 1, 2, 3, 4, 5, 6, 6], Vocal: [-2, -1, 1, 3, 5, 5, 4, 2, 1, 0], Pop: [2, 4, 2, 0, 1, 2, 4, 2, 1, 2], Rock: [5, 4, 2, -1, -2, -1, 2, 4, 5, 6], Jazz: [3, 3, 1, 1, 1, 1, 2, 1, 2, 3], Classic: [0, 1, 2, 2, 2, 2, 1, 2, 3, 4] }) readonly property var presetNames: ["Flat", "Bass", "Treble", "Vocal", "Pop", "Rock", "Jazz", "Classic"] property var queued: null function call(args) { if (job.running) { queued = args; return; } job.command = ["python3", Quickshell.shellPath("helpers/easyeffects.py")].concat(args); job.running = true; } function refresh() { call(["status"]); } function setBand(index, gain) { const next = bands.slice(); next[index] = Math.round(Math.max(-12, Math.min(12, gain))); bands = next; preset = "Custom"; } function apply() { if (installed) call(["apply", JSON.stringify(bands), preset]); } function usePreset(name) { if (!presets[name]) return; bands = presets[name].slice(); preset = name; apply(); } function setBypass(on) { bypass = on; call(["bypass", on ? "on" : "off"]); } Process { id: job stdout: StdioCollector { onStreamFinished: { try { const s = JSON.parse(text); root.installed = s.installed; root.running = s.running; root.bypass = s.bypass; root.error = s.error || ""; root.saved = s.bands; root.frequencies = s.frequencies; // Keep unapplied edits; otherwise follow the saved state. if (!root.known || !root.pending) { root.bands = s.bands.slice(); root.preset = s.preset; } root.known = true; } catch (e) { root.error = String(e); } } } onRunningChanged: if (!running && root.queued) { const next = root.queued; root.queued = null; root.call(next); } } IpcHandler { target: "equalizer" function status(): string { return JSON.stringify({ installed: root.installed, running: root.running, bypass: root.bypass, bands: root.bands, preset: root.preset, pending: root.pending, error: root.error }); } function refresh(): void { root.refresh(); } } }