Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import easymidi from 'easymidi';
- import notifier from 'node-notifier';
- import path from 'path';
- import Player from 'play-sound';
- import throttle from 'lodash.throttle';
- // Settings
- const ANSWER_DELAY = 3000;
- const RED_BUTTON = 80;
- const GREEN_BUTTON = 83;
- const BLUE_BUTTON = 71;
- const YELLOW_BUTTON = 68;
- // Helpers
- const assetPath = fileName => path.join(__dirname, `assets/${fileName}`);
- const labelQuiz = name => `La parole est aux ${name} !`;
- // Objects
- const buzzerSong = assetPath('buzzer.mp3')
- const player = new Player();
- const input = new easymidi.Input('MPD218 Port A');
- const labels = {
- [RED_BUTTON]: 'rouges ❤️',
- [GREEN_BUTTON]: 'verts 💚️',
- [BLUE_BUTTON]: 'bleus 💙️',
- [YELLOW_BUTTON]: 'jaunes 💛️',
- };
- const icons = {
- [RED_BUTTON]: assetPath('red.png'),
- [GREEN_BUTTON]: assetPath('green.png'),
- [BLUE_BUTTON]: assetPath('blue.png'),
- [YELLOW_BUTTON]: assetPath('yellow.png'),
- };
- input.on('noteon', throttle(({note}) => {
- if (![RED_BUTTON, GREEN_BUTTON, BLUE_BUTTON, YELLOW_BUTTON].includes(note)) {
- return;
- }
- notifier.notify({
- title: '🚨',
- icon: icons[note],
- message: labelQuiz(labels[note]),
- sound: false,
- });
- player.play(buzzerSong);
- }, ANSWER_DELAY, {
- trailing: false
- }));
Add Comment
Please, Sign In to add comment