Skip to content

Commit

Permalink
feat: Remote midi controller - change generic midi remote contrioller…
Browse files Browse the repository at this point in the history
… to a dedicated HUI controller
  • Loading branch information
olzzon committed Jun 3, 2019
1 parent fef6282 commit 73e4372
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 64 deletions.
4 changes: 2 additions & 2 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Settings from './Settings';
import { loadSnapshotState, saveSnapshotState } from '../utils/SettingsStorage';
import { MixerConnection } from '../utils/MixerConnection';
import { AutomationConnection } from '../utils/AutomationConnection';
import { MidiRemoteConnection } from '../utils/MidiRemoteConnection';
import { HuiMidiRemoteConnection } from '../utils/HuiMidiRemoteConnection';


class App extends Component<any, any> {
Expand All @@ -25,7 +25,7 @@ class App extends Component<any, any> {
componentWillMount() {
this.mixerConnection = new MixerConnection(this.props.store);
this.automationConnection = new AutomationConnection(this.mixerConnection);
this.midiRemoteConnection = new MidiRemoteConnection(this.mixerConnection);
this.midiRemoteConnection = new HuiMidiRemoteConnection(this.mixerConnection);
this.snapShopStoreTimer();
loadSnapshotState(this.props.store.channels[0], this.props.store.settings[0].numberOfChannels);
}
Expand Down
33 changes: 20 additions & 13 deletions src/constants/RemoteFaderPresets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface IRemoteProtocol {
STATE_CHANNEL_PGM: IMidiSendMessage,
STATE_CHANNEL_PST: IMidiSendMessage,
STATE_CHANNEL_PFL: IMidiSendMessage,
STATE_CHANNEL_FADER_LEVEL: IMidiSendMessage,
STATE_CHANNEL_FADER_LEVEL: Array<IMidiSendMessage>,
STATE_GRP_FADER_PGM: IMidiSendMessage,
STATE_GRP_FADER_PST: IMidiSendMessage,
STATE_GRP_FADER_LEVEL: IMidiSendMessage,
Expand All @@ -77,7 +77,7 @@ export const RemoteFaderPresets: { [key: string]: IRemoteProtocol } = {

hui: {
protocol: 'MIDI',
label: 'HUI Midicontroller',
label: 'Generic HUI Midicontroller',
mode: "client",
leadingZeros: true,
initializeCommands: [
Expand All @@ -104,9 +104,9 @@ export const RemoteFaderPresets: { [key: string]: IRemoteProtocol } = {
type: MidiReceiveTypes.disabled
},
CHANNEL_FADER_LEVEL: {
message: "",
message: "0",
value: "",
type: MidiReceiveTypes.pitchbend
type: MidiReceiveTypes.controlchange
},
GRP_FADER_PGM_ON_OFF: {
message: "",
Expand Down Expand Up @@ -155,11 +155,18 @@ export const RemoteFaderPresets: { [key: string]: IRemoteProtocol } = {
value: "",
type: MidiSendTypes.disabled
},
STATE_CHANNEL_FADER_LEVEL: {
message: "",
value: "",
type: MidiSendTypes.disabled
},
STATE_CHANNEL_FADER_LEVEL: [
{
message: "21",
value: "",
type: MidiSendTypes.sendControlChange
},
{
message: "01",
value: "",
type: MidiSendTypes.sendControlChange
},
],
STATE_GRP_FADER_PGM: {
message: "",
value: "",
Expand All @@ -177,10 +184,10 @@ export const RemoteFaderPresets: { [key: string]: IRemoteProtocol } = {
},
},
fader: {
min: -8192,
max: 8191,
zero: 4396,
step: 10,
min: 0,
max: 127,
zero: 70,
step: 1,
fadeTime: 40,
},
meter: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { IMixerProtocol, MixerProtocolPresets } from '../constants/MixerProtocol



export class MidiRemoteConnection {
export class HuiMidiRemoteConnection {
store: any;
mixerConnection: any;
remoteProtocol: IRemoteProtocol;
Expand All @@ -24,9 +24,9 @@ export class MidiRemoteConnection {

constructor(mixerConnection: any) {
this.mixerConnection = mixerConnection;
this.sendOutMessage = this.sendOutMessage.bind(this);
this.convertFromRemoteLevel = this.convertFromRemoteLevel.bind(this);
this.convertToRemoteLevel = this.convertToRemoteLevel.bind(this);
this.updateRemoteFaderLevel = this.updateRemoteFaderLevel.bind(this);

this.store = window.storeRedux.getState();
const unsubscribe = window.storeRedux.subscribe(() => {
Expand Down Expand Up @@ -57,13 +57,19 @@ export class MidiRemoteConnection {
setupRemoteFaderConnection() {
this.midiInput.addListener(this.midiReceiveTypes[this.remoteProtocol.fromRemote.CHANNEL_FADER_LEVEL.type], undefined,
(message: any) => {
console.log("Received 'controlchange' message (" + message.data + ").");
window.storeRedux.dispatch({
type:'SET_FADER_LEVEL',
channel: message.channel - 1,
level: message.data[2]
});
this.mixerConnection.updateOutLevel(message.channel-1);
//Fader changed:
if (message.data[1] < 9) {
console.log("Received 'controlchange' message (" + message.data + ").");
//Uint8Array
console.log("message.data-2 : ", message.data[2])
window.storeRedux.dispatch({
type:'SET_FADER_LEVEL',
channel: message.data[1],
level: this.convertFromRemoteLevel(message.data[2])
});
this.mixerConnection.updateOutLevel(message.data[1]);
this.updateRemoteFaderLevel(message, this.convertFromRemoteLevel(message.data[2]))
}
}
);
//for testing:
Expand Down Expand Up @@ -112,46 +118,11 @@ export class MidiRemoteConnection {
return newLevel //convert from mixer min-max to remote min-max
}


updateOutLevel(channelIndex: number) {
if (this.remoteProtocol.mode === "master" && this.store.channels[0].channel[channelIndex].pgmOn) {
window.storeRedux.dispatch({
type:'SET_OUTPUT_LEVEL',
channel: channelIndex,
level: this.store.channels[0].channel[channelIndex].faderLevel
});
}

this.sendOutMessage(
this.remoteProtocol.toRemote.STATE_CHANNEL_FADER_LEVEL,
channelIndex+1,
this.store.channels[0].channel[channelIndex].faderLevel
);
}

updatePflState(channelIndex: number) {

if (this.store.channels[0].channel[channelIndex].pflOn = true) {
this.sendOutMessage(
this.remoteProtocol.toRemote.STATE_CHANNEL_PFL,
channelIndex+1,
"1"
);
} else {
this.sendOutMessage(
this.remoteProtocol.toRemote.STATE_CHANNEL_PFL,
channelIndex+1,
"0"
);
}
}


updateFadeIOLevel(channelIndex: number, outputLevel: number) {
this.sendOutMessage(
this.remoteProtocol.toRemote.STATE_CHANNEL_FADER_LEVEL,
channelIndex+1,
String(outputLevel)
updateRemoteFaderLevel(channelIndex: number, outputLevel: number) {
this.midiOutput.sendControlChange(
String(21+channelIndex),
this.convertToRemoteLevel(outputLevel),
1
);
}

Expand Down

0 comments on commit 73e4372

Please sign in to comment.