diff --git a/index.js b/index.js index 2d6723d..90126f4 100644 --- a/index.js +++ b/index.js @@ -12,12 +12,13 @@ let device = vJoyDevice.create(1); var midiConfig; var advancedDebug = false; +var keysMode = false; var win; function createWindow () { win = new BrowserWindow({ - width: 800, + width: 900, height: 600, resizable: true, title: "MidiDrumHero", @@ -78,6 +79,14 @@ ipcMain.on('debugTypeChange', (event, arg) => { } }); +ipcMain.on('inputTypeChange', (event, arg) => { + if (arg == true) { + keysMode = true; + } else if (arg == false) { + keysMode = false; + } +}); + ipcMain.on('saveDrumPad', (event, arg) => { storage.get('config', (error, data) => { if (error) throw error; @@ -151,16 +160,39 @@ input.on('message', (deltaTime, message) => { if (advancedDebug == true) { win.webContents.send('midiLog', "Status byte: " + message[0].toString(16) + ", Midi Note: " + message[1] + ", Velocity: " + message[2]); } - - if (message[0] >= 144 && message[0] <= 159 && message[2] != 0) { - if (advancedDebug == false) { - win.webContents.send('midiLog', "Midi Note: " + message[1] + ", Velocity: " + message[2]); + + if (keysMode == false) { + if (message[0] >= 144 && message[0] <= 159 && message[2] != 0) { + if (advancedDebug == false) { + win.webContents.send('midiLog', "Midi Note: " + message[1] + ", Velocity: " + message[2]); + } + for (var entry of midiConfig) { + if ((parseInt(entry["midi"]) == message[1]) && (parseInt(entry["velocity"]) <= message[2])) { + vJoySetButton(parseInt(entry["button"]), true); + setTimeout(vJoySetButton, 50, parseInt(entry["button"]), false); + break; + } + } } - for (var entry of midiConfig) { - if ((parseInt(entry["midi"]) == message[1]) && (parseInt(entry["velocity"]) <= message[2])) { - vJoySetButton(parseInt(entry["button"]), true); - setTimeout(vJoySetButton, 50, parseInt(entry["button"]), false); - break; + } else if (keysMode == true) { + if (message[0] >= 128 && message[0] <= 159) { + if (advancedDebug == false) { + win.webContents.send('midiLog', "Midi Note: " + message[1] + ", Velocity: " + message[2]); + } + for (var entry of midiConfig) { + if (message[0] >= 144 && message[0] <= 159 && message[2] != 0) { + if ((parseInt(entry["midi"]) == message[1]) && (parseInt(entry["velocity"]) <= message[2])) { + vJoySetButton(parseInt(entry["button"]), true); + break; + } + } else if ((message[0] >= 128 && message[0] <= 143) || (message[0] >= 144 && message[0] <= 159 && message[2] == 0)) { + if (parseInt(entry["midi"]) == message[1]) { + vJoySetButton(parseInt(entry["button"]), false); + break; + } + } + + } } } diff --git a/src/index.html b/src/index.html index f735266..c594111 100644 --- a/src/index.html +++ b/src/index.html @@ -116,6 +116,10 @@