Tone.js/examples/quantization.html

79 lines
2.5 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
2019-01-09 01:21:29 +00:00
<title>Quantization</title>
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">
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>
</head>
<body>
2019-01-09 01:21:29 +00:00
<style>
#buttons {
display: flex;
margin: 10px 0;
}
#buttons tone-button {
flex-grow: 1;
margin: 5px;
}
</style>
2019-01-09 01:21:29 +00:00
<tone-example>
<tone-explanation label="Quantization">
Using the "@" symbol, <a href="https://github.com/Tonejs/Tone.js/wiki/Time" target="_blank">Time</a>
expressions can be <a href="https://en.wikipedia.org/wiki/Quantization_(music)" target="_blank">quantized</a>
(aligned to a subdivision). In this example, a note's start time is aligned to the given subdivision.
2019-01-09 01:21:29 +00:00
<br><br>
The Transport must be started
</tone-explanation>
2019-01-09 01:21:29 +00:00
<tone-content>
<tone-transport></tone-transport>
<div id="buttons">
<tone-button disabled id="at8n" label="@8n"></tone-button>
<tone-button disabled id="at4n" label="@4n"></tone-button>
<tone-button disabled id="at2n" label="@2n"></tone-button>
<tone-button disabled id="at1m" label="@1m"></tone-button>
</div>
</tone-content>
2019-01-09 01:21:29 +00:00
<tone-drawer collapsed>
<tone-synth polyphonic collapsed></tone-synth>
</tone-drawer>
</tone-example>
2019-01-09 01:21:29 +00:00
<script type="text/javascript">
var polySynth = new Tone.PolySynth(4, Tone.Synth).toMaster();
2019-01-09 01:21:29 +00:00
//bind the interface
document.querySelector("tone-transport").bind(Tone.Transport);
document.querySelector("tone-transport").addEventListener("play", e => {
//enable all of the buttons if it's playing
Array.from(document.querySelectorAll("tone-button")).forEach(el => {
if (e.detail){
el.removeAttribute("disabled");
} else {
el.setAttribute("disabled", "");
}
});
});
2019-01-09 01:21:29 +00:00
document.querySelector("#at8n").addEventListener("click", e => {
polySynth.triggerAttackRelease("B4", "8n", "@8n");
});
2019-01-09 01:21:29 +00:00
document.querySelector("#at4n").addEventListener("click", e => {
polySynth.triggerAttackRelease("E4", "8n", "@4n");
});
2019-01-09 01:21:29 +00:00
document.querySelector("#at2n").addEventListener("click", e => {
polySynth.triggerAttackRelease("G3", "8n", "@2n");
});
document.querySelector("#at1m").addEventListener("click", e => {
polySynth.triggerAttackRelease("C2", "8n", "@1m");
});
</script>
</body>
</html>