@blibliki/engine 0.1.25 → 0.1.27
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/dist/index.js +19484 -0
- package/dist/index.umd.cjs +227 -0
- package/dist/{build → src}/Engine.d.ts +10 -8
- package/dist/{build → src}/core/IO/AudioNode.d.ts +10 -9
- package/dist/{build → src}/core/IO/Collection.d.ts +5 -4
- package/dist/src/core/IO/ForwardNode/Base.d.ts +19 -0
- package/dist/src/core/IO/ForwardNode/index.d.ts +28 -0
- package/dist/{build → src}/core/IO/MidiNode.d.ts +9 -8
- package/dist/{build → src}/core/IO/Node.d.ts +11 -6
- package/dist/src/core/IO/index.d.ts +22 -0
- package/dist/{build → src}/core/Module/MonoModule.d.ts +9 -8
- package/dist/{build → src}/core/Module/PolyModule.d.ts +13 -10
- package/dist/src/core/Module/index.d.ts +7 -0
- package/dist/{build → src}/core/midi/ComputerKeyboardInput.d.ts +3 -2
- package/dist/{build → src}/core/midi/MidiDevice.d.ts +2 -1
- package/dist/{build → src}/core/midi/MidiDeviceManager.d.ts +2 -1
- package/dist/{build → src}/core/midi/MidiEvent.d.ts +3 -2
- package/dist/src/core/midi/index.d.ts +5 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/main.d.ts +0 -0
- package/dist/{build → src}/modules/BitCrusher.d.ts +3 -2
- package/dist/{build → src}/modules/Delay.d.ts +3 -2
- package/dist/{build → src}/modules/Distortion.d.ts +3 -2
- package/dist/{build → src}/modules/Effect.d.ts +3 -2
- package/dist/{build → src}/modules/Envelope/AmpEnvelope.d.ts +3 -2
- package/dist/{build → src}/modules/Envelope/Base.d.ts +4 -3
- package/dist/{build → src}/modules/Envelope/FreqEnvelope.d.ts +4 -3
- package/dist/src/modules/Envelope/index.d.ts +3 -0
- package/dist/{build → src}/modules/Filter.d.ts +4 -3
- package/dist/{build → src}/modules/LFO.d.ts +5 -4
- package/dist/{build → src}/modules/Master.d.ts +3 -2
- package/dist/{build → src}/modules/MidiSelector.d.ts +3 -2
- package/dist/{build → src}/modules/Oscillator.d.ts +7 -6
- package/dist/{build → src}/modules/Reverb.d.ts +3 -2
- package/dist/{build → src}/modules/Sequencer.d.ts +4 -3
- package/dist/{build → src}/modules/VirtualMidi.d.ts +7 -6
- package/dist/{build → src}/modules/VoiceScheduler.d.ts +6 -5
- package/dist/{build → src}/modules/Volume.d.ts +4 -3
- package/dist/src/modules/index.d.ts +18 -0
- package/dist/{build → src}/routes.d.ts +2 -1
- package/dist/test/MockingModules.d.ts +22 -0
- package/dist/test/Module/Oscillator.test.d.ts +1 -0
- package/dist/test/core/IO.test.d.ts +1 -0
- package/package.json +15 -16
- package/src/Engine.ts +14 -1
- package/src/core/IO/AudioNode.ts +8 -7
- package/src/core/IO/Collection.ts +11 -11
- package/src/core/IO/ForwardNode/Base.ts +99 -0
- package/src/core/IO/ForwardNode/index.ts +60 -0
- package/src/core/IO/MidiNode.ts +5 -5
- package/src/core/IO/Node.ts +49 -48
- package/src/core/IO/index.ts +28 -13
- package/src/core/Module/PolyModule.ts +26 -16
- package/src/main.ts +1 -0
- package/src/modules/Filter.ts +1 -1
- package/src/modules/LFO.ts +2 -3
- package/src/modules/Oscillator.ts +16 -8
- package/src/modules/index.ts +2 -2
- package/src/vite-env.d.ts +1 -0
- package/dist/build/core/IO/ForwardNode.d.ts +0 -38
- package/dist/build/core/IO/index.d.ts +0 -12
- package/dist/build/core/Module/index.d.ts +0 -6
- package/dist/build/core/midi/index.d.ts +0 -5
- package/dist/build/index.d.ts +0 -9
- package/dist/build/modules/Envelope/index.d.ts +0 -3
- package/dist/build/modules/index.d.ts +0 -17
- package/dist/main.cjs.js +0 -25
- package/dist/main.cjs.js.map +0 -1
- package/dist/main.esm.js +0 -25
- package/dist/main.esm.js.map +0 -1
- package/src/core/IO/ForwardNode.ts +0 -194
- /package/dist/{build → src}/core/Note/frequencyTable.d.ts +0 -0
- /package/dist/{build → src}/core/Note/index.d.ts +0 -0
- /package/dist/{build → src}/types.d.ts +0 -0
- /package/dist/{build → src}/utils.d.ts +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import Module,
|
|
3
|
-
import
|
|
1
|
+
import { default as Note } from '../core/Note';
|
|
2
|
+
import { default as Module, PolyModule } from '../core/Module';
|
|
3
|
+
import { Volume as Vol } from 'tone';
|
|
4
|
+
|
|
4
5
|
export interface VolumeInterface {
|
|
5
6
|
volume: number;
|
|
6
7
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AudioModule } from '../core/Module';
|
|
2
|
+
|
|
3
|
+
export { default as Master } from './Master';
|
|
4
|
+
export { default as Filter } from './Filter';
|
|
5
|
+
export { default as Oscillator, MonoOscillator } from './Oscillator';
|
|
6
|
+
export { default as VirtualMidi } from './VirtualMidi';
|
|
7
|
+
export { default as VoiceScheduler } from './VoiceScheduler';
|
|
8
|
+
export { default as Sequencer } from './Sequencer';
|
|
9
|
+
export type { ISequence } from './Sequencer';
|
|
10
|
+
export { Envelope, AmpEnvelope, FreqEnvelope, EnvelopeStages, } from './Envelope';
|
|
11
|
+
export interface ICreateModule {
|
|
12
|
+
id?: string;
|
|
13
|
+
name: string;
|
|
14
|
+
numberOfVoices?: number;
|
|
15
|
+
type: string;
|
|
16
|
+
props: any;
|
|
17
|
+
}
|
|
18
|
+
export declare function createModule(params: ICreateModule): AudioModule;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { default as Module, PolyModule } from '../src/core/Module';
|
|
2
|
+
|
|
3
|
+
interface IMonoMocking {
|
|
4
|
+
}
|
|
5
|
+
export declare class MockInternalModule {
|
|
6
|
+
connect(): void;
|
|
7
|
+
disconnect(): void;
|
|
8
|
+
dispose(): void;
|
|
9
|
+
}
|
|
10
|
+
export declare class MonoMocking extends Module<MockInternalModule, IMonoMocking> {
|
|
11
|
+
constructor(params: {
|
|
12
|
+
name: string;
|
|
13
|
+
props: Partial<IMonoMocking>;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export declare class PolyMocking extends PolyModule<MonoMocking, IMonoMocking> {
|
|
17
|
+
constructor(params: {
|
|
18
|
+
name: string;
|
|
19
|
+
props: Partial<IMonoMocking>;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,46 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blibliki/engine",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.27",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"source": "src/index.ts",
|
|
5
|
-
"main": "dist/
|
|
6
|
-
"module": "dist/
|
|
7
|
-
"types": "dist/
|
|
6
|
+
"main": "dist/index.umd.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/src/index.d.ts",
|
|
8
9
|
"files": [
|
|
9
10
|
"README.md",
|
|
10
11
|
"src",
|
|
11
12
|
"dist"
|
|
12
13
|
],
|
|
13
14
|
"dependencies": {
|
|
14
|
-
"@types/lodash": "^4.14.186",
|
|
15
15
|
"crypto-js": "^4.2.0",
|
|
16
16
|
"lodash": "^4.17.21",
|
|
17
17
|
"tone": "^14.7.77",
|
|
18
18
|
"uuid": "^8.3.2"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@rollup/plugin-commonjs": "^25.0.7",
|
|
22
|
-
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
23
|
-
"@rollup/plugin-terser": "^0.4.4",
|
|
24
|
-
"@rollup/plugin-typescript": "^11.1.6",
|
|
25
21
|
"@types/crypto-js": "^4.2.2",
|
|
26
22
|
"@types/jest": "^29.2.0",
|
|
23
|
+
"@types/lodash": "^4.14.186",
|
|
27
24
|
"@types/node": "^16.7.13",
|
|
28
25
|
"@types/uuid": "^8.3.4",
|
|
29
26
|
"@typescript-eslint/eslint-plugin": "^6.9.0",
|
|
30
27
|
"@typescript-eslint/parser": "^6.9.0",
|
|
28
|
+
"@vitest/browser": "^1.5.2",
|
|
31
29
|
"eslint": "^8.52.0",
|
|
32
|
-
"jest": "^29.2.2",
|
|
33
30
|
"prettier": "^2.7.1",
|
|
34
|
-
"rollup": "^4.10.0",
|
|
35
|
-
"ts-jest": "^29.0.3",
|
|
36
31
|
"typescript": "^5.2.2",
|
|
37
|
-
"
|
|
32
|
+
"vite": "^5.2.10",
|
|
33
|
+
"vite-plugin-dts": "^3.9.0",
|
|
34
|
+
"vitest": "^1.5.2",
|
|
35
|
+
"webdriverio": "^8.36.1"
|
|
38
36
|
},
|
|
39
37
|
"scripts": {
|
|
40
|
-
"
|
|
41
|
-
"build": "
|
|
38
|
+
"dev": "vite",
|
|
39
|
+
"build": "tsc && vite build",
|
|
40
|
+
"preview": "vite preview",
|
|
42
41
|
"lint": "eslint src",
|
|
43
42
|
"tsc": "tsc --noEmit",
|
|
44
|
-
"test": "
|
|
43
|
+
"test": "vitest"
|
|
45
44
|
}
|
|
46
45
|
}
|
package/src/Engine.ts
CHANGED
|
@@ -120,7 +120,7 @@ class Engine {
|
|
|
120
120
|
if (audioModule instanceof PolyModule && numberOfVoices)
|
|
121
121
|
audioModule.numberOfVoices = numberOfVoices;
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
if (numberOfVoices) this.updateRoutes();
|
|
124
124
|
|
|
125
125
|
return audioModule.serialize();
|
|
126
126
|
}
|
|
@@ -134,6 +134,7 @@ class Engine {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
addRoute(props: Optional<RouteInterface, "id">) {
|
|
137
|
+
if (!this.validRoute(props)) throw Error("Invalid route, incompatible IOs");
|
|
137
138
|
const route = createRoute(props);
|
|
138
139
|
const newRoutes = { ...this.routes, [route.id]: route };
|
|
139
140
|
|
|
@@ -143,6 +144,18 @@ class Engine {
|
|
|
143
144
|
return route;
|
|
144
145
|
}
|
|
145
146
|
|
|
147
|
+
validRoute(props: Optional<RouteInterface, "id">): boolean {
|
|
148
|
+
const { sourceId, sourceIOId, destinationId, destinationIOId } = props;
|
|
149
|
+
|
|
150
|
+
const output = this.findById(sourceId).outputs.find(sourceIOId);
|
|
151
|
+
const input = this.findById(destinationId).inputs.find(destinationIOId);
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
!!(output?.isMidi && input?.isMidi) ||
|
|
155
|
+
!!(output?.isAudio && input?.isAudio)
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
146
159
|
removeRoute(id: string) {
|
|
147
160
|
delete this.routes[id];
|
|
148
161
|
this.updateRoutes();
|
package/src/core/IO/AudioNode.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { InputNode } from "tone";
|
|
|
2
2
|
import IONode, { IOType, IIONode } from "./Node";
|
|
3
3
|
import MonoModule, { Connectable } from "../Module/index";
|
|
4
4
|
import { AnyObject } from "../../types";
|
|
5
|
-
import {
|
|
5
|
+
import { ForwardAudioInput } from "./ForwardNode";
|
|
6
|
+
import { AnyAudioInput, AnyAudioOuput } from ".";
|
|
6
7
|
|
|
7
8
|
export type AudioIO = AudioInput | AudioOutput;
|
|
8
9
|
|
|
@@ -31,11 +32,11 @@ export class AudioInput extends IONode implements IAudioInput {
|
|
|
31
32
|
this.internalModule = props.internalModule;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
plug(io:
|
|
35
|
+
plug(io: AnyAudioOuput, plugOther: boolean = true) {
|
|
35
36
|
super.plug(io, plugOther);
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
unPlug(io:
|
|
39
|
+
unPlug(io: AnyAudioOuput, plugOther: boolean = true) {
|
|
39
40
|
super.unPlug(io, plugOther);
|
|
40
41
|
}
|
|
41
42
|
|
|
@@ -57,16 +58,16 @@ export class AudioOutput extends IONode implements IAudioOutput {
|
|
|
57
58
|
this.internalModule = props.internalModule;
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
plug(io:
|
|
61
|
+
plug(io: AnyAudioInput, plugOther: boolean = true) {
|
|
61
62
|
super.plug(io, plugOther);
|
|
62
|
-
if (io instanceof
|
|
63
|
+
if (io instanceof ForwardAudioInput) return;
|
|
63
64
|
|
|
64
65
|
this.internalModule.connect(io.internalModule);
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
unPlug(io:
|
|
68
|
+
unPlug(io: AnyAudioInput, plugOther: boolean = true) {
|
|
68
69
|
super.unPlug(io, plugOther);
|
|
69
|
-
if (io instanceof
|
|
70
|
+
if (io instanceof ForwardAudioInput) return;
|
|
70
71
|
|
|
71
72
|
try {
|
|
72
73
|
this.internalModule.disconnect(io.internalModule);
|
|
@@ -3,7 +3,7 @@ import IO, { IOType } from "./Node";
|
|
|
3
3
|
import { AudioInput, AudioOutput } from "./AudioNode";
|
|
4
4
|
import { MidiInput, MidiOutput } from "./MidiNode";
|
|
5
5
|
import { IAnyIO } from ".";
|
|
6
|
-
import {
|
|
6
|
+
import { ForwardAudioInput, ForwardAudioOutput } from "./ForwardNode";
|
|
7
7
|
|
|
8
8
|
export default class IOCollection<AnyIO extends IO> {
|
|
9
9
|
plugableModule: AudioModule;
|
|
@@ -30,25 +30,25 @@ export default class IOCollection<AnyIO extends IO> {
|
|
|
30
30
|
|
|
31
31
|
io = new AudioOutput(this.plugableModule, props);
|
|
32
32
|
break;
|
|
33
|
-
case IOType.
|
|
33
|
+
case IOType.MidiInput:
|
|
34
|
+
io = new MidiInput(this.plugableModule, props);
|
|
35
|
+
break;
|
|
36
|
+
case IOType.MidiOutput:
|
|
37
|
+
io = new MidiOutput(this.plugableModule, props);
|
|
38
|
+
break;
|
|
39
|
+
case IOType.ForwardAudioInput:
|
|
34
40
|
if (this.plugableModule instanceof MonoModule) {
|
|
35
41
|
throw Error("MonoModule is not supported");
|
|
36
42
|
}
|
|
37
43
|
|
|
38
|
-
io = new
|
|
44
|
+
io = new ForwardAudioInput(this.plugableModule, props);
|
|
39
45
|
break;
|
|
40
|
-
case IOType.
|
|
46
|
+
case IOType.ForwardAudioOutput:
|
|
41
47
|
if (this.plugableModule instanceof MonoModule) {
|
|
42
48
|
throw Error("MonoModule is not supported");
|
|
43
49
|
}
|
|
44
50
|
|
|
45
|
-
io = new
|
|
46
|
-
break;
|
|
47
|
-
case IOType.MidiInput:
|
|
48
|
-
io = new MidiInput(this.plugableModule, props);
|
|
49
|
-
break;
|
|
50
|
-
case IOType.MidiOutput:
|
|
51
|
-
io = new MidiOutput(this.plugableModule, props);
|
|
51
|
+
io = new ForwardAudioOutput(this.plugableModule, props);
|
|
52
52
|
break;
|
|
53
53
|
default:
|
|
54
54
|
throw Error("Unknown IOType");
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import IONode, { IIONode, plugCompatibleIO, unPlugCompatibleIO } from "../Node";
|
|
2
|
+
|
|
3
|
+
import Module, { Connectable, PolyModule } from "../../Module";
|
|
4
|
+
import { AnyObject } from "../../../types";
|
|
5
|
+
import { AnyIO, ForwardAudioInput, ForwardAudioOutput } from "..";
|
|
6
|
+
|
|
7
|
+
export default class ForwardBaseNode extends IONode {
|
|
8
|
+
declare plugableModule: PolyModule<Module<Connectable, AnyObject>, AnyObject>;
|
|
9
|
+
|
|
10
|
+
constructor(
|
|
11
|
+
plugableModule: PolyModule<Module<Connectable, AnyObject>, AnyObject>,
|
|
12
|
+
props: IIONode
|
|
13
|
+
) {
|
|
14
|
+
super(plugableModule, props);
|
|
15
|
+
this.checkNameValidity();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get voices() {
|
|
19
|
+
return this.subModules.length;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get subModules() {
|
|
23
|
+
return this.plugableModule.audioModules;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
subModule(voiceNo: number) {
|
|
27
|
+
const adjustedVoiceNo = voiceNo % this.voices;
|
|
28
|
+
const mod = this.subModules.find((m) => m.voiceNo === adjustedVoiceNo);
|
|
29
|
+
if (!mod) throw Error(`Submodule with voiceNo ${voiceNo} not found`);
|
|
30
|
+
|
|
31
|
+
return mod;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get subIOs() {
|
|
35
|
+
const ios: IONode[] = [];
|
|
36
|
+
|
|
37
|
+
for (let voice = 0; voice < this.voices; voice++) {
|
|
38
|
+
ios.push(this.subIO(voice));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return ios;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
subIO(voiceNo: number) {
|
|
45
|
+
const ios = this.ioType.includes("Input")
|
|
46
|
+
? this.subModule(voiceNo).inputs
|
|
47
|
+
: this.subModule(voiceNo).outputs;
|
|
48
|
+
|
|
49
|
+
const io = ios.findByName(this.name);
|
|
50
|
+
if (!io) throw Error(`Could not forward io ${this.name}`);
|
|
51
|
+
|
|
52
|
+
return io;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
plug(io: AnyIO, plugOther: boolean = true) {
|
|
56
|
+
this.plugUnplug(io, plugOther, true);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
unPlug(io: AnyIO, plugOther: boolean = true) {
|
|
60
|
+
this.plugUnplug(io, plugOther, false);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
unPlugAll() {
|
|
64
|
+
IONode.unPlugAll(this);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private plugUnplug(io: AnyIO, plugOther: boolean, isPlug: boolean) {
|
|
68
|
+
isPlug ? super.plug(io, plugOther) : super.unPlug(io, plugOther);
|
|
69
|
+
if (
|
|
70
|
+
!plugOther &&
|
|
71
|
+
(io instanceof ForwardAudioOutput || io instanceof ForwardAudioInput)
|
|
72
|
+
)
|
|
73
|
+
return;
|
|
74
|
+
|
|
75
|
+
const plugCallback = isPlug ? plugCompatibleIO : unPlugCompatibleIO;
|
|
76
|
+
|
|
77
|
+
if (io instanceof ForwardAudioOutput || io instanceof ForwardAudioInput) {
|
|
78
|
+
const maxVoices = Math.max(this.voices, io.voices);
|
|
79
|
+
|
|
80
|
+
for (let voice = 0; voice < maxVoices; voice++) {
|
|
81
|
+
const thisIO = this.subIO(voice);
|
|
82
|
+
const otherIO = io.subIO(voice);
|
|
83
|
+
|
|
84
|
+
plugCallback(thisIO, otherIO);
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
for (let voice = 0; voice < this.voices; voice++) {
|
|
88
|
+
const thisIO = this.subIO(voice);
|
|
89
|
+
plugCallback(thisIO, io);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private checkNameValidity() {
|
|
95
|
+
const io = this.subIO(0);
|
|
96
|
+
|
|
97
|
+
if (!io) throw Error("You should forward to existing input");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { IOType, IIONode } from "../Node";
|
|
2
|
+
import Module, { Connectable, PolyModule } from "../../Module";
|
|
3
|
+
import { AnyObject } from "../../../types";
|
|
4
|
+
import { AnyAudioInput, AnyAudioOuput, AnyInput, AnyOuput } from "..";
|
|
5
|
+
import ForwardBaseNode from "./Base";
|
|
6
|
+
|
|
7
|
+
export interface IForwardAudioInput extends IIONode {
|
|
8
|
+
ioType: IOType.ForwardAudioInput;
|
|
9
|
+
}
|
|
10
|
+
export interface IForwardAudioOutput extends IIONode {
|
|
11
|
+
ioType: IOType.ForwardAudioOutput;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class ForwardAudioInput
|
|
15
|
+
extends ForwardBaseNode
|
|
16
|
+
implements IForwardAudioInput
|
|
17
|
+
{
|
|
18
|
+
declare plugableModule: PolyModule<Module<Connectable, AnyObject>, AnyObject>;
|
|
19
|
+
declare ioType: IOType.ForwardAudioInput;
|
|
20
|
+
declare connections: AnyAudioOuput[];
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
plugableModule: PolyModule<Module<Connectable, AnyObject>, AnyObject>,
|
|
24
|
+
props: IForwardAudioInput
|
|
25
|
+
) {
|
|
26
|
+
super(plugableModule, props);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
plug(io: AnyOuput, plugOther: boolean = true) {
|
|
30
|
+
super.plug(io, plugOther);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
unPlug(io: AnyOuput, plugOther: boolean = true) {
|
|
34
|
+
super.unPlug(io, plugOther);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class ForwardAudioOutput
|
|
39
|
+
extends ForwardBaseNode
|
|
40
|
+
implements IForwardAudioOutput
|
|
41
|
+
{
|
|
42
|
+
declare plugableModule: PolyModule<Module<Connectable, AnyObject>, AnyObject>;
|
|
43
|
+
declare ioType: IOType.ForwardAudioOutput;
|
|
44
|
+
declare connections: AnyAudioInput[];
|
|
45
|
+
|
|
46
|
+
constructor(
|
|
47
|
+
plugableModule: PolyModule<Module<Connectable, AnyObject>, AnyObject>,
|
|
48
|
+
props: IForwardAudioOutput
|
|
49
|
+
) {
|
|
50
|
+
super(plugableModule, props);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
plug(io: AnyInput, plugOther: boolean = true) {
|
|
54
|
+
super.plug(io, plugOther);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
unPlug(io: AnyInput, plugOther: boolean = true) {
|
|
58
|
+
super.unPlug(io, plugOther);
|
|
59
|
+
}
|
|
60
|
+
}
|
package/src/core/IO/MidiNode.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { AnyMidiInput, AnyMidiOuput } from ".";
|
|
1
2
|
import { AudioModule } from "../Module";
|
|
2
3
|
import { MidiEvent } from "../midi";
|
|
3
|
-
import { ForwardInput, ForwardOutput } from "./ForwardNode";
|
|
4
4
|
import IONode, { IOType, IIONode } from "./Node";
|
|
5
5
|
|
|
6
6
|
export interface IMidiInput extends IIONode {
|
|
@@ -22,11 +22,11 @@ export class MidiInput extends IONode implements IMidiInput {
|
|
|
22
22
|
this.onMidiEvent = props.onMidiEvent;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
plug(io:
|
|
25
|
+
plug(io: AnyMidiOuput, plugOther: boolean = true) {
|
|
26
26
|
super.plug(io, plugOther);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
unPlug(io:
|
|
29
|
+
unPlug(io: AnyMidiOuput, plugOther: boolean = true) {
|
|
30
30
|
super.unPlug(io, plugOther);
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -43,11 +43,11 @@ export class MidiOutput extends IONode implements IMidiOutput {
|
|
|
43
43
|
super(plugableModule, props);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
plug(io:
|
|
46
|
+
plug(io: AnyMidiInput, plugOther: boolean = true) {
|
|
47
47
|
super.plug(io, plugOther);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
unPlug(io:
|
|
50
|
+
unPlug(io: AnyMidiInput, plugOther: boolean = true) {
|
|
51
51
|
super.unPlug(io, plugOther);
|
|
52
52
|
}
|
|
53
53
|
|
package/src/core/IO/Node.ts
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import { AudioModule } from "../Module";
|
|
2
|
-
import {
|
|
3
|
-
AnyInput,
|
|
4
|
-
AnyOuput,
|
|
5
|
-
AudioInput,
|
|
6
|
-
AudioOutput,
|
|
7
|
-
ForwardInput,
|
|
8
|
-
ForwardOutput,
|
|
9
|
-
MidiInput,
|
|
10
|
-
MidiOutput,
|
|
11
|
-
} from ".";
|
|
2
|
+
import { AnyIO } from ".";
|
|
12
3
|
import { deterministicId } from "../../utils";
|
|
13
4
|
|
|
14
5
|
export interface IIONode {
|
|
@@ -29,48 +20,42 @@ export enum IOType {
|
|
|
29
20
|
AudioOutput = "audioOutput",
|
|
30
21
|
MidiInput = "midiInput",
|
|
31
22
|
MidiOutput = "midiOutput",
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
ForwardAudioInput = "forwardAudioInput",
|
|
24
|
+
ForwardAudioOutput = "forwardAudioOutput",
|
|
34
25
|
}
|
|
35
26
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
27
|
+
const AudioIO = [
|
|
28
|
+
IOType.AudioInput,
|
|
29
|
+
IOType.AudioOutput,
|
|
30
|
+
IOType.ForwardAudioInput,
|
|
31
|
+
IOType.ForwardAudioOutput,
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
const MidiIO = [IOType.MidiInput, IOType.MidiOutput];
|
|
35
|
+
|
|
36
|
+
const IOInputs = [
|
|
37
|
+
IOType.AudioInput,
|
|
38
|
+
IOType.MidiInput,
|
|
39
|
+
IOType.ForwardAudioInput,
|
|
40
|
+
];
|
|
41
|
+
const IOOutputs = [
|
|
42
|
+
IOType.AudioOutput,
|
|
43
|
+
IOType.MidiOutput,
|
|
44
|
+
IOType.ForwardAudioOutput,
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
export function plugCompatibleIO(io1: AnyIO, io2: AnyIO): void {
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
io1.plug(io2);
|
|
54
51
|
}
|
|
55
52
|
|
|
56
|
-
export function unPlugCompatibleIO(
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
input.unPlug(output);
|
|
63
|
-
} else if (input instanceof ForwardInput && output instanceof MidiOutput) {
|
|
64
|
-
input.unPlug(output);
|
|
65
|
-
} else if (input instanceof ForwardInput && output instanceof AudioOutput) {
|
|
66
|
-
input.unPlug(output);
|
|
67
|
-
} else if (input instanceof AudioInput && output instanceof ForwardOutput) {
|
|
68
|
-
input.unPlug(output);
|
|
69
|
-
} else if (input instanceof MidiInput && output instanceof ForwardOutput) {
|
|
70
|
-
input.unPlug(output);
|
|
71
|
-
} else {
|
|
72
|
-
throw Error("Input and output type is not compatible");
|
|
73
|
-
}
|
|
53
|
+
export function unPlugCompatibleIO(io1: AnyIO, io2: AnyIO) {
|
|
54
|
+
if (!io1.connections.some((io) => io.id === io2.id)) return;
|
|
55
|
+
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
io1.unPlug(io2);
|
|
74
59
|
}
|
|
75
60
|
|
|
76
61
|
export default abstract class IONode implements IIONode {
|
|
@@ -103,6 +88,22 @@ export default abstract class IONode implements IIONode {
|
|
|
103
88
|
if (plugOther) io.unPlug(this, false);
|
|
104
89
|
}
|
|
105
90
|
|
|
91
|
+
get isInput() {
|
|
92
|
+
return IOInputs.indexOf(this.ioType) > -1;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
get isOutput() {
|
|
96
|
+
return IOOutputs.indexOf(this.ioType) > -1;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
get isAudio() {
|
|
100
|
+
return AudioIO.indexOf(this.ioType) > -1;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
get isMidi() {
|
|
104
|
+
return MidiIO.indexOf(this.ioType) > -1;
|
|
105
|
+
}
|
|
106
|
+
|
|
106
107
|
abstract unPlugAll(): void;
|
|
107
108
|
|
|
108
109
|
serialize(): IIOSerialize {
|
package/src/core/IO/index.ts
CHANGED
|
@@ -8,17 +8,27 @@ import {
|
|
|
8
8
|
} from "./AudioNode";
|
|
9
9
|
import { IMidiInput, IMidiOutput, MidiInput, MidiOutput } from "./MidiNode";
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
ForwardAudioInput,
|
|
12
|
+
ForwardAudioOutput,
|
|
13
|
+
IForwardAudioInput,
|
|
14
|
+
IForwardAudioOutput,
|
|
15
15
|
} from "./ForwardNode";
|
|
16
16
|
|
|
17
|
-
type
|
|
18
|
-
type
|
|
19
|
-
type
|
|
20
|
-
type
|
|
21
|
-
type
|
|
17
|
+
type AnyAudioInput = AudioInput | ForwardAudioInput;
|
|
18
|
+
type AnyMidiInput = MidiInput;
|
|
19
|
+
type AnyAudioOuput = AudioOutput | ForwardAudioOutput;
|
|
20
|
+
type AnyMidiOuput = MidiOutput;
|
|
21
|
+
type AnyInput = AnyAudioInput | AnyMidiInput;
|
|
22
|
+
type AnyOuput = AnyAudioOuput | AnyMidiOuput;
|
|
23
|
+
type AnyIO = AnyInput | AnyOuput;
|
|
24
|
+
|
|
25
|
+
type IAnyAudioInput = IAudioInput | IForwardAudioInput;
|
|
26
|
+
type IAnyMidiInput = IMidiInput;
|
|
27
|
+
type IAnyAudioOuput = IAudioOutput | IForwardAudioOutput;
|
|
28
|
+
type IAnyMidiOuput = IMidiOutput;
|
|
29
|
+
type IAnyInput = IAnyAudioInput | IAnyMidiInput;
|
|
30
|
+
type IAnyOutput = IAnyAudioOuput | IAnyMidiOuput;
|
|
31
|
+
type IAnyIO = IAnyInput | IAnyOutput;
|
|
22
32
|
|
|
23
33
|
export {
|
|
24
34
|
IOCollection,
|
|
@@ -27,8 +37,8 @@ export {
|
|
|
27
37
|
AudioOutput,
|
|
28
38
|
MidiInput,
|
|
29
39
|
MidiOutput,
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
ForwardAudioInput,
|
|
41
|
+
ForwardAudioOutput,
|
|
32
42
|
};
|
|
33
43
|
export type {
|
|
34
44
|
IAnyIO,
|
|
@@ -37,11 +47,16 @@ export type {
|
|
|
37
47
|
IAudioOutput,
|
|
38
48
|
IMidiInput,
|
|
39
49
|
IMidiOutput,
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
IForwardAudioInput,
|
|
51
|
+
IForwardAudioOutput,
|
|
42
52
|
IAnyInput,
|
|
43
53
|
IAnyOutput,
|
|
44
54
|
IIOSerialize,
|
|
55
|
+
AnyAudioInput,
|
|
56
|
+
AnyMidiInput,
|
|
57
|
+
AnyAudioOuput,
|
|
58
|
+
AnyMidiOuput,
|
|
45
59
|
AnyInput,
|
|
46
60
|
AnyOuput,
|
|
61
|
+
AnyIO,
|
|
47
62
|
};
|