mirror of
https://github.com/Tonejs/Tone.js
synced 2024-12-27 03:53:07 +00:00
84 lines
2.2 KiB
HTML
84 lines
2.2 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>DAW</title>
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
|
<link rel="icon" type="image/png" sizes="174x174" href="./favicon.png">
|
|
|
|
<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>
|
|
<style type="text/css">
|
|
tone-play-toggle {
|
|
margin-bottom: 10px;
|
|
}
|
|
#tracks {
|
|
position: relative;
|
|
width: calc(100% - 10px);
|
|
margin-left: 10px;
|
|
}
|
|
|
|
#progress {
|
|
width: 1px;
|
|
height: 100%;
|
|
left: 0%;
|
|
position: absolute;
|
|
background-color: black;
|
|
}
|
|
img {
|
|
width: 100%;
|
|
height: 200px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<tone-example>
|
|
<tone-loader></tone-loader>
|
|
<tone-explanation label="DAW">
|
|
This beat is composed of 3 independent Players each with a different loop length, synced to the Transport to start at different times and different offsets. The players stay synchronized to the position and offset of the Transport.
|
|
</tone-explanation>
|
|
|
|
<tone-content>
|
|
<tone-play-toggle></tone-play-toggle>
|
|
<div id="tracks">
|
|
<div id="progress"></div>
|
|
<img src="./audio/loop/drum_loop.png">
|
|
</div>
|
|
<tone-position min="-1"></tone-position>
|
|
</tone-content>
|
|
</tone-example>
|
|
|
|
|
|
<script type="text/javascript">
|
|
//set the transport
|
|
Tone.Transport.bpm.value = 108;
|
|
Tone.Transport.loop = true;
|
|
Tone.Transport.loopStart = "4m";
|
|
Tone.Transport.loopEnd = "8m";
|
|
|
|
var kick = new Tone.Player({
|
|
url : "./audio/loop/kick.[mp3|ogg]",
|
|
loop : true
|
|
}).toMaster().sync().start(0);
|
|
|
|
var snare = new Tone.Player({
|
|
url : "./audio/loop/snare.[mp3|ogg]",
|
|
loop : true
|
|
}).toMaster().sync().start("2n");
|
|
|
|
var hh = new Tone.Player({
|
|
url : "./audio/loop/hh.[mp3|ogg]",
|
|
loop : true
|
|
}).toMaster().sync().start("3:3", "4n"); //start with an offset
|
|
|
|
//bind the transport
|
|
document.querySelector("tone-play-toggle").bind(Tone.Transport);
|
|
document.querySelector("tone-position").bind(Tone.Transport);
|
|
document.querySelector("tone-position").addEventListener("position", e => {
|
|
document.querySelector("#progress").style = `left: ${e.detail*100}%`;
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|