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-08-31 16:41:36 +00:00
|
|
|
|
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>
|
2017-08-31 16:41:36 +00:00
|
|
|
<div id="Explanation">
|
2016-07-07 20:10:29 +00:00
|
|
|
<a href="https://tonejs.github.io/docs/#Meter" target="_blank">Tone.Meter</a>
|
2017-08-31 16:41:36 +00:00
|
|
|
gives you the level of the incoming signal in decibels.
|
2016-05-18 01:27:46 +00:00
|
|
|
</div>
|
2017-08-31 16:41:36 +00:00
|
|
|
|
2016-05-18 01:27:46 +00:00
|
|
|
</div>
|
|
|
|
|
2017-08-31 16:41:36 +00:00
|
|
|
<script>
|
2016-05-18 01:27:46 +00:00
|
|
|
//create a level meter
|
2017-08-31 16:41:36 +00:00
|
|
|
var meter = new Tone.Meter();
|
2016-05-18 01:27:46 +00:00
|
|
|
|
|
|
|
var player = new Tone.Player({
|
2017-06-19 19:39:17 +00:00
|
|
|
"url" : "./audio/FWDL.[mp3|ogg]",
|
2016-05-18 01:27:46 +00:00
|
|
|
"loop" : true
|
|
|
|
}).connect(meter).toMaster();
|
2017-08-31 16:41:36 +00:00
|
|
|
|
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(){
|
2017-08-31 16:41:36 +00:00
|
|
|
var level = meter.getLevel();
|
|
|
|
level = Tone.dbToGain(level); //scale it between 0 - 1
|
2017-03-26 20:39:19 +00:00
|
|
|
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");
|
2017-08-31 16:41:36 +00:00
|
|
|
meterGraident.addColorStop(0.8, "#02FF24");
|
|
|
|
meterGraident.addColorStop(1, "#FF0202");
|
2017-03-26 20:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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>
|