1 | import { optionsFromArguments } from "../core/util/Defaults.js";
|
2 | import { Add } from "./Add.js";
|
3 | import { Multiply } from "./Multiply.js";
|
4 | import { SignalOperator } from "./SignalOperator.js";
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | export class Scale extends SignalOperator {
|
17 | constructor() {
|
18 | const options = optionsFromArguments(Scale.getDefaults(), arguments, [
|
19 | "min",
|
20 | "max",
|
21 | ]);
|
22 | super(options);
|
23 | this.name = "Scale";
|
24 | this._mult = this.input = new Multiply({
|
25 | context: this.context,
|
26 | value: options.max - options.min,
|
27 | });
|
28 | this._add = this.output = new Add({
|
29 | context: this.context,
|
30 | value: options.min,
|
31 | });
|
32 | this._min = options.min;
|
33 | this._max = options.max;
|
34 | this.input.connect(this.output);
|
35 | }
|
36 | static getDefaults() {
|
37 | return Object.assign(SignalOperator.getDefaults(), {
|
38 | max: 1,
|
39 | min: 0,
|
40 | });
|
41 | }
|
42 | |
43 |
|
44 |
|
45 | get min() {
|
46 | return this._min;
|
47 | }
|
48 | set min(min) {
|
49 | this._min = min;
|
50 | this._setRange();
|
51 | }
|
52 | |
53 |
|
54 |
|
55 | get max() {
|
56 | return this._max;
|
57 | }
|
58 | set max(max) {
|
59 | this._max = max;
|
60 | this._setRange();
|
61 | }
|
62 | |
63 |
|
64 |
|
65 | _setRange() {
|
66 | this._add.value = this._min;
|
67 | this._mult.value = this._max - this._min;
|
68 | }
|
69 | dispose() {
|
70 | super.dispose();
|
71 | this._add.dispose();
|
72 | this._mult.dispose();
|
73 | return this;
|
74 | }
|
75 | }
|
76 |
|
\ | No newline at end of file |