Tone.js/examples/stepSequencer.html

115 lines
2.8 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
2014-06-23 21:00:51 +00:00
<html>
<head>
<meta charset="utf-8">
2015-02-24 17:03:22 +00:00
<title>SCORE</title>
2014-06-23 21:00:51 +00:00
2015-02-24 17:03:22 +00:00
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
2014-09-06 19:35:31 +00:00
<script type="text/javascript" src="../build/Tone.js"></script>
2015-06-26 05:23:05 +00:00
<script type="text/javascript" src="./scripts/jquery.min.js"></script>
2015-06-27 21:25:01 +00:00
<script type="text/javascript" src="../../Notone.js/build/Notone.GUI.js"></script>
2015-02-24 17:03:22 +00:00
<script type="text/javascript" src="./scripts/Interface.js"></script>
2015-06-27 21:25:01 +00:00
<script type="text/javascript" src="./scripts/nexusUI.js"></script>
2015-02-24 17:03:22 +00:00
<link rel="stylesheet" type="text/css" href="./style/examples.css">
2014-06-23 21:00:51 +00:00
<script type="text/javascript">
2015-02-24 17:03:22 +00:00
// jshint ignore: start
</script>
2014-06-23 21:00:51 +00:00
2015-02-24 17:03:22 +00:00
</head>
<body>
<style type="text/css">
2015-06-27 21:25:01 +00:00
canvas {
margin-top: 3px;
}
2015-02-24 17:03:22 +00:00
</style>
2015-06-27 21:25:01 +00:00
<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.
2015-02-24 17:03:22 +00:00
</div>
2015-06-27 21:25:01 +00:00
<canvas nx="matrix"></canvas>
</div>
<script type="text/javascript">
2015-02-24 17:03:22 +00:00
//setup a polyphonic sampler
var keys = new Tone.PolySynth(4, Tone.Sampler, {
2014-09-04 04:06:01 +00:00
"A" : "./audio/casio/A1.mp3",
"C#" : "./audio/casio/Cs2.mp3",
"E" : "./audio/casio/E2.mp3",
"F#" : "./audio/casio/Fs2.mp3",
2015-02-24 17:03:22 +00:00
}, {
"envelope" : {
"release" : 0.2
}
}).toMaster();
keys.volume.value = -15;
2014-09-04 04:06:01 +00:00
2015-02-24 17:03:22 +00:00
//keep track of steps and notes
var stepNumber = 0;
2014-09-04 04:06:01 +00:00
var noteNames = ["A", "C#", "E", "F#"];
2015-02-24 17:03:22 +00:00
//the repeated callback
2014-09-04 04:06:01 +00:00
Tone.Transport.setInterval(function(time){
2015-02-24 17:03:22 +00:00
//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);
2014-09-04 04:06:01 +00:00
}
}
2015-02-24 17:03:22 +00:00
stepNumber++;
stepNumber = stepNumber % 16;
2014-09-04 04:06:01 +00:00
}, "16n");
2014-06-23 21:00:51 +00:00
2015-02-24 17:03:22 +00:00
//transport settings
Tone.Transport.loopEnd = "1m";
Tone.Transport.loop = true;
</script>
<script type="text/javascript">
2015-06-27 21:25:01 +00:00
nx.onload = function(){
nx.colorize("#f5871f");
matrix1.col = 16;
matrix1.init();
matrix1.resize($("#Content").width(), 250);
matrix1.draw();
}
$(function(){
2014-06-23 21:00:51 +00:00
2015-06-27 21:25:01 +00:00
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>
2014-06-23 21:00:51 +00:00
</body>
</html>