From 3ac9a72a9497c5ea8349d94eeefda3b9e0624944 Mon Sep 17 00:00:00 2001 From: ejj28 Date: Mon, 13 Apr 2020 14:07:31 -0400 Subject: [PATCH] Keyboard support --- index.js | 52 ++++++++++++++++++++++++++++++++++++++++---------- src/index.html | 4 ++++ src/index.js | 11 ++++++++++- 3 files changed, 56 insertions(+), 11 deletions(-) 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 @@

Dashboard

  • No Midi Devices Available
  • +
    + + +
    diff --git a/src/index.js b/src/index.js index 03a4858..52484cb 100644 --- a/src/index.js +++ b/src/index.js @@ -87,11 +87,20 @@ function addToDrumPadTable(velocity, button, midi) { "" + midi + "" + "" + velocity + "" + "" + button + "" + - "" + + "" + "" ); } +$('#keysSwitch').click(() => { + var checkedValue = document.querySelector('#keysSwitch').checked; + if (checkedValue == true) { + ipcRenderer.send('inputTypeChange', true); + } else if (checkedValue == false) { + ipcRenderer.send('inputTypeChange', false); + } +}); + // Social Media $("#github").click(function() { shell.openExternal("https://github.com/ejj28/mididrumhero");