Skip to content

Commit

Permalink
Added MIDI event for autoUpdateFaders and example in xp1apro-input.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jmkao committed Nov 19, 2021
1 parent 3de3e31 commit 7479b93
Show file tree
Hide file tree
Showing 12 changed files with 3,842 additions and 1,558 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ Visit the [online SPA](https://aniclover.com/obs-html-control/) in your browser.

Please read the [wiki](https://github.com/jmkao/obs-midi-ui/wiki) for the nuances between the different versions.

## Build
```quasar build -m electron```
115 changes: 115 additions & 0 deletions midi_dispatcher_js/lpminimk3apro-input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/* eslint-disable indent */
// Input: midiData {channel, control, value} or {channel, note}
// Output: [ eventName, eventData ]

const FADER_CHANNEL = 1;
const FADER_CONTROLS = [11, 12, 13, 14];

const SCENE_BTN_CHANNEL = 8;
const SCENE_ZERO_NOTE = 0;
const SCENE_MAX_NOTE = 100;

const SOURCE_BTN_CHANNEL = 10;
const SOURCE_ZERO_NOTE = 0;
const SOURCE_MAX_NOTE = 100;

const TIMETABLE_FWD_CHANNEL = 1;
const TIMETABLE_FWD_NOTE = 121;

const TIMETABLE_REV_CHANNEL = 1;
const TIMETABLE_REV_NOTE = 10;

const TRANSITION_CHANNEL = 7;
const TRANSITION_NOTE = 70;

const SCREENSHOT_CHANNEL = 1;
const SCREENSHOT_NOTE = 20;

const ZERO_TO_SCENE = [
12, 13, 14, 15,
8, 9, 10, 11,
4, 5, 6, 7,
0, 1, 2, 3
]

const ZERO_TO_SOURCE = [
12, 13, 14, 15,
8, 9, 10, 11,
4, 5, 6, 7,
0, 1, 2, 3
]

function mfRemap (data) {
if (data.channel === SCENE_BTN_CHANNEL && typeof data.note !== 'undefined') {
mapNote = ZERO_TO_SCENE.indexOf(data.note)
console.log(`mfRemap() scene note ${data.note} to ${mapNote}`)
if (mapNote != -1) {
data.note = mapNote + SCENE_ZERO_NOTE
}
} else if (data.channel === SOURCE_BTN_CHANNEL && typeof data.note !== 'undefined') {
mapNote = ZERO_TO_SOURCE.indexOf(data.note)
console.log(`mfRemap() source note ${data.note} to ${mapNote}`)
if (mapNote != -1) {
data.note = mapNote + SOURCE_ZERO_NOTE
}
}

return data
}

midiData = mfRemap(midiData)

var eventName = null;
var eventData = null;

if (midiData.channel === FADER_CHANNEL) {
var i = FADER_CONTROLS.indexOf(midiData.control);
if (i > -1) {
eventName = 'midiFader'+i;
eventData = midiData;
eventData.index = i;
}
}
if (midiData.channel === SCENE_BTN_CHANNEL) {
if (midiData.note >= SCENE_ZERO_NOTE && midiData.note <= SCENE_MAX_NOTE) {
eventName = 'scene' + (midiData.note - SCENE_ZERO_NOTE);
eventData = midiData;
console.log("Midi Emit: "+eventName);
}
}
if (midiData.channel === SOURCE_BTN_CHANNEL) {
if (midiData.note >= SOURCE_ZERO_NOTE && midiData.note <= SOURCE_MAX_NOTE) {
eventName = 'source' + (midiData.note - SOURCE_ZERO_NOTE);
eventData = midiData;
console.log("Midi Emit: "+eventName);
}
}
if (midiData.channel === TIMETABLE_FWD_CHANNEL) {
if (midiData.note === TIMETABLE_FWD_NOTE) {
eventName = 'timetable';
eventData = 'advance';
console.log("Midi Emit: "+eventName);
}
}
if (midiData.channel === TIMETABLE_REV_CHANNEL) {
if (midiData.note === TIMETABLE_REV_NOTE) {
eventName = 'timetable';
eventData = 'retract';
console.log("Midi Emit: "+eventName);
}
}
if (midiData.channel === SCREENSHOT_CHANNEL) {
if (midiData.note === SCREENSHOT_NOTE) {
eventName = 'screenshot';
eventData = 'active';
console.log("Midi Emit: "+eventName)
}
}
if (midiData.channel === TRANSITION_CHANNEL) {
if (midiData.note === TRANSITION_NOTE) {
eventName = 'transition';
console.log("Midi Emit: "+eventName);
}
}

return [eventName, eventData];
105 changes: 105 additions & 0 deletions midi_dispatcher_js/midifighter-input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* eslint-disable no-undef */
/* eslint-disable semi */
// Input: midiData {channel, control, value} or {channel, note}
// Output: [ eventName, eventData ]

const FADER_CHANNEL = 1;
const FADER_CONTROLS = [11, 12, 13, 14];

const SCENE_BTN_CHANNEL = 8;
const SCENE_ZERO_NOTE = 0;
const SCENE_MAX_NOTE = 63;

const SOURCE_BTN_CHANNEL = 10;
const SOURCE_ZERO_NOTE = 0;
const SOURCE_MAX_NOTE = 63;

const TIMETABLE_FWD_CHANNEL = 1;
const TIMETABLE_FWD_NOTE = 121;

const TIMETABLE_REV_CHANNEL = 1;
const TIMETABLE_REV_NOTE = 10;

const TRANSITION_CHANNEL = 7;
const TRANSITION_NOTE = 70;

const MF_CHANNEL = 3
const ZERO_TO_MF = [
39, 38, 37, 36,
43, 42, 41, 40,
47, 46, 45, 44,
51, 50, 49, 48,
55, 54, 53, 52,
59, 58, 57, 56,
63, 62, 61, 60,
67, 66, 65, 64,
71, 70, 69, 68,
75, 74, 73, 72,
79, 78, 77, 76,
83, 82, 81, 80,
87, 86, 85, 84,
91, 90, 89, 88,
95, 94, 93, 92,
99, 98, 97, 96
]

function mfRemap (data) {
if (data.channel === MF_CHANNEL && data.note && data.note > 35 && data.note < 100) {
mapNote = ZERO_TO_MF.indexOf(data.note)
console.log(`mfRemap() note ${data.note} to ${mapNote}`)

data.note = mapNote
}

return data
}

var eventName = null;
var eventData = null;

midiData = mfRemap(midiData)

if (midiData.channel === FADER_CHANNEL) {
var i = FADER_CONTROLS.indexOf(midiData.control);
if (i > -1) {
eventName = 'midiFader'+i;
eventData = midiData;
eventData.index = i;
}
}
if (midiData.channel === SCENE_BTN_CHANNEL) {
if (midiData.note >= SCENE_ZERO_NOTE && midiData.note <= SCENE_MAX_NOTE) {
eventName = 'scene' + (midiData.note - SCENE_ZERO_NOTE);
eventData = midiData;
console.log("Midi Emit: "+eventName);
}
}
if (midiData.channel === SOURCE_BTN_CHANNEL) {
if (midiData.note >= SOURCE_ZERO_NOTE && midiData.note <= SOURCE_MAX_NOTE) {
eventName = 'source' + (midiData.note - SOURCE_ZERO_NOTE);
eventData = midiData;
console.log("Midi Emit: "+eventName);
}
}
if (midiData.channel === TIMETABLE_FWD_CHANNEL) {
if (midiData.note === TIMETABLE_FWD_NOTE) {
eventName = 'timetable';
eventData = 'advance';
console.log("Midi Emit: "+eventName);
}
}
if (midiData.channel === TIMETABLE_REV_CHANNEL) {
if (midiData.note === TIMETABLE_REV_NOTE) {
eventName = 'timetable';
eventData = 'retract';
console.log("Midi Emit: "+eventName);
}
}
if (midiData.channel === TRANSITION_CHANNEL) {
if (midiData.note === TRANSITION_NOTE) {
eventName = 'transition';
console.log("Midi Emit: "+eventName);
}
}

return [eventName, eventData];
80 changes: 80 additions & 0 deletions midi_dispatcher_js/midifighter-output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* eslint-disable semi */
/* eslint-disable no-undef */
// Input 1: eventData { name, index, color }
// Input 2: midiOutput
// Output: none

const SCENE_LIGHT_CHANNEL = 16;

const SOURCE_LIGHT_CHANNEL = 16;

const ZERO_TO_MF = [
39, 38, 37, 36,
43, 42, 41, 40,
47, 46, 45, 44,
51, 50, 49, 48,
55, 54, 53, 52,
59, 58, 57, 56,
63, 62, 61, 60,
67, 66, 65, 64,
71, 70, 69, 68,
75, 74, 73, 72,
79, 78, 77, 76,
83, 82, 81, 80,
87, 86, 85, 84,
91, 90, 89, 88,
95, 94, 93, 92,
99, 98, 97, 96
]

console.log(eventData);

function remapMF (note) {
var mapNote = note
if (note >= 0 && note < 64) {

mapNote = ZERO_TO_MF[note]
}
console.log(`remapMF() output note ${note} to ${mapNote}`)
return mapNote
}

if (eventData.name === 'scene') {
const index = eventData.index
const color = eventData.color

// for (index = 0; index < 127; index ++)
// midiOutput.playNote(index+SCENE_LIGHT_ZERO_NOTE, SCENE_LIGHT_CHANNEL, {velocity: index, rawVelocity: true})

switch (color) {
case 'white':
midiOutput.playNote(remapMF(index), SCENE_LIGHT_CHANNEL, {velocity: 79, rawVelocity: true})
break;
case 'yellow':
midiOutput.playNote(remapMF(index), SCENE_LIGHT_CHANNEL, {velocity: 37, rawVelocity: true})
break;
case 'red':
midiOutput.playNote(remapMF(index), SCENE_LIGHT_CHANNEL, {velocity: 13, rawVelocity: true})
break;
}
} else if (eventData.name === 'source') {
const index = eventData.index;
const color = eventData.color;
switch (color) {
case 'white':
midiOutput.playNote(remapMF(index), SOURCE_LIGHT_CHANNEL, {velocity: 79, rawVelocity: true})
break;
case 'yellow':
midiOutput.playNote(remapMF(index), SOURCE_LIGHT_CHANNEL, {velocity: 37, rawVelocity: true})
break;
case 'red':
midiOutput.playNote(remapMF(index), SOURCE_LIGHT_CHANNEL, {velocity: 13, rawVelocity: true})
break;
}
} else if (eventData.name === 'init') {
for (index = 0; index < 64; index++) {
midiOutput.playNote(remapMF(index), SCENE_LIGHT_CHANNEL, {velocity: 1, rawVelocity: true})
midiOutput.playNote(remapMF(index), SOURCE_LIGHT_CHANNEL, {velocity: 1, rawVelocity: true})
// midiOutput.playNote(index+SOURCE_LIGHT_ZERO_NOTE, SOURCE_LIGHT_CHANNEL, {velocity: index, rawVelocity: true})
}
}
Loading

0 comments on commit 7479b93

Please sign in to comment.