Tone.js/examples/stepSequencer.html
2015-06-27 17:25:01 -04:00

115 lines
No EOL
2.8 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>SCORE</title>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<script type="text/javascript" src="../build/Tone.js"></script>
<script type="text/javascript" src="./scripts/jquery.min.js"></script>
<script type="text/javascript" src="../../Notone.js/build/Notone.GUI.js"></script>
<script type="text/javascript" src="./scripts/Interface.js"></script>
<script type="text/javascript" src="./scripts/nexusUI.js"></script>
<link rel="stylesheet" type="text/css" href="./style/examples.css">
<script type="text/javascript">
// jshint ignore: start
</script>
</head>
<body>
<style type="text/css">
canvas {
margin-top: 3px;
}
</style>
<div id="Content" class="FullScreen">
<div id="Title">Tone.Transport</div>
<div id="Explanation">
Tone.Transport is the application-wide timekeeper. It uses an OscillatorNode
as it's clock source which enables sample-accurate scheduling as well as
tempo-curves and automation. This example uses Tone.Transport.setInterval
to invoke a callback every 16th note.
</div>
<canvas nx="matrix"></canvas>
</div>
<script type="text/javascript">
//setup a polyphonic sampler
var keys = new Tone.PolySynth(4, Tone.Sampler, {
"A" : "./audio/casio/A1.mp3",
"C#" : "./audio/casio/Cs2.mp3",
"E" : "./audio/casio/E2.mp3",
"F#" : "./audio/casio/Fs2.mp3",
}, {
"envelope" : {
"release" : 0.2
}
}).toMaster();
keys.volume.value = -15;
//keep track of steps and notes
var stepNumber = 0;
var noteNames = ["A", "C#", "E", "F#"];
//the repeated callback
Tone.Transport.setInterval(function(time){
//get the notes at the step
var column = matrix1.matrix[stepNumber];
for (var i = 0; i < 4; i++){
if (column[i] === 1){
keys.triggerAttackRelease(noteNames[i], "32n", time);
}
}
stepNumber++;
stepNumber = stepNumber % 16;
}, "16n");
//transport settings
Tone.Transport.loopEnd = "1m";
Tone.Transport.loop = true;
</script>
<script type="text/javascript">
nx.onload = function(){
nx.colorize("#f5871f");
matrix1.col = 16;
matrix1.init();
matrix1.resize($("#Content").width(), 250);
matrix1.draw();
}
$(function(){
new Interface.Slider({
name : "BPM",
min : 80,
max : 200,
value : Tone.Transport.bpm.value,
drag : function(val){
Tone.Transport.bpm.value = val;
}
});
new Interface.Button({
text : "Start",
activeText : "Stop",
type : "toggle",
key : 32, //spacebar
start : function(){
Tone.Transport.start();
},
end : function(){
Tone.Transport.stop();
},
});
$(window).on("resize", function(){
matrix1.resize($("#Content").width(), 250);
matrix1.draw();
});
});
</script>
</body>
</html>