|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- const { app, BrowserWindow } = require('electron')
- const midi = require('midi')
-
- const SCREEN_HEIGHT = 64
- const SCREEN_WIDTH = 1200
-
- const createWindow = () => {
- const win = new BrowserWindow({
- width: SCREEN_WIDTH,
- height: SCREEN_HEIGHT,
- useContentSize: true,
- backgroundColor: '#000000',
- resizable: false,
- minimizable: false,
- maximizable: false,
- fullscreenable: false,
- webPreferences: {
- //devTools: false,
- nodeIntegration: true,
- }
- })
-
- win.loadFile('index.html')
-
- const input = new midi.Input()
-
- if (input.getPortCount() > 0) {
- input.openPort(0)
- }
-
- input.on('message', (deltaTime, message) => {
- const [type, data1, data2] = message
- switch (type) {
- case 144:
- win.webContents.send('note', data1 + ':' + data2)
- break
- case 176:
- win.webContents.send('pedal', data1 + ':' + data2)
- break
- }
- })
- }
-
- app
- .whenReady()
- .then(() => {
- createWindow()
- })
-
- app.on('window-all-closed', () => {
- if (process.platform !== 'darwin') {
- app.quit()
- }
- })
-
- app.on('activate', () => {
- if (BrowserWindow.getAllWindows().length === 0) {
- createWindow()
- }
- })
|