2016-05-18 01:27:46 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>Meter</title>
|
|
|
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
|
|
|
|
<link rel="icon" type="image/png" sizes="174x174" href="./style/favicon.png">
|
|
|
|
|
2017-03-18 16:35:37 +00:00
|
|
|
<script src="../build/Tone.js"></script>
|
|
|
|
<script src="./scripts/jquery.min.js"></script>
|
|
|
|
<script src="./scripts/draggabilly.js"></script>
|
|
|
|
<script src="https://tonejs.github.io/Logo/build/Logo.js"></script>
|
|
|
|
<script src="./scripts/StartAudioContext.js"></script>
|
|
|
|
<script src="./scripts/Interface.js"></script>
|
2016-05-18 01:27:46 +00:00
|
|
|
|
|
|
|
<link rel="stylesheet" type="text/css" href="./style/examples.css">
|
|
|
|
|
2017-03-18 16:35:37 +00:00
|
|
|
<script>
|
2016-05-18 01:27:46 +00:00
|
|
|
// jshint ignore: start
|
|
|
|
</script>
|
|
|
|
<style type="text/css">
|
|
|
|
canvas {
|
|
|
|
margin-top: 2px;
|
|
|
|
width: 100%;
|
|
|
|
height: 90px;
|
|
|
|
border-radius: 10px;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="Content" class="FullScreen">
|
|
|
|
<div id="Title">Meter</div>
|
|
|
|
<div id="Explanation">
|
2016-07-07 20:10:29 +00:00
|
|
|
<a href="https://tonejs.github.io/docs/#Meter" target="_blank">Tone.Meter</a>
|
2016-05-18 01:27:46 +00:00
|
|
|
gives you the level of the incoming signal (between 0-1). Values above 1
|
|
|
|
are clipping.
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2017-03-18 16:35:37 +00:00
|
|
|
<script>
|
2016-05-18 01:27:46 +00:00
|
|
|
//create a level meter
|
|
|
|
var meter = new Tone.Meter("level");
|
|
|
|
|
|
|
|
var player = new Tone.Player({
|
|
|
|
"url" : "./audio/FWDL.mp3",
|
|
|
|
"loop" : true
|
|
|
|
}).connect(meter).toMaster();
|
|
|
|
|
2017-03-26 20:39:19 +00:00
|
|
|
// GUI //
|
|
|
|
|
|
|
|
//start button
|
|
|
|
Interface.Button({
|
|
|
|
key : 32,
|
|
|
|
type : "toggle",
|
|
|
|
text : "Start",
|
|
|
|
activeText : "Stop",
|
|
|
|
start : function(){
|
|
|
|
player.start();
|
|
|
|
},
|
|
|
|
end : function(){
|
|
|
|
player.stop();
|
2016-05-18 01:27:46 +00:00
|
|
|
}
|
|
|
|
});
|
2017-03-26 20:39:19 +00:00
|
|
|
|
|
|
|
//drawing the FFT
|
|
|
|
var meterContext = $("<canvas>",{
|
|
|
|
"id" : "fft"
|
|
|
|
}).appendTo("#Content").get(0).getContext("2d");
|
|
|
|
|
|
|
|
var meterGraident;
|
|
|
|
|
|
|
|
function drawMeter(){
|
|
|
|
var level = meter.value * 0.8; //scale it since values go above 1 when clipping
|
|
|
|
meterContext.clearRect(0, 0, canvasWidth, canvasHeight);
|
|
|
|
meterContext.fillStyle = meterGraident;
|
|
|
|
meterContext.fillRect(0, 0, canvasWidth, canvasHeight);
|
|
|
|
meterContext.fillStyle = "white";
|
|
|
|
meterContext.fillRect(canvasWidth * level, 0, canvasWidth, canvasHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
//size the canvase
|
|
|
|
var canvasWidth, canvasHeight;
|
|
|
|
|
|
|
|
function sizeCanvases(){
|
|
|
|
canvasWidth = $("#fft").width();
|
|
|
|
canvasHeight = $("#fft").height();
|
|
|
|
meterContext.canvas.width = canvasWidth;
|
|
|
|
meterContext.canvas.height = canvasHeight;
|
|
|
|
//make the gradient
|
|
|
|
meterGraident = meterContext.createLinearGradient(0, 0, canvasWidth, canvasHeight);
|
|
|
|
meterGraident.addColorStop(0, "#BFFF02");
|
|
|
|
meterGraident.addColorStop(0.8, "#02FF24");
|
|
|
|
meterGraident.addColorStop(1, "#FF0202");
|
|
|
|
}
|
|
|
|
|
|
|
|
sizeCanvases();
|
|
|
|
$(window).resize(sizeCanvases);
|
|
|
|
|
|
|
|
function loop(){
|
|
|
|
requestAnimationFrame(loop);
|
|
|
|
//draw the meter level
|
|
|
|
drawMeter();
|
|
|
|
}
|
|
|
|
loop();
|
2016-05-18 01:27:46 +00:00
|
|
|
</script>
|
|
|
|
</body>
|
2017-03-18 16:35:37 +00:00
|
|
|
</html>
|