koel/resources/assets/js/stores/equalizerStore.ts

47 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-11-02 19:25:22 +00:00
import { preferenceStore as preferences } from '@/stores'
import { equalizerPresets as presets } from '@/config'
2022-04-15 14:24:30 +00:00
export const equalizerStore = {
2024-01-24 22:39:47 +00:00
getPresetByName (name: string) {
return presets.find(preset => preset.name === name)
2022-04-15 14:24:30 +00:00
},
/**
* Get the current equalizer config.
*/
2022-11-02 19:25:22 +00:00
getConfig () {
2024-04-23 21:01:27 +00:00
let config: EqualizerPreset | undefined
if (this.isCustom(preferences.equalizer)) return preferences.equalizer
if (preferences.equalizer.name !== null) {
2024-04-23 21:01:27 +00:00
config = this.getPresetByName(preferences.equalizer.name)
2022-04-15 14:24:30 +00:00
}
return config || presets[0]
},
2024-04-23 21:01:27 +00:00
isCustom (preset: any) {
return typeof preset === 'object'
&& preset !== null
&& preset.name === null
&& typeof preset.preamp === 'number'
&& Array.isArray(preset.gains)
&& preset.gains.length === 10
&& preset.gains.every((gain: any) => typeof gain === 'number')
2022-04-15 14:24:30 +00:00
},
/**
* Save the current equalizer config.
*/
saveConfig (name: EqualizerPreset['name'] | null, preamp: number, gains: number[]) {
const preset = name ? this.getPresetByName(name) : null
2022-11-02 19:25:22 +00:00
preferences.equalizer = preset || {
2022-04-15 14:24:30 +00:00
preamp,
2022-11-02 19:25:22 +00:00
gains,
name: null
2022-04-15 14:24:30 +00:00
}
}
}