2015-08-17 00:32:06 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
2016-02-18 21:17:45 +00:00
|
|
|
<title>Phasing</title>
|
2015-08-17 00:32:06 +00:00
|
|
|
|
2019-01-09 01:21:29 +00:00
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
|
|
|
<link rel="icon" type="image/png" sizes="174x174" href="./favicon.png">
|
2015-08-17 00:32:06 +00:00
|
|
|
|
2019-01-09 01:21:29 +00:00
|
|
|
<script src="https://unpkg.com/@webcomponents/webcomponentsjs@^2/webcomponents-bundle.js"></script>
|
|
|
|
<script src="../build/Tone.js"></script>
|
|
|
|
<script src="./js/tonejs-ui.js"></script>
|
2015-08-17 00:32:06 +00:00
|
|
|
</head>
|
2019-01-09 01:21:29 +00:00
|
|
|
<body>
|
2015-08-17 00:32:06 +00:00
|
|
|
<style type="text/css">
|
2019-01-09 01:21:29 +00:00
|
|
|
#loop {
|
|
|
|
margin-bottom: 10px;
|
|
|
|
display: flex;
|
|
|
|
background-color: #777;
|
|
|
|
border-radius: 20px;
|
|
|
|
padding: 10px;
|
2015-08-17 00:32:06 +00:00
|
|
|
}
|
2019-01-09 01:21:29 +00:00
|
|
|
tone-loop {
|
|
|
|
flex-grow: 1;
|
|
|
|
width: 40%;
|
|
|
|
height: 150px;
|
2015-08-17 00:32:06 +00:00
|
|
|
}
|
|
|
|
</style>
|
2019-01-09 01:21:29 +00:00
|
|
|
<tone-example>
|
|
|
|
<tone-explanation label="Piano Phase">
|
2015-12-05 19:00:44 +00:00
|
|
|
By slightly slowing down the playbackRate of the Tone.Sequence in the right channel,
|
|
|
|
the two identical melodies phase against each other in interesting ways.
|
2019-01-09 01:21:29 +00:00
|
|
|
<br><br>
|
2015-12-05 19:00:44 +00:00
|
|
|
Composition by Steve Reich. Inspiration from Alexander Chen.
|
2019-01-09 01:21:29 +00:00
|
|
|
</tone-explanation>
|
|
|
|
|
|
|
|
<tone-content>
|
|
|
|
<div id="loop">
|
|
|
|
<tone-loop id="left" color="#7F33ED"></tone-loop>
|
|
|
|
<tone-loop id="right" color="#1EDF3E"></tone-loop>
|
|
|
|
</div>
|
|
|
|
<tone-play-toggle></tone-play-toggle>
|
|
|
|
</tone-content>
|
|
|
|
</tone-example>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
2015-08-17 00:32:06 +00:00
|
|
|
//set the bpm and time signature first
|
2015-12-05 19:00:44 +00:00
|
|
|
Tone.Transport.timeSignature = [6, 4];
|
|
|
|
Tone.Transport.bpm.value = 180;
|
2015-08-17 00:32:06 +00:00
|
|
|
|
|
|
|
//L/R channel merging
|
2015-12-05 19:00:44 +00:00
|
|
|
var merge = new Tone.Merge();
|
2015-08-17 00:32:06 +00:00
|
|
|
|
2015-12-05 19:00:44 +00:00
|
|
|
//a little reverb
|
|
|
|
var reverb = new Tone.Freeverb({
|
2015-08-17 00:32:06 +00:00
|
|
|
"roomSize" : 0.2,
|
|
|
|
"wet" : 0.3
|
|
|
|
});
|
|
|
|
|
2015-12-05 19:00:44 +00:00
|
|
|
merge.chain(reverb, Tone.Master);
|
2015-08-17 00:32:06 +00:00
|
|
|
|
|
|
|
//the synth settings
|
|
|
|
var synthSettings = {
|
2019-01-09 01:21:29 +00:00
|
|
|
"oscillator" : {
|
|
|
|
"detune" : 0,
|
|
|
|
"type" : "custom",
|
2015-12-05 19:00:44 +00:00
|
|
|
"partials" : [2, 1, 2, 2],
|
2019-01-09 01:21:29 +00:00
|
|
|
"phase" : 0,
|
|
|
|
"volume" : 0
|
2015-08-17 00:32:06 +00:00
|
|
|
},
|
2019-01-09 01:21:29 +00:00
|
|
|
"envelope" : {
|
|
|
|
"attack" : 0.005,
|
|
|
|
"decay" : 0.3,
|
|
|
|
"sustain" : 0.2,
|
|
|
|
"release" : 1,
|
2015-08-17 00:32:06 +00:00
|
|
|
},
|
2019-01-09 01:21:29 +00:00
|
|
|
"portamento" : 0.01,
|
|
|
|
"volume" : -20
|
2015-08-17 00:32:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//left and right synthesizers
|
2016-05-23 23:52:56 +00:00
|
|
|
var synthL = new Tone.Synth(synthSettings).connect(merge.left);
|
|
|
|
var synthR = new Tone.Synth(synthSettings).connect(merge.right);
|
2015-08-17 00:32:06 +00:00
|
|
|
|
|
|
|
//the two Tone.Sequences
|
2015-12-05 19:00:44 +00:00
|
|
|
var partL = new Tone.Sequence(function(time, note){
|
2015-08-17 00:32:06 +00:00
|
|
|
synthL.triggerAttackRelease(note, "8n", time);
|
2016-02-18 21:17:45 +00:00
|
|
|
}, ["E4", "F#4", "B4", "C#5", "D5", "F#4", "E4", "C#5", "B4", "F#4", "D5", "C#5"], "8n").start();
|
2015-08-17 00:32:06 +00:00
|
|
|
|
2015-12-05 19:00:44 +00:00
|
|
|
var partR = new Tone.Sequence(function(time, note){
|
2015-08-17 00:32:06 +00:00
|
|
|
synthR.triggerAttackRelease(note, "8n", time);
|
2016-02-18 21:17:45 +00:00
|
|
|
}, ["E4", "F#4", "B4", "C#5", "D5", "F#4", "E4", "C#5", "B4", "F#4", "D5", "C#5"], "8n").start("2m");
|
2015-08-17 00:32:06 +00:00
|
|
|
|
|
|
|
//set the playback rate of the right part to be slightly slower
|
2015-12-05 19:00:44 +00:00
|
|
|
partR.playbackRate = 0.985;
|
2015-08-17 00:32:06 +00:00
|
|
|
|
2019-01-09 01:21:29 +00:00
|
|
|
document.querySelector("tone-play-toggle").bind(Tone.Transport);
|
|
|
|
document.querySelector("#left").bind(partL);
|
|
|
|
document.querySelector("#right").bind(partR);
|
|
|
|
/*// GUI //
|
2015-12-05 19:00:44 +00:00
|
|
|
|
2017-03-26 20:39:19 +00:00
|
|
|
Interface.Button({
|
|
|
|
key : 32,
|
|
|
|
type : "toggle",
|
|
|
|
text : "Start",
|
|
|
|
activeText : "Stop",
|
|
|
|
start : function(){
|
|
|
|
Tone.Transport.start("+0.1");
|
|
|
|
},
|
|
|
|
end : function(){
|
|
|
|
Tone.Transport.stop();
|
2015-08-17 00:32:06 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-03-26 20:39:19 +00:00
|
|
|
//draw two circles
|
|
|
|
var leftCanvas = $("#Left");
|
|
|
|
var rightCanvas = $("#Right");
|
|
|
|
var leftContext = leftCanvas.get(0).getContext("2d");
|
|
|
|
var rightContext = rightCanvas.get(0).getContext("2d");
|
|
|
|
var canvasWidth = leftCanvas.width() * 2;
|
|
|
|
var canvasHeight = leftCanvas.height() * 2;
|
|
|
|
var radius = Math.min(canvasWidth, canvasHeight);
|
|
|
|
|
|
|
|
function sizeCanvas(){
|
|
|
|
canvasWidth = leftCanvas.width() * 2;
|
|
|
|
canvasHeight = leftCanvas.height() * 2;
|
|
|
|
radius = Math.min(canvasWidth, canvasHeight) * 0.8;
|
|
|
|
|
|
|
|
leftContext.canvas.width = canvasWidth;
|
|
|
|
leftContext.canvas.height = canvasHeight;
|
|
|
|
|
|
|
|
rightContext.canvas.width = canvasWidth;
|
|
|
|
rightContext.canvas.height = canvasHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
$(window).on("resize", sizeCanvas);
|
|
|
|
|
|
|
|
sizeCanvas();
|
|
|
|
|
|
|
|
var twoPi = Math.PI * 2;
|
|
|
|
|
|
|
|
function loop(){
|
|
|
|
requestAnimationFrame(loop);
|
|
|
|
leftContext.lineWidth = radius * 0.1;
|
|
|
|
rightContext.lineWidth = radius * 0.1;
|
|
|
|
//draw the left progress
|
|
|
|
leftContext.clearRect(0, 0, canvasWidth, canvasHeight);
|
|
|
|
leftContext.strokeStyle = "#7F33ED";
|
|
|
|
leftContext.save();
|
|
|
|
leftContext.translate(canvasWidth / 2, canvasHeight / 2);
|
|
|
|
leftContext.rotate(-Math.PI / 2);
|
|
|
|
leftContext.beginPath();
|
|
|
|
leftContext.arc(0, 0, radius/2, 0, twoPi * partL.progress, false);
|
|
|
|
leftContext.stroke();
|
|
|
|
leftContext.restore();
|
|
|
|
|
|
|
|
//draw the left progress
|
|
|
|
rightContext.clearRect(0, 0, canvasWidth, canvasHeight);
|
|
|
|
rightContext.strokeStyle = "#1EDF3E";
|
|
|
|
rightContext.save();
|
|
|
|
rightContext.translate(canvasWidth / 2, canvasHeight / 2);
|
|
|
|
rightContext.rotate(-Math.PI / 2);
|
|
|
|
rightContext.beginPath();
|
|
|
|
rightContext.arc(0, 0, radius/2, 0, twoPi * partR.progress, false);
|
|
|
|
rightContext.stroke();
|
|
|
|
rightContext.restore();
|
|
|
|
}
|
2019-01-09 01:21:29 +00:00
|
|
|
loop();*/
|
2017-03-26 20:39:19 +00:00
|
|
|
|
|
|
|
</script>
|
2015-08-17 00:32:06 +00:00
|
|
|
</body>
|
2017-03-18 16:35:37 +00:00
|
|
|
</html>
|