Skip to content

Commit

Permalink
Keyboard support
Browse files Browse the repository at this point in the history
  • Loading branch information
ejj28 committed Apr 13, 2020
1 parent 15a4915 commit 3ac9a72
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 11 deletions.
52 changes: 42 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}


}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ <h1 class="h3 mb-0 text-gray-800">Dashboard</h1>
<li><a class='dropdown-item disabled'>No Midi Devices Available</a></li>
</ul>
</div>
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="keysSwitch">
<label class="custom-control-label" for="keysSwitch">Keys mode</label>
</div>
<a type="button" data-toggle="modal" data-target="#newDrumPadModal" class="btn btn-primary btn-icon-split btn-sm">
<span class="icon text-white">
<i class="fas fa-plus"></i>
Expand Down
11 changes: 10 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,20 @@ function addToDrumPadTable(velocity, button, midi) {
"<th scope='row'>" + midi + "</th>" +
"<td>" + velocity + "</td>" +
"<td>" + button + "</td>" +
"<td><button type='button' class='btn btn-danger' onclick='removeDrumPad(this)'>Remove</button></td>" +
"<td><button type='button' class='btn btn-danger btn-sm' onclick='removeDrumPad(this)'>Remove</button></td>" +
"</tr>"
);
}

$('#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");
Expand Down

0 comments on commit 3ac9a72

Please sign in to comment.