2014-10-22 22:49:42 +00:00
|
|
|
<!DOCTYPE html>
|
2014-03-15 03:17:18 +00:00
|
|
|
<html>
|
|
|
|
<head>
|
2014-10-22 22:49:42 +00:00
|
|
|
<meta charset="utf-8">
|
2014-03-15 05:02:33 +00:00
|
|
|
<title>Envelope</title>
|
2014-03-15 03:17:18 +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">
|
2014-08-26 03:47:07 +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-02-12 03:39:28 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<style type="text/css">
|
2015-06-26 05:23:05 +00:00
|
|
|
img {
|
2019-01-09 01:21:29 +00:00
|
|
|
display: block;
|
|
|
|
margin: 5px auto;
|
2015-06-27 22:02:55 +00:00
|
|
|
width: 300px!important;
|
2015-02-12 03:39:28 +00:00
|
|
|
}
|
2015-06-26 05:23:05 +00:00
|
|
|
|
2019-01-09 01:21:29 +00:00
|
|
|
tone-trigger {
|
|
|
|
margin-bottom: 10px;
|
2015-02-12 03:39:28 +00:00
|
|
|
}
|
|
|
|
</style>
|
2020-07-18 00:36:42 +00:00
|
|
|
<tone-example label="Envelope">
|
|
|
|
<div slot="explanation">
|
2015-06-27 21:25:01 +00:00
|
|
|
Envelopes ramp amplitude, frequency or any other parameter over time.
|
2019-01-09 01:21:29 +00:00
|
|
|
<a href="https://tonejs.github.io/docs/Envelope">Tone.Envelope</a> and the classes that extend it
|
2015-06-26 05:23:05 +00:00
|
|
|
implement an <a href="https://en.wikipedia.org/wiki/Synthesizer#ADSR_envelope" target="_blank">ADSR</a> envelope type
|
|
|
|
which splits its ramp into four distinct phases: Attack, Decay, Sustain, Release.
|
|
|
|
<img src="https://upload.wikimedia.org/wikipedia/commons/e/ea/ADSR_parameter.svg">
|
2020-07-18 00:36:42 +00:00
|
|
|
</div>
|
2019-01-09 01:21:29 +00:00
|
|
|
|
2020-07-18 00:36:42 +00:00
|
|
|
<div id="content">
|
|
|
|
<tone-momentary-button></tone-momentary-button>
|
|
|
|
</div>
|
2014-08-26 03:47:07 +00:00
|
|
|
|
2019-01-09 01:21:29 +00:00
|
|
|
</tone-example>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
2020-07-19 00:20:19 +00:00
|
|
|
const env = new Tone.AmplitudeEnvelope({
|
|
|
|
attack: 0.11,
|
|
|
|
decay: 0.21,
|
|
|
|
sustain: 0.5,
|
|
|
|
release: 1.2
|
2020-07-18 00:36:42 +00:00
|
|
|
}).toDestination();
|
2014-08-26 03:47:07 +00:00
|
|
|
|
2020-07-19 00:20:19 +00:00
|
|
|
// create an oscillator and connect it to the envelope
|
|
|
|
const osc = new Tone.Oscillator({
|
|
|
|
partials: [3, 2, 1],
|
|
|
|
type: "custom",
|
|
|
|
frequency: "C#4",
|
|
|
|
volume: -8,
|
2015-06-26 05:23:05 +00:00
|
|
|
}).connect(env).start();
|
2014-08-28 04:39:17 +00:00
|
|
|
|
2020-07-19 00:20:19 +00:00
|
|
|
// bind the interface
|
2020-07-18 00:36:42 +00:00
|
|
|
drawer().add({
|
|
|
|
tone: env,
|
2020-07-19 00:20:19 +00:00
|
|
|
name: "Envelope"
|
2020-07-18 00:36:42 +00:00
|
|
|
}).add({
|
|
|
|
tone: osc,
|
2020-07-19 00:20:19 +00:00
|
|
|
});
|
2015-06-26 05:23:05 +00:00
|
|
|
|
2020-07-18 00:36:42 +00:00
|
|
|
document.querySelector("tone-momentary-button").addEventListener("down", e => env.triggerAttack());
|
|
|
|
document.querySelector("tone-momentary-button").addEventListener("up", e => env.triggerRelease());
|
2014-03-15 03:17:18 +00:00
|
|
|
</script>
|
|
|
|
</body>
|
2017-03-18 16:35:37 +00:00
|
|
|
</html>
|