Skip to content

Commit

Permalink
fix: send state commands back to right ip and expose full state
Browse files Browse the repository at this point in the history
  • Loading branch information
Balte de Wit committed Jul 19, 2019
1 parent db58ee3 commit 3a6f257
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
22 changes: 13 additions & 9 deletions src/constants/AutomationPresets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ export interface IAutomationProtocol {
STATE_CHANNEL_PGM: string,
STATE_CHANNEL_PST: string,
STATE_CHANNEL_FADER_LEVEL: string,
STATE_FULL: string
},
toAutomation: {
STATE_CHANNEL_PGM: string,
STATE_CHANNEL_PST: string,
STATE_CHANNEL_FADER_LEVEL: string,
STATE_FULL: string
},
fader: {
min: number,
Expand Down Expand Up @@ -62,22 +64,24 @@ export const AutomationPresets: { [key: string]: IAutomationProtocol } = {
}
],
fromAutomation: {
CHANNEL_PGM_ON_OFF: '/ch/{value1}/mix/pgm',
CHANNEL_PST_ON_OFF: '/ch/{value1}/mix/pst',
CHANNEL_FADER_LEVEL: '/ch/{value1}/mix/faderlevel',
CHANNEL_PGM_ON_OFF: '/ch/{value1}/pgm',
CHANNEL_PST_ON_OFF: '/ch/{value1}/pst',
CHANNEL_FADER_LEVEL: '/ch/{value1}/faderlevel',
CHANNEL_VISIBLE: '/ch/{value1}/visible',
X_MIX: '/take',
SET_LABEL: '/ch/{value1}/label',
FADE_TO_BLACK: '/fadetoblack',
SNAP_RECALL: '/snap/{value1}',
STATE_CHANNEL_PGM: '/state/ch/{value1}/mix/pgm',
STATE_CHANNEL_PST: '/state/ch/{value1}/mix/pst',
STATE_CHANNEL_FADER_LEVEL: '/state/ch/{value1}/mix/faderlevel',
STATE_CHANNEL_PGM: '/state/ch/{value1}/pgm',
STATE_CHANNEL_PST: '/state/ch/{value1}/pst',
STATE_CHANNEL_FADER_LEVEL: '/state/ch/{value1}/faderlevel',
STATE_FULL: '/state/full'
},
toAutomation: {
STATE_CHANNEL_PGM: '/state/ch/{value1}/mix/pgm',
STATE_CHANNEL_PST: '/state/ch/{value1}/mix/pst',
STATE_CHANNEL_FADER_LEVEL: '/state/ch/{value1}/mix/faderlevel',
STATE_CHANNEL_PGM: '/state/ch/{value1}/pgm',
STATE_CHANNEL_PST: '/state/ch/{value1}/pst',
STATE_CHANNEL_FADER_LEVEL: '/state/ch/{value1}/faderlevel',
STATE_FULL: '/state/full'
},
fader: {
min: 0,
Expand Down
34 changes: 27 additions & 7 deletions src/utils/AutomationConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import osc from 'osc'; //Using OSC fork from PieceMeta/osc.js as it has excluded

//Utils:
import { IAutomationProtocol, AutomationPresets } from '../constants/AutomationPresets';
import { IChannel } from '../reducers/channelsReducer';

const AUTOMATION_OSC_PORT = 5255;
export class AutomationConnection {
Expand Down Expand Up @@ -32,11 +33,11 @@ export class AutomationConnection {
this.oscConnection
.on("ready", () => {
this.automationProtocol.initializeCommands.map((item) => {
this.sendOutMessage(item.mixerMessage, 1, item.value, item.type);
// this.sendOutMessage(item.oscMessage, 1, item.value, item.type);
console.log("Listening for Automation via OSC over UDP.");
});
})
.on('message', (message: any) => {
.on('message', (message: any, timetag: number | undefined, info: any) => {
console.log("RECIEVED AUTOMATION MESSAGE :", message.address, message.args[0]);
//Set state of Sisyfos:
if ( this.checkOscCommand(message.address, this.automationProtocol.fromAutomation
Expand Down Expand Up @@ -134,14 +135,31 @@ export class AutomationConnection {
});
window.mixerGenericConnection.updateOutLevels();
// Get state from Producers Audio Mixer:
} else if (this.checkOscCommand(message.address, this.automationProtocol.fromAutomation
.STATE_FULL)) {
this.sendOutMessage(
this.automationProtocol.toAutomation.STATE_FULL,
0,
JSON.stringify({
channel: this.store.channels[0].channel.map(({ faderLevel, pgmOn, pstOn }: IChannel) => ({
faderLevel, pgmOn, pstOn
})),
grpFader: this.store.channels[0].grpFader.map(({ faderLevel, pgmOn, pstOn }: IChannel) => ({
faderLevel, pgmOn, pstOn
}))
}),
"s",
info
)
} else if (this.checkOscCommand(message.address, this.automationProtocol.fromAutomation
.STATE_CHANNEL_PGM)) {
let ch = message.address.split("/")[3];
this.sendOutMessage(
this.automationProtocol.toAutomation.STATE_CHANNEL_PGM,
ch,
this.store.channels[0].channel[ch-1].pgmOn,
"i"
"i",
info
);
} else if (this.checkOscCommand(message.address, this.automationProtocol.fromAutomation
.STATE_CHANNEL_PST)) {
Expand All @@ -150,7 +168,8 @@ export class AutomationConnection {
this.automationProtocol.toAutomation.STATE_CHANNEL_PST,
ch,
this.store.channels[0].channel[ch-1].pstOn,
"i"
"i",
info
);
} else if (this.checkOscCommand(message.address, this.automationProtocol.fromAutomation
.STATE_CHANNEL_FADER_LEVEL)) {
Expand All @@ -159,7 +178,8 @@ export class AutomationConnection {
this.automationProtocol.toAutomation.STATE_CHANNEL_FADER_LEVEL,
ch,
this.store.channels[0].channel[ch-1].faderLevel,
"f"
"f",
info
);
}
})
Expand Down Expand Up @@ -189,7 +209,7 @@ export class AutomationConnection {
}
}

sendOutMessage(oscMessage: string, channel: number, value: string, type: string) {
sendOutMessage(oscMessage: string, channel: number, value: string, type: string, to: { ip: string, port: number }) {
let channelString = this.automationProtocol.leadingZeros ? ("0"+channel).slice(-2) : channel.toString();
let message = oscMessage.replace(
"{value1}",
Expand All @@ -204,7 +224,7 @@ export class AutomationConnection {
value: value
}
]
});
}, to.ip, to.port);
}
}
}
Expand Down

0 comments on commit 3a6f257

Please sign in to comment.