From e12fcc882258071043f891028b95ea978b43c2dd Mon Sep 17 00:00:00 2001 From: Chinmay Pendharkar Date: Wed, 18 Nov 2015 20:33:12 +0800 Subject: [PATCH] added all the code for making stuff work --- midi.js | 6 ++++-- script.js | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/midi.js b/midi.js index 8468c7e..c619296 100644 --- a/midi.js +++ b/midi.js @@ -46,8 +46,9 @@ function onMIDIInit (midi){ function onMIDIConect(input){ console.log("Input id:", input.id, input); input.onmidimessage = function(event){ - var midiMessage = MIDIMessage(event); - console.log("Parsed", midiMessage); + var channel = (event.data[0]-176)+1; + console.log("Parsed", channel); + triggerPlayer(channel); } } @@ -64,6 +65,7 @@ function makeMidiMsg(ch, state){ } window.switchOnLED = function(ch){ + console.log('setting led', ch); if (window.teensy && typeof window.teensy.send === 'function'){ var channels = [0,1,2]; channels.forEach(function(thisCh){ diff --git a/script.js b/script.js index 7ed4f9d..3497318 100644 --- a/script.js +++ b/script.js @@ -3,7 +3,6 @@ var blockBuzz = true, questionsJson, introClick = 1; - var onKeyPress = function(e) { if(e.keyCode > 48 && e.keyCode < 52) { triggerPlayer(e.keyCode - 48); @@ -13,6 +12,7 @@ var onKeyPress = function(e) { var onDocumentClick = function(e) { if(introClick == 1) { + switchOnLED(null); Array.prototype.forEach.call(document.querySelectorAll("#players input"), function(input) { input.readOnly = true; }); @@ -47,11 +47,13 @@ var onPlayerClick = function(e) { e.currentTarget.children[1].textContent = parseInt(e.currentTarget.children[1].textContent, 10) + answerValue; e.currentTarget.classList.remove("buzzed"); answerValue = 0; + switchOnLED(null); } else { try { document.querySelector(".buzzed").classList.remove("buzzed"); blockBuzz = false; + switchOnLED(null); } catch(e) {} } @@ -72,6 +74,7 @@ var onCardClick = function(e) { e.currentTarget.children[2].style.transformOrigin = x + "px " + y + "px 0px"; e.currentTarget.classList.add("open"); blockBuzz = false; + switchOnLED(null); answerValue = parseInt(e.currentTarget.children[0].textContent, 10); try { @@ -87,6 +90,7 @@ var triggerPlayer = function(player_number) { // player_numbers: 1, 2, 3 } blockBuzz = true; + switchOnLED(player_number-1); document.getElementById("player" + player_number).classList.add("buzzed"); }