Skip to content

Commit

Permalink
feat: multiple mixers, timer fade inout support
Browse files Browse the repository at this point in the history
  • Loading branch information
olzzon authored and olzzon committed Oct 5, 2020
1 parent b67c06d commit f59036a
Showing 1 changed file with 93 additions and 71 deletions.
164 changes: 93 additions & 71 deletions server/utils/MixerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ export class MixerGenericConnection {
store: any
mixerProtocol: IMixerProtocolGeneric[]
mixerConnection: any[]
timer: any
fadeActiveTimer: any
mixerTimers: {
chTimer: any[]
fadeActiveTimer: any[]
}[]

constructor() {
this.updateOutLevels = this.updateOutLevels.bind(this)
Expand Down Expand Up @@ -101,9 +103,18 @@ export class MixerGenericConnection {
})

//Setup timers for fade in & out
this.timer = new Array(state.channels[0].chConnection[0].channel.length)
this.fadeActiveTimer = new Array(
state.channels[0].chConnection[0].channel.length
this.mixerTimers = []
state.channels[0].chConnection.forEach(
(chConnection: IchConnection, index: number) => {
this.mixerTimers.push({
chTimer: new Array(
state.channels[0].chConnection[0].channel.length
),
fadeActiveTimer: new Array(
state.channels[0].chConnection[0].channel.length
),
})
}
)
}

Expand Down Expand Up @@ -425,14 +436,17 @@ export class MixerGenericConnection {
}
}

clearTimer(channelIndex: number) {
clearInterval(this.timer[channelIndex])
clearTimer(mixerIndex: number, channelIndex: number) {
clearInterval(this.mixerTimers[mixerIndex].chTimer[channelIndex])
}

delayedFadeActiveDisable(channelIndex: number) {
this.fadeActiveTimer[channelIndex] = setTimeout(() => {
store.dispatch(storeFadeActive(channelIndex, false))
}, state.settings[0].mixers[0].protocolLatency)
delayedFadeActiveDisable(mixerIndex: number, channelIndex: number) {
this.mixerTimers[mixerIndex].fadeActiveTimer[channelIndex] = setTimeout(
() => {
store.dispatch(storeFadeActive(channelIndex, false))
},
state.settings[0].mixers[0].protocolLatency
)
}

fadeInOut(mixerIndex: number, channelIndex: number, fadeTime: number) {
Expand All @@ -452,8 +466,10 @@ export class MixerGenericConnection {
state.channels[0].chConnection[mixerIndex].channel[channelIndex]
.fadeActive
) {
clearInterval(this.fadeActiveTimer[channelIndex])
this.clearTimer(channelIndex)
clearInterval(
this.mixerTimers[mixerIndex].fadeActiveTimer[channelIndex]
)
this.clearTimer(mixerIndex, channelIndex)
}
store.dispatch(storeFadeActive(channelIndex, true))
if (
Expand Down Expand Up @@ -485,69 +501,75 @@ export class MixerGenericConnection {
const dispatchResolution: number =
this.mixerProtocol[mixerIndex].FADE_DISPATCH_RESOLUTION * step
let dispatchTrigger: number = 0
this.clearTimer(channelIndex)
this.clearTimer(mixerIndex, channelIndex)

if (targetVal < outputLevel) {
this.timer[channelIndex] = setInterval(() => {
outputLevel += step
dispatchTrigger += step

if (dispatchTrigger > dispatchResolution) {
this.mixerConnection[mixerIndex].updateFadeIOLevel(
channelIndex,
outputLevel
)
store.dispatch(
storeSetOutputLevel(channelIndex, outputLevel)
)
dispatchTrigger = 0
}
this.mixerTimers[mixerIndex].chTimer[channelIndex] = setInterval(
() => {
outputLevel += step
dispatchTrigger += step

if (dispatchTrigger > dispatchResolution) {
this.mixerConnection[mixerIndex].updateFadeIOLevel(
channelIndex,
outputLevel
)
store.dispatch(
storeSetOutputLevel(channelIndex, outputLevel)
)
dispatchTrigger = 0
}

if (outputLevel <= targetVal) {
outputLevel = targetVal
if (outputLevel <= targetVal) {
outputLevel = targetVal
this.mixerConnection[mixerIndex].updateFadeIOLevel(
channelIndex,
outputLevel
)
this.clearTimer(mixerIndex, channelIndex)

store.dispatch(
storeSetOutputLevel(channelIndex, outputLevel)
)
this.delayedFadeActiveDisable(mixerIndex, channelIndex)
return true
}
},
FADE_INOUT_SPEED
)
} else {
this.mixerTimers[mixerIndex].chTimer[channelIndex] = setInterval(
() => {
outputLevel += step
dispatchTrigger += step
this.mixerConnection[mixerIndex].updateFadeIOLevel(
channelIndex,
outputLevel
)
this.clearTimer(channelIndex)

store.dispatch(
storeSetOutputLevel(channelIndex, outputLevel)
)
this.delayedFadeActiveDisable(channelIndex)
return true
}
}, FADE_INOUT_SPEED)
} else {
this.timer[channelIndex] = setInterval(() => {
outputLevel += step
dispatchTrigger += step
this.mixerConnection[mixerIndex].updateFadeIOLevel(
channelIndex,
outputLevel
)

if (dispatchTrigger > dispatchResolution) {
store.dispatch(
storeSetOutputLevel(channelIndex, outputLevel)
)
dispatchTrigger = 0
}
if (dispatchTrigger > dispatchResolution) {
store.dispatch(
storeSetOutputLevel(channelIndex, outputLevel)
)
dispatchTrigger = 0
}

if (outputLevel >= targetVal) {
outputLevel = targetVal
this.mixerConnection[mixerIndex].updateFadeIOLevel(
channelIndex,
outputLevel
)
this.clearTimer(channelIndex)
store.dispatch(
storeSetOutputLevel(channelIndex, outputLevel)
)
this.delayedFadeActiveDisable(channelIndex)
return true
}
}, FADE_INOUT_SPEED)
if (outputLevel >= targetVal) {
outputLevel = targetVal
this.mixerConnection[mixerIndex].updateFadeIOLevel(
channelIndex,
outputLevel
)
this.clearTimer(mixerIndex, channelIndex)
store.dispatch(
storeSetOutputLevel(channelIndex, outputLevel)
)
this.delayedFadeActiveDisable(mixerIndex, channelIndex)
return true
}
},
FADE_INOUT_SPEED
)
}
}

Expand All @@ -560,9 +582,9 @@ export class MixerGenericConnection {
this.mixerProtocol[mixerIndex].FADE_DISPATCH_RESOLUTION * step
let dispatchTrigger: number = 0

this.clearTimer(channelIndex)
this.clearTimer(mixerIndex, channelIndex)

this.timer[channelIndex] = setInterval(() => {
this.mixerTimers[mixerIndex].chTimer[channelIndex] = setInterval(() => {
outputLevel -= step
dispatchTrigger += step
this.mixerConnection[mixerIndex].updateFadeIOLevel(
Expand All @@ -581,9 +603,9 @@ export class MixerGenericConnection {
channelIndex,
outputLevel
)
this.clearTimer(channelIndex)
this.clearTimer(mixerIndex, channelIndex)
store.dispatch(storeSetOutputLevel(channelIndex, outputLevel))
this.delayedFadeActiveDisable(channelIndex)
this.delayedFadeActiveDisable(mixerIndex, channelIndex)
return true
}
}, FADE_INOUT_SPEED)
Expand Down

0 comments on commit f59036a

Please sign in to comment.