Skip to content

Instantly share code, notes, and snippets.

@baptadn
Created December 14, 2017 12:55
Show Gist options
  • Select an option

  • Save baptadn/f72359013ae068672e8a942d980f1335 to your computer and use it in GitHub Desktop.

Select an option

Save baptadn/f72359013ae068672e8a942d980f1335 to your computer and use it in GitHub Desktop.
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
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment