Simple monitor for displaying MIDI status for digital pianos.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

54 line
1004 B

  1. const { app, BrowserWindow } = require('electron')
  2. const midi = require('midi')
  3. const SCREEN_HEIGHT = 96
  4. const SCREEN_WIDTH = 1152
  5. const createWindow = () => {
  6. const win = new BrowserWindow({
  7. width: SCREEN_WIDTH,
  8. height: SCREEN_HEIGHT,
  9. webPreferences: {
  10. nodeIntegration: true
  11. }
  12. })
  13. win.loadFile('pages/piano.html')
  14. const input = new midi.Input()
  15. if (input.getPortCount() > 0) {
  16. input.openPort(0)
  17. }
  18. input.on('message', (deltaTime, message) => {
  19. const [type, data1, data2] = message
  20. switch (type) {
  21. case 144:
  22. win.webContents.send('note', data1 + ':' + data2)
  23. break
  24. case 176:
  25. win.webContents.send('pedal', data1 + ':' + data2)
  26. break
  27. }
  28. })
  29. }
  30. app
  31. .whenReady()
  32. .then(() => {
  33. createWindow()
  34. })
  35. app.on('window-all-closed', () => {
  36. if (process.platform !== 'darwin') {
  37. app.quit()
  38. }
  39. })
  40. app.on('activate', () => {
  41. if (BrowserWindow.getAllWindows().length === 0) {
  42. createWindow()
  43. }
  44. })