Tone.js/examples/score.html
2015-07-04 14:43:17 -04:00

163 lines
No EOL
3.6 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>SCORE</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-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="./scripts/Notone.GUI.js"></script>
<script type="text/javascript" src="./scripts/Interface.js"></script>
<link rel="stylesheet" type="text/css" href="./style/examples.css">
<script type="text/javascript">
// jshint ignore: start
</script>
</head>
<body>
<div id="Content">
<div id="Title">Scores</div>
<div id="Explanation">
Scores lets you to schedule a note on a particular "channel". Then use <code>Tone.Note.route</code>
to listen for events on that channel. Multiple notes can be put into a JSON-friendly score
which can be parsed using <code>Tone.Note.parseScore</code>.
<br><br>
Take a look at source to see the score format.
MIDI files can also be converted to JSON score format using utils/MidiToScore.js.
<br><br>
Docs for <a href="http://tonejs.org/docs/#Note.route">Tone.Note.route</a>
and <a href="http://tonejs.org/docs/#Note.parseScore">Tone.Note.parseScore</a>
</div>
</div>
<script id="ToneCode" type="text/javascript">
/*
KICK
*/
var kick = new Tone.DrumSynth({
"envelope" : {
"sustain" : 0,
"attack" : 0.02,
"decay" : 0.8
},
"octaves" : 10
}).toMaster();
Tone.Note.route("Kick", function(time){
kick.triggerAttackRelease("C2", "8n", time);
});
/*
SNARE
*/
var snare = new Tone.NoiseSynth().toMaster();
Tone.Note.route("Snare", function(time){
snare.triggerAttackRelease("8n", time);
});
/**
* PIANO
*/
var piano = new Tone.PolySynth(4, Tone.SimpleSynth).toMaster();
Tone.Note.route("Piano", function(time){
piano.triggerAttackRelease(["c4", "e4", "a4"], "8n", time);
});
/*
BASS
*/
var bass = new Tone.MonoSynth({
"volume" : -10,
"envelope" : {
"attack" : 0.1,
"decay" : 0.3,
"release" : 2,
},
"filterEnvelope" : {
"attack" : 0.01,
"decay" : 0.1,
"sustain" : 0.5,
"min" : 200,
"max" : 1200
}
}).toMaster();
Tone.Note.route("Bass", function(time, note, duration){
bass.triggerAttackRelease(note, duration, time);
});
/**
* SCORE
*/
var Score = {
"Kick" : [
"0:0", "0:2" ,
"1:0", "1:2" ,
"2:0", "2:2" ,
"3:0", "3:2" ,
],
"Snare" : [
"0:1", "0:3",
"1:1", "1:3",
"2:1", "2:3",
"3:1", "3:3"
],
"Piano" : [
"0:0", "0:0:3",
"1:0", "1:0:3",
"2:0", "2:0:3",
"3:0", "3:0:3"
],
//additional arguments to the array format are
//passed back to the route's callback function
"Bass" : [
["0:0", "C2", "4n"],
["1:0", "A2", "2n"],
["2:0", "F2", "4n"],
["3:0", "C2", "2n"],
]
};
Tone.Note.parseScore(Score);
Tone.Transport.loop = true;
Tone.Transport.bpm.value = 90;
Tone.Transport.setLoopPoints(0, "4m");
</script>
<script type="text/javascript">
$(function(){
Notone.config({
"search" : false,
"expandInDrawer" : true,
"hideDrawer" : Interface.isMobile,
"drawer" : true,
"container" : "body"
});
Notone.add(kick, "Kick");
Notone.add(snare, "Snare");
Notone.add(bass, "Bass");
new Interface.Button({
key : 32,
type : "toggle",
text : "Start",
activeText : "Stop",
start : function(){
Tone.Transport.start();
},
end : function(){
Tone.Transport.stop();
}
});
});
</script>
</body>
</html>