From e5358c7cffe3dfe66451c9a405cf4d7430ea2d65 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Tue, 5 Jan 2021 23:41:14 +0000 Subject: [PATCH] Automate play on PFL and disable on fader. --- src/mixer/state.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/mixer/state.ts b/src/mixer/state.ts index af2141e..f0637b3 100644 --- a/src/mixer/state.ts +++ b/src/mixer/state.ts @@ -663,7 +663,8 @@ export const { setTracklistItemID } = mixerState.actions; const FADE_TIME_SECONDS = 1; export const setVolume = ( player: number, - level: VolumePresetEnum + level: VolumePresetEnum, + fade: boolean = true ): AppThunk => (dispatch, getState) => { let volume: number; let uiLevel: number; @@ -701,6 +702,18 @@ export const setVolume = ( } } + // If we're fading up the volume, disable the PFL. + if (level !== "off") { + dispatch(setChannelPFL(player, false)); + } + + // If not fading, just do it. + if (!fade) { + dispatch(mixerState.actions.setPlayerVolume({ player, volume: uiLevel })); + dispatch(mixerState.actions.setPlayerGain({ player, gain: volume })); + return; + } + const state = getState().mixer.players[player]; const currentLevel = state.volume; @@ -747,6 +760,12 @@ export const setChannelPFL = ( player: number, enabled: boolean ): AppThunk => async (dispatch) => { + if (typeof audioEngine.players[player] !== "undefined") { + if (!audioEngine.players[player]?.isPlaying) { + dispatch(setVolume(player, "off", false)); + dispatch(play(player)); + } + } dispatch(mixerState.actions.setPlayerPFL({ player, enabled })); audioEngine.setPFL(player, enabled); };