Skip to content

Commit

Permalink
feat: Midas/Behringer OSC get inital Aux state from mixer
Browse files Browse the repository at this point in the history
  • Loading branch information
olzzon committed Jan 22, 2020
1 parent 79e5238 commit 7bb0741
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 13 deletions.
10 changes: 9 additions & 1 deletion server/constants/mixerProtocols/midasMaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ export const MidasMaster: IMixerProtocol = {
min: 0,
max: 1,
zero: 0.75
}
},
{
mixerMessage: '/ch/{channel}/mix/{argument}/level',
value: "",
type: "aux",
min: 0,
max: 1,
zero: 0.75
},
],
channelTypes: [{
channelTypeName: 'CH',
Expand Down
59 changes: 47 additions & 12 deletions server/utils/mixerConnections/OscMixerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from '../../reducers/faderActions'
import { SET_MIXER_ONLINE } from '../../reducers/settingsActions';
import { SOCKET_SET_VU } from '../../constants/SOCKET_IO_DISPATCHERS';
import { logger } from '../logger';
import { logger } from '../logger'

export class OscMixerConnection {
mixerProtocol: IMixerProtocol;
Expand Down Expand Up @@ -52,16 +52,8 @@ export class OscMixerConnection {
this.oscConnection
.on("ready", () => {
logger.info("Receiving state of desk", {})
this.initialCommands()

this.mixerProtocol.initializeCommands.forEach((item) => {
if (item.mixerMessage.includes("{channel}")) {
state.channels[0].channel.map((channel: any, index: any) => {
this.sendOutRequest(item.mixerMessage,(index +1));
});
} else {
this.sendOutMessage(item.mixerMessage, 1, item.value, item.type);
}
});
store.dispatch({
type: SET_MIXER_ONLINE,
mixerOnline: true
Expand All @@ -74,6 +66,7 @@ export class OscMixerConnection {
type: SET_MIXER_ONLINE,
mixerOnline: true
});
logger.verbose("Received OSC message: " + message.address, {})
if (this.checkOscCommand(message.address, this.mixerProtocol.channelTypes[0].fromMixer
.CHANNEL_VU[0].mixerMessage)){
if (state.settings[0].mixerProtocol.includes('behringer')) {
Expand Down Expand Up @@ -166,7 +159,7 @@ export class OscMixerConnection {
auxIndex = parseFloat(messageArray[index]) - 1
}
})

logger.verbose('Aux Message Channel : ' + ch + ' Aux Index :' + auxIndex + ' Level : ' + message.args[0])
store.dispatch({
type: SET_AUX_LEVEL,
channel: ch - 1,
Expand All @@ -184,7 +177,8 @@ export class OscMixerConnection {
label: message.args[0]
});
global.mainThreadHandler.updatePartialStore(state.channels[0].channel[ch - 1].assignedFader)
logger.verbose("OSC message: " + message.address, {})
} else {
logger.verbose("Unknown OSC message: " + message.address, {})
}
})
.on('error', (error: any) => {
Expand All @@ -211,6 +205,30 @@ export class OscMixerConnection {
}
}

initialCommands() {
this.mixerProtocol.initializeCommands.forEach((item) => {
if (item.mixerMessage.includes("{channel}")) {
if (item.type === 'aux') {
state.channels[0].channel.forEach((channel: any, index: number) => {
channel.auxLevel.forEach((auxLevel: any, auxIndex: number) => {
setTimeout(() => {
this.sendOutRequestAux(item.mixerMessage, auxIndex +1, state.faders[0].fader[channel.assignedFader].monitor)
},
state.faders[0].fader[channel.assignedFader].monitor * 10 + auxIndex * 100)
})
})
} else {
state.channels[0].channel.map((channel: any, index: any) => {
this.sendOutRequest(item.mixerMessage,(index +1));
});
}

} else {
this.sendOutMessage(item.mixerMessage, 1, item.value, item.type);
}
});
}

pingMixerCommand() {
//Ping OSC mixer if mixerProtocol needs it.
this.mixerProtocol.pingCommand.map((command) => {
Expand Down Expand Up @@ -284,6 +302,22 @@ export class OscMixerConnection {
}
}

sendOutRequestAux(oscMessage: string, channel: number, auxSend: number) {
let channelString = this.mixerProtocol.leadingZeros ? ("0"+channel).slice(-2) : channel.toString();
let message = oscMessage.replace(
"{channel}",
channelString
);
let auxSendNumber = this.mixerProtocol.leadingZeros ? ("0"+String(auxSend)).slice(-2) : String(auxSend);
message = message.replace('{argument}', auxSendNumber)
logger.verbose('Initial Aux Message : ' + message)
if (message != 'none') {
this.oscConnection.send({
address: message
});
}
}

updateOutLevel(channelIndex: number) {
let channelType = state.channels[0].channel[channelIndex].channelType;
let channelTypeIndex = state.channels[0].channel[channelIndex].channelTypeIndex;
Expand Down Expand Up @@ -383,6 +417,7 @@ export class OscMixerConnection {
"f"
);
}

updateAuxLevel(channelIndex: number, auxSendIndex: number, level: number) {
let channelType = state.channels[0].channel[channelIndex].channelType;
let channel = state.channels[0].channel[channelIndex].channelTypeIndex+1
Expand Down

0 comments on commit 7bb0741

Please sign in to comment.