Skip to content

Commit

Permalink
feat: QL1 receive fader state working
Browse files Browse the repository at this point in the history
  • Loading branch information
olzzon committed Jan 30, 2020
1 parent 8793170 commit d434dd3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 28 deletions.
4 changes: 2 additions & 2 deletions server/constants/mixerProtocols/yamahaQLCL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ export const YamahaQLCL: IMixerProtocol = {
leadingZeros: false,
pingCommand: [emptyMixerMessage()],
pingResponseCommand: [emptyMixerMessage()],
pingTime: 0,
pingTime: 10000,
initializeCommands: [emptyMixerMessage()],
channelTypes: [{
channelTypeName: 'CH',
channelTypeColor: '#2f2f2f',
fromMixer: {
CHANNEL_FADER_LEVEL: [emptyMixerMessage()], //PgmChange 0 - ignores this command
CHANNEL_OUT_GAIN: [{ mixerMessage: 'NOTIFY set MIXER:Current/InCh/Fader/Level', value: 0, type: '', min: -130, max: 10, zero: 1}], //PgmChange 0 - ignores this command
CHANNEL_OUT_GAIN: [{ mixerMessage: 'f0 43 10 3e 19 01 00 37 00 00 00 {channel} 00 00 00 {level} f7', value: 0, type: '', min: 0, max: 1, zero: 0.75}], //PgmChange 0 - ignores this command
CHANNEL_VU: [{ mixerMessage: "0", value: 0, type: 'f', min: 0, max: 1, zero: 0.75}], //PgmChange 0 - ignores this command
CHANNEL_NAME: [emptyMixerMessage()],
PFL: [emptyMixerMessage()],
Expand Down
85 changes: 59 additions & 26 deletions server/utils/mixerConnections/YamahaQlClConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,26 @@ import {
TOGGLE_PGM
} from '../../reducers/faderActions'
import { logger } from '../logger'
import { SET_MIXER_ONLINE } from '../../reducers/settingsActions'



export class QlClMixerConnection {
mixerProtocol: IMixerProtocol;
cmdChannelIndex: number;
midiConnection: any;
mixerProtocol: IMixerProtocol
cmdChannelIndex: number
midiConnection: any
mixerOnlineTimer: any


constructor(mixerProtocol: IMixerProtocol) {
this.sendOutMessage = this.sendOutMessage.bind(this);
this.pingMixerCommand = this.pingMixerCommand.bind(this);

store.dispatch({
type: SET_MIXER_ONLINE,
mixerOnline: false
});

this.mixerProtocol = mixerProtocol;

this.cmdChannelIndex = this.mixerProtocol.channelTypes[0].fromMixer.CHANNEL_OUT_GAIN[0].mixerMessage.split('/').findIndex(ch => ch === '{channel}');
Expand Down Expand Up @@ -53,10 +61,27 @@ export class QlClMixerConnection {
}
});
})
.on('data', (buffer: any) => {
let messages: string[] = buffer.toString().split('\n')
messages.forEach((message) => {
console.log("Received Message : ", message)
.on('data', (data: any) => {
clearTimeout(this.mixerOnlineTimer)
store.dispatch({
type: SET_MIXER_ONLINE,
mixerOnline: true
});

let buffers = []
let lastIndex = 0
for (let index=1; index<data.length; index++) {
if (data[index] === 241) {
buffers.push(data.slice(lastIndex, index - 1))
lastIndex = index
}
}
if (buffers.length === 0) {
buffers.push(data)
}

buffers.forEach((message) => {
console.log("Received Midi Message : ", message)
if (this.checkMidiCommand(message, this.mixerProtocol.channelTypes[0].fromMixer
.CHANNEL_VU[0].mixerMessage)) {
let mixerValues: string[] = message.split(' ')
Expand All @@ -71,11 +96,10 @@ export class QlClMixerConnection {
)
} else if (this.checkMidiCommand(message, this.mixerProtocol.channelTypes[0].fromMixer
.CHANNEL_OUT_GAIN[0].mixerMessage)) {
let mixerValues: string[] = message.split(' ')
let ch = 1 + parseInt(mixerValues[3])
let ch = 1 + parseInt(message[11])
let assignedFader = 1 + state.channels[0].channel[ch - 1].assignedFader
let mixerLevel: number = parseFloat(mixerValues[5])
let faderLevel = Math.pow(2, (mixerLevel - 1000) / 2000)
let mixerLevel: number = message[16] | message[15] << 8 // parseFloat(message[16])
let faderLevel = Math.pow(2, (mixerLevel) / 1920) - 1
//let faderLevel = Math.log10((mixerLevel + 32768) / (1000 + 32768))
if (!state.channels[0].channel[ch - 1].fadeActive
&& faderLevel > this.mixerProtocol.fader.min) {
Expand Down Expand Up @@ -103,7 +127,9 @@ export class QlClMixerConnection {
}

}
} /*else if (this.checkSCPCommand(message, this.mixerProtocol.channelTypes[0].fromMixer
global.mainThreadHandler.updatePartialStore(assignedFader - 1)

} /*else if (this.checkSCPCommand(message, this.mixerProtocol.channelTypes[0].fromMixer
.CHANNEL_NAME[0].mixerMessage)) {
let ch = message.split("/")[this.cmdChannelIndex];
store.dispatch({
Expand All @@ -116,7 +142,7 @@ export class QlClMixerConnection {
})
.on('error', (error: any) => {
logger.error("Error : " + String(error), {})
logger.info("Lost SCP connection", {})
logger.info("Lost QlCl connection", {})
});

//Ping OSC mixer if mixerProtocol needs it.
Expand All @@ -131,21 +157,28 @@ export class QlClMixerConnection {
}

pingMixerCommand() {
//Ping OSC mixer if mixerProtocol needs it.
this.mixerProtocol.pingCommand.map((command) => {
this.sendOutMessage(
command.mixerMessage,
0,
command.value,
command.type
);
});
this.mixerOnlineTimer = setTimeout(() => {
store.dispatch({
type: SET_MIXER_ONLINE,
mixerOnline: false
});
}, this.mixerProtocol.pingTime)
}

checkMidiCommand(message: string, command: string) {
if (!message) return false
if (message.slice(0, command.length) === command) return true;
return false;
checkMidiCommand(midiMessage: number[], command: string) {
if (!midiMessage) return false
let commandArray = command.split(' ')
let valid = true
for (let i=0; i <= 8; i++) {
if (i < midiMessage.length) {
if (("0" + midiMessage[i].toString(16)).substr(-2) !== commandArray[i]) {
valid = false
}
} else {
valid = false
}
}
return valid
}

sendOutMessage(message: string, channelIndex: number, value: string | number, type: string) {
Expand Down

0 comments on commit d434dd3

Please sign in to comment.