Last active
September 21, 2016 10:32
-
-
Save benschmaus/af6cd2675be88c0123741ce65129c3b9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
loadAPI(1); | |
host.defineController("Script Lab", "NoteInput Testing", "1.0", "d5a765f7-647a-488e-938f-dcb653742457"); | |
host.defineMidiPorts(1, 0); | |
var input; | |
var disableNotesToAudioEngine = []; | |
var defaultNotesForAudioEngine = []; | |
var isShiftMode = false; | |
for (var i = 0; i < 128; i++) { | |
disableNotesToAudioEngine[i] = -1; | |
defaultNotesForAudioEngine[i] = i; | |
} | |
function init() { | |
var mi = host.getMidiInPort(0); | |
mi.setMidiCallback(onMidi); | |
input = mi.createNoteInput(""); | |
// make note messages visibile to onMidi callback | |
input.setShouldConsumeEvents(false); | |
println("initialized"); | |
} | |
function onMidi(status, data1, data2) { | |
var command = status & 0xf0; | |
var channel = (status & 0x0f) + 1; | |
println("channel=" + channel + ", command=" + command + ", data1=" + data1 + ", data2=" + data2); | |
switch (command) { | |
case 0x90: | |
if (isShiftMode) { | |
host.showPopupNotification("launch clip with note " + data1); | |
} | |
break; | |
case 0xB0: | |
if (data1 == 25) { | |
if (data2 > 0) { | |
isShiftMode = true; | |
input.setKeyTranslationTable(disableNotesToAudioEngine); | |
} else { | |
isShiftMode = false; | |
input.setKeyTranslationTable(defaultNotesForAudioEngine); | |
} | |
println("shift mode set to " + isShiftMode); | |
} | |
break; | |
default: | |
// do other stuff, like handle CCs, here... | |
} | |
} | |
function exit() { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment