Tone.js/examples/polySynth.html
2024-05-15 15:24:20 -04:00

68 lines
1.7 KiB
HTML

<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>PolySynth</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://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.4.3/webcomponents-bundle.js"></script>
<link
href="https://fonts.googleapis.com/css?family=Material+Icons&display=block"
rel="stylesheet"
/>
<script src="../build/Tone.js"></script>
<script src="./js/tone-ui.js"></script>
<script src="./js/components.js"></script>
</head>
<body>
<style>
tone-piano {
margin-bottom: 10px;
}
</style>
<tone-example label="Polyphony">
<div slot="explanation">
<a href="https://tonejs.github.io/docs/latest/classes/PolySynth"
>Tone.PolySynth</a
>
handles voice creation and allocation for any monophonic
instruments passed in as the second parameter. PolySynth is not
a synthesizer by itself, it merely manages voices of one of the
other types of synths, allowing any of the monophonic
synthesizers to be polyphonic.
</div>
<div id="content"></div>
</tone-example>
<script type="text/javascript">
const synth = new Tone.PolySynth(Tone.Synth, {
oscillator: {
partials: [0, 2, 3, 4],
},
}).toDestination();
piano({
parent: document.querySelector("#content"),
polyphonic: true,
noteon: (note) => synth.triggerAttack(note.name),
noteoff: (note) => synth.triggerRelease(note.name),
});
ui({
tone: synth,
parent: document.querySelector("#content"),
});
</script>
</body>
</html>