mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-15 16:17:58 +00:00
148 lines
3.5 KiB
HTML
148 lines
3.5 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">
|
|
<link rel="icon" type="image/png" sizes="174x174" href="./style/favicon.png">
|
|
|
|
<script src="../build/Tone.js"></script>
|
|
<script src="./scripts/jquery.min.js"></script>
|
|
<script src="./scripts/draggabilly.js"></script>
|
|
<script src="./scripts/StartAudioContext.js"></script>
|
|
<script src="./scripts/Interface.js"></script>
|
|
<script src="https://tonejs.github.io/Logo/build/Logo.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="./style/examples.css">
|
|
|
|
<script>
|
|
// jshint ignore: start
|
|
</script>
|
|
|
|
</head>
|
|
<body>
|
|
<div id="Content">
|
|
<div id="Title">Events</div>
|
|
<div id="Explanation">
|
|
Tone's Event classes (<a href="https://tonejs.github.io/docs/#Event">Tone.Event</a>,
|
|
<a href="https://tonejs.github.io/docs/#Loop">Tone.Loop</a>,
|
|
<a href="https://tonejs.github.io/docs/#Part">Tone.Part</a> and
|
|
<a href="https://tonejs.github.io/docs/#Sequence">Tone.Sequence</a>)
|
|
simplify scheduling events along the Transport. Each class abstracts away calls to
|
|
<a href="https://tonejs.github.io/docs/#Transport.schedule">Transport.schedule</a> or
|
|
<a href="https://tonejs.github.io/docs/#Transport.scheduleRepeat">scheduleRepeat</a>
|
|
and lets you create precise, rhythmic events which are startable, stoppable and loopable.
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<script id="ToneCode">
|
|
/*
|
|
KICK
|
|
*/
|
|
var kick = new Tone.MembraneSynth({
|
|
"envelope" : {
|
|
"sustain" : 0,
|
|
"attack" : 0.02,
|
|
"decay" : 0.8
|
|
},
|
|
"octaves" : 10
|
|
}).toMaster();
|
|
|
|
var kickPart = new Tone.Loop(function(time){
|
|
kick.triggerAttackRelease("C2", "8n", time);
|
|
}, "2n").start(0);
|
|
|
|
|
|
/*
|
|
SNARE
|
|
*/
|
|
var snare = new Tone.NoiseSynth({
|
|
"volume" : -5,
|
|
"envelope" : {
|
|
"attack" : 0.001,
|
|
"decay" : 0.2,
|
|
"sustain" : 0
|
|
},
|
|
"filterEnvelope" : {
|
|
"attack" : 0.001,
|
|
"decay" : 0.1,
|
|
"sustain" : 0
|
|
}
|
|
}).toMaster();
|
|
|
|
var snarePart = new Tone.Loop(function(time){
|
|
snare.triggerAttack(time);
|
|
}, "2n").start("4n");
|
|
|
|
|
|
/**
|
|
* PIANO
|
|
*/
|
|
var piano = new Tone.PolySynth(4, Tone.Synth, {
|
|
"volume" : -8,
|
|
"oscillator" : {
|
|
"partials" : [1, 2, 1],
|
|
},
|
|
"portamento" : 0.05
|
|
}).toMaster()
|
|
|
|
var cChord = ["C4", "E4", "G4", "B4"];
|
|
var dChord = ["D4", "F4", "A4", "C5"];
|
|
var gChord = ["B3", "D4", "E4", "A4"];
|
|
|
|
var pianoPart = new Tone.Part(function(time, chord){
|
|
piano.triggerAttackRelease(chord, "8n", time);
|
|
}, [["0:0:2", cChord], ["0:1", cChord], ["0:1:3", dChord], ["0:2:2", cChord], ["0:3", cChord], ["0:3:2", gChord]]).start("2m");
|
|
|
|
pianoPart.loop = true;
|
|
pianoPart.loopEnd = "1m";
|
|
pianoPart.humanize = true;
|
|
|
|
|
|
/*
|
|
BASS
|
|
*/
|
|
var bass = new Tone.MonoSynth({
|
|
"volume" : -10,
|
|
"envelope" : {
|
|
"attack" : 0.1,
|
|
"decay" : 0.3,
|
|
"release" : 2,
|
|
},
|
|
"filterEnvelope" : {
|
|
"attack" : 0.001,
|
|
"decay" : 0.01,
|
|
"sustain" : 0.5,
|
|
"baseFrequency" : 200,
|
|
"octaves" : 2.6
|
|
}
|
|
}).toMaster();
|
|
|
|
var bassPart = new Tone.Sequence(function(time, note){
|
|
bass.triggerAttackRelease(note, "16n", time);
|
|
}, ["C2", ["C3", ["C3", "D2"]], "E2", ["D2", "A1"]]).start(0);
|
|
|
|
bassPart.probability = 0.9;
|
|
|
|
//set the transport
|
|
Tone.Transport.bpm.value = 90;
|
|
|
|
// GUI //
|
|
|
|
Interface.Button({
|
|
key : 32,
|
|
type : "toggle",
|
|
text : "Start",
|
|
activeText : "Stop",
|
|
start : function(){
|
|
Tone.Transport.start("+0.1");
|
|
},
|
|
end : function(){
|
|
Tone.Transport.stop();
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|