Skip to content

Commit

Permalink
Merge pull request #350 from bbc/fix/triggervalue-per-channel
Browse files Browse the repository at this point in the history
Fix: set triggervalue per channel
  • Loading branch information
nytamin authored Oct 7, 2024
2 parents dff2a69 + 54734d5 commit ac7ec2f
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 8 deletions.
30 changes: 25 additions & 5 deletions packages/timeline-state-resolver-types/src/integrations/sisyfos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,41 @@ export interface SisyfosChannelOptions {
export interface TimelineContentSisyfosTriggerValue extends TimelineContentSisyfos {
type: TimelineContentTypeSisyfos.TRIGGERVALUE

/**
* If this value changes, commands will be sent to set each channel that is
* mapped to its expected state regardless of whether that state changed
*/
triggerValue: string
}
export interface TimelineContentSisyfosChannel extends TimelineContentSisyfos, SisyfosChannelOptions {
export interface TimelineContentSisyfosChannel
extends SisyfosTimelineObjectProps,
TimelineContentSisyfos,
SisyfosChannelOptions {
type: TimelineContentTypeSisyfos.CHANNEL
resync?: boolean
overridePriority?: number // defaults to 0
triggerValue?: string
}
export interface TimelineContentSisyfosChannels extends TimelineContentSisyfos {
export interface TimelineContentSisyfosChannels extends SisyfosTimelineObjectProps, TimelineContentSisyfos {
type: TimelineContentTypeSisyfos.CHANNELS
channels: ({
/** The mapping layer to look up the channel from */
mappedLayer: string
} & SisyfosChannelOptions)[]
}
interface SisyfosTimelineObjectProps {
/**
* When this is set to true it will do a full resync with Sisyfos, first
* request the remote end's state and then diffing the local state against that
* (depending on channel count this is a slow operation)
*/
resync?: boolean
/**
* If you have multiple references to 1 channel in different timeline obejcts,
* the one with the highest overridePriority will be used
*/
overridePriority?: number // defaults to 0
/**
* If this value changes, commands will be sent to set the channels in this
* object to their expected state regardless of wheter the state of these
* channels changed
*/
triggerValue?: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -887,8 +887,16 @@ describe('Sisyfos', () => {
mappingType: MappingSisyfosType.Channels,
},
}
const myTriggerMapping0: Mapping<SomeMappingSisyfos> = {
device: DeviceType.SISYFOS,
deviceId: 'mySisyfos',
options: {
mappingType: MappingSisyfosType.Channels,
},
}
const myChannelMapping: Mappings = {
sisyfos_channels_base: myChannelMapping0,
sisyfos_channels_base_trigger: myTriggerMapping0,
sisyfos_channel_1: myChannelMapping1,
sisyfos_channel_2: myChannelMapping2,
sisyfos_channels: myChannelMapping3,
Expand Down Expand Up @@ -942,10 +950,21 @@ describe('Sisyfos', () => {
isPgm: 0,
},
],
triggerValue: 'a',
overridePriority: -999,
},
},
{
id: 'baseline_trigger',
enable: {
while: 1,
},
layer: 'sisyfos_channels_base_trigger',
content: {
deviceType: DeviceType.SISYFOS,
type: TimelineContentTypeSisyfos.TRIGGERVALUE,
triggerValue: 'a',
},
},
{
id: 'obj1',
enable: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ export type SisyfosCommand =

export interface SisyfosChannel extends SisyfosChannelAPI {
timelineObjIds: string[]
triggerValue?: string
}
export interface SisyfosState {
channels: { [index: string]: SisyfosChannel }
Expand Down
29 changes: 27 additions & 2 deletions packages/timeline-state-resolver/src/integrations/sisyfos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ export class SisyfosMessageDevice extends DeviceWithState<SisyfosState, DeviceOp
channel: number
isLookahead: boolean
timelineObjId: string
triggerValue?: string
} & SisyfosChannelOptions)[] = []

_.each(state.layers, (tlObject, layerName) => {
Expand All @@ -339,8 +340,12 @@ export class SisyfosMessageDevice extends DeviceWithState<SisyfosState, DeviceOp
deviceState.resync = deviceState.resync || content.resync
}

// Allow retrigger without valid channel mapping
if ('triggerValue' in content && content.triggerValue !== undefined) {
// Allow global retrigger without valid channel mapping
if (
'triggerValue' in content &&
content.triggerValue !== undefined &&
content.type === TimelineContentTypeSisyfos.TRIGGERVALUE
) {
deviceState.triggerValue = content.triggerValue
}

Expand Down Expand Up @@ -371,6 +376,7 @@ export class SisyfosMessageDevice extends DeviceWithState<SisyfosState, DeviceOp
overridePriority: content.overridePriority || 0,
isLookahead: layer.isLookahead || false,
timelineObjId: layer.id,
triggerValue: content.triggerValue,
})
deviceState.resync = deviceState.resync || content.resync || false
} else if (
Expand All @@ -387,6 +393,7 @@ export class SisyfosMessageDevice extends DeviceWithState<SisyfosState, DeviceOp
overridePriority: content.overridePriority || 0,
isLookahead: layer.isLookahead || false,
timelineObjId: layer.id,
triggerValue: content.triggerValue,
})
deviceState.resync = deviceState.resync || content.resync || false
} else if (
Expand All @@ -402,6 +409,7 @@ export class SisyfosMessageDevice extends DeviceWithState<SisyfosState, DeviceOp
overridePriority: content.overridePriority || 0,
isLookahead: layer.isLookahead || false,
timelineObjId: layer.id,
triggerValue: content.triggerValue,
})
} else if (
referencedMapping &&
Expand All @@ -417,6 +425,7 @@ export class SisyfosMessageDevice extends DeviceWithState<SisyfosState, DeviceOp
overridePriority: content.overridePriority || 0,
isLookahead: layer.isLookahead || false,
timelineObjId: layer.id,
triggerValue: content.triggerValue,
})
}
})
Expand Down Expand Up @@ -449,6 +458,7 @@ export class SisyfosMessageDevice extends DeviceWithState<SisyfosState, DeviceOp
if (newChannel.muteOn !== undefined) channel.muteOn = newChannel.muteOn
if (newChannel.inputGain !== undefined) channel.inputGain = newChannel.inputGain
if (newChannel.inputSelector !== undefined) channel.inputSelector = newChannel.inputSelector
if (newChannel.triggerValue !== undefined) channel.triggerValue = newChannel.triggerValue

channel.timelineObjIds.push(newChannel.timelineObjId)
}
Expand Down Expand Up @@ -516,6 +526,21 @@ export class SisyfosMessageDevice extends DeviceWithState<SisyfosState, DeviceOp
return
}

if (newChannel.triggerValue && oldChannel?.triggerValue !== newChannel.triggerValue) {
// note - should we only do this if we have an oldchannel?
debug('reset channel ' + index)
commands.push({
context: `Channel ${index} reset`,
content: {
type: SisyfosCommandType.SET_CHANNEL,
channel: Number(index),
values: newChannel,
},
timelineObjId: newChannel.timelineObjIds[0] || '',
})
return
}

if (oldChannel && oldChannel.pgmOn !== newChannel.pgmOn) {
debug(`Channel ${index} pgm goes from "${oldChannel.pgmOn}" to "${newChannel.pgmOn}"`)
const values: number[] = [newChannel.pgmOn]
Expand Down

0 comments on commit ac7ec2f

Please sign in to comment.