refactor(eq): 更新EQ页面以优化预设缓存和滤波器管理
- 添加实时滑块预览状态以改善用户体验 - 重构预设缓存逻辑,使用新的PeqPresetLocalCache类型管理滤波器和增益设置 - 更新相关函数以支持新的预设缓存机制,减少重复计算 - 增强滤波器持久化逻辑,确保在耳机切换时正确保存和应用滤波器设置
This commit is contained in:
@@ -52,6 +52,13 @@ export const DEFAULT_BANDS = [
|
||||
/* ── PEQ catalog item type ── */
|
||||
export type PeqCatalogItem = NonNullable<PeqState["peq"]>[number];
|
||||
|
||||
/** 本地编辑缓存(按预设名称);syncPeq 拉取时优先于设备 catalog */
|
||||
export type PeqPresetLocalCache = {
|
||||
filters?: PeqFilter[];
|
||||
preamp?: number;
|
||||
autoPre?: number;
|
||||
};
|
||||
|
||||
/* ── Flat preset filters ── */
|
||||
export const FLAT_PRESET_FILTERS: PeqFilter[] = [
|
||||
{ type: 4, fc: 80, gain: 0, q: 0.1 },
|
||||
|
||||
@@ -31,6 +31,18 @@ export function formatBandFreqDisplay(freq: number) {
|
||||
: `${freq} Hz`;
|
||||
}
|
||||
|
||||
export function formatBandGainDisplay(gain: unknown) {
|
||||
const db = typeof gain === "number" && Number.isFinite(gain) ? gain : Number(gain);
|
||||
if (!Number.isFinite(db)) return "0.0 dB";
|
||||
const text = db.toFixed(1);
|
||||
return `${db >= 0 ? `+${text}` : text} dB`;
|
||||
}
|
||||
|
||||
export function formatBandQDisplay(q: unknown) {
|
||||
const n = typeof q === "number" && Number.isFinite(q) ? q : Number(q);
|
||||
return Number.isFinite(n) ? n.toFixed(2) : "—";
|
||||
}
|
||||
|
||||
/* ── Band param value for input field ── */
|
||||
export function formatBandParamForInput(
|
||||
kind: BandParamKind,
|
||||
@@ -131,9 +143,19 @@ export function cloneBands(
|
||||
return source.map((band) => ({ ...band }));
|
||||
}
|
||||
|
||||
/* ── Frequency label for band grid ── */
|
||||
export function freqLabel(f: number) {
|
||||
return f >= 1000 ? `${(f / 1000).toFixed(1)}K` : `${f}`;
|
||||
/* ── Frequency label for band grid (numeric only; avoid browser translate → words) ── */
|
||||
export function freqLabel(freq: unknown) {
|
||||
const hz =
|
||||
typeof freq === "number" && Number.isFinite(freq)
|
||||
? freq
|
||||
: Number(freq);
|
||||
if (!Number.isFinite(hz)) return "—";
|
||||
if (hz >= 1000) {
|
||||
const k = hz / 1000;
|
||||
const text = k >= 10 ? String(Math.round(k)) : k.toFixed(1).replace(/\.0$/, "");
|
||||
return `${text}K`;
|
||||
}
|
||||
return String(Math.round(hz));
|
||||
}
|
||||
|
||||
/* ── Build PEQ catalog sync key ── */
|
||||
|
||||
Reference in New Issue
Block a user