@blibliki/engine 0.1.27 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +252 -76
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +765 -0
- package/dist/index.d.ts +765 -0
- package/dist/index.js +2 -19484
- package/dist/index.js.map +1 -0
- package/package.json +16 -27
- package/src/Engine.ts +158 -177
- package/src/core/IO/AudioIO.ts +72 -0
- package/src/core/IO/Base.ts +118 -0
- package/src/core/IO/Collection.ts +123 -47
- package/src/core/IO/MidiIO.ts +43 -0
- package/src/core/IO/PolyAudioIO.ts +115 -0
- package/src/core/IO/index.ts +7 -61
- package/src/core/Note/frequencyTable.ts +144 -144
- package/src/core/Note/index.ts +49 -59
- package/src/core/Route.ts +79 -0
- package/src/core/Timing/Scheduler.ts +37 -0
- package/src/core/Timing/Time.ts +103 -0
- package/src/core/Timing/Transport.ts +104 -0
- package/src/core/Timing/index.ts +16 -0
- package/src/core/index.ts +36 -0
- package/src/core/midi/{ComputerKeyboardInput.ts → ComputerKeyboardDevice.ts} +31 -11
- package/src/core/midi/MidiDevice.ts +38 -31
- package/src/core/midi/MidiDeviceManager.ts +54 -55
- package/src/core/midi/MidiEvent.ts +36 -60
- package/src/core/module/Module.ts +233 -0
- package/src/core/module/PolyModule.ts +246 -0
- package/src/core/module/VoiceScheduler.ts +121 -0
- package/src/core/module/index.ts +3 -0
- package/src/core/schema.ts +41 -0
- package/src/index.ts +31 -9
- package/src/modules/BiquadFilter.ts +162 -0
- package/src/modules/Constant.ts +72 -0
- package/src/modules/Envelope.ts +178 -0
- package/src/modules/Filter.ts +109 -104
- package/src/modules/Gain.ts +78 -0
- package/src/modules/Inspector.ts +59 -0
- package/src/modules/Master.ts +18 -21
- package/src/modules/MidiSelector.ts +50 -50
- package/src/modules/Oscillator.ts +203 -158
- package/src/modules/Scale.ts +79 -0
- package/src/modules/StepSequencer.ts +61 -0
- package/src/modules/VirtualMidi.ts +33 -49
- package/src/modules/index.ts +159 -74
- package/src/nodePolyfill.ts +25 -0
- package/src/processors/filter-processor.ts +82 -0
- package/src/processors/index.ts +28 -0
- package/src/processors/scale-processor.ts +81 -0
- package/dist/index.umd.cjs +0 -227
- package/dist/src/Engine.d.ts +0 -83
- package/dist/src/core/IO/AudioNode.d.ts +0 -36
- package/dist/src/core/IO/Collection.d.ts +0 -14
- package/dist/src/core/IO/ForwardNode/Base.d.ts +0 -19
- package/dist/src/core/IO/ForwardNode/index.d.ts +0 -28
- package/dist/src/core/IO/MidiNode.d.ts +0 -31
- package/dist/src/core/IO/Node.d.ts +0 -41
- package/dist/src/core/IO/index.d.ts +0 -22
- package/dist/src/core/Module/MonoModule.d.ts +0 -68
- package/dist/src/core/Module/PolyModule.d.ts +0 -62
- package/dist/src/core/Module/index.d.ts +0 -7
- package/dist/src/core/Note/frequencyTable.d.ts +0 -4
- package/dist/src/core/Note/index.d.ts +0 -28
- package/dist/src/core/midi/ComputerKeyboardInput.d.ts +0 -12
- package/dist/src/core/midi/MidiDevice.d.ts +0 -30
- package/dist/src/core/midi/MidiDeviceManager.d.ts +0 -15
- package/dist/src/core/midi/MidiEvent.d.ts +0 -22
- package/dist/src/core/midi/index.d.ts +0 -5
- package/dist/src/index.d.ts +0 -9
- package/dist/src/main.d.ts +0 -0
- package/dist/src/modules/BitCrusher.d.ts +0 -17
- package/dist/src/modules/Delay.d.ts +0 -20
- package/dist/src/modules/Distortion.d.ts +0 -17
- package/dist/src/modules/Effect.d.ts +0 -20
- package/dist/src/modules/Envelope/AmpEnvelope.d.ts +0 -19
- package/dist/src/modules/Envelope/Base.d.ts +0 -67
- package/dist/src/modules/Envelope/FreqEnvelope.d.ts +0 -26
- package/dist/src/modules/Envelope/index.d.ts +0 -3
- package/dist/src/modules/Filter.d.ts +0 -43
- package/dist/src/modules/LFO.d.ts +0 -45
- package/dist/src/modules/Master.d.ts +0 -12
- package/dist/src/modules/MidiSelector.d.ts +0 -22
- package/dist/src/modules/Oscillator.d.ts +0 -56
- package/dist/src/modules/Reverb.d.ts +0 -20
- package/dist/src/modules/Sequencer.d.ts +0 -43
- package/dist/src/modules/VirtualMidi.d.ts +0 -33
- package/dist/src/modules/VoiceScheduler.d.ts +0 -45
- package/dist/src/modules/Volume.d.ts +0 -27
- package/dist/src/modules/index.d.ts +0 -18
- package/dist/src/routes.d.ts +0 -19
- package/dist/src/types.d.ts +0 -5
- package/dist/src/utils.d.ts +0 -1
- package/dist/test/MockingModules.d.ts +0 -22
- package/dist/test/Module/Oscillator.test.d.ts +0 -1
- package/dist/test/core/IO.test.d.ts +0 -1
- package/src/core/IO/AudioNode.ts +0 -82
- package/src/core/IO/ForwardNode/Base.ts +0 -99
- package/src/core/IO/ForwardNode/index.ts +0 -60
- package/src/core/IO/MidiNode.ts +0 -67
- package/src/core/IO/Node.ts +0 -118
- package/src/core/Module/MonoModule.ts +0 -219
- package/src/core/Module/PolyModule.ts +0 -218
- package/src/core/Module/index.ts +0 -15
- package/src/core/midi/index.ts +0 -5
- package/src/main.ts +0 -1
- package/src/modules/BitCrusher.ts +0 -45
- package/src/modules/Delay.ts +0 -53
- package/src/modules/Distortion.ts +0 -45
- package/src/modules/Effect.ts +0 -46
- package/src/modules/Envelope/AmpEnvelope.ts +0 -23
- package/src/modules/Envelope/Base.ts +0 -176
- package/src/modules/Envelope/FreqEnvelope.ts +0 -64
- package/src/modules/Envelope/index.ts +0 -3
- package/src/modules/LFO.ts +0 -149
- package/src/modules/Reverb.ts +0 -53
- package/src/modules/Sequencer.ts +0 -178
- package/src/modules/VoiceScheduler.ts +0 -145
- package/src/modules/Volume.ts +0 -72
- package/src/routes.ts +0 -49
- package/src/types.ts +0 -3
- package/src/utils.ts +0 -18
- package/src/vite-env.d.ts +0 -1
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import { MidiEvent } from "../midi";
|
|
2
|
-
import { v4 as uuidv4 } from "uuid";
|
|
3
|
-
import Module, { Connectable } from "./MonoModule";
|
|
4
|
-
import {
|
|
5
|
-
IOCollection,
|
|
6
|
-
IOType,
|
|
7
|
-
IMidiInput,
|
|
8
|
-
IMidiOutput,
|
|
9
|
-
MidiOutput,
|
|
10
|
-
MidiInput,
|
|
11
|
-
AnyInput,
|
|
12
|
-
AnyOuput,
|
|
13
|
-
ForwardAudioInput,
|
|
14
|
-
} from "../IO";
|
|
15
|
-
import { AudioModule } from "./index";
|
|
16
|
-
import { plugCompatibleIO } from "../IO/Node";
|
|
17
|
-
import { deterministicId } from "../../utils";
|
|
18
|
-
import {
|
|
19
|
-
ForwardAudioOutput,
|
|
20
|
-
IForwardAudioInput,
|
|
21
|
-
IForwardAudioOutput,
|
|
22
|
-
} from "../IO/ForwardNode";
|
|
23
|
-
|
|
24
|
-
interface PolyModuleInterface<MonoAudioModule, PropsInterface> {
|
|
25
|
-
id?: string;
|
|
26
|
-
name: string;
|
|
27
|
-
numberOfVoices?: number;
|
|
28
|
-
child: new (params: {
|
|
29
|
-
id?: string;
|
|
30
|
-
name: string;
|
|
31
|
-
props: PropsInterface;
|
|
32
|
-
}) => MonoAudioModule;
|
|
33
|
-
props: PropsInterface;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export default abstract class PolyModule<
|
|
37
|
-
MonoAudioModule extends Module<Connectable, PropsInterface>,
|
|
38
|
-
PropsInterface
|
|
39
|
-
> {
|
|
40
|
-
static readonly moduleName: string;
|
|
41
|
-
|
|
42
|
-
readonly id: string;
|
|
43
|
-
readonly child: new (params: {
|
|
44
|
-
id?: string;
|
|
45
|
-
name: string;
|
|
46
|
-
props: PropsInterface;
|
|
47
|
-
}) => MonoAudioModule;
|
|
48
|
-
_name: string;
|
|
49
|
-
audioModules: MonoAudioModule[];
|
|
50
|
-
inputs: IOCollection<AnyInput>;
|
|
51
|
-
outputs: IOCollection<AnyOuput>;
|
|
52
|
-
private _numberOfVoices: number;
|
|
53
|
-
|
|
54
|
-
constructor(params: PolyModuleInterface<MonoAudioModule, PropsInterface>) {
|
|
55
|
-
this.id = params.id || uuidv4();
|
|
56
|
-
delete params.id;
|
|
57
|
-
|
|
58
|
-
this.audioModules = [];
|
|
59
|
-
|
|
60
|
-
const { child, props: extraProps, ...basicProps } = params;
|
|
61
|
-
this.child = child;
|
|
62
|
-
Object.assign(this, basicProps);
|
|
63
|
-
|
|
64
|
-
this.numberOfVoices = params.numberOfVoices || 1;
|
|
65
|
-
this.inputs = new IOCollection<AnyInput>(this);
|
|
66
|
-
this.outputs = new IOCollection<AnyOuput>(this);
|
|
67
|
-
|
|
68
|
-
Object.assign(this, { props: extraProps });
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
get name() {
|
|
72
|
-
return this._name;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
set name(value: string) {
|
|
76
|
-
this._name = value;
|
|
77
|
-
this.audioModules.forEach((m) => (m.name = value));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
get props() {
|
|
81
|
-
if (this.audioModules.length === 0) {
|
|
82
|
-
throw Error("There isn't any initialized module");
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return this.audioModules[0].props;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
set props(value: PropsInterface) {
|
|
89
|
-
Object.assign(this, value);
|
|
90
|
-
this.audioModules.forEach((m) => (m.props = value));
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
get numberOfVoices() {
|
|
94
|
-
return this._numberOfVoices;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
set numberOfVoices(value: number) {
|
|
98
|
-
this._numberOfVoices = value;
|
|
99
|
-
this.adjustNumberOfModules();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
plug(audioModule: AudioModule, from: string, to: string) {
|
|
103
|
-
const output = this.outputs.findByName(from);
|
|
104
|
-
if (!output) throw Error(`Output ${from} not exist`);
|
|
105
|
-
|
|
106
|
-
const input = audioModule.inputs.findByName(to);
|
|
107
|
-
if (!input) throw Error(`Input ${to} not exist`);
|
|
108
|
-
|
|
109
|
-
plugCompatibleIO(input, output);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
unPlugAll() {
|
|
113
|
-
this.outputs.unPlugAll();
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
dispose() {
|
|
117
|
-
this.unPlugAll();
|
|
118
|
-
this.audioModules.forEach((m) => m.dispose());
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
onMidiEvent = (midiEvent: MidiEvent) => {
|
|
122
|
-
const voiceNo = midiEvent.voiceNo || 0;
|
|
123
|
-
const audioModule = this.findVoice(voiceNo);
|
|
124
|
-
audioModule?.onMidiEvent(midiEvent);
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
serialize() {
|
|
128
|
-
if (this.audioModules.length === 0)
|
|
129
|
-
throw Error("There isn't any initialized module");
|
|
130
|
-
|
|
131
|
-
const klass = this.constructor as typeof PolyModule;
|
|
132
|
-
|
|
133
|
-
return {
|
|
134
|
-
...this.audioModules[0].serialize(),
|
|
135
|
-
id: this.id,
|
|
136
|
-
type: klass.moduleName,
|
|
137
|
-
numberOfVoices: this.numberOfVoices,
|
|
138
|
-
inputs: this.inputs.serialize(),
|
|
139
|
-
outputs: this.outputs.serialize(),
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
protected find(callback: (audioModule: MonoAudioModule) => boolean) {
|
|
144
|
-
const audioModule = this.audioModules.find(callback);
|
|
145
|
-
if (!audioModule) throw Error(`Audio module not found`);
|
|
146
|
-
|
|
147
|
-
return audioModule;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
protected findVoice(voiceNo: number) {
|
|
151
|
-
return this.audioModules.find((m) => m.voiceNo === voiceNo);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
protected registerForwardAudioInput(
|
|
155
|
-
props: Omit<IForwardAudioInput, "ioType">
|
|
156
|
-
): ForwardAudioInput {
|
|
157
|
-
return this.inputs.add({ ...props, ioType: IOType.ForwardAudioInput });
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
protected registerForwardAudioOutput(
|
|
161
|
-
props: Omit<IForwardAudioOutput, "ioType">
|
|
162
|
-
): ForwardAudioOutput {
|
|
163
|
-
return this.outputs.add({ ...props, ioType: IOType.ForwardAudioOutput });
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
protected registerMidiInput(props: Omit<IMidiInput, "ioType">): MidiInput {
|
|
167
|
-
return this.inputs.add({ ...props, ioType: IOType.MidiInput });
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
protected registerMidiOutput(props: Omit<IMidiOutput, "ioType">): MidiOutput {
|
|
171
|
-
return this.outputs.add({ ...props, ioType: IOType.MidiOutput });
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
protected registerBasicOutputs() {
|
|
175
|
-
this.registerForwardAudioOutput({ name: "output" });
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
protected registerBasicInputs() {
|
|
179
|
-
this.registerForwardAudioInput({ name: "input" });
|
|
180
|
-
this.registerMidiIn();
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
protected registerMidiIn() {
|
|
184
|
-
this.registerMidiInput({
|
|
185
|
-
name: "midi in",
|
|
186
|
-
onMidiEvent: this.onMidiEvent,
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
private adjustNumberOfModules() {
|
|
191
|
-
if (this.audioModules.length === this.numberOfVoices) return;
|
|
192
|
-
|
|
193
|
-
if (this.audioModules.length > this.numberOfVoices) {
|
|
194
|
-
const audioModule = this.audioModules.pop();
|
|
195
|
-
audioModule?.dispose();
|
|
196
|
-
} else {
|
|
197
|
-
const voiceNo = this.audioModules.length;
|
|
198
|
-
const id = deterministicId(this.id, voiceNo.toString());
|
|
199
|
-
const props = voiceNo === 0 ? ({} as PropsInterface) : this.props;
|
|
200
|
-
const audioModule = new this.child({
|
|
201
|
-
id,
|
|
202
|
-
name: this.name,
|
|
203
|
-
props: {
|
|
204
|
-
...props,
|
|
205
|
-
voiceNo,
|
|
206
|
-
},
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
if (audioModule instanceof PolyModule) {
|
|
210
|
-
throw Error("Polymodule not supported");
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
this.audioModules.push(audioModule);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
this.adjustNumberOfModules();
|
|
217
|
-
}
|
|
218
|
-
}
|
package/src/core/Module/index.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import Module, { Connectable } from "./MonoModule";
|
|
2
|
-
import PolyModule from "./PolyModule";
|
|
3
|
-
|
|
4
|
-
export { default, DummnyInternalModule } from "./MonoModule";
|
|
5
|
-
export { default as PolyModule } from "./PolyModule";
|
|
6
|
-
export type {
|
|
7
|
-
ModuleInterface,
|
|
8
|
-
Connectable,
|
|
9
|
-
Triggerable,
|
|
10
|
-
Startable,
|
|
11
|
-
} from "./MonoModule";
|
|
12
|
-
|
|
13
|
-
export type AudioModule =
|
|
14
|
-
| Module<Connectable, any>
|
|
15
|
-
| PolyModule<Module<Connectable, any>, any>;
|
package/src/core/midi/index.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { default as MidiEvent } from "./MidiEvent";
|
|
2
|
-
export { default as MidiDevice } from "./MidiDevice";
|
|
3
|
-
export { default as MidiDeviceManager } from "./MidiDeviceManager";
|
|
4
|
-
export type { MidiDeviceInterface } from "./MidiDevice";
|
|
5
|
-
export type { MidiEventType } from "./MidiEvent";
|
package/src/main.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
console.log("Hello from Blibliki");
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { BitCrusher as InternalBitCrasher } from "tone";
|
|
2
|
-
|
|
3
|
-
import Effect, { EffectInterface } from "./Effect";
|
|
4
|
-
|
|
5
|
-
interface BitCrusherInterface extends EffectInterface {
|
|
6
|
-
bits: number;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const InitialProps: Partial<BitCrusherInterface> = {
|
|
10
|
-
bits: 16,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default class BitCrusher extends Effect<
|
|
14
|
-
InternalBitCrasher,
|
|
15
|
-
BitCrusherInterface
|
|
16
|
-
> {
|
|
17
|
-
static moduleName = "BitCrusher";
|
|
18
|
-
|
|
19
|
-
constructor(params: {
|
|
20
|
-
id?: string;
|
|
21
|
-
name: string;
|
|
22
|
-
props: Partial<BitCrusherInterface>;
|
|
23
|
-
}) {
|
|
24
|
-
const { id, name, props } = params;
|
|
25
|
-
|
|
26
|
-
super({
|
|
27
|
-
id,
|
|
28
|
-
name,
|
|
29
|
-
internalModule: new InternalBitCrasher(),
|
|
30
|
-
props: {
|
|
31
|
-
...InitialProps,
|
|
32
|
-
...props,
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get bits() {
|
|
38
|
-
return this._props["bits"];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
set bits(value: number) {
|
|
42
|
-
this._props = { ...this.props, bits: value };
|
|
43
|
-
this.internalModule.bits.value = this.bits;
|
|
44
|
-
}
|
|
45
|
-
}
|
package/src/modules/Delay.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { FeedbackDelay } from "tone";
|
|
2
|
-
|
|
3
|
-
import Effect, { EffectInterface } from "./Effect";
|
|
4
|
-
|
|
5
|
-
interface DelayInterface extends EffectInterface {
|
|
6
|
-
delayTime: number;
|
|
7
|
-
feedback: number;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const InitialProps: Partial<DelayInterface> = {
|
|
11
|
-
delayTime: 1,
|
|
12
|
-
feedback: 0.3,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export default class Delay extends Effect<FeedbackDelay, DelayInterface> {
|
|
16
|
-
static moduleName = "Delay";
|
|
17
|
-
|
|
18
|
-
constructor(params: {
|
|
19
|
-
id?: string;
|
|
20
|
-
name: string;
|
|
21
|
-
props: Partial<DelayInterface>;
|
|
22
|
-
}) {
|
|
23
|
-
const { id, name, props } = params;
|
|
24
|
-
|
|
25
|
-
super({
|
|
26
|
-
id,
|
|
27
|
-
name,
|
|
28
|
-
internalModule: new FeedbackDelay(),
|
|
29
|
-
props: {
|
|
30
|
-
...InitialProps,
|
|
31
|
-
...props,
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
get delayTime() {
|
|
37
|
-
return this._props["delayTime"];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
set delayTime(value: number) {
|
|
41
|
-
this._props = { ...this.props, delayTime: value };
|
|
42
|
-
this.internalModule.delayTime.value = this.delayTime;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
get feedback() {
|
|
46
|
-
return this._props["feedback"];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
set feedback(value: number) {
|
|
50
|
-
this._props = { ...this.props, feedback: value };
|
|
51
|
-
this.internalModule.feedback.value = this.feedback;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Distortion as InternalDistortion } from "tone";
|
|
2
|
-
|
|
3
|
-
import Effect, { EffectInterface } from "./Effect";
|
|
4
|
-
|
|
5
|
-
interface DistortionInterface extends EffectInterface {
|
|
6
|
-
drive: number;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const InitialProps: Partial<DistortionInterface> = {
|
|
10
|
-
drive: 0.3,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default class Distortion extends Effect<
|
|
14
|
-
InternalDistortion,
|
|
15
|
-
DistortionInterface
|
|
16
|
-
> {
|
|
17
|
-
static moduleName = "Distortion";
|
|
18
|
-
|
|
19
|
-
constructor(params: {
|
|
20
|
-
id?: string;
|
|
21
|
-
name: string;
|
|
22
|
-
props: Partial<DistortionInterface>;
|
|
23
|
-
}) {
|
|
24
|
-
const { id, name, props } = params;
|
|
25
|
-
|
|
26
|
-
super({
|
|
27
|
-
id,
|
|
28
|
-
name,
|
|
29
|
-
internalModule: new InternalDistortion(),
|
|
30
|
-
props: {
|
|
31
|
-
...InitialProps,
|
|
32
|
-
...props,
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get drive() {
|
|
38
|
-
return this._props["drive"];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
set drive(value: number) {
|
|
42
|
-
this._props = { ...this.props, drive: value };
|
|
43
|
-
this.internalModule.distortion = this.drive;
|
|
44
|
-
}
|
|
45
|
-
}
|
package/src/modules/Effect.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Signal } from "tone";
|
|
2
|
-
import Module, { Connectable } from "../core/Module";
|
|
3
|
-
|
|
4
|
-
interface EffectLike extends Connectable {
|
|
5
|
-
wet: Signal<"normalRange">;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface EffectInterface {
|
|
9
|
-
wet: number;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const InitialProps: EffectInterface = {
|
|
13
|
-
wet: 1,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export default abstract class Effect<
|
|
17
|
-
InternalEffect extends EffectLike,
|
|
18
|
-
ModuleInterface extends EffectInterface
|
|
19
|
-
> extends Module<InternalEffect, ModuleInterface> {
|
|
20
|
-
constructor(params: {
|
|
21
|
-
id?: string;
|
|
22
|
-
name: string;
|
|
23
|
-
internalModule: InternalEffect;
|
|
24
|
-
props: Partial<ModuleInterface>;
|
|
25
|
-
}) {
|
|
26
|
-
const { id, name, internalModule, props } = params;
|
|
27
|
-
|
|
28
|
-
super(internalModule, {
|
|
29
|
-
id,
|
|
30
|
-
name,
|
|
31
|
-
props: { ...InitialProps, ...props } as ModuleInterface,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
this.registerBasicInputs();
|
|
35
|
-
this.registerBasicOutputs();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
get wet() {
|
|
39
|
-
return this._props["wet"];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
set wet(value: number) {
|
|
43
|
-
this._props = { ...this.props, wet: value };
|
|
44
|
-
this.internalModule.wet.value = this.wet;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { AmplitudeEnvelope } from "tone";
|
|
2
|
-
|
|
3
|
-
import Base, { EnvelopeInterface, PolyBase } from "./Base";
|
|
4
|
-
|
|
5
|
-
class MonoAmpEnvelope extends Base<AmplitudeEnvelope> {
|
|
6
|
-
constructor(params: { id?: string; name: string; props: EnvelopeInterface }) {
|
|
7
|
-
const { id, name, props } = params;
|
|
8
|
-
super({ id, name, internalModule: new AmplitudeEnvelope(), props });
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default class AmpEnvelope extends PolyBase<MonoAmpEnvelope> {
|
|
13
|
-
static moduleName = "AmpEnvelope";
|
|
14
|
-
|
|
15
|
-
constructor(params: {
|
|
16
|
-
id?: string;
|
|
17
|
-
name: string;
|
|
18
|
-
props: Partial<EnvelopeInterface>;
|
|
19
|
-
}) {
|
|
20
|
-
const { id, name, props } = params;
|
|
21
|
-
super({ id, name, child: MonoAmpEnvelope, props });
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { Envelope as Env } from "tone";
|
|
2
|
-
|
|
3
|
-
import Module, {
|
|
4
|
-
PolyModule,
|
|
5
|
-
Connectable,
|
|
6
|
-
Triggerable,
|
|
7
|
-
} from "../../core/Module";
|
|
8
|
-
import Note from "../../core/Note";
|
|
9
|
-
|
|
10
|
-
export const enum EnvelopeStages {
|
|
11
|
-
Attack = "attack",
|
|
12
|
-
Decay = "decay",
|
|
13
|
-
Sustain = "sustain",
|
|
14
|
-
Release = "release",
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const MAX_TIME = 2;
|
|
18
|
-
const MIN_TIME = 0.01;
|
|
19
|
-
const SUSTAIN_MAX_VALUE = 1;
|
|
20
|
-
const SUSTAIN_MIN_VALUE = 0;
|
|
21
|
-
|
|
22
|
-
export interface EnvelopeInterface {
|
|
23
|
-
attack: number;
|
|
24
|
-
decay: number;
|
|
25
|
-
sustain: number;
|
|
26
|
-
release: number;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const InitialProps: EnvelopeInterface = {
|
|
30
|
-
attack: MIN_TIME,
|
|
31
|
-
decay: MIN_TIME,
|
|
32
|
-
sustain: SUSTAIN_MAX_VALUE,
|
|
33
|
-
release: MIN_TIME,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export default abstract class EnvelopeModule<EnvelopeLike extends Env>
|
|
37
|
-
extends Module<EnvelopeLike, EnvelopeInterface>
|
|
38
|
-
implements Triggerable
|
|
39
|
-
{
|
|
40
|
-
activeNote?: string;
|
|
41
|
-
triggeredAt: number;
|
|
42
|
-
|
|
43
|
-
constructor(params: {
|
|
44
|
-
id?: string;
|
|
45
|
-
name: string;
|
|
46
|
-
internalModule: EnvelopeLike;
|
|
47
|
-
props: EnvelopeInterface;
|
|
48
|
-
}) {
|
|
49
|
-
const { id, name, props, internalModule } = params;
|
|
50
|
-
|
|
51
|
-
super(internalModule, {
|
|
52
|
-
id,
|
|
53
|
-
name,
|
|
54
|
-
props: { ...InitialProps, ...props },
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
this.registerBasicInputs();
|
|
58
|
-
this.registerBasicOutputs();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
get attack() {
|
|
62
|
-
return this._props["attack"];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
set attack(value: number) {
|
|
66
|
-
this.setStage(EnvelopeStages.Attack, value);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
get decay() {
|
|
70
|
-
return this._props["decay"];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
set decay(value: number) {
|
|
74
|
-
this.setStage(EnvelopeStages.Decay, value);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
get sustain() {
|
|
78
|
-
return this._props["sustain"];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
set sustain(value: number) {
|
|
82
|
-
this.setStage(EnvelopeStages.Sustain, value);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
get release() {
|
|
86
|
-
return this._props["release"];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
set release(value: number) {
|
|
90
|
-
this.setStage(EnvelopeStages.Release, value);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
setStage(stage: EnvelopeStages, value: number) {
|
|
94
|
-
const calculatedValue =
|
|
95
|
-
value === 0 ? this.minTime(stage) : this.maxTime(stage) * value;
|
|
96
|
-
this._props = { ...this.props, [stage]: value };
|
|
97
|
-
this.internalModule[stage] = calculatedValue;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
triggerAttack = (note: Note, triggeredAt: number) => {
|
|
101
|
-
this.activeNote = note.fullName;
|
|
102
|
-
this.triggeredAt = triggeredAt;
|
|
103
|
-
|
|
104
|
-
this.internalModule.triggerAttack(triggeredAt, note.velocity);
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
triggerRelease = (note: Note, triggeredAt: number) => {
|
|
108
|
-
if (this.activeNote && this.activeNote !== note.fullName) return;
|
|
109
|
-
|
|
110
|
-
this.internalModule.triggerRelease(triggeredAt);
|
|
111
|
-
this.activeNote = undefined;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
private maxTime(stage: EnvelopeStages): number {
|
|
115
|
-
return stage === EnvelopeStages.Sustain ? SUSTAIN_MAX_VALUE : MAX_TIME;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
private minTime(stage: EnvelopeStages): number {
|
|
119
|
-
return stage === EnvelopeStages.Sustain ? SUSTAIN_MIN_VALUE : MIN_TIME;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export abstract class PolyBase<
|
|
124
|
-
EnvelopeModule extends Module<Connectable, EnvelopeInterface>
|
|
125
|
-
> extends PolyModule<EnvelopeModule, EnvelopeInterface> {
|
|
126
|
-
constructor(params: {
|
|
127
|
-
id?: string;
|
|
128
|
-
name: string;
|
|
129
|
-
child: new (params: {
|
|
130
|
-
id?: string;
|
|
131
|
-
name: string;
|
|
132
|
-
props: EnvelopeInterface;
|
|
133
|
-
}) => EnvelopeModule;
|
|
134
|
-
props: Partial<EnvelopeInterface>;
|
|
135
|
-
}) {
|
|
136
|
-
const { id, name, child, props } = params;
|
|
137
|
-
super({
|
|
138
|
-
id,
|
|
139
|
-
name,
|
|
140
|
-
child,
|
|
141
|
-
props: { ...InitialProps, ...props },
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
this.registerBasicInputs();
|
|
145
|
-
this.registerBasicOutputs();
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
class MonoEnvelope extends EnvelopeModule<Env> {
|
|
150
|
-
constructor(params: { id?: string; name: string; props: EnvelopeInterface }) {
|
|
151
|
-
const { id, name, props } = params;
|
|
152
|
-
super({ id, name, internalModule: new Env(), props });
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export class Envelope extends PolyBase<MonoEnvelope> {
|
|
157
|
-
static moduleName = "Envelope";
|
|
158
|
-
|
|
159
|
-
constructor(params: {
|
|
160
|
-
id?: string;
|
|
161
|
-
name: string;
|
|
162
|
-
props: Partial<EnvelopeInterface>;
|
|
163
|
-
}) {
|
|
164
|
-
const { id, name, props } = params;
|
|
165
|
-
|
|
166
|
-
super({
|
|
167
|
-
id,
|
|
168
|
-
name,
|
|
169
|
-
child: MonoEnvelope,
|
|
170
|
-
props: {
|
|
171
|
-
...InitialProps,
|
|
172
|
-
...props,
|
|
173
|
-
},
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { FrequencyEnvelope } from "tone";
|
|
2
|
-
|
|
3
|
-
import Filter from "../Filter";
|
|
4
|
-
import Base, { EnvelopeInterface, PolyBase } from "./Base";
|
|
5
|
-
|
|
6
|
-
interface FreqEnvelopeInterface extends Partial<EnvelopeInterface> {
|
|
7
|
-
amount?: number;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const InitialProps: FreqEnvelopeInterface = {
|
|
11
|
-
amount: 0,
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export class MonoFreqEnvelope extends Base<FrequencyEnvelope> {
|
|
15
|
-
private _frequency: number;
|
|
16
|
-
private _amount: number;
|
|
17
|
-
filter: Filter;
|
|
18
|
-
|
|
19
|
-
constructor(params: { id?: string; name: string; props: EnvelopeInterface }) {
|
|
20
|
-
const { id, name, props } = params;
|
|
21
|
-
|
|
22
|
-
super({
|
|
23
|
-
id,
|
|
24
|
-
name,
|
|
25
|
-
internalModule: new FrequencyEnvelope(),
|
|
26
|
-
props: {
|
|
27
|
-
...InitialProps,
|
|
28
|
-
...props,
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
get frequency() {
|
|
34
|
-
return this._frequency;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
set frequency(value: number) {
|
|
38
|
-
this._frequency = value;
|
|
39
|
-
this.internalModule.baseFrequency = value;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
get amount() {
|
|
43
|
-
return this._amount;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
set amount(value: number) {
|
|
47
|
-
this._amount = value;
|
|
48
|
-
|
|
49
|
-
this.internalModule.octaves = value;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export default class FreqEnvelope extends PolyBase<MonoFreqEnvelope> {
|
|
54
|
-
static moduleName = "FreqEnvelope";
|
|
55
|
-
|
|
56
|
-
constructor(params: {
|
|
57
|
-
id?: string;
|
|
58
|
-
name: string;
|
|
59
|
-
props: Partial<EnvelopeInterface>;
|
|
60
|
-
}) {
|
|
61
|
-
const { id, name, props } = params;
|
|
62
|
-
super({ id, name, child: MonoFreqEnvelope, props });
|
|
63
|
-
}
|
|
64
|
-
}
|