@blibliki/engine 0.1.17 → 0.1.19

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 (161) hide show
  1. package/README.md +13 -1
  2. package/{build → dist/build}/Engine.d.ts +14 -22
  3. package/dist/build/core/IO/AudioNode.d.ts +35 -0
  4. package/dist/build/core/IO/Collection.d.ts +13 -0
  5. package/dist/build/core/IO/ForwardNode.d.ts +38 -0
  6. package/dist/build/core/IO/MidiNode.d.ts +30 -0
  7. package/dist/build/core/IO/Node.d.ts +36 -0
  8. package/dist/build/core/IO/index.d.ts +12 -0
  9. package/dist/build/core/Module/MonoModule.d.ts +67 -0
  10. package/dist/build/core/Module/PolyModule.d.ts +57 -0
  11. package/dist/build/core/Module/index.d.ts +6 -0
  12. package/{build → dist/build/core}/Note/index.d.ts +3 -0
  13. package/{build → dist/build/core/midi}/MidiDevice.d.ts +1 -1
  14. package/dist/build/core/midi/MidiEvent.d.ts +21 -0
  15. package/dist/build/core/midi/index.d.ts +5 -0
  16. package/dist/build/index.d.ts +9 -0
  17. package/{build/Module → dist/build/modules}/BitCrusher.d.ts +5 -1
  18. package/{build/Module → dist/build/modules}/Delay.d.ts +5 -1
  19. package/{build/Module → dist/build/modules}/Distortion.d.ts +5 -1
  20. package/{build/Module → dist/build/modules}/Effect.d.ts +7 -2
  21. package/{build/Module → dist/build/modules}/Envelope/AmpEnvelope.d.ts +10 -2
  22. package/{build/Module → dist/build/modules}/Envelope/Base.d.ts +30 -11
  23. package/{build/Module → dist/build/modules}/Envelope/FreqEnvelope.d.ts +10 -3
  24. package/{build/Module → dist/build/modules}/Filter.d.ts +13 -13
  25. package/{build/Module → dist/build/modules}/Master.d.ts +5 -2
  26. package/{build/Module → dist/build/modules}/MidiSelector.d.ts +9 -5
  27. package/{build/Module → dist/build/modules}/Oscillator.d.ts +15 -9
  28. package/{build/Module → dist/build/modules}/Reverb.d.ts +5 -1
  29. package/{build/Module → dist/build/modules}/Sequencer.d.ts +9 -5
  30. package/{build/Module → dist/build/modules}/VirtualMidi.d.ts +12 -8
  31. package/dist/build/modules/VoiceScheduler.d.ts +43 -0
  32. package/dist/build/modules/Volume.d.ts +26 -0
  33. package/dist/build/modules/index.d.ts +16 -0
  34. package/{build → dist/build}/routes.d.ts +6 -5
  35. package/dist/build/types.d.ts +5 -0
  36. package/dist/build/utils.d.ts +1 -0
  37. package/dist/main.cjs.js +33 -0
  38. package/dist/main.cjs.js.map +1 -0
  39. package/dist/main.esm.js +33 -0
  40. package/dist/main.esm.js.map +1 -0
  41. package/package.json +26 -22
  42. package/src/Engine.ts +27 -36
  43. package/src/core/IO/AudioNode.ts +77 -0
  44. package/src/core/IO/Collection.ts +76 -0
  45. package/src/core/IO/ForwardNode.ts +192 -0
  46. package/src/core/IO/MidiNode.ts +67 -0
  47. package/src/core/IO/Node.ts +117 -0
  48. package/src/core/IO/index.ts +47 -0
  49. package/src/core/Module/MonoModule.ts +219 -0
  50. package/src/core/Module/PolyModule.ts +206 -0
  51. package/src/core/Module/index.ts +15 -0
  52. package/src/{Note → core/Note}/index.ts +19 -4
  53. package/src/{MidiDeviceManager.ts → core/midi/MidiDeviceManager.ts} +20 -15
  54. package/src/core/midi/MidiEvent.ts +91 -0
  55. package/src/core/midi/index.ts +5 -0
  56. package/src/index.ts +8 -12
  57. package/src/{Module → modules}/BitCrusher.ts +15 -4
  58. package/src/{Module → modules}/Delay.ts +15 -4
  59. package/src/{Module → modules}/Distortion.ts +15 -4
  60. package/src/{Module → modules}/Effect.ts +10 -6
  61. package/src/modules/Envelope/AmpEnvelope.ts +23 -0
  62. package/src/{Module → modules}/Envelope/Base.ts +50 -31
  63. package/src/{Module → modules}/Envelope/FreqEnvelope.ts +18 -23
  64. package/src/{Module → modules}/Filter.ts +18 -46
  65. package/src/{Module → modules}/Master.ts +8 -2
  66. package/src/{Module → modules}/MidiSelector.ts +18 -14
  67. package/src/{Module → modules}/Oscillator.ts +27 -16
  68. package/src/{Module → modules}/Reverb.ts +15 -4
  69. package/src/{Module → modules}/Sequencer.ts +17 -13
  70. package/src/{Module → modules}/VirtualMidi.ts +16 -12
  71. package/src/modules/VoiceScheduler.ts +145 -0
  72. package/src/{Module → modules}/Volume.ts +23 -15
  73. package/src/{Module → modules}/index.ts +14 -21
  74. package/src/routes.ts +19 -18
  75. package/src/types.ts +3 -0
  76. package/src/utils.ts +18 -0
  77. package/build/Engine.js +0 -165
  78. package/build/Engine.js.map +0 -1
  79. package/build/MidiDevice.js +0 -45
  80. package/build/MidiDevice.js.map +0 -1
  81. package/build/MidiDeviceManager.js +0 -59
  82. package/build/MidiDeviceManager.js.map +0 -1
  83. package/build/MidiEvent.d.ts +0 -18
  84. package/build/MidiEvent.js +0 -64
  85. package/build/MidiEvent.js.map +0 -1
  86. package/build/Module/Base.d.ts +0 -63
  87. package/build/Module/Base.js +0 -138
  88. package/build/Module/Base.js.map +0 -1
  89. package/build/Module/BitCrusher.js +0 -22
  90. package/build/Module/BitCrusher.js.map +0 -1
  91. package/build/Module/DataSequencer.d.ts +0 -26
  92. package/build/Module/DataSequencer.js +0 -91
  93. package/build/Module/DataSequencer.js.map +0 -1
  94. package/build/Module/Delay.js +0 -30
  95. package/build/Module/Delay.js.map +0 -1
  96. package/build/Module/Distortion.js +0 -22
  97. package/build/Module/Distortion.js.map +0 -1
  98. package/build/Module/Effect.js +0 -22
  99. package/build/Module/Effect.js.map +0 -1
  100. package/build/Module/Envelope/AmpEnvelope.js +0 -14
  101. package/build/Module/Envelope/AmpEnvelope.js.map +0 -1
  102. package/build/Module/Envelope/Base.js +0 -106
  103. package/build/Module/Envelope/Base.js.map +0 -1
  104. package/build/Module/Envelope/FreqEnvelope.js +0 -50
  105. package/build/Module/Envelope/FreqEnvelope.js.map +0 -1
  106. package/build/Module/Envelope/index.js +0 -4
  107. package/build/Module/Envelope/index.js.map +0 -1
  108. package/build/Module/Filter.js +0 -100
  109. package/build/Module/Filter.js.map +0 -1
  110. package/build/Module/IO.d.ts +0 -39
  111. package/build/Module/IO.js +0 -59
  112. package/build/Module/IO.js.map +0 -1
  113. package/build/Module/Master.js +0 -12
  114. package/build/Module/Master.js.map +0 -1
  115. package/build/Module/MidiSelector.js +0 -50
  116. package/build/Module/MidiSelector.js.map +0 -1
  117. package/build/Module/Oscillator.js +0 -136
  118. package/build/Module/Oscillator.js.map +0 -1
  119. package/build/Module/PolyModule.d.ts +0 -49
  120. package/build/Module/PolyModule.js +0 -175
  121. package/build/Module/PolyModule.js.map +0 -1
  122. package/build/Module/Reverb.js +0 -30
  123. package/build/Module/Reverb.js.map +0 -1
  124. package/build/Module/Sequencer.js +0 -131
  125. package/build/Module/Sequencer.js.map +0 -1
  126. package/build/Module/VirtualMidi.js +0 -53
  127. package/build/Module/VirtualMidi.js.map +0 -1
  128. package/build/Module/VoiceScheduler.d.ts +0 -38
  129. package/build/Module/VoiceScheduler.js +0 -130
  130. package/build/Module/VoiceScheduler.js.map +0 -1
  131. package/build/Module/Volume.d.ts +0 -20
  132. package/build/Module/Volume.js +0 -48
  133. package/build/Module/Volume.js.map +0 -1
  134. package/build/Module/index.d.ts +0 -14
  135. package/build/Module/index.js +0 -66
  136. package/build/Module/index.js.map +0 -1
  137. package/build/Note/frequencyTable.js +0 -146
  138. package/build/Note/frequencyTable.js.map +0 -1
  139. package/build/Note/index.js +0 -81
  140. package/build/Note/index.js.map +0 -1
  141. package/build/index.d.ts +0 -8
  142. package/build/index.js +0 -5
  143. package/build/index.js.map +0 -1
  144. package/build/routes.js +0 -31
  145. package/build/routes.js.map +0 -1
  146. package/jest.config.js +0 -19
  147. package/src/MidiEvent.ts +0 -93
  148. package/src/Module/Base.ts +0 -223
  149. package/src/Module/DataSequencer.ts +0 -121
  150. package/src/Module/Envelope/AmpEnvelope.ts +0 -17
  151. package/src/Module/IO.ts +0 -85
  152. package/src/Module/PolyModule.ts +0 -234
  153. package/src/Module/VoiceScheduler.ts +0 -161
  154. package/test/Module/Oscillator.test.ts +0 -9
  155. package/tsconfig.json +0 -22
  156. /package/{build → dist/build/core}/Note/frequencyTable.d.ts +0 -0
  157. /package/{build → dist/build/core/midi}/MidiDeviceManager.d.ts +0 -0
  158. /package/{build/Module → dist/build/modules}/Envelope/index.d.ts +0 -0
  159. /package/src/{Note → core/Note}/frequencyTable.ts +0 -0
  160. /package/src/{MidiDevice.ts → core/midi/MidiDevice.ts} +0 -0
  161. /package/src/{Module → modules}/Envelope/index.ts +0 -0
@@ -1,234 +0,0 @@
1
- import MidiEvent from "../MidiEvent";
2
- import { v4 as uuidv4 } from "uuid";
3
- import Module, { Connectable, Voicable } from "./Base";
4
- import { Input, Output, IOInterface } from "./IO";
5
- import { AudioModule } from "../Module";
6
-
7
- interface PolyModuleInterface<MonoAudioModule, PropsInterface> {
8
- name: string;
9
- child: new (name: string, props: PropsInterface) => MonoAudioModule;
10
- props: PropsInterface;
11
- }
12
-
13
- export default abstract class PolyModule<
14
- MonoAudioModule extends Module<Connectable, any>,
15
- PropsInterface extends Voicable
16
- > {
17
- static readonly moduleName: string;
18
-
19
- readonly id: string;
20
- readonly child: new (name: string, props: PropsInterface) => MonoAudioModule;
21
- _name: string;
22
- audioModules: MonoAudioModule[];
23
- inputs: Input[] = [];
24
- outputs: Output[] = [];
25
- private _numberOfVoices: number;
26
-
27
- constructor(params: PolyModuleInterface<MonoAudioModule, PropsInterface>) {
28
- this.id = uuidv4();
29
- this.audioModules = [];
30
-
31
- const { child, props: extraProps, ...basicProps } = params;
32
- this.child = child;
33
- Object.assign(this, basicProps);
34
-
35
- this.numberOfVoices = 1;
36
-
37
- Object.assign(this, { props: extraProps });
38
- this.registerNumberOfVoicesInput();
39
- }
40
-
41
- get name() {
42
- return this._name;
43
- }
44
-
45
- set name(value: string) {
46
- this._name = value;
47
- this.audioModules.forEach((m) => (m.name = value));
48
- }
49
-
50
- get props() {
51
- if (this.audioModules.length === 0) {
52
- throw Error("There isn't any initialized module");
53
- }
54
-
55
- return this.audioModules[0].props;
56
- }
57
-
58
- set props(value: PropsInterface) {
59
- Object.assign(this, value);
60
- this.audioModules.forEach((m) => (m.props = value));
61
- }
62
-
63
- get numberOfVoices() {
64
- return this._numberOfVoices;
65
- }
66
-
67
- set numberOfVoices(value: number) {
68
- this._numberOfVoices = value;
69
- this.adjustNumberOfModules();
70
- }
71
-
72
- plug(audioModule: AudioModule, from: string, to: string) {
73
- const output = this.outputs.find((i) => i.name === from);
74
- if (!output) throw Error(`Output ${from} not exist`);
75
-
76
- const input = audioModule.inputs.find((i) => i.name === to);
77
- if (!input)
78
- throw Error(`Input ${to} in module ${audioModule.name} not exist`);
79
-
80
- output.plug(input);
81
- }
82
-
83
- unplugAll() {
84
- this.outputs.forEach((o) => o.unPlugAll());
85
- }
86
-
87
- dispose() {
88
- this.audioModules.forEach((m) => {
89
- m.dispose();
90
- });
91
- }
92
-
93
- midiTriggered = (
94
- midiEvent: MidiEvent,
95
- voiceNo: number = 0,
96
- noteIndex?: number
97
- ) => {
98
- const audioModule = this.findVoice(voiceNo);
99
- audioModule?.midiTriggered(midiEvent, noteIndex);
100
- };
101
-
102
- serialize() {
103
- if (this.audioModules.length === 0)
104
- throw Error("There isn't any initialized module");
105
-
106
- const klass = this.constructor as typeof PolyModule;
107
-
108
- return {
109
- ...this.audioModules[0].serialize(),
110
- id: this.id,
111
- type: klass.moduleName,
112
- inputs: this.inputs.map((i) => i.serialize()),
113
- outputs: this.outputs.map((i) => i.serialize()),
114
- };
115
- }
116
-
117
- protected connect = (
118
- inputAudioModule: AudioModule,
119
- attribute: string = "internalModule"
120
- ) => {
121
- if (inputAudioModule instanceof PolyModule) {
122
- inputAudioModule.audioModules.forEach((m) => {
123
- if (m.voiceNo === undefined) throw Error("Voice error");
124
-
125
- const audioModule = this.findVoice(m.voiceNo);
126
- audioModule?.connect(m, attribute);
127
- });
128
- return;
129
- }
130
-
131
- this.audioModules.forEach((m) => m.connect(inputAudioModule, attribute));
132
- };
133
-
134
- protected disconnect = (
135
- inputAudioModule: AudioModule,
136
- attribute: string = "internalModule"
137
- ) => {
138
- if (inputAudioModule instanceof PolyModule) {
139
- inputAudioModule.audioModules.forEach((m) => {
140
- if (m.voiceNo === undefined) throw Error("Voice error");
141
-
142
- const audioModule = this.findVoice(m.voiceNo);
143
-
144
- try {
145
- audioModule?.disconnect(m, attribute);
146
- } catch (e) {
147
- console.log(e);
148
- }
149
- });
150
- return;
151
- }
152
-
153
- try {
154
- this.audioModules.forEach((m) =>
155
- m.disconnect(inputAudioModule, attribute)
156
- );
157
- } catch (e) {
158
- console.log(e);
159
- }
160
- };
161
-
162
- protected registerInput(props: IOInterface): Input {
163
- const input = new Input(this, props);
164
- this.inputs.push(input);
165
-
166
- return input;
167
- }
168
-
169
- protected registerOutput(props: IOInterface): Output {
170
- const output = new Output(this, props);
171
- this.outputs.push(output);
172
-
173
- return output;
174
- }
175
-
176
- protected find(callback: (audioModule: MonoAudioModule) => boolean) {
177
- const audioModule = this.audioModules.find(callback);
178
- if (!audioModule) throw Error(`Audio module not found`);
179
-
180
- return audioModule;
181
- }
182
-
183
- protected findVoice(voiceNo: number) {
184
- return this.audioModules.find((m) => m.voiceNo === voiceNo);
185
- }
186
-
187
- protected registerBasicOutputs() {
188
- this.registerOutput({
189
- name: "output",
190
- onPlug: (output: Output) => {
191
- this.connect(output.audioModule);
192
- },
193
- onUnPlug: (output: Output) => {
194
- this.disconnect(output.audioModule);
195
- },
196
- });
197
- }
198
-
199
- protected registerBasicInputs() {
200
- this.registerInput({
201
- name: "input",
202
- });
203
- }
204
-
205
- private registerNumberOfVoicesInput() {
206
- this.registerInput({
207
- name: "number of voices",
208
- });
209
- }
210
-
211
- private adjustNumberOfModules() {
212
- if (this.audioModules.length === this.numberOfVoices) return;
213
-
214
- if (this.audioModules.length > this.numberOfVoices) {
215
- const audioModule = this.audioModules.pop();
216
- audioModule?.dispose();
217
- } else {
218
- const props = this.audioModules.length
219
- ? this.props
220
- : ({} as PropsInterface);
221
- const audioModule = new this.child(this.name, {
222
- ...props,
223
- voiceNo: this.audioModules.length,
224
- });
225
-
226
- if (audioModule instanceof PolyModule)
227
- throw Error("Polymodule not supported");
228
-
229
- this.audioModules.push(audioModule as MonoAudioModule);
230
- }
231
-
232
- this.adjustNumberOfModules();
233
- }
234
- }
@@ -1,161 +0,0 @@
1
- import Module, { DummnyInternalModule, Voicable } from "./Base";
2
- import MidiEvent from "../MidiEvent";
3
- import { Input, Output } from "./IO";
4
- import PolyModule from "./PolyModule";
5
-
6
- export interface VoiceSchedulerInterface extends Voicable {
7
- polyNumber: number;
8
- }
9
-
10
- export default class VoiceScheduler extends PolyModule<
11
- Voice,
12
- VoiceSchedulerInterface
13
- > {
14
- static moduleName = "VoiceScheduler";
15
- midiOutput: Output;
16
- numberOfVoicesOut: Output;
17
-
18
- constructor(name: string, props: VoiceSchedulerInterface) {
19
- super({
20
- name,
21
- child: Voice,
22
- props,
23
- });
24
-
25
- this.registerInputs();
26
- this.registerOutputs();
27
- this.polyNumber = this.numberOfVoices;
28
- }
29
-
30
- set polyNumber(value: number) {
31
- super.numberOfVoices = value;
32
- if (!this.numberOfVoicesOut) return;
33
-
34
- this.numberOfVoicesOut.connections.forEach((input) => {
35
- if (input.audioModule instanceof Module) return;
36
-
37
- input.audioModule.numberOfVoices = value;
38
- });
39
- }
40
-
41
- get polyNumber() {
42
- return this.numberOfVoices;
43
- }
44
-
45
- midiTriggered = (midiEvent: MidiEvent) => {
46
- let voices: Array<Voice | undefined>;
47
-
48
- switch (midiEvent.type) {
49
- case "noteOn":
50
- voices = this.findFreeVoices(midiEvent.notes.length);
51
-
52
- break;
53
- case "noteOff":
54
- voices = midiEvent.notes.map((note) => {
55
- return this.audioModules.find((v) => v.activeNote === note.fullName);
56
- });
57
- break;
58
- default:
59
- throw Error("This type is not a note");
60
- }
61
-
62
- if (voices.length === 0) return;
63
-
64
- voices.forEach((voice, i) => {
65
- if (!voice) return;
66
-
67
- voice.midiTriggered(midiEvent, i);
68
- this.midiOutput.connections.forEach((input) => {
69
- input.pluggable(midiEvent, voice.voiceNo, i);
70
- });
71
- });
72
- };
73
-
74
- serialize() {
75
- const serialize = super.serialize();
76
- delete serialize.props.voiceNo;
77
-
78
- return {
79
- ...serialize,
80
- props: { ...serialize.props, polyNumber: this.polyNumber },
81
- };
82
- }
83
-
84
- private findFreeVoices(num: number = 1): Voice[] {
85
- let voices = this.audioModules.filter((v) => !v.activeNote).slice(0, num);
86
-
87
- if (voices.length === 0) {
88
- voices = this.audioModules
89
- .sort((a, b) => {
90
- if (!a || !b) return 0;
91
-
92
- return a.triggeredAt - b.triggeredAt;
93
- })
94
- .slice(0, num);
95
- }
96
-
97
- return voices;
98
- }
99
-
100
- private registerInputs() {
101
- this.registerInput({
102
- name: "midi in",
103
- pluggable: this.midiTriggered,
104
- });
105
- }
106
-
107
- private registerOutputs() {
108
- this.numberOfVoicesOut = this.registerOutput({
109
- name: "number of voices",
110
- onPlug: (input: Input) => {
111
- if (input.audioModule instanceof Module) return;
112
-
113
- input.audioModule.numberOfVoices = this.numberOfVoices;
114
- },
115
- });
116
-
117
- this.midiOutput = this.registerOutput({ name: "midi out" });
118
- }
119
- }
120
-
121
- export interface VoiceInterface extends Voicable {}
122
-
123
- class Voice extends Module<DummnyInternalModule, VoiceInterface> {
124
- midiEvent: MidiEvent | null;
125
- activeNote: string | null;
126
- triggeredAt: number;
127
- midiOutput: Output;
128
-
129
- constructor(name: string, props: VoiceInterface) {
130
- super(new DummnyInternalModule(), {
131
- name,
132
- props,
133
- });
134
- }
135
-
136
- midiTriggered = (midiEvent: MidiEvent, noteIndex?: number) => {
137
- if (this.voiceNo === undefined) throw Error("Voice without voiceNo");
138
- if (noteIndex === undefined) return;
139
-
140
- const { triggeredAt, notes, type } = midiEvent;
141
- const note = notes[noteIndex];
142
-
143
- if (!note) return;
144
- const noteName = note.fullName;
145
-
146
- switch (type) {
147
- case "noteOn":
148
- this.activeNote = noteName;
149
- this.triggeredAt = triggeredAt;
150
- this.midiEvent = midiEvent;
151
-
152
- break;
153
- case "noteOff":
154
- this.activeNote = null;
155
- this.midiEvent = null;
156
- break;
157
- default:
158
- throw Error("This type is not a note");
159
- }
160
- };
161
- }
@@ -1,9 +0,0 @@
1
- import { describe, expect, it } from "@jest/globals";
2
-
3
- import { Oscillator } from "../../src/Module";
4
-
5
- describe("Oscillator", () => {
6
- it("has proper module name", () => {
7
- expect(Oscillator.moduleName).toBe("Oscillator");
8
- });
9
- });
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
- }
File without changes
File without changes
File without changes