@blibliki/engine 0.1.27 → 0.3.2
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 +19 -28
- 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
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { IAnyAudioContext, IModule, Module } from "@/core";
|
|
2
|
+
import { IModuleConstructor } from "@/core/module/Module";
|
|
3
|
+
import { IPolyModuleConstructor, PolyModule } from "@/core/module/PolyModule";
|
|
4
|
+
import { PropSchema } from "@/core/schema";
|
|
5
|
+
import { ICreateModule, ModuleType } from ".";
|
|
6
|
+
|
|
7
|
+
export type IGain = IModule<ModuleType.Gain>;
|
|
8
|
+
export type IGainProps = {
|
|
9
|
+
gain: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const gainPropSchema: PropSchema<IGainProps> = {
|
|
13
|
+
gain: {
|
|
14
|
+
kind: "number",
|
|
15
|
+
min: 0,
|
|
16
|
+
max: Infinity,
|
|
17
|
+
step: 0.01,
|
|
18
|
+
label: "Gain",
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const DEFAULT_PROPS: IGainProps = { gain: 1 };
|
|
23
|
+
|
|
24
|
+
export class MonoGain extends Module<ModuleType.Gain> {
|
|
25
|
+
declare audioNode: GainNode;
|
|
26
|
+
|
|
27
|
+
constructor(engineId: string, params: ICreateModule<ModuleType.Gain>) {
|
|
28
|
+
const props = { ...DEFAULT_PROPS, ...params.props };
|
|
29
|
+
const audioNodeConstructor = (context: IAnyAudioContext) =>
|
|
30
|
+
new GainNode(context);
|
|
31
|
+
|
|
32
|
+
super(engineId, {
|
|
33
|
+
...params,
|
|
34
|
+
audioNodeConstructor,
|
|
35
|
+
props,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
this.registerDefaultIOs();
|
|
39
|
+
this.registerAdditionalInputs();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
protected onSetGain(value: IGainProps["gain"]) {
|
|
43
|
+
this.audioNode.gain.value = value;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private registerAdditionalInputs() {
|
|
47
|
+
this.registerAudioInput({
|
|
48
|
+
name: "gain",
|
|
49
|
+
getAudioNode: () => this.audioNode.gain,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default class Gain extends PolyModule<ModuleType.Gain> {
|
|
55
|
+
constructor(
|
|
56
|
+
engineId: string,
|
|
57
|
+
params: IPolyModuleConstructor<ModuleType.Gain>,
|
|
58
|
+
) {
|
|
59
|
+
const props = { ...DEFAULT_PROPS, ...params.props };
|
|
60
|
+
const monoModuleConstructor = (
|
|
61
|
+
engineId: string,
|
|
62
|
+
params: IModuleConstructor<ModuleType.Gain>,
|
|
63
|
+
) => new MonoGain(engineId, params);
|
|
64
|
+
|
|
65
|
+
super(engineId, {
|
|
66
|
+
...params,
|
|
67
|
+
props,
|
|
68
|
+
monoModuleConstructor,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
this.registerAdditionalInputs();
|
|
72
|
+
this.registerDefaultIOs();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private registerAdditionalInputs() {
|
|
76
|
+
this.registerAudioInput({ name: "gain" });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { IAnyAudioContext, IModule, Module } from "@/core";
|
|
2
|
+
import { PropSchema } from "@/core/schema";
|
|
3
|
+
import { ICreateModule, ModuleType } from ".";
|
|
4
|
+
|
|
5
|
+
export type IInspector = IModule<ModuleType.Inspector>;
|
|
6
|
+
export type IInspectorProps = {
|
|
7
|
+
fftSize: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const inspectorPropSchema: PropSchema<IInspectorProps> = {
|
|
11
|
+
fftSize: {
|
|
12
|
+
kind: "enum",
|
|
13
|
+
options: [32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768],
|
|
14
|
+
label: "FFT size",
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const DEFAULT_PROPS: IInspectorProps = { fftSize: 512 };
|
|
19
|
+
|
|
20
|
+
export default class Inspector extends Module<ModuleType.Inspector> {
|
|
21
|
+
declare audioNode: AnalyserNode;
|
|
22
|
+
private _buffer?: Float32Array<ArrayBuffer>;
|
|
23
|
+
|
|
24
|
+
constructor(engineId: string, params: ICreateModule<ModuleType.Inspector>) {
|
|
25
|
+
const props = { ...DEFAULT_PROPS, ...params.props };
|
|
26
|
+
const audioNodeConstructor = (context: IAnyAudioContext) =>
|
|
27
|
+
new AnalyserNode(context);
|
|
28
|
+
|
|
29
|
+
super(engineId, {
|
|
30
|
+
...params,
|
|
31
|
+
props,
|
|
32
|
+
audioNodeConstructor,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
this.registerDefaultIOs("in");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
protected onSetFftSize(value: number) {
|
|
39
|
+
this._buffer = new Float32Array(value);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get buffer() {
|
|
43
|
+
if (this._buffer) return this._buffer;
|
|
44
|
+
|
|
45
|
+
this._buffer = new Float32Array(this.props.fftSize);
|
|
46
|
+
|
|
47
|
+
return this._buffer;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
getValue(): number {
|
|
51
|
+
return this.getValues()[0];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
getValues(): Float32Array {
|
|
55
|
+
this.audioNode.getFloatTimeDomainData(this.buffer);
|
|
56
|
+
|
|
57
|
+
return this.buffer;
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/modules/Master.ts
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import Module from "
|
|
1
|
+
import { EmptyObject } from "@blibliki/utils";
|
|
2
|
+
import { IAnyAudioContext, IModule, Module } from "@/core";
|
|
3
|
+
import { PropSchema } from "@/core/schema";
|
|
4
|
+
import { ICreateModule, ModuleType } from ".";
|
|
3
5
|
|
|
4
|
-
export
|
|
6
|
+
export type IMaster = IModule<ModuleType.Master>;
|
|
7
|
+
export type IMasterProps = EmptyObject;
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
typeof Destination,
|
|
8
|
-
MasterInterface
|
|
9
|
-
> {
|
|
10
|
-
static moduleName = "Master";
|
|
9
|
+
const DEFAULT_PROPS: IMasterProps = {};
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
super(getDestination(), {
|
|
14
|
-
id,
|
|
15
|
-
name: "Master",
|
|
16
|
-
});
|
|
11
|
+
export const masterPropSchema: PropSchema<IMasterProps> = {};
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
export default class Master extends Module<ModuleType.Master> {
|
|
14
|
+
declare audioNode: AudioDestinationNode;
|
|
15
|
+
|
|
16
|
+
constructor(engineId: string, params: ICreateModule<ModuleType.Master>) {
|
|
17
|
+
const props = { ...DEFAULT_PROPS, ...params.props };
|
|
18
|
+
const audioNodeConstructor = (context: IAnyAudioContext) =>
|
|
19
|
+
context.destination;
|
|
20
|
+
|
|
21
|
+
super(engineId, { ...params, audioNodeConstructor, props });
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
this.inputs.unPlugAll();
|
|
26
|
-
this.outputs.unPlugAll();
|
|
23
|
+
this.registerDefaultIOs("in");
|
|
27
24
|
}
|
|
28
25
|
}
|
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { IModule, Module, MidiOutput } from "@/core";
|
|
2
|
+
import MidiEvent from "@/core/midi/MidiEvent";
|
|
3
|
+
import { PropSchema } from "@/core/schema";
|
|
4
|
+
import { ICreateModule, ModuleType } from ".";
|
|
5
|
+
|
|
6
|
+
export type IMidiSelector = IModule<ModuleType.MidiSelector>;
|
|
7
|
+
export type IMidiSelectorProps = {
|
|
8
|
+
selectedId: string | undefined | null;
|
|
9
|
+
};
|
|
9
10
|
|
|
10
|
-
const
|
|
11
|
-
selectedId:
|
|
11
|
+
export const midiSelectorPropSchema: PropSchema<IMidiSelectorProps> = {
|
|
12
|
+
selectedId: {
|
|
13
|
+
kind: "string",
|
|
14
|
+
label: "Midi device ID",
|
|
15
|
+
},
|
|
12
16
|
};
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
constructor(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
super(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
props: { ...InitialProps, ...props },
|
|
18
|
+
const DEFAULT_PROPS: IMidiSelectorProps = { selectedId: undefined };
|
|
19
|
+
|
|
20
|
+
export default class MidiSelector extends Module<ModuleType.MidiSelector> {
|
|
21
|
+
declare audioNode: undefined;
|
|
22
|
+
midiOutput!: MidiOutput;
|
|
23
|
+
_forwardMidiEvent?: (midiEvent: MidiEvent) => void;
|
|
24
|
+
|
|
25
|
+
constructor(
|
|
26
|
+
engineId: string,
|
|
27
|
+
params: ICreateModule<ModuleType.MidiSelector>,
|
|
28
|
+
) {
|
|
29
|
+
const props = { ...DEFAULT_PROPS, ...params.props };
|
|
30
|
+
|
|
31
|
+
super(engineId, {
|
|
32
|
+
...params,
|
|
33
|
+
props,
|
|
31
34
|
});
|
|
32
35
|
|
|
36
|
+
this.addEventListener(this.props.selectedId);
|
|
37
|
+
|
|
33
38
|
this.registerOutputs();
|
|
34
|
-
this.addEventListener(this.selectedId);
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
41
|
+
protected onSetSelectedId(value: string | null) {
|
|
42
|
+
if (!this.superInitialized) return;
|
|
40
43
|
|
|
41
|
-
set selectedId(value: string | null) {
|
|
42
44
|
this.removeEventListener();
|
|
43
|
-
|
|
44
|
-
this._props = { ...this.props, selectedId: value };
|
|
45
|
-
|
|
46
45
|
this.addEventListener(value);
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
this.
|
|
51
|
-
super.dispose();
|
|
52
|
-
}
|
|
48
|
+
private get forwardMidiEvent() {
|
|
49
|
+
if (this._forwardMidiEvent) return this._forwardMidiEvent;
|
|
53
50
|
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
this._forwardMidiEvent = (midiEvent: MidiEvent) => {
|
|
52
|
+
this.midiOutput.onMidiEvent(midiEvent);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return this._forwardMidiEvent;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
private addEventListener(midiId: string | null) {
|
|
59
|
-
if (!
|
|
58
|
+
private addEventListener(midiId: string | undefined | null) {
|
|
59
|
+
if (!midiId) return;
|
|
60
60
|
|
|
61
|
-
const midiDevice =
|
|
61
|
+
const midiDevice = this.engine.findMidiDevice(midiId);
|
|
62
62
|
midiDevice?.addEventListener(this.forwardMidiEvent);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
private forwardMidiEvent = (midiEvent: MidiEvent) => {
|
|
66
|
-
this.midiOutput.onMidiEvent(midiEvent);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
65
|
private removeEventListener() {
|
|
70
|
-
if (!this.selectedId) return;
|
|
66
|
+
if (!this.props.selectedId) return;
|
|
71
67
|
|
|
72
|
-
const midiDevice =
|
|
68
|
+
const midiDevice = this.engine.findMidiDevice(this.props.selectedId);
|
|
73
69
|
midiDevice?.removeEventListener(this.forwardMidiEvent);
|
|
74
70
|
}
|
|
71
|
+
|
|
72
|
+
private registerOutputs() {
|
|
73
|
+
this.midiOutput = this.registerMidiOutput({ name: "midi out" });
|
|
74
|
+
}
|
|
75
75
|
}
|