Guest User

Untitled

a guest
Dec 17th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. import easymidi from 'easymidi';
  2. import notifier from 'node-notifier';
  3. import path from 'path';
  4. import Player from 'play-sound';
  5. import throttle from 'lodash.throttle';
  6.  
  7. // Settings
  8. const ANSWER_DELAY = 3000;
  9. const RED_BUTTON = 80;
  10. const GREEN_BUTTON = 83;
  11. const BLUE_BUTTON = 71;
  12. const YELLOW_BUTTON = 68;
  13.  
  14. // Helpers
  15. const assetPath = fileName => path.join(__dirname, `assets/${fileName}`);
  16. const labelQuiz = name => `La parole est aux ${name} !`;
  17.  
  18. // Objects
  19. const buzzerSong = assetPath('buzzer.mp3')
  20. const player = new Player();
  21. const input = new easymidi.Input('MPD218 Port A');
  22.  
  23. const labels = {
  24. [RED_BUTTON]: 'rouges ❤️',
  25. [GREEN_BUTTON]: 'verts 💚️',
  26. [BLUE_BUTTON]: 'bleus 💙️',
  27. [YELLOW_BUTTON]: 'jaunes 💛️',
  28. };
  29.  
  30. const icons = {
  31. [RED_BUTTON]: assetPath('red.png'),
  32. [GREEN_BUTTON]: assetPath('green.png'),
  33. [BLUE_BUTTON]: assetPath('blue.png'),
  34. [YELLOW_BUTTON]: assetPath('yellow.png'),
  35. };
  36.  
  37. input.on('noteon', throttle(({note}) => {
  38. if (![RED_BUTTON, GREEN_BUTTON, BLUE_BUTTON, YELLOW_BUTTON].includes(note)) {
  39. return;
  40. }
  41.  
  42. notifier.notify({
  43. title: '🚨',
  44. icon: icons[note],
  45. message: labelQuiz(labels[note]),
  46. sound: false,
  47. });
  48.  
  49. player.play(buzzerSong);
  50. }, ANSWER_DELAY, {
  51. trailing: false
  52. }));
Add Comment
Please, Sign In to add comment