2015-12-05 18:20:53 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
2019-01-09 01:21:29 +00:00
|
|
|
<title>Quantization</title>
|
2015-12-05 18:20:53 +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-12-05 18:20:53 +00:00
|
|
|
|
2020-07-18 00:58:09 +00:00
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.4.3/webcomponents-bundle.js"></script>
|
2020-07-18 00:36:42 +00:00
|
|
|
<link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet"/>
|
2019-01-09 01:21:29 +00:00
|
|
|
<script src="../build/Tone.js"></script>
|
2020-07-18 00:58:09 +00:00
|
|
|
<script src="./js/tone-ui.js"></script>
|
|
|
|
<script src="./js/components.js"></script>
|
2015-12-05 18:20:53 +00:00
|
|
|
</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;
|
2015-12-05 18:20:53 +00:00
|
|
|
}
|
2020-07-18 00:36:42 +00:00
|
|
|
#progress {
|
|
|
|
margin: 10px;
|
|
|
|
color: #8c8c8c;
|
|
|
|
}
|
2015-12-05 18:20:53 +00:00
|
|
|
</style>
|
2020-07-18 00:36:42 +00:00
|
|
|
<tone-example label="Quantization">
|
|
|
|
<div slot="explanation">
|
2015-12-05 18:20:53 +00:00
|
|
|
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
|
2020-07-18 00:36:42 +00:00
|
|
|
</div>
|
2015-12-05 18:20:53 +00:00
|
|
|
|
2020-07-18 00:36:42 +00:00
|
|
|
<div id="content">
|
|
|
|
<div id="progress"></div>
|
|
|
|
<tone-play-toggle></tone-play-toggle>
|
2019-01-09 01:21:29 +00:00
|
|
|
<div id="buttons">
|
2020-07-18 00:36:42 +00:00
|
|
|
<tone-button disabled id="at8n" label="@8n">@8n</tone-button>
|
|
|
|
<tone-button disabled id="at4n" label="@4n">@4n</tone-button>
|
|
|
|
<tone-button disabled id="at2n" label="@2n">@2n</tone-button>
|
|
|
|
<tone-button disabled id="at1m" label="@1m">@1m</tone-button>
|
2019-01-09 01:21:29 +00:00
|
|
|
</div>
|
2020-07-18 00:36:42 +00:00
|
|
|
</div>
|
2019-01-09 01:21:29 +00:00
|
|
|
</tone-example>
|
2015-12-05 18:20:53 +00:00
|
|
|
|
2019-01-09 01:21:29 +00:00
|
|
|
<script type="text/javascript">
|
2020-07-19 00:20:19 +00:00
|
|
|
const polySynth = new Tone.PolySynth(Tone.Synth).toDestination();
|
2020-07-18 00:36:42 +00:00
|
|
|
|
2020-07-19 00:20:19 +00:00
|
|
|
function loop() {
|
|
|
|
requestAnimationFrame(loop);
|
2020-07-19 17:50:20 +00:00
|
|
|
// @ts-ignore
|
2020-07-19 00:20:19 +00:00
|
|
|
const [bar, beat, sixteenth] = Tone.Transport.position.split(":");
|
|
|
|
document.querySelector("#progress").textContent = `
|
2020-07-18 00:36:42 +00:00
|
|
|
bar: ${bar}, beat: ${beat}, sixteenth: ${sixteenth}
|
2020-07-19 00:20:19 +00:00
|
|
|
`;
|
2020-07-18 00:36:42 +00:00
|
|
|
}
|
2020-07-19 00:20:19 +00:00
|
|
|
loop();
|
2015-12-05 18:20:53 +00:00
|
|
|
|
2020-07-19 00:20:19 +00:00
|
|
|
// bind the interface
|
2020-07-18 00:36:42 +00:00
|
|
|
document.querySelector("tone-play-toggle").addEventListener("start", e => {
|
2020-07-19 00:20:19 +00:00
|
|
|
Tone.Transport.start();
|
2020-07-19 17:50:20 +00:00
|
|
|
// enable all of the buttons if it's playing
|
|
|
|
// @ts-ignore
|
2020-07-18 00:36:42 +00:00
|
|
|
Array.from(document.querySelectorAll("tone-button")).forEach(el => el.disabled = false);
|
2015-12-05 18:20:53 +00:00
|
|
|
});
|
2020-07-19 00:20:19 +00:00
|
|
|
document.querySelector("tone-play-toggle").addEventListener("stop", () => {
|
|
|
|
Tone.Transport.stop();
|
2020-07-19 17:50:20 +00:00
|
|
|
// disable all of the buttons if it's not playing
|
|
|
|
// @ts-ignore
|
2020-07-18 00:36:42 +00:00
|
|
|
Array.from(document.querySelectorAll("tone-button")).forEach(el => el.disabled = true);
|
2020-07-19 00:20:19 +00:00
|
|
|
});
|
2019-01-09 01:21:29 +00:00
|
|
|
document.querySelector("#at8n").addEventListener("click", e => {
|
|
|
|
polySynth.triggerAttackRelease("B4", "8n", "@8n");
|
2015-12-05 18:20:53 +00:00
|
|
|
});
|
2019-01-09 01:21:29 +00:00
|
|
|
document.querySelector("#at4n").addEventListener("click", e => {
|
|
|
|
polySynth.triggerAttackRelease("E4", "8n", "@4n");
|
2015-12-05 18:20:53 +00:00
|
|
|
});
|
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");
|
2015-12-05 18:20:53 +00:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</body>
|
2017-03-18 16:35:37 +00:00
|
|
|
</html>
|