Skip to content

Commit

Permalink
Merge pull request #669 from Jocke4f/feat_atem_aux
Browse files Browse the repository at this point in the history
Added auxBus support for BMD ATEM devices
  • Loading branch information
josephdadams authored Jun 22, 2024
2 parents cd2959a + 14d79c2 commit ead0f12
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/sources/BlackmagicATEM.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

import { logger } from "..";
import { Atem, listVisibleInputs } from 'atem-connection';
import { RecordingStatus, StreamingStatus } from 'atem-connection/dist/enums';
import { RegisterTallyInput } from "../_decorators/RegisterTallyInput.decorator";
Expand Down Expand Up @@ -51,9 +51,11 @@ export class BlackmagicATEMSource extends TallyInput {
private atemClient: Atem;
private pgmList = new Set<number | string>();
private prvList = new Set<number | string>();
private auxList = new Set<number | string>();

private oldPgmList = new Set<number | string>();
private oldPrvList = new Set<number | string>();
private oldAuxList = new Set<number | string>();

constructor(source: Source) {
super(source);
Expand All @@ -80,7 +82,9 @@ export class BlackmagicATEMSource extends TallyInput {

this.atemClient.on('stateChanged', (state, paths) => {
for (const path of paths) {
if ((path.indexOf('video.mixEffects') > -1) || (path.indexOf('video.ME') > -1) || (path.indexOf('video.downstreamKeyers') > -1)) {
if ((path.indexOf('video.mixEffects') > -1) || (path.indexOf('video.downstreamKeyers') > -1)) {
this.processATEMState(state);
} else if ((path.indexOf('video.auxilliaries') > -1)) {
this.processATEMState(state);
} else if (path == "streaming.status") {
this.processATEMState(state);
Expand All @@ -100,12 +104,22 @@ export class BlackmagicATEMSource extends TallyInput {
private processATEMState(state) {
this.pgmList = new Set();
this.prvList = new Set();
this.auxList = new Set();

// Process video.mixEffects.X.programInput (X: No of MixEffect)
// video.mixEffects.X.previewInput (X: No of MixEffect)
for (let i = 0; i < state.video.mixEffects.length; i++) {
if (this.source.data.me_onair?.includes((i + 1).toString())) {
listVisibleInputs("program", state, i).forEach(n => this.pgmList.add(n));
listVisibleInputs("preview", state, i).forEach(n => this.prvList.add(n));
}
}

// Process video.auxilliaries.X (X: No of auxBus)
for (let i = 0; i < state.video.auxilliaries.length; i++) {
this.auxList.add(state.video.auxilliaries[i])
}

switch (this.atemClient.state.streaming?.status?.state) {
case StreamingStatus.Connecting:
case StreamingStatus.Stopping:
Expand All @@ -131,10 +145,13 @@ export class BlackmagicATEMSource extends TallyInput {

private processATEMTally(): void {
const areSetsEqual = (a, b) => a.size === b.size && [...a].every(value => b.has(value)); //https://stackoverflow.com/a/44827922
if(areSetsEqual(this.prvList, this.oldPrvList) && areSetsEqual(this.pgmList, this.oldPgmList)) return;
if(areSetsEqual(this.prvList, this.oldPrvList)
&& areSetsEqual(this.pgmList, this.oldPgmList)
&& areSetsEqual(this.auxList, this.oldAuxList)) return;

this.removeBusFromAllAddresses("preview");
this.removeBusFromAllAddresses("program");
this.removeBusFromAllAddresses("aux");
let cutBusMode = this.source.data.cut_bus_mode;

if (cutBusMode === 'on') {
Expand All @@ -153,10 +170,17 @@ export class BlackmagicATEMSource extends TallyInput {
this.addBusToAddress(address.toString(), "preview");
}
}

// Handle aux independent of Program/Preview mode or Cut Bus mode.
for (const address of this.auxList) {
this.addBusToAddress(address.toString(), "aux");
}

this.sendTallyData();

this.oldPrvList = this.prvList;
this.oldPgmList = this.pgmList;
this.oldAuxList = this.auxList;
}

public exit(): void {
Expand Down

0 comments on commit ead0f12

Please sign in to comment.