Skip to content

Commit

Permalink
fix: update ruby pgm from external update
Browse files Browse the repository at this point in the history
  • Loading branch information
mint-dewit committed Nov 21, 2023
1 parent e6ae5d0 commit 36604fb
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 117 deletions.
4 changes: 2 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@tv2media/logger": "^2.0.1",
"atem-connection": "^3.2.0",
"casparcg-connection": "^5.1.0",
"emberplus-connection": "^0.1.2",
"emberplus-connection": "^0.2.1",
"express": "^4.18.2",
"node-emberplus": "^3.0.5",
"node-vmix": "^1.6.1",
Expand All @@ -36,4 +36,4 @@
"webmidi": "^2.5.1",
"shared": "file:../shared"
}
}
}
56 changes: 24 additions & 32 deletions server/src/utils/mixerConnections/EmberMixerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import {
storeSetChLabel,
} from '../../../../shared/src/actions/channelActions'
import { storeSetMixerOnline } from '../../../../shared/src/actions/settingsActions'
import { IChannelReference, IFader } from '../../../../shared/src/reducers/fadersReducer'
import {
IChannelReference,
IFader,
} from '../../../../shared/src/reducers/fadersReducer'
import { EmberElement, NumberedTreeNode } from 'emberplus-connection/dist/model'

export class EmberMixerConnection {
mixerProtocol: IMixerProtocol
Expand All @@ -49,9 +53,12 @@ export class EmberMixerConnection {
}

private getAssignedFaderIndex(channelIndex: number) {
return state.faders[0].fader.findIndex(
(fader: IFader) => fader.assignedChannels?.some((assigned: IChannelReference) => {
return (assigned.mixerIndex === this.mixerIndex && assigned.channelIndex === channelIndex)
return state.faders[0].fader.findIndex((fader: IFader) =>
fader.assignedChannels?.some((assigned: IChannelReference) => {
return (
assigned.mixerIndex === this.mixerIndex &&
assigned.channelIndex === channelIndex
)
})
)
}
Expand Down Expand Up @@ -212,17 +219,13 @@ export class EmberMixerConnection {
channelTypeIndex
)
}
store.dispatch(
storeShowChannel(assignedFaderIndex, true)
)
store.dispatch(storeShowChannel(assignedFaderIndex, true))
global.mainThreadHandler.updatePartialStore(
assignedFaderIndex
)
} else {
logger.info(`Channel ${ch} offline`)
store.dispatch(
storeShowChannel(assignedFaderIndex, false)
)
store.dispatch(storeShowChannel(assignedFaderIndex, false))
global.mainThreadHandler.updatePartialStore(
assignedFaderIndex
)
Expand All @@ -249,7 +252,10 @@ export class EmberMixerConnection {
)
if (!node) return

await this.emberConnection.subscribe(node, cb)
await this.emberConnection.subscribe(
node as NumberedTreeNode<EmberElement>,
cb
)

cb(node)
} catch (e) {
Expand Down Expand Up @@ -285,9 +291,7 @@ export class EmberMixerConnection {
)

if (!channel.fadeActive && level >= 0 && level <= 1) {
store.dispatch(
storeFaderLevel(assignedFaderIndex, level)
)
store.dispatch(storeFaderLevel(assignedFaderIndex, level))
store.dispatch({
type: SET_OUTPUT_LEVEL,
channel: assignedFaderIndex,
Expand All @@ -297,9 +301,7 @@ export class EmberMixerConnection {

// toggle pgm based on level
logger.trace(`Set Channel ${ch} pgmOn ${level > 0}`)
store.dispatch(
storeSetPgm(assignedFaderIndex, level > 0)
)
store.dispatch(storeSetPgm(assignedFaderIndex, level > 0))

global.mainThreadHandler.updatePartialStore(
assignedFaderIndex
Expand Down Expand Up @@ -357,9 +359,7 @@ export class EmberMixerConnection {
)
)
}
global.mainThreadHandler.updatePartialStore(
assignedFaderIndex
)
global.mainThreadHandler.updatePartialStore(assignedFaderIndex)
}
)
}
Expand Down Expand Up @@ -390,9 +390,7 @@ export class EmberMixerConnection {
(node.contents as Model.Parameter).value as boolean
)
)
global.mainThreadHandler.updatePartialStore(
assignedFaderIndex
)
global.mainThreadHandler.updatePartialStore(assignedFaderIndex)
}
)
}
Expand Down Expand Up @@ -429,9 +427,7 @@ export class EmberMixerConnection {
// assume it is in db now
level = this._faderLevelToFloat(Number(level), 0)
store.dispatch(storeInputGain(assignedFaderIndex, level))
global.mainThreadHandler.updatePartialStore(
assignedFaderIndex
)
global.mainThreadHandler.updatePartialStore(assignedFaderIndex)
}
)
}
Expand Down Expand Up @@ -510,9 +506,7 @@ export class EmberMixerConnection {
(node.contents as Model.Parameter).value as boolean
)
)
global.mainThreadHandler.updatePartialStore(
assignedFaderIndex
)
global.mainThreadHandler.updatePartialStore(assignedFaderIndex)
}
)
// subscribe to input selectors
Expand Down Expand Up @@ -623,9 +617,7 @@ export class EmberMixerConnection {
(node.contents as Model.Parameter).value as boolean
)
)
global.mainThreadHandler.updatePartialStore(
assignedFaderIndex
)
global.mainThreadHandler.updatePartialStore(assignedFaderIndex)
}
)
}
Expand Down
148 changes: 85 additions & 63 deletions server/src/utils/mixerConnections/LawoRubyConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import {
storeSetAMix,
storeCapability,
storeShowChannel,
storeSetPgm,
} from '../../../../shared/src/actions/faderActions'
import { logger } from '../logger'
import { storeSetMixerOnline } from '../../../../shared/src/actions/settingsActions'
import { storeSetChLabel } from '../../../../shared/src/actions/channelActions'
import { EmberElement, NumberedTreeNode } from 'emberplus-connection/dist/model'

// TODO - should these be util functions?
export function floatToDB(f: number): number {
Expand Down Expand Up @@ -122,7 +124,9 @@ export class LawoRubyMixerConnection {
'Ruby.Sources'
)
// get the sources
const req = await this.emberConnection.getDirectory(sourceNode)
const req = await this.emberConnection.getDirectory(
sourceNode as NumberedTreeNode<EmberElement>
)
const sources = await req.response

// map sourceNames to their fader number
Expand Down Expand Up @@ -251,36 +255,37 @@ export class LawoRubyMixerConnection {
if (node.contents.type !== Model.ElementType.Parameter) return

logger.debug(`Subscription of channel level: ${command}`)
this.emberConnection.subscribe(node, () => {
logger.trace(`Receiving Level from Ch ${ch}`)
if (
!state.channels[0].chMixerConnection[this.mixerIndex]
.channel[ch - 1].fadeActive &&
(node.contents as Model.Parameter).value as number >
this.mixerProtocol.channelTypes[typeIndex].fromMixer
.CHANNEL_OUT_GAIN[0].min
) {
store.dispatch(
storeFaderLevel(
ch - 1,
dbToFloat(
(node.contents as Model.Parameter)
.value as number
)
)
)
global.mainThreadHandler.updatePartialStore(ch - 1)
if (remoteConnections) {
remoteConnections.updateRemoteFaderState(
ch - 1,
dbToFloat(
(node.contents as Model.Parameter)
.value as number
this.emberConnection.subscribe(
node as NumberedTreeNode<EmberElement>,
() => {
const levelDB = (node.contents as Model.Parameter)
.value as number
logger.debug(`Receiving Level from Ch ${ch}: ${levelDB}`)
if (
!state.channels[0].chMixerConnection[this.mixerIndex]
.channel[ch - 1].fadeActive &&
levelDB >=
this.mixerProtocol.channelTypes[typeIndex].fromMixer
.CHANNEL_OUT_GAIN[0].min
) {
// update the fader
const level = dbToFloat(levelDB)
store.dispatch(storeFaderLevel(ch - 1, level))

// toggle pgm based on level
logger.trace(`Set Channel ${ch} pgmOn ${level > 0}`)
store.dispatch(storeSetPgm(ch - 1, level > 0))

global.mainThreadHandler.updatePartialStore(ch - 1)
if (remoteConnections) {
remoteConnections.updateRemoteFaderState(
ch - 1,
level
)
)
}
}
}
})
)
} catch (e) {
logger.data(e).debug('error when subscribing to fader level')
}
Expand All @@ -303,15 +308,22 @@ export class LawoRubyMixerConnection {
if (node.contents.type !== Model.ElementType.Parameter) return

logger.debug(`Subscription of channel gain: ${command}`)
this.emberConnection.subscribe(node, () => {
logger.trace(`Receiving Gain from Ch ${ch}`)
const value = (node.contents as Model.Parameter).value as number
const level = (value - proto.min) / (proto.max - proto.min)
if ((node.contents as Model.Parameter).value as number > proto.min) {
store.dispatch(storeInputGain(ch - 1, level))
global.mainThreadHandler.updatePartialStore(ch - 1)
this.emberConnection.subscribe(
node as NumberedTreeNode<EmberElement>,
() => {
logger.trace(`Receiving Gain from Ch ${ch}`)
const value = (node.contents as Model.Parameter)
.value as number
const level = (value - proto.min) / (proto.max - proto.min)
if (
((node.contents as Model.Parameter).value as number) >
proto.min
) {
store.dispatch(storeInputGain(ch - 1, level))
global.mainThreadHandler.updatePartialStore(ch - 1)
}
}
})
)
} catch (e) {
logger.data(e).debug('Error when subscribing to gain level')
}
Expand Down Expand Up @@ -340,24 +352,31 @@ export class LawoRubyMixerConnection {
}

logger.debug(`Subscription of channel input selector: ${command}`)
this.emberConnection.subscribe(node, () => {
logger.trace(`Receiving InpSelector from Ch ${ch}`)
this.mixerProtocol.channelTypes[
typeIndex
].fromMixer.CHANNEL_INPUT_SELECTOR.forEach((selector, i) => {
if (
selector.value ===
(node.contents as Model.Parameter).value
) {
store.dispatch({
type: SET_INPUT_SELECTOR,
channel: ch - 1,
selected: i + 1,
})
global.mainThreadHandler.updatePartialStore(ch - 1)
}
})
})
this.emberConnection.subscribe(
node as NumberedTreeNode<EmberElement>,
() => {
logger.trace(`Receiving InpSelector from Ch ${ch}`)
this.mixerProtocol.channelTypes[
typeIndex
].fromMixer.CHANNEL_INPUT_SELECTOR.forEach(
(selector, i) => {
if (
selector.value ===
(node.contents as Model.Parameter).value
) {
store.dispatch({
type: SET_INPUT_SELECTOR,
channel: ch - 1,
selected: i + 1,
})
global.mainThreadHandler.updatePartialStore(
ch - 1
)
}
}
)
}
)
} catch (e) {
if (e.message.match(/could not find node/i)) {
logger.debug(`set_cap ${ch} hasInputSel false`)
Expand Down Expand Up @@ -392,16 +411,19 @@ export class LawoRubyMixerConnection {
}

logger.debug(`Subscription of AMix state: ${command}`)
this.emberConnection.subscribe(node, () => {
logger.trace(`Receiving AMix state from Ch ${ch}`)
store.dispatch(
storeSetAMix(
ch - 1,
(node.contents as Model.Parameter).value === 1
this.emberConnection.subscribe(
node as NumberedTreeNode<EmberElement>,
() => {
logger.trace(`Receiving AMix state from Ch ${ch}`)
store.dispatch(
storeSetAMix(
ch - 1,
(node.contents as Model.Parameter).value === 1
)
)
)
global.mainThreadHandler.updatePartialStore(ch - 1)
})
global.mainThreadHandler.updatePartialStore(ch - 1)
}
)
} catch (e) {
if (e.message.match(/could not find node/i)) {
logger.debug(`set_cap ${ch - 1} hasAMix false`)
Expand Down
Loading

0 comments on commit 36604fb

Please sign in to comment.