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

81 lines
1.8 KiB
HTML

<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>MonoSynth</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="MonoSynth">
<div slot="explanation">
<a href="https://tonejs.github.io/docs/latest/classes/MonoSynth"
>Tone.MonoSynth</a
>
is composed of one oscillator, one filter, and two envelopes.
Both envelopes are triggered simultaneously when a note is
triggered.
</div>
<div id="content"></div>
</tone-example>
<script type="text/javascript">
const synth = new Tone.PolySynth(Tone.MonoSynth, {
volume: -8,
oscillator: {
type: "square8",
},
envelope: {
attack: 0.05,
decay: 0.3,
sustain: 0.4,
release: 0.8,
},
filterEnvelope: {
attack: 0.001,
decay: 0.7,
sustain: 0.1,
release: 0.8,
baseFrequency: 300,
octaves: 4,
},
}).toDestination();
piano({
noteon: (note) => synth.triggerAttack(note.name),
noteoff: (note) => synth.triggerRelease(note.name),
parent: document.querySelector("#content"),
});
ui({
tone: synth,
parent: document.querySelector("#content"),
name: "MonoSynth",
});
</script>
</body>
</html>