-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added MIDI event for autoUpdateFaders and example in xp1apro-input.js
- Loading branch information
Showing
12 changed files
with
3,842 additions
and
1,558 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) | ||
} | ||
} |
Oops, something went wrong.