|
| 1 | +import { DeserializedCommand, WritableCommand } from '../CommandBase' |
| 2 | +import { MultiViewerWindowOverlayPropertiesState } from '../../state/settings' |
| 3 | +import { AtemState, AtemStateUtil, InvalidIdError } from '../../state' |
| 4 | + |
| 5 | +export class MultiViewerWindowOverlayPropertiesCommand extends WritableCommand<MultiViewerWindowOverlayPropertiesState> { |
| 6 | + public static MaskFlags = { |
| 7 | + labelVisible: 1 << 0, |
| 8 | + borderVisible: 1 << 1, |
| 9 | + } |
| 10 | + |
| 11 | + public static readonly rawName = 'CMvO' |
| 12 | + |
| 13 | + public readonly multiViewerId: number |
| 14 | + public readonly windowIndex: number |
| 15 | + |
| 16 | + constructor(multiviewerId: number, windowIndex: number) { |
| 17 | + super() |
| 18 | + |
| 19 | + this.multiViewerId = multiviewerId |
| 20 | + this.windowIndex = windowIndex |
| 21 | + } |
| 22 | + |
| 23 | + public serialize(): Buffer { |
| 24 | + const buffer = Buffer.alloc(8) |
| 25 | + buffer.writeUInt8(this.multiViewerId, 0) |
| 26 | + buffer.writeUInt8(this.windowIndex || 0, 1) |
| 27 | + |
| 28 | + let value = 0 |
| 29 | + if (this.properties.labelVisible) value |= 0x01 |
| 30 | + if (this.properties.borderVisible) value |= 0x02 |
| 31 | + |
| 32 | + buffer.writeUInt8(value, 3) |
| 33 | + buffer.writeUInt8(this.flag, 5) |
| 34 | + return buffer |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +export class MultiViewerWindowOverlayPropertiesUpdateCommand extends DeserializedCommand<MultiViewerWindowOverlayPropertiesState> { |
| 39 | + public static readonly rawName = 'MvOv' |
| 40 | + |
| 41 | + public readonly multiViewerId: number |
| 42 | + public readonly windowIndex: number |
| 43 | + |
| 44 | + constructor(multiviewerId: number, windowIndex: number, props: MultiViewerWindowOverlayPropertiesState) { |
| 45 | + super(props) |
| 46 | + |
| 47 | + this.multiViewerId = multiviewerId |
| 48 | + this.windowIndex = windowIndex |
| 49 | + } |
| 50 | + |
| 51 | + public static deserialize(rawCommand: Buffer): MultiViewerWindowOverlayPropertiesUpdateCommand { |
| 52 | + const multiViewerId = rawCommand.readUInt8(0) |
| 53 | + const windowIndex = rawCommand.readUInt8(1) |
| 54 | + |
| 55 | + const values = rawCommand.readUInt8(3) |
| 56 | + |
| 57 | + const props: MultiViewerWindowOverlayPropertiesState = { |
| 58 | + labelVisible: (values & 0x01) > 0, |
| 59 | + borderVisible: (values & 0x02) > 0, |
| 60 | + } |
| 61 | + |
| 62 | + return new MultiViewerWindowOverlayPropertiesUpdateCommand(multiViewerId, windowIndex, props) |
| 63 | + } |
| 64 | + |
| 65 | + public applyToState(state: AtemState): string { |
| 66 | + if (!state.info.multiviewer || this.multiViewerId >= state.info.multiviewer.count) { |
| 67 | + throw new InvalidIdError('MultiViewer', this.multiViewerId) |
| 68 | + } |
| 69 | + |
| 70 | + const multiviewer = AtemStateUtil.getMultiViewer(state, this.multiViewerId) |
| 71 | + const window = multiviewer.windows[this.windowIndex] |
| 72 | + if (!window) { |
| 73 | + throw new InvalidIdError('MultiViewer Window', this.multiViewerId, this.windowIndex) |
| 74 | + } |
| 75 | + window.overlayProperties = this.properties |
| 76 | + |
| 77 | + return `settings.multiViewers.${this.multiViewerId}.windows.${this.windowIndex}.overlayProperties` |
| 78 | + } |
| 79 | +} |
0 commit comments