import { ConstructorOptions } from 'audiomotion-analyzer'; import butterchurnPresets from 'butterchurn-presets'; import { useEffect, useMemo, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import styles from './visualizer-settings-form.module.css'; import { useSettingsStoreActions, useVisualizerSettings } from '/@/renderer/store/settings.store'; import { ActionIcon } from '/@/shared/components/action-icon/action-icon'; import { Button } from '/@/shared/components/button/button'; import { Checkbox } from '/@/shared/components/checkbox/checkbox'; import { ColorInput } from '/@/shared/components/color-input/color-input'; import { Divider } from '/@/shared/components/divider/divider'; import { Fieldset } from '/@/shared/components/fieldset/fieldset'; import { Group } from '/@/shared/components/group/group'; import { MultiSelect } from '/@/shared/components/multi-select/multi-select'; import { NumberInput } from '/@/shared/components/number-input/number-input'; import { SegmentedControl } from '/@/shared/components/segmented-control/segmented-control'; import { Select, SelectProps } from '/@/shared/components/select/select'; import { Slider, SliderProps } from '/@/shared/components/slider/slider'; import { Stack } from '/@/shared/components/stack/stack'; import { TextInput } from '/@/shared/components/text-input/text-input'; import { Text } from '/@/shared/components/text/text'; import { Textarea } from '/@/shared/components/textarea/textarea'; import { toast } from '/@/shared/components/toast/toast'; const modeOptions: { label: string; value: ConstructorOptions['mode'] | string }[] = [ { label: '[0] Bars', value: '0' }, { label: '[1] Circle', value: '1' }, { label: '[2] Wave', value: '2' }, { label: '[3] Rainbow', value: '3' }, { label: '[4] Rings', value: '4' }, { label: '[5] Mirror', value: '5' }, { label: '[6] Line', value: '6' }, { label: '[7] Particles', value: '7' }, { label: '[8] Full octave / 10 bands', value: '8' }, { label: '[10] Outline bars', value: '10' }, ]; const colorModeOptions: { label: string; value: ConstructorOptions['colorMode'] }[] = [ { label: 'Gradient', value: 'gradient' }, { label: 'Bar-Index', value: 'bar-index' }, { label: 'Bar-Level', value: 'bar-level' }, ]; const gradientOptions: { label: string; value: ConstructorOptions['gradient'] }[] = [ { label: 'Classic', value: 'classic' }, { label: 'Prism', value: 'prism' }, { label: 'Rainbow', value: 'rainbow' }, { label: 'Steelblue', value: 'steelblue' }, { label: 'Orangered', value: 'orangered' }, ]; const channelLayoutOptions: { label: string; value: ConstructorOptions['channelLayout'] }[] = [ { label: 'Single', value: 'single' }, { label: 'Dual-Combined', value: 'dual-combined' }, { label: 'Dual-Horizontal', value: 'dual-horizontal' }, { label: 'Dual-Vertical', value: 'dual-vertical' }, ]; const fftSizeOptions: { label: string; value: ConstructorOptions['fftSize'] | string }[] = [ { label: '1024', value: '1024' }, { label: '2048', value: '2048' }, { label: '4096', value: '4096' }, { label: '8192', value: '8192' }, { label: '16384', value: '16384' }, { label: '32768', value: '32768' }, ]; const frequencyScaleOptions: { label: string; value: ConstructorOptions['frequencyScale'] }[] = [ { label: 'Bark', value: 'bark' }, { label: 'Linear', value: 'linear' }, { label: 'Log', value: 'log' }, { label: 'Mel', value: 'mel' }, ]; const weightingFilterOptions = [ { label: 'None', value: '' }, { label: 'A', value: 'A' }, { label: 'B', value: 'B' }, { label: 'C', value: 'C' }, { label: 'D', value: 'D' }, { label: 'Z', value: 'Z' }, ]; const minFreqOptions = [ { label: '20', value: '20' }, { label: '30', value: '30' }, { label: '40', value: '40' }, { label: '50', value: '50' }, ]; const maxFreqOptions = [ { label: '8000', value: '8000' }, { label: '10000', value: '10000' }, { label: '15000', value: '15000' }, { label: '20000', value: '20000' }, { label: '22050', value: '22050' }, ]; const barSpaceOptions = [ { label: '0', value: '0' }, { label: '0.1', value: '0.1' }, { label: '0.25', value: '0.2' }, { label: '0.4', value: '0.4' }, { label: '0.5', value: '0.5' }, { label: '0.75', value: '0.7' }, { label: '1.0', value: '1.0' }, ]; const useUpdateAudioMotionAnalyzer = () => { const visualizer = useVisualizerSettings(); const { setSettings } = useSettingsStoreActions(); const updateProperty = ( property: K, value: (typeof visualizer.audiomotionanalyzer)[K], ) => { setSettings({ visualizer: { ...visualizer, audiomotionanalyzer: { ...visualizer.audiomotionanalyzer, [property]: value, }, }, }); }; return { updateProperty, visualizer }; }; const useUpdateButterchurn = () => { const visualizer = useVisualizerSettings(); const { setSettings } = useSettingsStoreActions(); const updateProperty = ( property: K, value: (typeof visualizer.butterchurn)[K], ) => { setSettings({ visualizer: { ...visualizer, butterchurn: { ...visualizer.butterchurn, [property]: value, }, }, }); }; return { updateProperty, visualizer }; }; export const VisualizerSettingsForm = () => { const { t } = useTranslation(); const visualizer = useVisualizerSettings(); const { setSettings } = useSettingsStoreActions(); const visualizerTypeOptions = useMemo( () => [ { label: 'AudioMotion Analyzer', value: 'audiomotionanalyzer' }, { label: 'Butterchurn', value: 'butterchurn' }, ], [], ); const handleTypeChange = (value: string) => { setSettings({ visualizer: { ...visualizer, type: value as 'audiomotionanalyzer' | 'butterchurn', }, }); }; return (
{visualizer.type === 'audiomotionanalyzer' && ( <> )} {visualizer.type === 'butterchurn' && ( <> )}
); }; const VisualizerSelect = (props: SelectProps) => { return