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-23 22:50:50 +00:00
|
|
|
getPresetByName (name: EqualizerPreset['name']) {
|
|
|
|
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-01-23 22:50:50 +00:00
|
|
|
let config: EqualizerPreset|undefined
|
|
|
|
|
|
|
|
if (this.isCustom(preferences.equalizer)) return preferences.equalizer
|
|
|
|
|
|
|
|
if (preferences.equalizer.name !== null) {
|
|
|
|
config = this.getPresetByName(preferences.equalizer.name)
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
2024-01-23 22:50:50 +00:00
|
|
|
return config || presets[0]
|
|
|
|
},
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2024-01-23 22:50:50 +00:00
|
|
|
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,
|
2024-01-23 22:50:50 +00:00
|
|
|
name: null
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|