1 | import { __decorate } from "tslib";
|
2 | import { FrequencyClass } from "../core/type/Frequency.js";
|
3 | import { optionsFromArguments } from "../core/util/Defaults.js";
|
4 | import { noOp } from "../core/util/Interface.js";
|
5 | import { Instrument } from "../instrument/Instrument.js";
|
6 | import { timeRange } from "../core/util/Decorator.js";
|
7 |
|
8 |
|
9 |
|
10 | export class Monophonic extends Instrument {
|
11 | constructor() {
|
12 | const options = optionsFromArguments(Monophonic.getDefaults(), arguments);
|
13 | super(options);
|
14 | this.portamento = options.portamento;
|
15 | this.onsilence = options.onsilence;
|
16 | }
|
17 | static getDefaults() {
|
18 | return Object.assign(Instrument.getDefaults(), {
|
19 | detune: 0,
|
20 | onsilence: noOp,
|
21 | portamento: 0,
|
22 | });
|
23 | }
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | triggerAttack(note, time, velocity = 1) {
|
35 | this.log("triggerAttack", note, time, velocity);
|
36 | const seconds = this.toSeconds(time);
|
37 | this._triggerEnvelopeAttack(seconds, velocity);
|
38 | this.setNote(note, seconds);
|
39 | return this;
|
40 | }
|
41 | |
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | triggerRelease(time) {
|
51 | this.log("triggerRelease", time);
|
52 | const seconds = this.toSeconds(time);
|
53 | this._triggerEnvelopeRelease(seconds);
|
54 | return this;
|
55 | }
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | setNote(note, time) {
|
68 | const computedTime = this.toSeconds(time);
|
69 | const computedFrequency = note instanceof FrequencyClass ? note.toFrequency() : note;
|
70 | if (this.portamento > 0 && this.getLevelAtTime(computedTime) > 0.05) {
|
71 | const portTime = this.toSeconds(this.portamento);
|
72 | this.frequency.exponentialRampTo(computedFrequency, portTime, computedTime);
|
73 | }
|
74 | else {
|
75 | this.frequency.setValueAtTime(computedFrequency, computedTime);
|
76 | }
|
77 | return this;
|
78 | }
|
79 | }
|
80 | __decorate([
|
81 | timeRange(0)
|
82 | ], Monophonic.prototype, "portamento", void 0);
|
83 |
|
\ | No newline at end of file |