Tone.js/examples/stepSequencer.html

97 lines
2.6 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-02-24 17:03:22 +00:00
<script type="text/javascript" src="../build/Tone.Preset.js"></script>
<script type="text/javascript" src="./deps/jquery.min.js"></script>
<script type="text/javascript" src="./deps/qwerty-hancock.js"></script>
<script type="text/javascript" src="./deps/nexusUI.js"></script>
<script type="text/javascript" src="./deps/prism.js"></script>
<script type="text/javascript" src="./scripts/Interface.js"></script>
<link rel="stylesheet" type="text/css" href="./style/examples.css">
<link rel="stylesheet" type="text/css" href="./style/prism.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">
</style>
<div id="Explanation">
Tone.Transport
<br>
<br>
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>
<div id="Content">
<div id="LoadingBar"></div>
<div id="Controls"></div>
<div id="Rack">
2014-09-04 04:06:01 +00:00
2015-02-24 17:03:22 +00:00
</div>
<div id="Code"></div>
</div>
<script id="ToneCode" type="text/javascript">
//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">
Interface.Loading("LoadingBar");
2015-02-25 05:49:03 +00:00
Interface.Rack("Rack", "Step Sequencer");
2015-02-24 17:03:22 +00:00
Interface.StepSequencer("Rack", 32, 8).randomize();
Interface.Slider("Rack", Tone.Transport, "bpm", 100, 150);
Interface.Toggle("Rack", function(on){
2014-09-04 04:06:01 +00:00
if (on){
Tone.Transport.start();
2014-09-04 04:06:01 +00:00
} else {
Tone.Transport.stop();
}
2015-02-24 17:03:22 +00:00
});
Interface.Code("Code", "ToneCode");
2014-06-23 21:00:51 +00:00
</script>
2014-06-23 21:00:51 +00:00
</body>
</html>