feat: remove useless api file

This commit is contained in:
2026-08-06 21:14:41 +02:00
parent 470b95ace3
commit fbcaaf31aa
2 changed files with 76 additions and 72 deletions
-48
View File
@@ -1,48 +0,0 @@
import { invoke } from '@tauri-apps/api/core';
import { DSPState, Meters, InputChannel } from '../types/dsp408State';
export const createDSP408 = (ip: string, port: number, deviceId: number) =>
invoke<number>('create_dsp408', {
ip,
port,
deviceId,
});
export const removeDSP408 = (id: number) => invoke('remove_dsp408', { id });
export const connectDSP408 = (id: number) => invoke('connect_dsp408', { id });
export const disconnectDSP408 = (id: number) => invoke('disconnect_dsp408', { id });
export const getDSP408State = (id: number) => invoke<DSPState>('get_dsp_state', { id });
export const recallPresetDSP408 = (id: number, presetIndex: number) =>
invoke<boolean>('recall_preset', {
id,
presetIndex,
});
export const DSP408SetCurrentPresetName = (id: number, name: string) =>
invoke<boolean>('set_current_preset_name', {
id,
name,
});
export const getDSP408MeterLevels = (id: number) => invoke<Meters>('get_meter_levels', { id });
export const DSP408SetGate = (
id: number,
channel: InputChannel,
threshold: number,
attack: number,
hold: number,
release: number
) =>
invoke<boolean>('set_gate', {
id,
channel,
threshold,
attack,
hold,
release,
});
+76 -24
View File
@@ -12,18 +12,20 @@ import {
OutputChannel, OutputChannel,
Ratio, Ratio,
DelayUnit, DelayUnit,
Meters,
DSPState,
} from '../types/dsp408State'; } from '../types/dsp408State';
import { // import {
createDSP408, // createDSP408,
removeDSP408, // removeDSP408,
connectDSP408, // connectDSP408,
disconnectDSP408, // disconnectDSP408,
getDSP408State, // getDSP408State,
recallPresetDSP408, // recallPresetDSP408,
DSP408SetCurrentPresetName, // DSP408SetCurrentPresetName,
getDSP408MeterLevels, // getDSP408MeterLevels,
} from '../api/dsp408'; // } from '../api/dsp408';
type NotifyFunction = (message: string, type: 'success' | 'error', dspName?: string) => void; type NotifyFunction = (message: string, type: 'success' | 'error', dspName?: string) => void;
@@ -97,7 +99,9 @@ function useDSPPolling(
} }
try { try {
const meters = await getDSP408MeterLevels(dsp.id); const meters = await invoke<Meters>('get_meter_levels', {
id: dsp.id,
});
if (stopped) return; if (stopped) return;
@@ -207,9 +211,11 @@ export function useDSP408(
})); }));
try { try {
await connectDSP408(dsp.id); await invoke<DSPState>('connect_dsp408', { id: dsp.id });
const state = await getDSP408State(dsp.id); const state = await invoke<DSPState>('get_dsp_state', {
id: dsp.id,
});
updateDSP(setDsps, dsp.id, (d) => ({ updateDSP(setDsps, dsp.id, (d) => ({
...d, ...d,
@@ -234,7 +240,7 @@ export function useDSP408(
setPollingPaused(dsp.id, true); setPollingPaused(dsp.id, true);
try { try {
await disconnectDSP408(dsp.id); await invoke('disconnect_dsp408', { id: dsp.id });
updateDSP(setDsps, dsp.id, (d) => ({ updateDSP(setDsps, dsp.id, (d) => ({
...d, ...d,
@@ -253,7 +259,11 @@ export function useDSP408(
// Add / Remove // Add / Remove
async function addDSP(dsp: Omit<DSP, 'id' | 'status' | 'state' | 'meters' | 'pollingPaused'>) { async function addDSP(dsp: Omit<DSP, 'id' | 'status' | 'state' | 'meters' | 'pollingPaused'>) {
try { try {
const id = await createDSP408(dsp.ip, dsp.port, dsp.deviceId); const id = await invoke<number>('create_dsp408', {
ip: dsp.ip,
port: dsp.port,
deviceId: dsp.deviceId,
});
const newDsp: DSP = { const newDsp: DSP = {
id, id,
@@ -278,7 +288,9 @@ export function useDSP408(
setPollingPaused(dsp.id, true); setPollingPaused(dsp.id, true);
try { try {
await removeDSP408(dsp.id); await invoke('remove_dsp408', {
id: dsp.id,
});
setDsps((prev) => { setDsps((prev) => {
const next = prev.filter((d) => d.id !== dsp.id); const next = prev.filter((d) => d.id !== dsp.id);
@@ -302,7 +314,10 @@ export function useDSP408(
async function recallPreset(dsp: DSP, presetIndex: number) { async function recallPreset(dsp: DSP, presetIndex: number) {
return withPollingPaused(dsp, async () => { return withPollingPaused(dsp, async () => {
try { try {
const success = await recallPresetDSP408(dsp.id, presetIndex); const success = await invoke<boolean>('recall_preset', {
id: dsp.id,
presetIndex,
});
if (!success) { if (!success) {
notify('Failed to recall preset', 'error', dsp.name); notify('Failed to recall preset', 'error', dsp.name);
@@ -341,7 +356,10 @@ export function useDSP408(
try { try {
const paddedName = name.slice(0, 14).padEnd(14, ' '); const paddedName = name.slice(0, 14).padEnd(14, ' ');
const success = await DSP408SetCurrentPresetName(dsp.id, paddedName); const success = await invoke<boolean>('set_current_preset_name', {
id: dsp.id,
name: paddedName,
});
if (!success) { if (!success) {
notify('Failed to rename preset', 'error', dsp.name); notify('Failed to rename preset', 'error', dsp.name);
@@ -393,16 +411,50 @@ export function useDSP408(
if (!success) { if (!success) {
notify('Failed to set gain', 'error', dsp.name); notify('Failed to set gain', 'error', dsp.name);
return false; return false;
} }
const state = await getDSP408State(dsp.id); updateDSP(setDsps, dsp.id, (d) => {
if (!d.state) return d;
updateDSP(setDsps, dsp.id, (d) => ({ const currentConfig = d.state.current_config;
...d,
state, if ('Input' in channel) {
})); return {
...d,
state: {
...d.state,
current_config: {
...currentConfig,
input_states: {
...currentConfig.input_states,
[channel.Input]: {
...currentConfig.input_states[channel.Input],
gain,
},
},
},
},
};
}
return {
...d,
state: {
...d.state,
current_config: {
...currentConfig,
output_states: {
...currentConfig.output_states,
[channel.Output]: {
...currentConfig.output_states[channel.Output],
gain,
},
},
},
},
};
});
notify('Gain updated', 'success', dsp.name); notify('Gain updated', 'success', dsp.name);