Tone.js/examples/simpleSynth.html

89 lines
1.9 KiB
HTML
Raw Normal View History

2024-05-15 19:24:20 +00:00
<!doctype html>
2015-06-26 05:23:05 +00:00
<html>
2024-05-15 19:24:20 +00:00
<head>
<meta charset="utf-8" />
<title>Synth</title>
2015-06-26 05:23:05 +00:00
2024-05-15 19:24:20 +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-06-26 05:23:05 +00:00
2024-05-15 19:24:20 +00:00
<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="Synth">
<div slot="explanation">
<a
href="https://tonejs.github.io/docs/latest/classes/Synth"
target="_blank"
>Tone.Synth</a
>
is composed simply of a
<a
href="https://tonejs.github.io/docs/latest/classes/OmniOscillator"
target="_blank"
>Tone.OmniOscillator</a
>
routed through a
<a
href="https://tonejs.github.io/docs/latest/classes/AmplitudeEnvelope"
target="_blank"
>Tone.AmplitudeEnvelope</a
>.
</div>
2015-06-26 05:23:05 +00:00
2024-05-15 19:24:20 +00:00
<div id="content"></div>
</tone-example>
2015-06-26 05:23:05 +00:00
2024-05-15 19:24:20 +00:00
<script type="text/javascript">
const synth = new Tone.Synth({
oscillator: {
type: "amtriangle",
harmonicity: 0.5,
modulationType: "sine",
},
envelope: {
attackCurve: "exponential",
attack: 0.05,
decay: 0.2,
sustain: 0.2,
release: 1.5,
},
portamento: 0.05,
}).toDestination();
2015-06-26 05:23:05 +00:00
2024-05-15 19:24:20 +00:00
piano({
tone: synth,
parent: document.querySelector("#content"),
noteon: (note) => synth.triggerAttack(note.name),
noteoff: (note) => synth.triggerRelease(),
});
2024-05-15 19:24:20 +00:00
ui({
tone: synth,
name: "Synth",
parent: document.querySelector("#content"),
});
</script>
</body>
</html>