Skip to content

Commit

Permalink
feat: support multiple mixers in Fade in-out
Browse files Browse the repository at this point in the history
  • Loading branch information
olzzon authored and olzzon committed Oct 5, 2020
1 parent f29b09f commit b67c06d
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions server/utils/MixerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ export class MixerGenericConnection {
}

state.channels[0].chConnection.forEach(
(chConnection: IchConnection) => {
(chConnection: IchConnection, mixerIndex: number) => {
chConnection.channel.forEach(
(channel: IChannel, channelIndex: number) => {
if (faderIndex === channel.assignedFader) {
this.fadeInOut(channelIndex, fadeTime)
this.fadeInOut(mixerIndex, channelIndex, fadeTime)
}
}
)
Expand Down Expand Up @@ -435,21 +435,22 @@ export class MixerGenericConnection {
}, state.settings[0].mixers[0].protocolLatency)
}

fadeInOut(channelIndex: number, fadeTime: number) {
fadeInOut(mixerIndex: number, channelIndex: number, fadeTime: number) {
let faderIndex =
state.channels[0].chConnection[0].channel[channelIndex]
state.channels[0].chConnection[mixerIndex].channel[channelIndex]
.assignedFader
if (
!state.faders[0].fader[faderIndex].pgmOn &&
!state.faders[0].fader[faderIndex].voOn &&
state.channels[0].chConnection[0].channel[channelIndex]
state.channels[0].chConnection[mixerIndex].channel[channelIndex]
.outputLevel === 0
) {
return
}
//Clear Old timer or set Fade to active:
if (
state.channels[0].chConnection[0].channel[channelIndex].fadeActive
state.channels[0].chConnection[mixerIndex].channel[channelIndex]
.fadeActive
) {
clearInterval(this.fadeActiveTimer[channelIndex])
this.clearTimer(channelIndex)
Expand All @@ -459,15 +460,21 @@ export class MixerGenericConnection {
state.faders[0].fader[faderIndex].pgmOn ||
state.faders[0].fader[faderIndex].voOn
) {
this.fadeUp(channelIndex, fadeTime, faderIndex)
this.fadeUp(mixerIndex, channelIndex, fadeTime, faderIndex)
} else {
this.fadeDown(channelIndex, fadeTime)
this.fadeDown(mixerIndex, channelIndex, fadeTime)
}
}

fadeUp(channelIndex: number, fadeTime: number, faderIndex: number) {
fadeUp(
mixerIndex: number,
channelIndex: number,
fadeTime: number,
faderIndex: number
) {
let outputLevel =
state.channels[0].chConnection[0].channel[channelIndex].outputLevel
state.channels[0].chConnection[mixerIndex].channel[channelIndex]
.outputLevel
let targetVal = state.faders[0].fader[faderIndex].faderLevel

if (state.faders[0].fader[faderIndex].voOn) {
Expand All @@ -476,7 +483,7 @@ export class MixerGenericConnection {
const step: number =
(targetVal - outputLevel) / (fadeTime / FADE_INOUT_SPEED)
const dispatchResolution: number =
this.mixerProtocol[0].FADE_DISPATCH_RESOLUTION * step
this.mixerProtocol[mixerIndex].FADE_DISPATCH_RESOLUTION * step
let dispatchTrigger: number = 0
this.clearTimer(channelIndex)

Expand All @@ -486,7 +493,7 @@ export class MixerGenericConnection {
dispatchTrigger += step

if (dispatchTrigger > dispatchResolution) {
this.mixerConnection[0].updateFadeIOLevel(
this.mixerConnection[mixerIndex].updateFadeIOLevel(
channelIndex,
outputLevel
)
Expand All @@ -498,7 +505,7 @@ export class MixerGenericConnection {

if (outputLevel <= targetVal) {
outputLevel = targetVal
this.mixerConnection[0].updateFadeIOLevel(
this.mixerConnection[mixerIndex].updateFadeIOLevel(
channelIndex,
outputLevel
)
Expand All @@ -515,7 +522,7 @@ export class MixerGenericConnection {
this.timer[channelIndex] = setInterval(() => {
outputLevel += step
dispatchTrigger += step
this.mixerConnection[0].updateFadeIOLevel(
this.mixerConnection[mixerIndex].updateFadeIOLevel(
channelIndex,
outputLevel
)
Expand All @@ -529,7 +536,7 @@ export class MixerGenericConnection {

if (outputLevel >= targetVal) {
outputLevel = targetVal
this.mixerConnection[0].updateFadeIOLevel(
this.mixerConnection[mixerIndex].updateFadeIOLevel(
channelIndex,
outputLevel
)
Expand All @@ -544,20 +551,24 @@ export class MixerGenericConnection {
}
}

fadeDown(channelIndex: number, fadeTime: number) {
fadeDown(mixerIndex: number, channelIndex: number, fadeTime: number) {
let outputLevel =
state.channels[0].chConnection[0].channel[channelIndex].outputLevel
state.channels[0].chConnection[mixerIndex].channel[channelIndex]
.outputLevel
const step = outputLevel / (fadeTime / FADE_INOUT_SPEED)
const dispatchResolution: number =
this.mixerProtocol[0].FADE_DISPATCH_RESOLUTION * step
this.mixerProtocol[mixerIndex].FADE_DISPATCH_RESOLUTION * step
let dispatchTrigger: number = 0

this.clearTimer(channelIndex)

this.timer[channelIndex] = setInterval(() => {
outputLevel -= step
dispatchTrigger += step
this.mixerConnection[0].updateFadeIOLevel(channelIndex, outputLevel)
this.mixerConnection[mixerIndex].updateFadeIOLevel(
channelIndex,
outputLevel
)

if (dispatchTrigger > dispatchResolution) {
store.dispatch(storeSetOutputLevel(channelIndex, outputLevel))
Expand All @@ -566,7 +577,7 @@ export class MixerGenericConnection {

if (outputLevel <= 0) {
outputLevel = 0
this.mixerConnection[0].updateFadeIOLevel(
this.mixerConnection[mixerIndex].updateFadeIOLevel(
channelIndex,
outputLevel
)
Expand Down

0 comments on commit b67c06d

Please sign in to comment.