diff --git a/client/utils/SocketClientHandlers.ts b/client/utils/SocketClientHandlers.ts index 437df2af..5c11a3e5 100644 --- a/client/utils/SocketClientHandlers.ts +++ b/client/utils/SocketClientHandlers.ts @@ -26,6 +26,10 @@ import { SOCKET_RETURN_MIXER_PRESET_LIST, SOCKET_RETURN_PAGES_LIST, } from '../../server/constants/SOCKET_IO_DISPATCHERS' +import { + IchConnection, + InumberOfChannels, +} from '../../server/reducers/channelsReducer' export const socketClientHandlers = () => { window.socketIoClient @@ -39,15 +43,14 @@ export const socketClientHandlers = () => { }) .on(SOCKET_SET_FULL_STORE, (payload: any) => { // console.log('STATE RECEIVED :', payload) - - let numberOfChannels: number[] = [] if (window.mixerProtocol) { - window.mixerProtocol.channelTypes.forEach( - (item: any, index: number) => { - numberOfChannels.push( - payload.settings[0].mixers[0] - .numberOfChannelsInType[index] - ) + let numberOfChannels: InumberOfChannels[] = [] + payload.channels[0].chConnection.forEach( + (chConnection: IchConnection, mixerIndex: number) => { + numberOfChannels.push({ numberOfTypeInCh: [] }) + numberOfChannels[mixerIndex].numberOfTypeInCh = [ + chConnection.channel.length, + ] } ) window.storeRedux.dispatch( diff --git a/server/reducers/channelActions.ts b/server/reducers/channelActions.ts index d49007c0..9cffbf2a 100644 --- a/server/reducers/channelActions.ts +++ b/server/reducers/channelActions.ts @@ -1,4 +1,4 @@ -import { IChannel, IChannels } from './channelsReducer' +import { IChannel, IChannels, InumberOfChannels } from './channelsReducer' export const SET_OUTPUT_LEVEL = 'SET_OUTPUT_LEVEL' export const SET_AUX_LEVEL = 'SET_AUX_LEVEL' @@ -36,12 +36,12 @@ export const storeSetAuxLevel = ( export const storeSetCompleteChState = ( allState: IChannels, - numberOfTypeChannels: number[] + numberOfChannels: InumberOfChannels[] ) => { return { type: SET_COMPLETE_CH_STATE, allState: allState, - numberOfTypeChannels: numberOfTypeChannels, + numberOfTypeChannels: numberOfChannels, } } diff --git a/server/reducers/channelsReducer.ts b/server/reducers/channelsReducer.ts index 9838baf8..3338df3a 100644 --- a/server/reducers/channelsReducer.ts +++ b/server/reducers/channelsReducer.ts @@ -28,24 +28,27 @@ export interface IChannel { } } -const defaultChannelsReducerState = (numberOfChannels: any) => { - let defaultObj: Array = [ +export interface InumberOfChannels { + numberOfTypeInCh: number[] +} + +const defaultChannelsReducerState = ( + numberOfChannels: InumberOfChannels[] +): IChannels[] => { + let defaultObj: IChannels[] = [ { - chConnection: [ - { - channel: [], - }, - ], + chConnection: [], }, ] for ( let mixerIndex = 0; - mixerIndex++; - mixerIndex < numberOfChannels.length + mixerIndex < numberOfChannels.length; + mixerIndex++ ) { let totalNumberOfChannels = 0 - numberOfChannels[mixerIndex].nuberOfTypeChannels.forEach( + defaultObj[0].chConnection.push({ channel: [] }) + numberOfChannels[mixerIndex].numberOfTypeInCh.forEach( (channelTypeSize: any, typeIndex: number) => { for (let index = 0; index < channelTypeSize; index++) { defaultObj[0].chConnection[mixerIndex].channel[ @@ -68,7 +71,7 @@ const defaultChannelsReducerState = (numberOfChannels: any) => { } export const channels = ( - state = defaultChannelsReducerState([{ numberOfTypeChannels: 1 }]), + state = defaultChannelsReducerState([{ numberOfTypeInCh: [1] }]), action: any ): Array => { let nextState = [ @@ -85,22 +88,28 @@ export const channels = ( return nextState case SET_COMPLETE_CH_STATE: nextState = defaultChannelsReducerState(action.numberOfTypeChannels) - if ( - action.allState.chConnection[0].channel.length == - nextState[0].chConnection[0].channel.length - ) { - action.allState.chConnection[0].channel.forEach( - (channel: any, index: number) => { - if ( - index < nextState[0].chConnection[0].channel.length - ) { - nextState[0].chConnection[0].channel[ - index - ] = channel + + nextState[0].chConnection.forEach( + (chConnection: IchConnection, mixerIndex: number) => { + chConnection.channel.forEach( + (channel: any, index: number) => { + if ( + index < + action.allState.chConnection[mixerIndex] + ?.channel.length + ) { + nextState[0].chConnection[mixerIndex].channel[ + index + ] = + action.allState.chConnection[ + mixerIndex + ].channel[index] + } } - } - ) - } + ) + } + ) + return nextState case SET_SINGLE_CH_STATE: nextState[0].chConnection[0].channel[action.channelIndex] = diff --git a/server/utils/MixerConnection.ts b/server/utils/MixerConnection.ts index fb1870e6..6ea7c5a0 100644 --- a/server/utils/MixerConnection.ts +++ b/server/utils/MixerConnection.ts @@ -33,17 +33,11 @@ export class MixerGenericConnection { mixerProtocol: IMixerProtocolGeneric[] mixerConnection: any[] mixerTimers: { - chTimer: any[] - fadeActiveTimer: any[] + chTimer: NodeJS.Timeout[] + fadeActiveTimer: NodeJS.Timeout[] }[] constructor() { - this.updateOutLevels = this.updateOutLevels.bind(this) - this.updateOutLevel = this.updateOutLevel.bind(this) - this.fadeInOut = this.fadeInOut.bind(this) - this.fadeUp = this.fadeUp.bind(this) - this.fadeDown = this.fadeDown.bind(this) - this.clearTimer = this.clearTimer.bind(this) this.mixerProtocol = [] this.mixerConnection = [] // Get mixer protocol @@ -102,33 +96,54 @@ export class MixerGenericConnection { } }) + //Setup timers for fade in & out + this.initializeTimers() + } + + initializeTimers = () => { //Setup timers for fade in & out this.mixerTimers = [] state.channels[0].chConnection.forEach( - (chConnection: IchConnection, index: number) => { - this.mixerTimers.push({ - chTimer: new Array( - state.channels[0].chConnection[index].channel.length - ), - fadeActiveTimer: new Array( - state.channels[0].chConnection[index].channel.length - ), - }) + (chConnection: IchConnection, mixerIndex: number) => { + this.mixerTimers.push({ chTimer: [], fadeActiveTimer: [] }) + state.channels[0].chConnection[mixerIndex].channel.forEach( + (channel) => { + this.mixerTimers[mixerIndex].chTimer.push(undefined) + this.mixerTimers[mixerIndex].fadeActiveTimer.push( + undefined + ) + } + ) } ) } - getPresetFileExtention(): string { + clearTimer = (mixerIndex: number, channelIndex: number) => { + if (this.mixerTimers[mixerIndex]?.chTimer[channelIndex]) { + clearInterval(this.mixerTimers[mixerIndex].chTimer[channelIndex]) + } + } + + delayedFadeActiveDisable = (mixerIndex: number, channelIndex: number) => { + this.mixerTimers[mixerIndex].fadeActiveTimer[channelIndex] = setTimeout( + () => { + store.dispatch(storeFadeActive(mixerIndex, channelIndex, false)) + }, + state.settings[0].mixers[0].protocolLatency + ) + } + + getPresetFileExtention = (): string => { //TODO: atm mixer presets only supports first mixer connected to Sisyfos return this.mixerProtocol[0].presetFileExtension || '' } - loadMixerPreset(presetName: string) { + loadMixerPreset = (presetName: string) => { //TODO: atm mixer presets only supports first mixer connected to Sisyfos this.mixerConnection[0].loadMixerPreset(presetName) } - checkForAutoResetThreshold(channel: number) { + checkForAutoResetThreshold = (channel: number) => { if ( state.faders[0].fader[channel].faderLevel <= state.settings[0].autoResetLevel / 100 @@ -141,20 +156,20 @@ export class MixerGenericConnection { } } - updateFadeToBlack() { + updateFadeToBlack = () => { state.faders[0].fader.forEach((channel: any, index: number) => { this.updateOutLevel(index) }) } - updateOutLevels() { + updateOutLevels = () => { state.faders[0].fader.forEach((channel: any, index: number) => { this.updateOutLevel(index) this.updateNextAux(index) }) } - updateOutLevel(faderIndex: number, fadeTime: number = -1) { + updateOutLevel = (faderIndex: number, fadeTime: number = -1) => { if (fadeTime === -1) { if (state.faders[0].fader[faderIndex].voOn) { fadeTime = state.settings[0].voFadeTime @@ -183,7 +198,7 @@ export class MixerGenericConnection { } } - updateInputGain(faderIndex: number) { + updateInputGain = (faderIndex: number) => { let level = state.faders[0].fader[faderIndex].inputGain state.channels[0].chConnection.forEach( (chConnection: IchConnection, mixerIndex: number) => { @@ -201,7 +216,7 @@ export class MixerGenericConnection { ) } - updateInputSelector(faderIndex: number) { + updateInputSelector = (faderIndex: number) => { let inputSelected = state.faders[0].fader[faderIndex].inputSelector console.log(faderIndex, inputSelected) state.channels[0].chConnection.forEach( @@ -219,11 +234,11 @@ export class MixerGenericConnection { ) } - updatePflState(channelIndex: number) { + updatePflState = (channelIndex: number) => { this.mixerConnection[0].updatePflState(channelIndex) } - updateMuteState(faderIndex: number) { + updateMuteState = (faderIndex: number) => { state.channels[0].chConnection.forEach( (chConnection: IchConnection, mixerIndex: number) => { chConnection.channel.forEach( @@ -240,7 +255,7 @@ export class MixerGenericConnection { ) } - updateAMixState(faderIndex: number) { + updateAMixState = (faderIndex: number) => { state.channels[0].chConnection.forEach( (chConnection: IchConnection, mixerIndex: number) => { chConnection.channel.forEach( @@ -257,7 +272,7 @@ export class MixerGenericConnection { ) } - updateNextAux(faderIndex: number) { + updateNextAux = (faderIndex: number) => { let level = 0 if (state.faders[0].fader[faderIndex].pstOn) { level = state.faders[0].fader[faderIndex].faderLevel @@ -283,7 +298,7 @@ export class MixerGenericConnection { ) } - updateThreshold(faderIndex: number) { + updateThreshold = (faderIndex: number) => { let level = state.faders[0].fader[faderIndex].threshold state.channels[0].chConnection.forEach( (chConnection: IchConnection, mixerIndex: number) => { @@ -300,7 +315,7 @@ export class MixerGenericConnection { } ) } - updateRatio(faderIndex: number) { + updateRatio = (faderIndex: number) => { let level = state.faders[0].fader[faderIndex].ratio state.channels[0].chConnection.forEach( (chConnection: IchConnection, mixerIndex: number) => { @@ -317,7 +332,7 @@ export class MixerGenericConnection { } ) } - updateDelayTime(faderIndex: number) { + updateDelayTime = (faderIndex: number) => { let delayTime = state.faders[0].fader[faderIndex].delayTime state.channels[0].chConnection.forEach( (chConnection: IchConnection, mixerIndex: number) => { @@ -334,7 +349,7 @@ export class MixerGenericConnection { } ) } - updateLow(faderIndex: number) { + updateLow = (faderIndex: number) => { let level = state.faders[0].fader[faderIndex].low state.channels[0].chConnection.forEach( (chConnection: IchConnection, mixerIndex: number) => { @@ -351,7 +366,7 @@ export class MixerGenericConnection { } ) } - updateLoMid(faderIndex: number) { + updateLoMid = (faderIndex: number) => { let level = state.faders[0].fader[faderIndex].loMid state.channels[0].chConnection.forEach( (chConnection: IchConnection, mixerIndex: number) => { @@ -368,7 +383,7 @@ export class MixerGenericConnection { } ) } - updateMid(faderIndex: number) { + updateMid = (faderIndex: number) => { let level = state.faders[0].fader[faderIndex].mid state.channels[0].chConnection.forEach( (chConnection: IchConnection, mixerIndex: number) => { @@ -385,7 +400,7 @@ export class MixerGenericConnection { } ) } - updateHigh(faderIndex: number) { + updateHigh = (faderIndex: number) => { let level = state.faders[0].fader[faderIndex].high state.channels[0].chConnection.forEach( (chConnection: IchConnection, mixerIndex: number) => { @@ -403,7 +418,7 @@ export class MixerGenericConnection { ) } - updateAuxLevel(channelIndex: number, auxSendIndex: number) { + updateAuxLevel = (channelIndex: number, auxSendIndex: number) => { let channel = state.channels[0].chConnection[0].channel[channelIndex] if (channel.auxLevel[auxSendIndex] > -1) { this.mixerConnection[0].updateAuxLevel( @@ -414,19 +429,19 @@ export class MixerGenericConnection { } } - updateChannelName(channelIndex: number) { + updateChannelName = (channelIndex: number) => { this.mixerConnection[0].updateChannelName(channelIndex) } - injectCommand(command: string[]) { + injectCommand = (command: string[]) => { this.mixerConnection[0].injectCommand(command) } - updateChannelSettings( + updateChannelSettings = ( channelIndex: number, setting: string, value: string - ) { + ) => { if (this.mixerProtocol[0].protocol === 'CasparCG') { this.mixerConnection[0].updateChannelSetting( channelIndex, @@ -436,20 +451,11 @@ export class MixerGenericConnection { } } - clearTimer(mixerIndex: number, channelIndex: number) { - clearInterval(this.mixerTimers[mixerIndex].chTimer[channelIndex]) - } - - delayedFadeActiveDisable(mixerIndex: number, channelIndex: number) { - this.mixerTimers[mixerIndex].fadeActiveTimer[channelIndex] = setTimeout( - () => { - store.dispatch(storeFadeActive(mixerIndex, channelIndex, false)) - }, - state.settings[0].mixers[0].protocolLatency - ) - } - - fadeInOut(mixerIndex: number, channelIndex: number, fadeTime: number) { + fadeInOut = ( + mixerIndex: number, + channelIndex: number, + fadeTime: number + ) => { let faderIndex = state.channels[0].chConnection[mixerIndex].channel[channelIndex] .assignedFader @@ -461,6 +467,12 @@ export class MixerGenericConnection { ) { return } + if ( + this.mixerTimers.length === 1 && + this.mixerTimers[0].chTimer.length === 1 + ) { + this.initializeTimers() + } //Clear Old timer or set Fade to active: if ( state.channels[0].chConnection[mixerIndex].channel[channelIndex] @@ -482,12 +494,12 @@ export class MixerGenericConnection { } } - fadeUp( + fadeUp = ( mixerIndex: number, channelIndex: number, fadeTime: number, faderIndex: number - ) { + ) => { let outputLevel = state.channels[0].chConnection[mixerIndex].channel[channelIndex] .outputLevel @@ -589,7 +601,7 @@ export class MixerGenericConnection { } } - fadeDown(mixerIndex: number, channelIndex: number, fadeTime: number) { + fadeDown = (mixerIndex: number, channelIndex: number, fadeTime: number) => { let outputLevel = state.channels[0].chConnection[mixerIndex].channel[channelIndex] .outputLevel diff --git a/server/utils/SettingsStorage.ts b/server/utils/SettingsStorage.ts index 25d5f548..1e6581cd 100644 --- a/server/utils/SettingsStorage.ts +++ b/server/utils/SettingsStorage.ts @@ -7,6 +7,7 @@ import { store } from '../reducers/store' import { storeSetCompleteChState } from '../reducers/channelActions' import { SET_COMPLETE_FADER_STATE } from '../reducers/faderActions' import { logger } from './logger' +import { InumberOfChannels } from '../reducers/channelsReducer' export const loadSettings = (storeRedux: any) => { let settingsInterface = storeRedux.settings[0] @@ -41,7 +42,7 @@ export const saveSettings = (settings: any) => { export const loadSnapshotState = ( stateSnapshot: any, stateChannelSnapshot: any, - numberOfChannels: Array, + numberOfChannels: InumberOfChannels[], numberOfFaders: number, fileName: string, loadAll: boolean diff --git a/server/utils/SnapshotHandler.ts b/server/utils/SnapshotHandler.ts index 86e1884e..32d9bf84 100644 --- a/server/utils/SnapshotHandler.ts +++ b/server/utils/SnapshotHandler.ts @@ -3,10 +3,11 @@ import { loadSnapshotState, saveSnapshotState } from './SettingsStorage' import { mixerProtocolPresets } from '../mainClasses' import { state } from '../reducers/store' import { logger } from './logger' +import { InumberOfChannels } from '../reducers/channelsReducer' const path = require('path') export class SnapshotHandler { - numberOfChannels: any[] = [{ numberOfChannelInTypes: [] }] + numberOfChannels: InumberOfChannels[] = [] settingsPath: string = '' constructor() { @@ -15,12 +16,19 @@ export class SnapshotHandler { this.snapShopStoreTimer() // Count total number of channels: - for (let i = 0; i++; i < state.settings[0].numberOfMixers) { + for ( + let mixerIndex = 0; + mixerIndex < state.settings[0].numberOfMixers; + mixerIndex++ + ) { + this.numberOfChannels.push({ numberOfTypeInCh: [] }) mixerProtocolPresets[ - state.settings[0].mixers[i].mixerProtocol + state.settings[0].mixers[mixerIndex].mixerProtocol ].channelTypes.forEach((item: any, index: number) => { - this.numberOfChannels[i].numberOfChannelInTypes.push( - state.settings[0].mixers[0].numberOfChannelsInType[index] + this.numberOfChannels[mixerIndex].numberOfTypeInCh.push( + state.settings[0].mixers[mixerIndex].numberOfChannelsInType[ + index + ] ) }) }