@blibliki/engine 0.1.18 → 0.1.20

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.
Files changed (54) hide show
  1. package/dist/build/Engine.d.ts +81 -0
  2. package/dist/build/core/IO/AudioNode.d.ts +35 -0
  3. package/dist/build/core/IO/Collection.d.ts +13 -0
  4. package/dist/build/core/IO/ForwardNode.d.ts +38 -0
  5. package/dist/build/core/IO/MidiNode.d.ts +30 -0
  6. package/dist/build/core/IO/Node.d.ts +36 -0
  7. package/dist/build/core/IO/index.d.ts +12 -0
  8. package/dist/build/core/Module/MonoModule.d.ts +67 -0
  9. package/dist/build/core/Module/PolyModule.d.ts +57 -0
  10. package/dist/build/core/Module/index.d.ts +6 -0
  11. package/dist/build/core/Note/frequencyTable.d.ts +4 -0
  12. package/dist/build/core/Note/index.d.ts +28 -0
  13. package/dist/build/core/midi/MidiDevice.d.ts +25 -0
  14. package/dist/build/core/midi/MidiDeviceManager.d.ts +13 -0
  15. package/dist/build/core/midi/MidiEvent.d.ts +21 -0
  16. package/dist/build/core/midi/index.d.ts +5 -0
  17. package/dist/build/index.d.ts +9 -0
  18. package/dist/build/modules/BitCrusher.d.ts +16 -0
  19. package/dist/build/modules/Delay.d.ts +19 -0
  20. package/dist/build/modules/Distortion.d.ts +16 -0
  21. package/dist/build/modules/Effect.d.ts +19 -0
  22. package/dist/build/modules/Envelope/AmpEnvelope.d.ts +18 -0
  23. package/dist/build/modules/Envelope/Base.d.ts +66 -0
  24. package/dist/build/modules/Envelope/FreqEnvelope.d.ts +25 -0
  25. package/dist/build/modules/Envelope/index.d.ts +3 -0
  26. package/dist/build/modules/Filter.d.ts +37 -0
  27. package/dist/build/modules/Master.d.ts +11 -0
  28. package/dist/build/modules/MidiSelector.d.ts +21 -0
  29. package/dist/build/modules/Oscillator.d.ts +51 -0
  30. package/dist/build/modules/Reverb.d.ts +19 -0
  31. package/dist/build/modules/Sequencer.d.ts +42 -0
  32. package/dist/build/modules/VirtualMidi.d.ts +32 -0
  33. package/dist/build/modules/VoiceScheduler.d.ts +43 -0
  34. package/dist/build/modules/Volume.d.ts +26 -0
  35. package/dist/build/modules/index.d.ts +16 -0
  36. package/dist/build/routes.d.ts +18 -0
  37. package/dist/build/types.d.ts +5 -0
  38. package/dist/build/utils.d.ts +1 -0
  39. package/dist/main.cjs.js +2 -2
  40. package/dist/main.cjs.js.map +1 -0
  41. package/dist/main.esm.js +33 -0
  42. package/dist/main.esm.js.map +1 -0
  43. package/package.json +14 -9
  44. package/src/modules/Envelope/Base.ts +3 -0
  45. package/src/modules/MidiSelector.ts +3 -3
  46. package/src/modules/VirtualMidi.ts +4 -2
  47. package/.eslintrc.js +0 -14
  48. package/.parcerc +0 -6
  49. package/jest.config.js +0 -19
  50. package/rollup.config.mjs +0 -21
  51. package/test/MockingModules.ts +0 -27
  52. package/test/Module/Oscillator.test.ts +0 -9
  53. package/test/core/IO.test.ts +0 -172
  54. package/tsconfig.json +0 -22
package/package.json CHANGED
@@ -1,10 +1,15 @@
1
1
  {
2
2
  "name": "@blibliki/engine",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/main.cjs.js",
6
6
  "module": "dist/main.esm.js",
7
7
  "types": "dist/build/index.d.ts",
8
+ "files": [
9
+ "README.md",
10
+ "src",
11
+ "dist"
12
+ ],
8
13
  "dependencies": {
9
14
  "@types/lodash": "^4.14.186",
10
15
  "crypto-js": "^4.2.0",
@@ -12,13 +17,6 @@
12
17
  "tone": "^14.7.77",
13
18
  "uuid": "^8.3.2"
14
19
  },
15
- "scripts": {
16
- "start": "tsc -w -p tsconfig.json",
17
- "build": "rollup -c",
18
- "lint": "eslint src",
19
- "ts:check": "tsc --noEmit",
20
- "test": "jest"
21
- },
22
20
  "devDependencies": {
23
21
  "@rollup/plugin-commonjs": "^25.0.7",
24
22
  "@rollup/plugin-node-resolve": "^15.2.3",
@@ -37,5 +35,12 @@
37
35
  "ts-jest": "^29.0.3",
38
36
  "typescript": "^5.2.2",
39
37
  "typescript-language-server": "^4.0.0"
38
+ },
39
+ "scripts": {
40
+ "start": "tsc -w -p tsconfig.json",
41
+ "build": "rollup -c",
42
+ "lint": "eslint src",
43
+ "ts:check": "tsc --noEmit",
44
+ "test": "jest"
40
45
  }
41
- }
46
+ }
@@ -105,7 +105,10 @@ export default abstract class EnvelopeModule<EnvelopeLike extends Env>
105
105
  };
106
106
 
107
107
  triggerRelease = (note: Note, triggeredAt: number) => {
108
+ if (this.activeNote && this.activeNote !== note.fullName) return;
109
+
108
110
  this.internalModule.triggerRelease(triggeredAt);
111
+ this.activeNote = undefined;
109
112
  };
110
113
 
111
114
  private maxTime(stage: EnvelopeStages): number {
@@ -59,10 +59,10 @@ export default class MidiSelector extends Module<
59
59
  if (!this.onMidiEvent || !midiId) return; // Ugly hack because of weird super bug
60
60
 
61
61
  const midiDevice = Engine.midiDeviceManager.find(midiId);
62
- midiDevice?.addEventListener(this.onMidiEvent);
62
+ midiDevice?.addEventListener(this.forwardMidiEvent);
63
63
  }
64
64
 
65
- private _onMidiEvent = (midiEvent: MidiEvent) => {
65
+ private forwardMidiEvent = (midiEvent: MidiEvent) => {
66
66
  this.midiOutput.onMidiEvent(midiEvent);
67
67
  };
68
68
 
@@ -70,6 +70,6 @@ export default class MidiSelector extends Module<
70
70
  if (!this.selectedId) return;
71
71
 
72
72
  const midiDevice = Engine.midiDeviceManager.find(this.selectedId);
73
- midiDevice?.removeEventListener(this._onMidiEvent);
73
+ midiDevice?.removeEventListener(this.forwardMidiEvent);
74
74
  }
75
75
  }
@@ -48,16 +48,18 @@ export default class VirtualMidi extends Module<
48
48
  this.midiOutput.onMidiEvent(midiEvent);
49
49
  }
50
50
 
51
- triggerAttack = (note: Note) => {
51
+ triggerAttack = (note: Note, triggerAttack: number) => {
52
52
  this.activeNotes = [...this.activeNotes, note.fullName];
53
53
  Engine._triggerPropsUpdate(this.id, this.props);
54
+ this.sendMidi(MidiEvent.fromNote(note, true, triggerAttack));
54
55
  };
55
56
 
56
- triggerRelease = (note: Note) => {
57
+ triggerRelease = (note: Note, triggerAttack: number) => {
57
58
  this.activeNotes = this.activeNotes.filter(
58
59
  (name) => name !== note.fullName
59
60
  );
60
61
  Engine._triggerPropsUpdate(this.id, this.props);
62
+ this.sendMidi(MidiEvent.fromNote(note, false, triggerAttack));
61
63
  };
62
64
 
63
65
  serialize() {
package/.eslintrc.js DELETED
@@ -1,14 +0,0 @@
1
- module.exports = {
2
- extends: [
3
- "eslint:recommended",
4
- "plugin:@typescript-eslint/recommended",
5
- "plugin:@typescript-eslint/recommended-requiring-type-checking",
6
- ],
7
- parser: "@typescript-eslint/parser",
8
- plugins: ["@typescript-eslint"],
9
- parserOptions: {
10
- project: true,
11
- tsconfigRootDir: __dirname,
12
- },
13
- root: true,
14
- };
package/.parcerc DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "extends": "@parcel/config-default",
3
- "transformers": {
4
- "*.{ts,tsx}": ["@parcel/transformer-typescript-tsc"]
5
- }
6
- }
package/jest.config.js DELETED
@@ -1,19 +0,0 @@
1
- /** @type {import('ts-jest').JestConfigWithTsJest} */
2
- module.exports = {
3
- preset: "ts-jest",
4
- testEnvironment: "node",
5
- rootDir: "test",
6
- moduleNameMapper: {
7
- "^src/(.*)$": "<rootDir>/../src/$1",
8
- },
9
- transform: {
10
- // '^.+\\.[tj]sx?$' to process js/ts with `ts-jest`
11
- // '^.+\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest`
12
- "^.+\\.tsx?$": [
13
- "ts-jest",
14
- {
15
- diagnostics: false,
16
- },
17
- ],
18
- },
19
- };
package/rollup.config.mjs DELETED
@@ -1,21 +0,0 @@
1
- import typescript from "@rollup/plugin-typescript";
2
- import { nodeResolve } from "@rollup/plugin-node-resolve";
3
- import commonjs from "@rollup/plugin-commonjs";
4
- import terser from "@rollup/plugin-terser";
5
-
6
- export default {
7
- input: "src/index.ts", // Entry point
8
- output: [
9
- {
10
- file: "dist/main.cjs.js",
11
- format: "cjs", // CommonJS
12
- sourcemap: true,
13
- },
14
- {
15
- file: "dist/main.esm.js",
16
- format: "esm", // ES Modules
17
- sourcemap: true,
18
- },
19
- ],
20
- plugins: [typescript(), nodeResolve(), commonjs(), terser()],
21
- };
@@ -1,27 +0,0 @@
1
- import Module, { DummnyInternalModule, PolyModule } from "../src/core/Module";
2
-
3
- interface IMonoMocking {}
4
-
5
- export class MonoMocking extends Module<DummnyInternalModule, IMonoMocking> {
6
- constructor(name: string, props: Partial<IMonoMocking>) {
7
- super(new DummnyInternalModule(), {
8
- name,
9
- props,
10
- });
11
- this.registerDefaultMidiInput();
12
- this.registerMidiOutput({ name: "midi out" });
13
- }
14
- }
15
-
16
- export class PolyMocking extends PolyModule<MonoMocking, IMonoMocking> {
17
- constructor(name: string, props: Partial<IMonoMocking>) {
18
- super({
19
- name,
20
- child: MonoMocking,
21
- props,
22
- });
23
-
24
- this.registerInput({ name: "midi in" });
25
- this.registerOutput({ name: "midi out" });
26
- }
27
- }
@@ -1,9 +0,0 @@
1
- import { describe, expect, it } from "@jest/globals";
2
-
3
- import { Oscillator } from "../../src/modules";
4
-
5
- describe("Oscillator", () => {
6
- it("has proper module name", () => {
7
- expect(Oscillator.moduleName).toBe("Oscillator");
8
- });
9
- });
@@ -1,172 +0,0 @@
1
- import { describe, expect, it, beforeEach } from "@jest/globals";
2
- import { MonoMocking, PolyMocking } from "../MockingModules";
3
- import {
4
- ForwardInput,
5
- ForwardOutput,
6
- MidiInput,
7
- MidiOutput,
8
- } from "../../src/core/IO";
9
-
10
- describe("IO", () => {
11
- let monoModule1: MonoMocking, monoModule2: MonoMocking;
12
- let polyModule: PolyMocking;
13
- let midiIn: MidiInput, midiOut: MidiOutput;
14
- let forwardMidiIn: ForwardInput, forwardMidiOut: ForwardOutput;
15
-
16
- beforeEach(() => {
17
- monoModule1 = new MonoMocking("module1", {});
18
- monoModule2 = new MonoMocking("module2", {});
19
- polyModule = new PolyMocking("polyModule", {});
20
-
21
- midiIn = monoModule1.inputs.findByName("midi in") as MidiInput;
22
- midiOut = monoModule2.outputs.findByName("midi out") as MidiOutput;
23
- forwardMidiIn = polyModule.inputs.findByName("midi in") as ForwardInput;
24
- forwardMidiOut = polyModule.outputs.findByName("midi out") as ForwardOutput;
25
- });
26
-
27
- describe("plug midi with midi", () => {
28
- beforeEach(() => {
29
- midiOut.plug(midiIn);
30
- });
31
-
32
- it("has one connection", () => {
33
- expect(midiIn.connections.length).toBe(1);
34
- expect(midiOut.connections.length).toBe(1);
35
- });
36
-
37
- it("has midi in connected with midi out", () => {
38
- expect(
39
- midiIn.connections.find((con) => con.id === midiOut.id)
40
- ).toBeDefined();
41
- });
42
-
43
- it("has midi out connected with midi in", () => {
44
- expect(
45
- midiOut.connections.find((con) => con.id === midiIn.id)
46
- ).toBeDefined();
47
- });
48
-
49
- describe("unplug midi", () => {
50
- beforeEach(() => {
51
- midiOut.unPlug(midiIn);
52
- });
53
-
54
- it("unplugged midi in from midi out", () => {
55
- expect(
56
- midiIn.connections.find((con) => con.id === midiOut.id)
57
- ).toBeUndefined();
58
- });
59
-
60
- it("unplugged midi out from midi in", () => {
61
- expect(
62
- midiOut.connections.find((con) => con.id === midiIn.id)
63
- ).toBeUndefined();
64
- });
65
- });
66
-
67
- describe("unplug all", () => {
68
- beforeEach(() => {
69
- midiOut.unPlugAll();
70
- });
71
-
72
- it("unplugged midi in from midi out", () => {
73
- expect(midiIn.connections.length).toBe(0);
74
- });
75
-
76
- it("unplugged midi out from midi in", () => {
77
- expect(midiOut.connections.length).toBe(0);
78
- });
79
- });
80
- });
81
-
82
- describe("plug midi out with forward in", () => {
83
- beforeEach(() => {
84
- midiOut.plug(forwardMidiIn);
85
- });
86
-
87
- it("has one connection", () => {
88
- expect(forwardMidiIn.connections.length).toBe(1);
89
- expect(midiOut.connections.length).toBe(2);
90
- });
91
-
92
- describe("unplug all", () => {
93
- beforeEach(() => {
94
- midiOut.unPlugAll();
95
- });
96
-
97
- it("unplugged midi in from midi out", () => {
98
- expect(forwardMidiIn.connections.length).toBe(0);
99
- expect(
100
- forwardMidiIn.subInputs.map((input) => input.connections).flat()
101
- .length
102
- ).toBe(0);
103
- });
104
-
105
- it("unplugged midi out from midi in", () => {
106
- expect(midiOut.connections.length).toBe(0);
107
- });
108
- });
109
- });
110
-
111
- describe("plug forwardMidiOut with midiIn", () => {
112
- beforeEach(() => {
113
- forwardMidiOut.plug(midiIn);
114
- });
115
-
116
- it("has one connection", () => {
117
- expect(forwardMidiOut.connections.length).toBe(1);
118
- expect(midiIn.connections.length).toBe(2);
119
- });
120
-
121
- describe("unplug all", () => {
122
- beforeEach(() => {
123
- forwardMidiOut.unPlugAll();
124
- });
125
-
126
- it("unplugged midi in from midi out", () => {
127
- expect(forwardMidiOut.connections.length).toBe(0);
128
- expect(
129
- forwardMidiOut.subOutputs.map((input) => input.connections).flat()
130
- .length
131
- ).toBe(0);
132
- });
133
-
134
- it("unplugged midi out from midi in", () => {
135
- expect(midiIn.connections.length).toBe(0);
136
- });
137
- });
138
- });
139
-
140
- describe("plug forwardMidiOut with forwardMidiIn", () => {
141
- beforeEach(() => {
142
- forwardMidiOut.plug(forwardMidiIn);
143
- });
144
-
145
- it("has one connection", () => {
146
- expect(forwardMidiOut.connections.length).toBe(1);
147
- expect(forwardMidiIn.connections.length).toBe(1);
148
- });
149
-
150
- describe("unplug all", () => {
151
- beforeEach(() => {
152
- forwardMidiOut.unPlugAll();
153
- });
154
-
155
- it("unplugged midi in from midi out", () => {
156
- expect(forwardMidiOut.connections.length).toBe(0);
157
- expect(
158
- forwardMidiOut.subOutputs.map((input) => input.connections).flat()
159
- .length
160
- ).toBe(0);
161
- });
162
-
163
- it("unplugged midi out from midi in", () => {
164
- expect(forwardMidiIn.connections.length).toBe(0);
165
- expect(
166
- forwardMidiIn.subInputs.map((input) => input.connections).flat()
167
- .length
168
- ).toBe(0);
169
- });
170
- });
171
- });
172
- });
package/tsconfig.json DELETED
@@ -1,22 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "esnext",
4
- "moduleResolution": "node",
5
- "target": "esnext",
6
- "declaration": true,
7
- "lib": ["dom", "dom.iterable", "esnext"],
8
- "strict": true,
9
- "allowJs": true,
10
- "skipLibCheck": true,
11
- "esModuleInterop": true,
12
- "allowSyntheticDefaultImports": true,
13
- "strictPropertyInitialization": false,
14
- "forceConsistentCasingInFileNames": true,
15
- "noFallthroughCasesInSwitch": true,
16
- "resolveJsonModule": true,
17
- "isolatedModules": true,
18
- "sourceMap": true,
19
- "outDir": "build"
20
- },
21
- "include": ["src"]
22
- }