65 lines
1.8 KiB
JavaScript
65 lines
1.8 KiB
JavaScript
const electron = require("electron");
|
|
|
|
let volumeMeterLeft;
|
|
let volumeMeterRight;
|
|
|
|
function sendControl(name, value = 0x00) {
|
|
electron.ipcRenderer.invoke("control", name, value);
|
|
}
|
|
|
|
electron.contextBridge.exposeInMainWorld("controller", {
|
|
"load": function (deckIndex) {
|
|
sendControl("deck" + String(deckIndex) + ".load");
|
|
},
|
|
"play_pause": function (deckIndex) {
|
|
sendControl("deck" + String(deckIndex) + ".play_pause");
|
|
},
|
|
"sync": function (deckIndex) {
|
|
sendControl("deck" + String(deckIndex) + ".sync");
|
|
},
|
|
"volume": function (deckIndex, value) {
|
|
sendControl("deck" + String(deckIndex) + ".volume", value);
|
|
},
|
|
"eq": function (deckIndex, freq, value) {
|
|
sendControl("deck" + String(deckIndex) + ".eq_" + freq, value);
|
|
},
|
|
"speed": function (deckIndex, value) {
|
|
sendControl("deck" + String(deckIndex) + ".speed", value);
|
|
},
|
|
"pad": function (deckIndex, padIndex) {
|
|
sendControl("deck" + String(deckIndex) + ".pad" + String(padIndex));
|
|
},
|
|
"crossfade": function (value) {
|
|
sendControl("master.crossfade", value);
|
|
}
|
|
});
|
|
|
|
electron.ipcRenderer.on("signal", function (event, name, value = 0x00) {
|
|
switch (name) {
|
|
case "master.volume.left":
|
|
volumeMeterLeft.style.height = String(Math.round((value / 80) * 100)) + "%";
|
|
break;
|
|
case "master.volume.right":
|
|
volumeMeterRight.style.height = String(Math.round((value / 80) * 100)) + "%";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
});
|
|
|
|
electron.ipcRenderer.invoke("load-driver", "linux-rawmidi");
|
|
electron.ipcRenderer.invoke("load-mappings", "numark-mixtrackplatinum");
|
|
|
|
(async function () {
|
|
var devices = await electron.ipcRenderer.invoke("list-devices");
|
|
|
|
if (devices.length > 0) {
|
|
electron.ipcRenderer.invoke("open-device", devices[0]);
|
|
}
|
|
})();
|
|
|
|
window.onload = function (event) {
|
|
volumeMeterLeft = document.querySelector("#volume-meter-left");
|
|
volumeMeterRight = document.querySelector("#volume-meter-right");
|
|
};
|