Files
controller-v2/client/src/pages/eq/peqMappers.ts
T

42 lines
1.2 KiB
TypeScript
Raw Normal View History

import { getFilterType } from "@/lib/peqAudio";
import type { PeqFilter, PeqState } from "@/lib/luxsinApi";
import type { EqBand } from "./types";
export function cloneBands(source: EqBand[]) {
return source.map((band) => ({ ...band }));
}
export function buildPeqCatalogSyncKey(
remote: Pick<PeqState, "peq" | "peqSelect"> | null | undefined,
devicePeqSelect?: number,
): string {
const items = remote?.peq;
if (!items?.length) return items ? "empty" : "";
const select = devicePeqSelect ?? remote?.peqSelect ?? 0;
return `${select}|${items.map((p) => p.name).join("\u0001")}`;
}
export function getUniquePresetName(base: string, existingNames: string[]) {
if (!existingNames.includes(base)) return base;
let index = 1;
while (existingNames.includes(`${base}_${index}`)) {
index += 1;
}
return `${base}_${index}`;
}
/** UI band row → device `PeqFilter` (fc + numeric type), same as legacy `getFilterVal` mapping via `getFilterType`. */
export function bandToPeqFilter(b: {
freq: number;
gain: number;
q: number;
type: string | number;
}): PeqFilter {
return {
fc: b.freq,
gain: b.gain,
q: b.q,
type: getFilterType(b.type),
};
}