Skip to content

Commit

Permalink
new timer and metronome tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Forrest Oliphant committed Apr 16, 2012
1 parent cb710c5 commit 009e6b8
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 1 deletion.
4 changes: 3 additions & 1 deletion metronome.html
Expand Up @@ -50,7 +50,7 @@

var bpm, ms, beat;
var loopInterval;
var currentBeat = true;
var currentBeat = false;

var running = false;

Expand Down Expand Up @@ -100,6 +100,8 @@
action: function (m) {
running = false;
clearInterval(loopInterval);
$(".light").removeClass("on");
currentBeat = false;
},
type: "bang"
}
Expand Down
105 changes: 105 additions & 0 deletions timer.html
@@ -0,0 +1,105 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>timer</title>
<meta name="author" content="forresto">
<meta name="description" content="countdown to bang in ms" />

<script src="http://meemoo.org/meemoo/v1/meemoo-min.js"></script>

<style type="text/css">
html, body {
font-family: Verdana;
font-size: 35px;
}
</style>

</head>
<body>

<div id="info"></div>

<button id="start" type="button" onclick="Meemoo.inputs.start()">start</button>
<button id="cancel" type="button" onclick="Meemoo.inputs.stop()">stop</button>

<script type="text/javascript">

// shim layer with setTimeout fallback
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback ){
window.setTimeout(callback, 1000 / 60);
};
})();

var time = 3000;
var timer, starttime, cancel;

var info = document.getElementById('info');

function setTime(_time){
_time = parseInt(_time, 10);
if (_time===_time){
time = _time;
info.innerHTML = time;
}
}

function startTimer(){
cancel = false;
start = Date.now();
timerLoop();
}

function cancelTimer(){
cancel = true;
}

function timerLoop(){
var delta = Date.now() - start;
if (cancel) {
info.innerHTML = time;
} else if (delta >= time) {
Meemoo.send("bang", "!");
info.innerHTML = time;
} else {
info.innerHTML = time +":<br/>"+ (time-delta);
requestAnimFrame(timerLoop);
}
}

Meemoo.setInfo({
title: "timer",
author: "forresto",
description: "countdown to bang"
}).addInputs({
ms: {
action: setTime,
type: "int",
default: time,
description: "timer time, in milliseconds"
},
start: {
action: startTimer,
type: "bang"
},
stop: {
action: cancelTimer,
type: "bang"
}
}).addOutputs({
bang: {
type: "bang"
}
});

</script>

</body>
</html>

0 comments on commit 009e6b8

Please sign in to comment.