Skip to content

Commit

Permalink
feat: Skaarhoj - further refatoring to prepare support
Browse files Browse the repository at this point in the history
  • Loading branch information
olzzon authored and olzzon committed May 2, 2020
1 parent 6123142 commit 999aafb
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
//While developing mixer specific settings will be in one file.
//At first release these will be in seperate files
//So it´s easy to add new equipment.

export interface IMidiSendMessage {
message: string
value: any
Expand Down
164 changes: 164 additions & 0 deletions server/constants/remoteProtocols/SkaarhojProtocol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
export interface IRawSendMessage {
message: string
value: any
type: RawSendTypes
}

export enum RawSendTypes {
disabled,
playNote,
stopNote,
sendControlChange,
sendPitchBend,
}

export interface IRawReceiveMessage {
message: string
value: any
type: RawReceiveTypes
}
export enum RawReceiveTypes {
disabled,
noteon,
noteoff,
controlchange,
pitchbend,
}

export interface IRemoteProtocol {
protocol: string
label: string
mode: string
leadingZeros: boolean
initializeCommands: [IRawSendMessage]
fromRemote: {
CHANNEL_PGM_ON_OFF: IRawReceiveMessage
CHANNEL_PST_ON_OFF: IRawReceiveMessage
CHANNEL_PFL_ON_OFF: IRawReceiveMessage
CHANNEL_FADER_LEVEL: IRawReceiveMessage
X_MIX: IRawReceiveMessage
FADE_TO_BLACK: IRawReceiveMessage
SNAP_RECALL: IRawReceiveMessage
}
toRemote: {
STATE_CHANNEL_PGM: IRawSendMessage
STATE_CHANNEL_PST: IRawSendMessage
STATE_CHANNEL_PFL: IRawSendMessage
STATE_CHANNEL_FADER_LEVEL: Array<IRawSendMessage>
}
fader: {
min: number
max: number
zero: number
step: number
}
meter: {
min: number
max: number
zero: number
test: number
}
}

export const RemoteFaderPresets: { [key: string]: IRemoteProtocol } = {
rawPanel: {
protocol: 'RAW',
label: 'Generic Skaarhoj Protocol',
mode: 'client',
leadingZeros: false,
initializeCommands: [
{
message: '',
value: '',
type: RawSendTypes.disabled,
},
],
fromRemote: {
CHANNEL_PGM_ON_OFF: {
message: '',
value: '',
type: RawReceiveTypes.disabled,
},
CHANNEL_PST_ON_OFF: {
message: '',
value: '',
type: RawReceiveTypes.disabled,
},
CHANNEL_PFL_ON_OFF: {
message: '',
value: '',
type: RawReceiveTypes.disabled,
},
CHANNEL_FADER_LEVEL: {
message: '0',
value: '',
type: RawReceiveTypes.controlchange,
},
X_MIX: {
message: '',
value: '',
type: RawReceiveTypes.disabled,
},
FADE_TO_BLACK: {
message: '',
value: '',
type: RawReceiveTypes.disabled,
},
SNAP_RECALL: {
message: '',
value: '',
type: RawReceiveTypes.disabled,
},
},
toRemote: {
STATE_CHANNEL_PGM: {
message: '',
value: '',
type: RawSendTypes.disabled,
},
STATE_CHANNEL_PST: {
message: '',
value: '',
type: RawSendTypes.disabled,
},
STATE_CHANNEL_PFL: {
message: '',
value: '',
type: RawSendTypes.disabled,
},
STATE_CHANNEL_FADER_LEVEL: [
{
message: '21',
value: '',
type: RawSendTypes.sendControlChange,
},
{
message: '01',
value: '',
type: RawSendTypes.sendControlChange,
},
],
},
fader: {
min: 0,
max: 127,
zero: 70,
step: 1,
},
meter: {
min: 0,
max: 1,
zero: 0.75,
test: 0.6,
},
},
}

export const RemoteFaderProtocolList = Object.getOwnPropertyNames(
RemoteFaderPresets
).map((preset) => {
return {
value: preset,
label: RemoteFaderPresets[preset].label,
}
})
2 changes: 1 addition & 1 deletion server/utils/RemoteConnection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// import { HuiMidiRemoteConnection } from './remoteConnections/HuiMidiRemoteConnection'
import { HuiMidiRemoteConnection } from './remoteConnections/HuiMidiRemoteConnection'
import { SkaarhojRemoteConnection } from './remoteConnections/SkaarhojRemoteConnection'

export class RemoteConnection {
Expand Down
2 changes: 1 addition & 1 deletion server/utils/remoteConnections/HuiMidiRemoteConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
IRemoteProtocol,
RemoteFaderPresets,
MidiReceiveTypes,
} from '../../constants/RemoteFaderPresets'
} from '../../constants/remoteProtocols/HuiRemoteFaderPresets'
import { MixerProtocolPresets } from '../../constants/MixerProtocolPresets'

export class HuiMidiRemoteConnection {
Expand Down
54 changes: 27 additions & 27 deletions server/utils/remoteConnections/SkaarhojRemoteConnection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//Node Modules:
const net = require('net')
const Net = require('net')
import { store, state } from '../../reducers/store'
import { mixerGenericConnection } from '../../mainClasses'

Expand All @@ -13,31 +13,31 @@ import {
import {
IRemoteProtocol,
RemoteFaderPresets,
MidiReceiveTypes,
} from '../../constants/RemoteFaderPresets'
RawReceiveTypes,
} from '../../constants/remoteProtocols/SkaarhojProtocol'
import { MixerProtocolPresets } from '../../constants/MixerProtocolPresets'
import { logger } from '../logger'

export class SkaarhojRemoteConnection {
store: any
remoteProtocol: IRemoteProtocol
midiReceiveTypes = MidiReceiveTypes
rawReceiveTypes = RawReceiveTypes
mixerProtocol: any
midiInput: any
midiOutput: any
activeHuiChannel: number = 0
rawInput: any
rawOutput: any
activeRawChannel: number = 0

constructor() {
this.convertFromRemoteLevel = this.convertFromRemoteLevel.bind(this)
this.convertToRemoteLevel = this.convertToRemoteLevel.bind(this)
this.updateRemoteFaderState = this.updateRemoteFaderState.bind(this)

this.remoteProtocol = RemoteFaderPresets.hui
this.remoteProtocol = RemoteFaderPresets.rawPanel
this.mixerProtocol =
MixerProtocolPresets[state.settings[0].mixerProtocol] ||
MixerProtocolPresets.genericMidi

const server = net.createServer((socket: any) => {
const server = Net.createServer((socket: any) => {
socket.write('Echo server\r\n')
socket.pipe(socket)
})
Expand All @@ -58,8 +58,8 @@ export class SkaarhojRemoteConnection {
}

setupRemoteFaderConnection() {
this.midiInput.addListener(
this.midiReceiveTypes[
this.rawInput.addListener(
this.rawReceiveTypes[
this.remoteProtocol.fromRemote.CHANNEL_FADER_LEVEL.type
],
undefined,
Expand All @@ -83,33 +83,33 @@ export class SkaarhojRemoteConnection {
console.log('Received message (' + message.data + ').')
if (message.data[2] < 9) {
//Set active channel for next midi message:
this.activeHuiChannel = message.data[2]
this.activeRawChannel = message.data[2]
} else if (message.data[2] && message.data[2] === 65) {
//SELECT button - toggle PGM ON/OFF
store.dispatch({
type: TOGGLE_PGM,
channel: this.activeHuiChannel,
channel: this.activeRawChannel,
})
mixerGenericConnection.updateOutLevel(
this.activeHuiChannel
this.activeRawChannel
)
this.updateRemotePgmPstPfl(this.activeHuiChannel)
this.updateRemotePgmPstPfl(this.activeRawChannel)
} else if (message.data[2] && message.data[2] === 67) {
//SOLO button - toggle PFL ON/OFF
store.dispatch({
type: TOGGLE_PFL,
channel: this.activeHuiChannel,
channel: this.activeRawChannel,
})
mixerGenericConnection.updateOutLevel(
this.activeHuiChannel
this.activeRawChannel
)
this.updateRemotePgmPstPfl(this.activeHuiChannel)
this.updateRemotePgmPstPfl(this.activeRawChannel)
}
}
}
)
//for testing:
this.midiInput.addListener('noteon', 'all', (error: any) => {
this.rawInput.addListener('noteon', 'all', (error: any) => {
console.log(
"Received 'noteon' message (" +
error.note.name +
Expand Down Expand Up @@ -143,7 +143,7 @@ export class SkaarhojRemoteConnection {
}

updateRemoteFaderState(channelIndex: number, outputLevel: number) {
if (!this.midiOutput) {
if (!this.rawOutput) {
return
}
console.log(
Expand All @@ -153,30 +153,30 @@ export class SkaarhojRemoteConnection {
'OutputLevel : ',
this.convertToRemoteLevel(outputLevel)
)
this.midiOutput.sendControlChange(
this.rawOutput.sendControlChange(
channelIndex,
this.convertToRemoteLevel(outputLevel),
1
)
this.midiOutput.sendControlChange(32 + channelIndex, 0, 1)
this.rawOutput.sendControlChange(32 + channelIndex, 0, 1)
this.updateRemotePgmPstPfl(channelIndex)
}

updateRemotePgmPstPfl(channelIndex: number) {
if (!this.midiOutput) {
if (!this.rawOutput) {
return
}
//Update SELECT button:
this.midiOutput.sendControlChange(12, channelIndex, 1)
this.midiOutput.sendControlChange(
this.rawOutput.sendControlChange(12, channelIndex, 1)
this.rawOutput.sendControlChange(
44,
1 + 64 * (state.faders[0].fader[channelIndex].pgmOn ? 1 : 0),
1
)

//Update SOLO button:
this.midiOutput.sendControlChange(12, channelIndex, 1)
this.midiOutput.sendControlChange(
this.rawOutput.sendControlChange(12, channelIndex, 1)
this.rawOutput.sendControlChange(
44,
3 + 64 * (state.faders[0].fader[channelIndex].pflOn ? 1 : 0),
1
Expand Down

0 comments on commit 999aafb

Please sign in to comment.