@blibliki/engine 0.1.21 → 0.1.22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blibliki/engine",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/main.cjs.js",
6
6
  "module": "dist/main.esm.js",
@@ -40,7 +40,7 @@
40
40
  "start": "tsc -w -p tsconfig.json",
41
41
  "build": "rollup -c",
42
42
  "lint": "eslint src",
43
- "ts:check": "tsc --noEmit",
43
+ "tsc": "tsc --noEmit",
44
44
  "test": "jest"
45
45
  }
46
46
  }
package/src/Engine.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Context, now, setContext } from "tone";
2
2
  import { MidiEvent, MidiDeviceManager } from "./core/midi";
3
3
 
4
- import { AudioModule, Startable } from "./core/Module";
5
- import { createModule, VirtualMidi, VoiceScheduler } from "./modules";
4
+ import { AudioModule, PolyModule, Startable } from "./core/Module";
5
+ import { createModule, VirtualMidi } from "./modules";
6
6
  import { applyRoutes, createRoute, RouteInterface } from "./routes";
7
7
  import { AnyObject, Optional } from "./types";
8
8
 
@@ -17,6 +17,15 @@ interface InitializeInterface {
17
17
  context?: Partial<ContextInterface>;
18
18
  }
19
19
 
20
+ export interface UpdateModuleProps {
21
+ id: string;
22
+ changes: {
23
+ name?: string;
24
+ numberOfVoices?: number;
25
+ props?: AnyObject;
26
+ };
27
+ }
28
+
20
29
  class Engine {
21
30
  midiDeviceManager: MidiDeviceManager;
22
31
  private static instance: Engine;
@@ -65,12 +74,21 @@ class Engine {
65
74
  addModule(params: {
66
75
  id?: string;
67
76
  name: string;
77
+ numberOfVoices?: number;
68
78
  type: string;
69
79
  props?: AnyObject;
70
80
  }) {
71
- const { id, name, type, props = {} } = params;
81
+ const { id, name, numberOfVoices, type, props = {} } = params;
72
82
 
73
- const audioModule = createModule({ id, name, type, props: {} });
83
+ const audioModule = createModule({
84
+ id,
85
+ name,
86
+ type,
87
+ props: {},
88
+ });
89
+ if (audioModule instanceof PolyModule && numberOfVoices) {
90
+ audioModule.numberOfVoices = numberOfVoices;
91
+ }
74
92
  audioModule.props = props;
75
93
  this.modules[audioModule.id] = audioModule;
76
94
 
@@ -90,9 +108,19 @@ class Engine {
90
108
  return moduleRouteIds;
91
109
  }
92
110
 
93
- updateNameModule(id: string, name: string) {
111
+ updateModule(params: UpdateModuleProps) {
112
+ const {
113
+ id,
114
+ changes: { name, numberOfVoices, props = {} },
115
+ } = params;
94
116
  const audioModule = this.findById(id);
95
- audioModule.name = name;
117
+
118
+ audioModule.props = props;
119
+ if (name) audioModule.name = name;
120
+ if (audioModule instanceof PolyModule && numberOfVoices)
121
+ audioModule.numberOfVoices = numberOfVoices;
122
+
123
+ //if (numberOfVoices) this.updateRoutes();
96
124
 
97
125
  return audioModule.serialize();
98
126
  }
@@ -105,16 +133,6 @@ class Engine {
105
133
  this.propsUpdateCallbacks.forEach((callback) => callback(id, props));
106
134
  }
107
135
 
108
- updatePropsModule(id: string, props: AnyObject) {
109
- const audioModule = this.findById(id);
110
-
111
- const applyRoutesRequired = this.applyRoutesRequired(audioModule, props);
112
- audioModule.props = props;
113
- if (applyRoutesRequired) this.updateRoutes();
114
-
115
- return audioModule.serialize();
116
- }
117
-
118
136
  addRoute(props: Optional<RouteInterface, "id">) {
119
137
  const route = createRoute(props);
120
138
  const newRoutes = { ...this.routes, [route.id]: route };
@@ -198,13 +216,6 @@ class Engine {
198
216
  applyRoutes(Object.values(this.routes));
199
217
  }
200
218
 
201
- private applyRoutesRequired(audioModule: AudioModule, props: AnyObject) {
202
- if (!props.polyNumber) return false;
203
- if (!(audioModule instanceof VoiceScheduler)) return false;
204
-
205
- return props.polyNumber !== audioModule.polyNumber;
206
- }
207
-
208
219
  private moduleRouteIds(id: string) {
209
220
  const cloneRoutes = { ...this.routes };
210
221
 
@@ -20,6 +20,7 @@ import { deterministicId } from "../../utils";
20
20
  interface PolyModuleInterface<MonoAudioModule, PropsInterface> {
21
21
  id?: string;
22
22
  name: string;
23
+ numberOfVoices?: number;
23
24
  child: new (params: {
24
25
  id?: string;
25
26
  name: string;
@@ -56,7 +57,7 @@ export default abstract class PolyModule<
56
57
  this.child = child;
57
58
  Object.assign(this, basicProps);
58
59
 
59
- this.numberOfVoices = 1;
60
+ this.numberOfVoices = params.numberOfVoices || 1;
60
61
  this.inputs = new IOCollection<ForwardInput>(this);
61
62
  this.outputs = new IOCollection<ForwardOutput>(this);
62
63
 
@@ -129,6 +130,7 @@ export default abstract class PolyModule<
129
130
  ...this.audioModules[0].serialize(),
130
131
  id: this.id,
131
132
  type: klass.moduleName,
133
+ numberOfVoices: this.numberOfVoices,
132
134
  inputs: this.inputs.serialize(),
133
135
  outputs: this.outputs.serialize(),
134
136
  };
@@ -32,6 +32,7 @@ export {
32
32
  export interface ICreateModule {
33
33
  id?: string;
34
34
  name: string;
35
+ numberOfVoices?: number;
35
36
  type: string;
36
37
  props: any;
37
38
  }