From 04fa89c0f006bdb2d373395d2c9743112a4a6fe3 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Fri, 5 Nov 2021 08:31:46 -0700 Subject: [PATCH] Add playback presets --- .../settings/ConfigPanels/PlaybackConfig.tsx | 132 +++++++++++++----- 1 file changed, 94 insertions(+), 38 deletions(-) diff --git a/src/components/settings/ConfigPanels/PlaybackConfig.tsx b/src/components/settings/ConfigPanels/PlaybackConfig.tsx index 7232595..09a6bc3 100644 --- a/src/components/settings/ConfigPanels/PlaybackConfig.tsx +++ b/src/components/settings/ConfigPanels/PlaybackConfig.tsx @@ -1,8 +1,9 @@ -import React, { useRef } from 'react'; +import React, { useRef, useState } from 'react'; import settings from 'electron-settings'; -import { ControlLabel, RadioGroup } from 'rsuite'; +import { ButtonToolbar, ControlLabel, RadioGroup } from 'rsuite'; import { ConfigPanel } from '../styled'; import { + StyledButton, StyledInputNumber, StyledInputPicker, StyledInputPickerContainer, @@ -13,9 +14,46 @@ import { setPlaybackSetting, setPlayerVolume } from '../../../redux/playQueueSli const PlaybackConfig = () => { const dispatch = useAppDispatch(); + const [crossfadeDuration, setCrossfadeDuration] = useState( + Number(settings.getSync('fadeDuration')) + ); + const [pollingInterval, setPollingInterval] = useState( + Number(settings.getSync('pollingInterval')) + ); + const [volumeFade, setVolumeFade] = useState(Boolean(settings.getSync('volumeFade'))); const playQueue = useAppSelector((state) => state.playQueue); const crossfadePickerContainerRef = useRef(null); + const handleSetCrossfadeDuration = (e: number) => { + settings.setSync('fadeDuration', Number(e)); + dispatch( + setPlaybackSetting({ + setting: 'fadeDuration', + value: Number(e), + }) + ); + + if (Number(e) === 0) { + dispatch(setPlayerVolume({ player: 1, volume: playQueue.volume })); + dispatch(setPlayerVolume({ player: 2, volume: playQueue.volume })); + } + }; + + const handleSetPollingInterval = (e: number) => { + settings.setSync('pollingInterval', Number(e)); + dispatch( + setPlaybackSetting({ + setting: 'pollingInterval', + value: Number(e), + }) + ); + }; + + const handleSetVolumeFade = (e: boolean) => { + settings.setSync('volumeFade', e); + dispatch(setPlaybackSetting({ setting: 'volumeFade', value: e })); + }; + return (

@@ -25,11 +63,6 @@ const PlaybackConfig = () => { increases the application's CPU usage.

-

- If volume fade is disabled, then the fading-in track will start at the specified crossfade - duration at full volume. -

-

Setting the crossfade duration to 0 will enable{' '} gapless playback mode. All other playback settings except the polling @@ -37,51 +70,38 @@ const PlaybackConfig = () => { 10 and 20 for increased transition accuracy. Note that the gapless playback is not true gapless and may work better or worse on specific albums.

+ +

+ If volume fade is disabled, then the fading-in track will start at the specified crossfade + duration at full volume. +

+

*Enable the debug window if you want to view the differences between each fade type

-
+
Crossfade duration (s) { - settings.setSync('fadeDuration', Number(e)); - dispatch( - setPlaybackSetting({ - setting: 'fadeDuration', - value: Number(e), - }) - ); - - if (Number(e) === 0) { - dispatch(setPlayerVolume({ player: 1, volume: playQueue.volume })); - dispatch(setPlayerVolume({ player: 2, volume: playQueue.volume })); - } - }} + onChange={(e: number) => handleSetCrossfadeDuration(e)} />
Polling interval (ms) { - settings.setSync('pollingInterval', Number(e)); - dispatch( - setPlaybackSetting({ - setting: 'pollingInterval', - value: Number(e), - }) - ); - }} + onChange={(e: number) => handleSetPollingInterval(e)} />
@@ -133,15 +153,51 @@ const PlaybackConfig = () => { { - settings.setSync('volumeFade', e); - dispatch(setPlaybackSetting({ setting: 'volumeFade', value: e })); - }} + defaultValue={volumeFade} + value={volumeFade} + onChange={(e: boolean) => handleSetVolumeFade(e)} > Enabled Disabled +
+
Presets
+ + { + setCrossfadeDuration(0); + setPollingInterval(15); + handleSetCrossfadeDuration(0); + handleSetPollingInterval(15); + }} + > + Gapless + + { + setCrossfadeDuration(7); + setPollingInterval(50); + setVolumeFade(true); + handleSetCrossfadeDuration(7); + handleSetPollingInterval(50); + handleSetVolumeFade(true); + }} + > + Fade + + { + setCrossfadeDuration(0); + setPollingInterval(200); + setVolumeFade(false); + handleSetCrossfadeDuration(0); + handleSetPollingInterval(200); + handleSetVolumeFade(false); + }} + > + Normal + +
);