@djodjonx/x32-simulator 0.0.6 → 0.0.8
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/CHANGELOG.md +77 -0
- package/README.md +177 -101
- package/dist/SchemaRegistry-aSJvYTM7.cjs +7495 -0
- package/dist/SchemaRegistry-ffv4HZRa.mjs +7329 -0
- package/dist/index.cjs +5 -2
- package/dist/index.d.cts +184 -48
- package/dist/index.d.mts +184 -48
- package/dist/index.mjs +2 -2
- package/dist/server.cjs +399 -27
- package/dist/server.mjs +400 -27
- package/package.json +3 -1
- package/dist/SchemaRegistry-D4eIJord.mjs +0 -2180
- package/dist/SchemaRegistry-DE6iObDv.cjs +0 -2298
|
@@ -1,2298 +0,0 @@
|
|
|
1
|
-
//#region rolldown:runtime
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
-
__defProp(to, key, {
|
|
14
|
-
get: ((k) => from[k]).bind(null, key),
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
-
value: mod,
|
|
24
|
-
enumerable: true
|
|
25
|
-
}) : target, mod));
|
|
26
|
-
|
|
27
|
-
//#endregion
|
|
28
|
-
let os = require("os");
|
|
29
|
-
os = __toESM(os);
|
|
30
|
-
let node_events = require("node:events");
|
|
31
|
-
let node_dgram = require("node:dgram");
|
|
32
|
-
node_dgram = __toESM(node_dgram);
|
|
33
|
-
let node_buffer = require("node:buffer");
|
|
34
|
-
|
|
35
|
-
//#region src/application/use-cases/ProcessPacketUseCase.ts
|
|
36
|
-
var ProcessPacketUseCase = class {
|
|
37
|
-
constructor(messageHandler, gateway) {
|
|
38
|
-
this.messageHandler = messageHandler;
|
|
39
|
-
this.gateway = gateway;
|
|
40
|
-
}
|
|
41
|
-
execute(packet, rinfo) {
|
|
42
|
-
if (packet.oscType === "bundle") packet.elements?.forEach((el) => this.execute(el, rinfo));
|
|
43
|
-
else if (packet.oscType === "message") {
|
|
44
|
-
const args = packet.args.map((arg) => {
|
|
45
|
-
if (typeof arg === "object" && arg !== null && "value" in arg) return arg.value;
|
|
46
|
-
return arg;
|
|
47
|
-
});
|
|
48
|
-
this.messageHandler.handle({
|
|
49
|
-
address: packet.address,
|
|
50
|
-
args
|
|
51
|
-
}, rinfo).forEach((reply) => {
|
|
52
|
-
this.gateway.send(rinfo, reply.address, reply.args);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/domain/ports/ILogger.ts
|
|
60
|
-
/**
|
|
61
|
-
* Standard log categories for the domain.
|
|
62
|
-
*/
|
|
63
|
-
let LogCategory = /* @__PURE__ */ function(LogCategory$1) {
|
|
64
|
-
LogCategory$1["SYSTEM"] = "SYSTEM";
|
|
65
|
-
LogCategory$1["OSC_IN"] = "OSC_IN";
|
|
66
|
-
LogCategory$1["OSC_OUT"] = "OSC_OUT";
|
|
67
|
-
LogCategory$1["DISPATCH"] = "DISPATCH";
|
|
68
|
-
LogCategory$1["STATE"] = "STATE";
|
|
69
|
-
LogCategory$1["SUB"] = "SUB";
|
|
70
|
-
LogCategory$1["METER"] = "METER";
|
|
71
|
-
return LogCategory$1;
|
|
72
|
-
}({});
|
|
73
|
-
|
|
74
|
-
//#endregion
|
|
75
|
-
//#region src/application/use-cases/BroadcastUpdatesUseCase.ts
|
|
76
|
-
var BroadcastUpdatesUseCase = class {
|
|
77
|
-
constructor(subscriptionManager, state, gateway, logger, meterService, schemaRegistry) {
|
|
78
|
-
this.subscriptionManager = subscriptionManager;
|
|
79
|
-
this.state = state;
|
|
80
|
-
this.gateway = gateway;
|
|
81
|
-
this.logger = logger;
|
|
82
|
-
this.meterService = meterService;
|
|
83
|
-
this.schemaRegistry = schemaRegistry;
|
|
84
|
-
}
|
|
85
|
-
execute() {
|
|
86
|
-
this.subscriptionManager.getSubscribers().forEach((sub) => {
|
|
87
|
-
if (sub.type === "path" || !sub.alias) {
|
|
88
|
-
if (sub.type === "meter" && sub.meterPath) {
|
|
89
|
-
const meterData = this.meterService.generateMeterData(sub.meterPath, this.state);
|
|
90
|
-
this.gateway.send({
|
|
91
|
-
address: sub.address,
|
|
92
|
-
port: sub.port
|
|
93
|
-
}, sub.meterPath, [meterData.toBlob()]);
|
|
94
|
-
}
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
const rinfo = {
|
|
98
|
-
address: sub.address,
|
|
99
|
-
port: sub.port
|
|
100
|
-
};
|
|
101
|
-
if (sub.type === "batch" && sub.paths) {
|
|
102
|
-
if (sub.paths.length === 1 && sub.paths[0].startsWith("/meters")) {
|
|
103
|
-
const meterData = this.meterService.generateMeterData(sub.paths[0], this.state);
|
|
104
|
-
this.gateway.send(rinfo, sub.alias, [meterData.toBlob()]);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
let stride;
|
|
108
|
-
const dataSize = sub.paths.length * 4;
|
|
109
|
-
const factor = sub.factor || 0;
|
|
110
|
-
const count = sub.count || 0;
|
|
111
|
-
if (factor > 0) stride = Math.max(factor * 4, dataSize);
|
|
112
|
-
else stride = sub.paths.length === 3 ? 16 : dataSize;
|
|
113
|
-
const blobSize = count * stride;
|
|
114
|
-
if (isNaN(blobSize) || blobSize < 0) {
|
|
115
|
-
this.logger.error(LogCategory.SYSTEM, `Invalid blob size`, {
|
|
116
|
-
alias: sub.alias,
|
|
117
|
-
blobSize,
|
|
118
|
-
count,
|
|
119
|
-
stride,
|
|
120
|
-
factor,
|
|
121
|
-
dataSize
|
|
122
|
-
});
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const blob = Buffer.alloc(blobSize);
|
|
126
|
-
for (let i = 0; i < count; i++) {
|
|
127
|
-
const root = this.schemaRegistry.getRootFromIndex(sub.start + i);
|
|
128
|
-
let currentOffset = i * stride;
|
|
129
|
-
if (!root) continue;
|
|
130
|
-
sub.paths.forEach((s, pIdx) => {
|
|
131
|
-
if (pIdx * 4 >= stride) return;
|
|
132
|
-
if (s.startsWith("/meters")) blob.writeFloatLE(0, currentOffset);
|
|
133
|
-
else {
|
|
134
|
-
const target = `${root}${s}`;
|
|
135
|
-
const node = this.schemaRegistry.getNode(target);
|
|
136
|
-
let val = this.state.get(target);
|
|
137
|
-
if (val === void 0) val = node ? node.default : 0;
|
|
138
|
-
if (typeof val === "number") if (node && node.type === "f") blob.writeFloatLE(val, currentOffset);
|
|
139
|
-
else blob.writeInt32LE(val, currentOffset);
|
|
140
|
-
else blob.writeInt32LE(0, currentOffset);
|
|
141
|
-
}
|
|
142
|
-
currentOffset += 4;
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
this.gateway.send(rinfo, sub.alias, [blob]);
|
|
146
|
-
} else if (sub.type === "format" && sub.pattern) {
|
|
147
|
-
const stride = sub.factor ? sub.factor * 4 : 4;
|
|
148
|
-
const start = sub.start || 0;
|
|
149
|
-
const count = sub.count || 0;
|
|
150
|
-
const totalSize = (start + count) * stride;
|
|
151
|
-
if (isNaN(totalSize) || totalSize < 0) return;
|
|
152
|
-
const blob = Buffer.alloc(totalSize);
|
|
153
|
-
let offset = start * stride;
|
|
154
|
-
for (let i = start; i < start + count; i++) {
|
|
155
|
-
const id = i.toString().padStart(2, "0");
|
|
156
|
-
const target = sub.pattern.replace(/\*\*?/, id);
|
|
157
|
-
let val = this.state.get(target);
|
|
158
|
-
if (val === void 0) val = 0;
|
|
159
|
-
if (typeof val === "number") {
|
|
160
|
-
const node = this.schemaRegistry.getNode(target);
|
|
161
|
-
if (node && node.type === "f") blob.writeFloatLE(val, offset);
|
|
162
|
-
else blob.writeInt32LE(val, offset);
|
|
163
|
-
} else blob.writeInt32LE(0, offset);
|
|
164
|
-
offset += stride;
|
|
165
|
-
}
|
|
166
|
-
this.gateway.send(rinfo, sub.alias, [blob]);
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
broadcastSingleChange(path, value) {
|
|
171
|
-
this.subscriptionManager.getSubscribers().forEach((sub) => {
|
|
172
|
-
if (path === sub.path || sub.path === "/xremote" || sub.path && sub.path.includes("*") && path.startsWith(sub.path.split("*")[0])) this.gateway.send({
|
|
173
|
-
address: sub.address,
|
|
174
|
-
port: sub.port
|
|
175
|
-
}, path, [value]);
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
//#endregion
|
|
181
|
-
//#region src/application/use-cases/ManageSessionsUseCase.ts
|
|
182
|
-
var ManageSessionsUseCase = class {
|
|
183
|
-
constructor(subscriptionManager) {
|
|
184
|
-
this.subscriptionManager = subscriptionManager;
|
|
185
|
-
}
|
|
186
|
-
cleanup() {
|
|
187
|
-
this.subscriptionManager.cleanup();
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
//#endregion
|
|
192
|
-
//#region src/domain/entities/SubscriptionManager.ts
|
|
193
|
-
/**
|
|
194
|
-
* Manages OSC client subscriptions and their lifecycle.
|
|
195
|
-
*/
|
|
196
|
-
var SubscriptionManager = class {
|
|
197
|
-
logger;
|
|
198
|
-
subscribers = [];
|
|
199
|
-
constructor(logger) {
|
|
200
|
-
this.logger = logger;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Cleans up expired subscriptions.
|
|
204
|
-
* Standard X32 subscriptions last 10 seconds.
|
|
205
|
-
*/
|
|
206
|
-
cleanup() {
|
|
207
|
-
const now = Date.now();
|
|
208
|
-
const initialCount = this.subscribers.length;
|
|
209
|
-
this.subscribers = this.subscribers.filter((s) => {
|
|
210
|
-
const active = s.expires > now;
|
|
211
|
-
if (!active) this.logger.debug(LogCategory.SUB, `Expired subscriber`, {
|
|
212
|
-
type: s.type,
|
|
213
|
-
ip: s.address,
|
|
214
|
-
port: s.port,
|
|
215
|
-
path: "path" in s ? s.path : s.alias
|
|
216
|
-
});
|
|
217
|
-
return active;
|
|
218
|
-
});
|
|
219
|
-
if (this.subscribers.length !== initialCount) this.logger.info(LogCategory.SUB, `Cleanup finished`, {
|
|
220
|
-
removed: initialCount - this.subscribers.length,
|
|
221
|
-
remaining: this.subscribers.length
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Gets all active subscribers.
|
|
226
|
-
* @returns Array of subscribers.
|
|
227
|
-
*/
|
|
228
|
-
getSubscribers() {
|
|
229
|
-
return this.subscribers;
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Adds or renews a path-based subscription (e.g. /subscribe or /xremote).
|
|
233
|
-
* @param rinfo - Client remote info.
|
|
234
|
-
* @param path - Subscription path.
|
|
235
|
-
*/
|
|
236
|
-
addPathSubscriber(rinfo, path) {
|
|
237
|
-
const key = `${rinfo.address}:${rinfo.port}:${path}`;
|
|
238
|
-
const expires = Date.now() + 1e4;
|
|
239
|
-
const existing = this.subscribers.find((s) => s.type === "path" && `${s.address}:${s.port}:${s.path}` === key);
|
|
240
|
-
if (existing) {
|
|
241
|
-
existing.expires = expires;
|
|
242
|
-
this.logger.debug(LogCategory.SUB, `Renewed subscription`, {
|
|
243
|
-
ip: rinfo.address,
|
|
244
|
-
path
|
|
245
|
-
});
|
|
246
|
-
} else {
|
|
247
|
-
this.subscribers.push({
|
|
248
|
-
type: "path",
|
|
249
|
-
address: rinfo.address,
|
|
250
|
-
port: rinfo.port,
|
|
251
|
-
path,
|
|
252
|
-
expires
|
|
253
|
-
});
|
|
254
|
-
this.logger.info(LogCategory.SUB, `New subscription`, {
|
|
255
|
-
ip: rinfo.address,
|
|
256
|
-
path
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Adds or renews a batch subscription.
|
|
262
|
-
* @param rinfo - Client remote info.
|
|
263
|
-
* @param alias - Response alias.
|
|
264
|
-
* @param paths - Target paths.
|
|
265
|
-
* @param start - Start index.
|
|
266
|
-
* @param count - Count.
|
|
267
|
-
* @param factor - Frequency factor.
|
|
268
|
-
* @param args - Command arguments.
|
|
269
|
-
*/
|
|
270
|
-
addBatchSubscriber(rinfo, alias, paths, start, count, factor, args) {
|
|
271
|
-
const expires = Date.now() + 1e4;
|
|
272
|
-
this.subscribers = this.subscribers.filter((s) => !(s.type === "batch" && s.alias === alias && s.address === rinfo.address));
|
|
273
|
-
this.subscribers.push({
|
|
274
|
-
type: "batch",
|
|
275
|
-
address: rinfo.address,
|
|
276
|
-
port: rinfo.port,
|
|
277
|
-
alias,
|
|
278
|
-
paths,
|
|
279
|
-
start,
|
|
280
|
-
count,
|
|
281
|
-
factor,
|
|
282
|
-
expires,
|
|
283
|
-
args
|
|
284
|
-
});
|
|
285
|
-
this.logger.info(LogCategory.SUB, `Batch subscription`, {
|
|
286
|
-
alias,
|
|
287
|
-
count: paths.length,
|
|
288
|
-
factor,
|
|
289
|
-
ip: rinfo.address,
|
|
290
|
-
args
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Adds or renews a format subscription.
|
|
295
|
-
* @param rinfo - Client remote info.
|
|
296
|
-
* @param alias - Response alias.
|
|
297
|
-
* @param pattern - Path pattern.
|
|
298
|
-
* @param start - Start index.
|
|
299
|
-
* @param count - Count.
|
|
300
|
-
* @param factor - Frequency factor.
|
|
301
|
-
*/
|
|
302
|
-
addFormatSubscriber(rinfo, alias, pattern, start, count, factor) {
|
|
303
|
-
const expires = Date.now() + 1e4;
|
|
304
|
-
this.subscribers = this.subscribers.filter((s) => !(s.type === "format" && s.alias === alias && s.address === rinfo.address));
|
|
305
|
-
this.subscribers.push({
|
|
306
|
-
type: "format",
|
|
307
|
-
address: rinfo.address,
|
|
308
|
-
port: rinfo.port,
|
|
309
|
-
alias,
|
|
310
|
-
pattern,
|
|
311
|
-
start,
|
|
312
|
-
count,
|
|
313
|
-
factor,
|
|
314
|
-
expires
|
|
315
|
-
});
|
|
316
|
-
this.logger.info(LogCategory.SUB, `Format subscription`, {
|
|
317
|
-
alias,
|
|
318
|
-
pattern,
|
|
319
|
-
factor,
|
|
320
|
-
ip: rinfo.address
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* Adds or renews a high-frequency meter subscription.
|
|
325
|
-
* @param rinfo - Client remote info.
|
|
326
|
-
* @param meterPath - Target meter path.
|
|
327
|
-
*/
|
|
328
|
-
addMeterSubscriber(rinfo, meterPath) {
|
|
329
|
-
const expires = Date.now() + 1e4;
|
|
330
|
-
const existing = this.subscribers.find((s) => s.type === "meter" && s.meterPath === meterPath && s.address === rinfo.address);
|
|
331
|
-
this.subscribers = this.subscribers.filter((s) => !(s.type === "meter" && s.meterPath === meterPath && s.address === rinfo.address));
|
|
332
|
-
this.subscribers.push({
|
|
333
|
-
type: "meter",
|
|
334
|
-
address: rinfo.address,
|
|
335
|
-
port: rinfo.port,
|
|
336
|
-
meterPath,
|
|
337
|
-
expires
|
|
338
|
-
});
|
|
339
|
-
if (!existing) this.logger.info(LogCategory.SUB, `Meter subscription`, {
|
|
340
|
-
path: meterPath,
|
|
341
|
-
ip: rinfo.address
|
|
342
|
-
});
|
|
343
|
-
else this.logger.debug(LogCategory.SUB, `Meter renewal`, {
|
|
344
|
-
path: meterPath,
|
|
345
|
-
ip: rinfo.address
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* Removes a subscription.
|
|
350
|
-
* @param rinfo - Client remote info.
|
|
351
|
-
* @param path - Subscription path.
|
|
352
|
-
*/
|
|
353
|
-
removeSubscriber(rinfo, path) {
|
|
354
|
-
const initial = this.subscribers.length;
|
|
355
|
-
this.subscribers = this.subscribers.filter((s) => !(s.address === rinfo.address && s.port === rinfo.port && s.path === path));
|
|
356
|
-
if (this.subscribers.length < initial) this.logger.info(LogCategory.SUB, `Unsubscribed`, {
|
|
357
|
-
path,
|
|
358
|
-
ip: rinfo.address
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
//#endregion
|
|
364
|
-
//#region src/domain/services/strategies/NodeDiscoveryStrategy.ts
|
|
365
|
-
/**
|
|
366
|
-
* Handles the /node command for tree traversal/discovery.
|
|
367
|
-
* Returns a list of child nodes for a given path.
|
|
368
|
-
*/
|
|
369
|
-
var NodeDiscoveryStrategy = class {
|
|
370
|
-
constructor(schemaRegistry) {
|
|
371
|
-
this.schemaRegistry = schemaRegistry;
|
|
372
|
-
}
|
|
373
|
-
canHandle(address) {
|
|
374
|
-
return address === "/node";
|
|
375
|
-
}
|
|
376
|
-
execute(msg, _source) {
|
|
377
|
-
const queryPath = msg.args[0] || "/";
|
|
378
|
-
const children = /* @__PURE__ */ new Set();
|
|
379
|
-
const prefix = queryPath.endsWith("/") ? queryPath : `${queryPath}/`;
|
|
380
|
-
for (const key of this.schemaRegistry.getAllPaths()) if (key.startsWith(prefix)) {
|
|
381
|
-
const segment = key.slice(prefix.length).split("/")[0];
|
|
382
|
-
if (segment) children.add(segment);
|
|
383
|
-
}
|
|
384
|
-
return [{
|
|
385
|
-
address: "/node",
|
|
386
|
-
args: [queryPath, ...children]
|
|
387
|
-
}];
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
//#endregion
|
|
392
|
-
//#region src/domain/services/strategies/StaticResponseStrategy.ts
|
|
393
|
-
/**
|
|
394
|
-
* Handles discovery and static information queries.
|
|
395
|
-
* e.g., /status, /xinfo, /-prefs/...
|
|
396
|
-
*/
|
|
397
|
-
var StaticResponseStrategy = class {
|
|
398
|
-
constructor(serverIp, serverName, serverModel, staticResponseService) {
|
|
399
|
-
this.serverIp = serverIp;
|
|
400
|
-
this.serverName = serverName;
|
|
401
|
-
this.serverModel = serverModel;
|
|
402
|
-
this.staticResponseService = staticResponseService;
|
|
403
|
-
}
|
|
404
|
-
canHandle(address) {
|
|
405
|
-
return !!this.staticResponseService.getResponse(address);
|
|
406
|
-
}
|
|
407
|
-
execute(msg, _source) {
|
|
408
|
-
const rawResponse = this.staticResponseService.getResponse(msg.address);
|
|
409
|
-
if (!rawResponse) return [];
|
|
410
|
-
const args = rawResponse.map((arg) => {
|
|
411
|
-
if (typeof arg === "string") return arg.replace("{{ip}}", this.serverIp).replace("{{name}}", this.serverName).replace("{{model}}", this.serverModel);
|
|
412
|
-
return arg;
|
|
413
|
-
});
|
|
414
|
-
return [{
|
|
415
|
-
address: msg.address,
|
|
416
|
-
args
|
|
417
|
-
}];
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
|
|
421
|
-
//#endregion
|
|
422
|
-
//#region src/domain/services/strategies/SubscriptionStrategy.ts
|
|
423
|
-
var SubscriptionStrategy = class {
|
|
424
|
-
constructor(subscriptionManager, state, logger) {
|
|
425
|
-
this.subscriptionManager = subscriptionManager;
|
|
426
|
-
this.state = state;
|
|
427
|
-
this.logger = logger;
|
|
428
|
-
}
|
|
429
|
-
canHandle(address) {
|
|
430
|
-
return [
|
|
431
|
-
"/subscribe",
|
|
432
|
-
"/renew",
|
|
433
|
-
"/unsubscribe",
|
|
434
|
-
"/xremote"
|
|
435
|
-
].includes(address);
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* Handles Session and Subscription lifecycle.
|
|
439
|
-
*
|
|
440
|
-
* ROUTES:
|
|
441
|
-
* - /xremote: Firehose subscription (requests all console updates for 10s).
|
|
442
|
-
* - /subscribe [path]: Requests updates for a specific node path for 10s.
|
|
443
|
-
* - /renew [path]: Resets the 10s watchdog timer for a path.
|
|
444
|
-
* - /unsubscribe [path]: Stops updates for a path.
|
|
445
|
-
* @param msg - Parsed OSC message.
|
|
446
|
-
* @param source - Source address and port of the packet.
|
|
447
|
-
* @returns Returns the current value of the path upon subscription.
|
|
448
|
-
*/
|
|
449
|
-
execute(msg, source) {
|
|
450
|
-
const addr = msg.address;
|
|
451
|
-
if (addr === "/xremote") {
|
|
452
|
-
this.subscriptionManager.addPathSubscriber(source, "/xremote");
|
|
453
|
-
return [{
|
|
454
|
-
address: "/xremote",
|
|
455
|
-
args: []
|
|
456
|
-
}];
|
|
457
|
-
}
|
|
458
|
-
if (addr === "/unsubscribe") {
|
|
459
|
-
this.subscriptionManager.removeSubscriber(source, msg.args[0]);
|
|
460
|
-
this.logger.debug(LogCategory.SUB, `[UNSUB] ${msg.args[0]}`);
|
|
461
|
-
return [];
|
|
462
|
-
}
|
|
463
|
-
const target = msg.args[0];
|
|
464
|
-
this.subscriptionManager.addPathSubscriber(source, target);
|
|
465
|
-
const val = this.state.get(target);
|
|
466
|
-
if (val !== void 0) {
|
|
467
|
-
this.logger.debug(LogCategory.SUB, `[SUB] ${target} -> ${val}`);
|
|
468
|
-
return [{
|
|
469
|
-
address: target,
|
|
470
|
-
args: [val]
|
|
471
|
-
}];
|
|
472
|
-
}
|
|
473
|
-
return [];
|
|
474
|
-
}
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
//#endregion
|
|
478
|
-
//#region src/domain/services/strategies/BatchStrategy.ts
|
|
479
|
-
/**
|
|
480
|
-
* Handles bulk data subscription requests from advanced clients like X32-Edit or Mixing Station.
|
|
481
|
-
*
|
|
482
|
-
* SUPPORTED COMMANDS:
|
|
483
|
-
* - /formatsubscribe: Requests a range of numbered nodes (e.g. /ch/01-32/mix/fader).
|
|
484
|
-
* - /batchsubscribe: Aggregates multiple parameters into a single binary blob response.
|
|
485
|
-
*/
|
|
486
|
-
var BatchStrategy = class {
|
|
487
|
-
/**
|
|
488
|
-
* Initializes the strategy.
|
|
489
|
-
* @param subscriptionManager - Session manager.
|
|
490
|
-
* @param logger - Logger instance.
|
|
491
|
-
*/
|
|
492
|
-
constructor(subscriptionManager, logger) {
|
|
493
|
-
this.subscriptionManager = subscriptionManager;
|
|
494
|
-
this.logger = logger;
|
|
495
|
-
}
|
|
496
|
-
/** @inheritdoc */
|
|
497
|
-
canHandle(address) {
|
|
498
|
-
return ["/batchsubscribe", "/formatsubscribe"].includes(address);
|
|
499
|
-
}
|
|
500
|
-
/** @inheritdoc */
|
|
501
|
-
execute(msg, source) {
|
|
502
|
-
const addr = msg.address;
|
|
503
|
-
if (addr === "/formatsubscribe") {
|
|
504
|
-
const alias = msg.args[0];
|
|
505
|
-
const pattern = msg.args[1];
|
|
506
|
-
const start = msg.args[2];
|
|
507
|
-
const end = msg.args[3];
|
|
508
|
-
const factor = msg.args[4];
|
|
509
|
-
const count = end - start + 1;
|
|
510
|
-
this.subscriptionManager.addFormatSubscriber(source, alias, pattern, start, count, factor);
|
|
511
|
-
this.logger.debug(LogCategory.SUB, `[FORMAT] ${alias} factor: ${factor}`);
|
|
512
|
-
return [];
|
|
513
|
-
}
|
|
514
|
-
if (addr === "/batchsubscribe") {
|
|
515
|
-
const alias = msg.args[0];
|
|
516
|
-
const firstIntIndex = msg.args.findIndex((a) => typeof a === "number");
|
|
517
|
-
if (firstIntIndex === -1) return [];
|
|
518
|
-
const paths = msg.args.slice(1, firstIntIndex);
|
|
519
|
-
const intArgs = msg.args.slice(firstIntIndex);
|
|
520
|
-
const factor = intArgs.pop();
|
|
521
|
-
const cmdArgs = intArgs;
|
|
522
|
-
this.subscriptionManager.addBatchSubscriber(source, alias, paths, 0, 1, factor, cmdArgs);
|
|
523
|
-
this.logger.debug(LogCategory.SUB, `[BATCH] ${alias} paths: ${JSON.stringify(paths)} args: ${JSON.stringify(cmdArgs)} factor: ${factor}`);
|
|
524
|
-
return [];
|
|
525
|
-
}
|
|
526
|
-
return [];
|
|
527
|
-
}
|
|
528
|
-
};
|
|
529
|
-
|
|
530
|
-
//#endregion
|
|
531
|
-
//#region src/domain/services/strategies/MeterStrategy.ts
|
|
532
|
-
/**
|
|
533
|
-
* Handles high-frequency metering data requests.
|
|
534
|
-
* Meters are sent as binary blobs to optimize network bandwidth.
|
|
535
|
-
* Supports both direct address requests (/meters/1) and argument-based requests (/meters ,s "/meters/1").
|
|
536
|
-
*/
|
|
537
|
-
var MeterStrategy = class {
|
|
538
|
-
/**
|
|
539
|
-
* Initializes the strategy.
|
|
540
|
-
* @param subscriptionManager - Session manager.
|
|
541
|
-
* @param state - Current mixer state.
|
|
542
|
-
* @param meterService - Service to generate meter data.
|
|
543
|
-
*/
|
|
544
|
-
constructor(subscriptionManager, state, meterService) {
|
|
545
|
-
this.subscriptionManager = subscriptionManager;
|
|
546
|
-
this.state = state;
|
|
547
|
-
this.meterService = meterService;
|
|
548
|
-
}
|
|
549
|
-
/** @inheritdoc */
|
|
550
|
-
canHandle(address) {
|
|
551
|
-
return address.startsWith("/meters");
|
|
552
|
-
}
|
|
553
|
-
/** @inheritdoc */
|
|
554
|
-
execute(msg, source) {
|
|
555
|
-
let meterPath = msg.address;
|
|
556
|
-
if (msg.address === "/meters" && typeof msg.args[0] === "string" && msg.args[0].startsWith("/meters")) meterPath = msg.args[0];
|
|
557
|
-
this.subscriptionManager.addMeterSubscriber(source, meterPath);
|
|
558
|
-
const blob = this.meterService.generateMeterData(meterPath, this.state).toBlob();
|
|
559
|
-
return [{
|
|
560
|
-
address: meterPath,
|
|
561
|
-
args: [blob]
|
|
562
|
-
}];
|
|
563
|
-
}
|
|
564
|
-
};
|
|
565
|
-
|
|
566
|
-
//#endregion
|
|
567
|
-
//#region src/domain/services/strategies/StateAccessStrategy.ts
|
|
568
|
-
/**
|
|
569
|
-
* General-purpose strategy for reading and writing console parameters.
|
|
570
|
-
* acts as the fallback for any command that matches the schema.
|
|
571
|
-
*
|
|
572
|
-
* LOGIC:
|
|
573
|
-
* - If no arguments: Treats as a QUERY (GET) and returns the current value.
|
|
574
|
-
* - If arguments provided: Treats as an UPDATE (SET) and stores the new value.
|
|
575
|
-
*/
|
|
576
|
-
var StateAccessStrategy = class {
|
|
577
|
-
/**
|
|
578
|
-
* Initializes the strategy.
|
|
579
|
-
* @param state - Current mixer state.
|
|
580
|
-
* @param logger - Logger instance.
|
|
581
|
-
* @param schemaRegistry - Registry to validate addresses.
|
|
582
|
-
*/
|
|
583
|
-
constructor(state, logger, schemaRegistry) {
|
|
584
|
-
this.state = state;
|
|
585
|
-
this.logger = logger;
|
|
586
|
-
this.schemaRegistry = schemaRegistry;
|
|
587
|
-
}
|
|
588
|
-
/** @inheritdoc */
|
|
589
|
-
canHandle(address) {
|
|
590
|
-
return this.schemaRegistry.has(address);
|
|
591
|
-
}
|
|
592
|
-
/** @inheritdoc */
|
|
593
|
-
execute(msg, _source) {
|
|
594
|
-
const addr = msg.address;
|
|
595
|
-
const node = this.schemaRegistry.getNode(addr);
|
|
596
|
-
if (msg.args.length === 0) {
|
|
597
|
-
const val$1 = this.state.get(addr);
|
|
598
|
-
if (val$1 !== void 0) return [{
|
|
599
|
-
address: addr,
|
|
600
|
-
args: [val$1]
|
|
601
|
-
}];
|
|
602
|
-
return [];
|
|
603
|
-
}
|
|
604
|
-
const val = msg.args[0];
|
|
605
|
-
if (node) {
|
|
606
|
-
if (!node.validate(val)) {
|
|
607
|
-
this.logger.warn(LogCategory.DISPATCH, `[TYPE ERR] ${addr} expected ${node.type}, got ${typeof val}`);
|
|
608
|
-
return [];
|
|
609
|
-
}
|
|
610
|
-
this.state.set(addr, val);
|
|
611
|
-
this.logger.debug(LogCategory.STATE, `[SET] ${addr} -> ${val}`);
|
|
612
|
-
if (addr.startsWith("/config/mute/")) {
|
|
613
|
-
const groupIdx = parseInt(addr.split("/").pop(), 10);
|
|
614
|
-
if (!isNaN(groupIdx)) this.state.handleMuteGroupChange(groupIdx, val);
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
return [];
|
|
618
|
-
}
|
|
619
|
-
};
|
|
620
|
-
|
|
621
|
-
//#endregion
|
|
622
|
-
//#region src/domain/services/OscMessageHandler.ts
|
|
623
|
-
/**
|
|
624
|
-
* The central dispatcher for incoming OSC messages.
|
|
625
|
-
* Uses a Chain of Responsibility (Strategy pattern) to delegate handling.
|
|
626
|
-
* Order of strategies is critical for correct prioritization.
|
|
627
|
-
*/
|
|
628
|
-
var OscMessageHandler = class {
|
|
629
|
-
/** List of active command strategies. */
|
|
630
|
-
strategies;
|
|
631
|
-
/**
|
|
632
|
-
* Initializes the handler with all available strategies.
|
|
633
|
-
* @param state - Global mixer state.
|
|
634
|
-
* @param subscriptionManager - Active client sessions.
|
|
635
|
-
* @param logger - Logger instance.
|
|
636
|
-
* @param serverIp - Host IP reported in handshakes.
|
|
637
|
-
* @param serverName - Console name reported in handshakes.
|
|
638
|
-
* @param serverModel - Console model reported in handshakes.
|
|
639
|
-
* @param meterService - Service for metering.
|
|
640
|
-
* @param schemaRegistry - Service for schema validation.
|
|
641
|
-
* @param staticResponseService - Service for static responses.
|
|
642
|
-
*/
|
|
643
|
-
constructor(state, subscriptionManager, logger, serverIp, serverName, serverModel, meterService, schemaRegistry, staticResponseService) {
|
|
644
|
-
this.logger = logger;
|
|
645
|
-
this.meterService = meterService;
|
|
646
|
-
this.schemaRegistry = schemaRegistry;
|
|
647
|
-
this.staticResponseService = staticResponseService;
|
|
648
|
-
this.strategies = [
|
|
649
|
-
new NodeDiscoveryStrategy(this.schemaRegistry),
|
|
650
|
-
new SubscriptionStrategy(subscriptionManager, state, logger),
|
|
651
|
-
new BatchStrategy(subscriptionManager, logger),
|
|
652
|
-
new MeterStrategy(subscriptionManager, state, this.meterService),
|
|
653
|
-
new StateAccessStrategy(state, logger, this.schemaRegistry),
|
|
654
|
-
new StaticResponseStrategy(serverIp, serverName, serverModel, this.staticResponseService)
|
|
655
|
-
];
|
|
656
|
-
}
|
|
657
|
-
/**
|
|
658
|
-
* Dispatches an incoming message to the first matching strategy.
|
|
659
|
-
* @param msg - Parsed OSC message.
|
|
660
|
-
* @param source - Source address and port of the packet.
|
|
661
|
-
* @returns Array of replies generated by the strategy.
|
|
662
|
-
*/
|
|
663
|
-
handle(msg, source) {
|
|
664
|
-
const addr = msg.address;
|
|
665
|
-
if (!addr.startsWith("/meters")) this.logger.debug(LogCategory.DISPATCH, `Handling`, {
|
|
666
|
-
addr,
|
|
667
|
-
args: msg.args
|
|
668
|
-
});
|
|
669
|
-
for (const strategy of this.strategies) if (strategy.canHandle(addr)) {
|
|
670
|
-
const replies = strategy.execute(msg, source);
|
|
671
|
-
if (replies.length > 0) this.logger.debug(LogCategory.DISPATCH, `Strategy ${strategy.constructor.name} replied`, { count: replies.length });
|
|
672
|
-
return replies;
|
|
673
|
-
}
|
|
674
|
-
this.logger.warn(LogCategory.DISPATCH, `Unknown Command`, {
|
|
675
|
-
addr,
|
|
676
|
-
args: msg.args,
|
|
677
|
-
ip: source.address
|
|
678
|
-
});
|
|
679
|
-
return [];
|
|
680
|
-
}
|
|
681
|
-
};
|
|
682
|
-
|
|
683
|
-
//#endregion
|
|
684
|
-
//#region src/domain/models/MeterData.ts
|
|
685
|
-
/**
|
|
686
|
-
* Represents a set of meter values for a specific meter path.
|
|
687
|
-
* Handles the storage of float values and serialization to X32-specific binary blobs.
|
|
688
|
-
*/
|
|
689
|
-
var MeterData = class {
|
|
690
|
-
_path;
|
|
691
|
-
_values;
|
|
692
|
-
/**
|
|
693
|
-
* Creates a new MeterData instance.
|
|
694
|
-
* @param path - The meter OSC path (e.g., "/meters/1").
|
|
695
|
-
* @param values - The array of float values (0.0 - 1.0 or similar).
|
|
696
|
-
*/
|
|
697
|
-
constructor(path, values) {
|
|
698
|
-
this._path = path;
|
|
699
|
-
this._values = values;
|
|
700
|
-
}
|
|
701
|
-
/**
|
|
702
|
-
* Gets the meter path.
|
|
703
|
-
*/
|
|
704
|
-
get path() {
|
|
705
|
-
return this._path;
|
|
706
|
-
}
|
|
707
|
-
/**
|
|
708
|
-
* Gets the values.
|
|
709
|
-
*/
|
|
710
|
-
get values() {
|
|
711
|
-
return [...this._values];
|
|
712
|
-
}
|
|
713
|
-
/**
|
|
714
|
-
* Generates an optimized binary blob for X32 meters (mixed endianness).
|
|
715
|
-
* Structure: [Size (Int32BE)] [Count (Int32LE)] [Float1 (LE)] [Float2 (LE)] ...
|
|
716
|
-
* @returns Buffer containing the OSC blob.
|
|
717
|
-
*/
|
|
718
|
-
toBlob() {
|
|
719
|
-
const count = this._values.length;
|
|
720
|
-
const totalSize = 8 + count * 4;
|
|
721
|
-
const blob = Buffer.alloc(totalSize);
|
|
722
|
-
blob.writeInt32BE(totalSize, 0);
|
|
723
|
-
blob.writeInt32LE(count, 4);
|
|
724
|
-
for (let i = 0; i < count; i++) blob.writeFloatLE(this._values[i], 8 + i * 4);
|
|
725
|
-
return blob;
|
|
726
|
-
}
|
|
727
|
-
};
|
|
728
|
-
|
|
729
|
-
//#endregion
|
|
730
|
-
//#region src/domain/models/MeterConfig.ts
|
|
731
|
-
/**
|
|
732
|
-
* Configuration for meter counts per path.
|
|
733
|
-
*/
|
|
734
|
-
const METER_COUNTS = {
|
|
735
|
-
"/meters/0": 70,
|
|
736
|
-
"/meters/1": 96,
|
|
737
|
-
"/meters/2": 49,
|
|
738
|
-
"/meters/3": 22,
|
|
739
|
-
"/meters/4": 82,
|
|
740
|
-
"/meters/5": 27,
|
|
741
|
-
"/meters/6": 4,
|
|
742
|
-
"/meters/7": 16,
|
|
743
|
-
"/meters/8": 6,
|
|
744
|
-
"/meters/9": 32,
|
|
745
|
-
"/meters/10": 32,
|
|
746
|
-
"/meters/11": 5,
|
|
747
|
-
"/meters/12": 4,
|
|
748
|
-
"/meters/13": 48,
|
|
749
|
-
"/meters/14": 80,
|
|
750
|
-
"/meters/15": 50,
|
|
751
|
-
"/meters/16": 48
|
|
752
|
-
};
|
|
753
|
-
|
|
754
|
-
//#endregion
|
|
755
|
-
//#region src/domain/services/MeterService.ts
|
|
756
|
-
/**
|
|
757
|
-
* Service responsible for generating meter values and data.
|
|
758
|
-
* Mimics the physics/audio engine of the X32.
|
|
759
|
-
*/
|
|
760
|
-
var MeterService = class {
|
|
761
|
-
/**
|
|
762
|
-
* Generates a MeterData object for a given path.
|
|
763
|
-
* @param path - The meter OSC path (e.g., "/meters/1").
|
|
764
|
-
* @param state - The current X32 state (for correlating faders to meters).
|
|
765
|
-
* @returns MeterData object containing the values.
|
|
766
|
-
*/
|
|
767
|
-
generateMeterData(path, state) {
|
|
768
|
-
const count = METER_COUNTS[path];
|
|
769
|
-
if (count === void 0) return new MeterData(path, []);
|
|
770
|
-
const values = [];
|
|
771
|
-
for (let i = 0; i < count; i++) {
|
|
772
|
-
let val = Math.random() * .05;
|
|
773
|
-
if (state && path === "/meters/1") {
|
|
774
|
-
if (i < 32) {
|
|
775
|
-
const faderPath = `/ch/${(i + 1).toString().padStart(2, "0")}/mix/fader`;
|
|
776
|
-
const fader = state.get(faderPath);
|
|
777
|
-
if (typeof fader === "number") val = fader > .01 ? fader * (.9 + Math.random() * .1) : 0;
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
values.push(val);
|
|
781
|
-
}
|
|
782
|
-
return new MeterData(path, values);
|
|
783
|
-
}
|
|
784
|
-
};
|
|
785
|
-
|
|
786
|
-
//#endregion
|
|
787
|
-
//#region src/domain/services/StaticResponseService.ts
|
|
788
|
-
/**
|
|
789
|
-
* Static OSC responses for X32 Discovery and System status.
|
|
790
|
-
*/
|
|
791
|
-
const STATIC_RESPONSES_DATA = {
|
|
792
|
-
"/xinfo": [
|
|
793
|
-
"{{ip}}",
|
|
794
|
-
"{{name}}",
|
|
795
|
-
"{{model}}",
|
|
796
|
-
"4.06"
|
|
797
|
-
],
|
|
798
|
-
"/info": [
|
|
799
|
-
"V2.05",
|
|
800
|
-
"{{name}}",
|
|
801
|
-
"{{model}}",
|
|
802
|
-
"4.06"
|
|
803
|
-
],
|
|
804
|
-
"/status": [
|
|
805
|
-
"active",
|
|
806
|
-
"{{ip}}",
|
|
807
|
-
"{{name}}"
|
|
808
|
-
],
|
|
809
|
-
"/-prefs/invertmutes": [0],
|
|
810
|
-
"/-prefs/fine": [0],
|
|
811
|
-
"/-prefs/bright": [50],
|
|
812
|
-
"/-prefs/contrast": [50],
|
|
813
|
-
"/-prefs/led_bright": [50],
|
|
814
|
-
"/-prefs/lcd_bright": [50],
|
|
815
|
-
"/-stat/userpar/1/value": [0],
|
|
816
|
-
"/-stat/userpar/2/value": [0],
|
|
817
|
-
"/-stat/tape/state": [0],
|
|
818
|
-
"/-stat/aes50/A": [0],
|
|
819
|
-
"/-stat/aes50/B": [0],
|
|
820
|
-
"/-stat/solo": [0],
|
|
821
|
-
"/-stat/rtasource": [0],
|
|
822
|
-
"/-urec/errorcode": [0],
|
|
823
|
-
"/-prefs/rta/gain": [0],
|
|
824
|
-
"/-prefs/rta/autogain": [0],
|
|
825
|
-
"/-prefs/hardmute": [0],
|
|
826
|
-
"/-prefs/dcamute": [0],
|
|
827
|
-
"/config/mono/mode": [0],
|
|
828
|
-
"/config/amixenable/X": [0],
|
|
829
|
-
"/config/amixenable/Y": [0],
|
|
830
|
-
"/-show/prepos/current": [0],
|
|
831
|
-
"/-show/showfile/current": [""],
|
|
832
|
-
"/-action/setrtasrc": [0],
|
|
833
|
-
"/-action/playtrack": [0],
|
|
834
|
-
"/-action/goscene": [0],
|
|
835
|
-
"/-action/setscene": [0]
|
|
836
|
-
};
|
|
837
|
-
/**
|
|
838
|
-
* Service providing static system responses.
|
|
839
|
-
* Mimics the fixed firmware responses of the X32.
|
|
840
|
-
*/
|
|
841
|
-
var StaticResponseService = class {
|
|
842
|
-
responses = STATIC_RESPONSES_DATA;
|
|
843
|
-
/**
|
|
844
|
-
* Retrieves a static response for a given path.
|
|
845
|
-
* @param path - The OSC path.
|
|
846
|
-
* @returns The response arguments or undefined.
|
|
847
|
-
*/
|
|
848
|
-
getResponse(path) {
|
|
849
|
-
return this.responses[path];
|
|
850
|
-
}
|
|
851
|
-
};
|
|
852
|
-
|
|
853
|
-
//#endregion
|
|
854
|
-
//#region src/application/use-cases/SimulationService.ts
|
|
855
|
-
/**
|
|
856
|
-
* Gets the first non-internal IPv4 address found on this machine.
|
|
857
|
-
* @returns Detected IP or localhost.
|
|
858
|
-
*/
|
|
859
|
-
function getLocalIp() {
|
|
860
|
-
const interfaces = os.networkInterfaces();
|
|
861
|
-
for (const name of Object.keys(interfaces)) for (const iface of interfaces[name]) if (iface.family === "IPv4" && !iface.internal) return iface.address;
|
|
862
|
-
return "127.0.0.1";
|
|
863
|
-
}
|
|
864
|
-
/**
|
|
865
|
-
* The core service that manages the X32 simulation, including networking,
|
|
866
|
-
* state management, and OSC message handling.
|
|
867
|
-
*/
|
|
868
|
-
var SimulationService = class {
|
|
869
|
-
subscriptionManager;
|
|
870
|
-
messageHandler;
|
|
871
|
-
processPacket;
|
|
872
|
-
broadcastUpdates;
|
|
873
|
-
manageSessions;
|
|
874
|
-
meterService;
|
|
875
|
-
staticResponseService;
|
|
876
|
-
updateInterval = null;
|
|
877
|
-
cleanupInterval = null;
|
|
878
|
-
/**
|
|
879
|
-
* Creates a new SimulationService instance.
|
|
880
|
-
* @param gateway - The network gateway for OSC communication.
|
|
881
|
-
* @param logger - The logger service.
|
|
882
|
-
* @param stateRepo - The repository managing the mixer state.
|
|
883
|
-
* @param schemaRegistry - The registry for X32 OSC schema.
|
|
884
|
-
* @param port - UDP port to listen on (default 10023).
|
|
885
|
-
* @param ip - IP address to bind to (default '0.0.0.0').
|
|
886
|
-
* @param name - Reported console name.
|
|
887
|
-
* @param model - Reported console model.
|
|
888
|
-
*/
|
|
889
|
-
constructor(gateway, logger, stateRepo, schemaRegistry, port = 10023, ip = "0.0.0.0", name = "osc-server", model = "X32") {
|
|
890
|
-
this.gateway = gateway;
|
|
891
|
-
this.logger = logger;
|
|
892
|
-
this.stateRepo = stateRepo;
|
|
893
|
-
this.schemaRegistry = schemaRegistry;
|
|
894
|
-
this.port = port;
|
|
895
|
-
this.ip = ip;
|
|
896
|
-
const state = this.stateRepo.getState();
|
|
897
|
-
this.subscriptionManager = new SubscriptionManager(logger);
|
|
898
|
-
this.meterService = new MeterService();
|
|
899
|
-
this.staticResponseService = new StaticResponseService();
|
|
900
|
-
const reportedIp = this.ip === "0.0.0.0" ? getLocalIp() : this.ip;
|
|
901
|
-
this.messageHandler = new OscMessageHandler(state, this.subscriptionManager, logger, reportedIp, name, model, this.meterService, this.schemaRegistry, this.staticResponseService);
|
|
902
|
-
this.processPacket = new ProcessPacketUseCase(this.messageHandler, gateway);
|
|
903
|
-
this.broadcastUpdates = new BroadcastUpdatesUseCase(this.subscriptionManager, state, gateway, logger, this.meterService, this.schemaRegistry);
|
|
904
|
-
this.manageSessions = new ManageSessionsUseCase(this.subscriptionManager);
|
|
905
|
-
state.on("change", (evt) => {
|
|
906
|
-
this.logger.info(LogCategory.STATE, `State Changed`, evt);
|
|
907
|
-
this.broadcastUpdates.broadcastSingleChange(evt.address, evt.value);
|
|
908
|
-
});
|
|
909
|
-
this.gateway.onPacket((packet, source) => this.processPacket.execute(packet, source));
|
|
910
|
-
}
|
|
911
|
-
/**
|
|
912
|
-
* Starts the simulator server and internal loops.
|
|
913
|
-
*/
|
|
914
|
-
async start() {
|
|
915
|
-
await this.gateway.start(this.port, this.ip);
|
|
916
|
-
this.cleanupInterval = setInterval(() => {
|
|
917
|
-
this.manageSessions.cleanup();
|
|
918
|
-
}, 5e3);
|
|
919
|
-
this.updateInterval = setInterval(() => {
|
|
920
|
-
this.broadcastUpdates.execute();
|
|
921
|
-
}, 100);
|
|
922
|
-
}
|
|
923
|
-
/**
|
|
924
|
-
* Stops the simulator server and stops all internal loops.
|
|
925
|
-
*/
|
|
926
|
-
async stop() {
|
|
927
|
-
if (this.updateInterval) clearInterval(this.updateInterval);
|
|
928
|
-
if (this.cleanupInterval) clearInterval(this.cleanupInterval);
|
|
929
|
-
await this.gateway.stop();
|
|
930
|
-
}
|
|
931
|
-
/**
|
|
932
|
-
* Resets the mixer state to default values.
|
|
933
|
-
*/
|
|
934
|
-
resetState() {
|
|
935
|
-
this.stateRepo.reset();
|
|
936
|
-
}
|
|
937
|
-
};
|
|
938
|
-
|
|
939
|
-
//#endregion
|
|
940
|
-
//#region src/domain/entities/X32State.ts
|
|
941
|
-
/**
|
|
942
|
-
* Manages the internal "Digital Twin" state of the X32 console.
|
|
943
|
-
* It acts as a single source of truth for all parameters.
|
|
944
|
-
* Emits 'change' events whenever a value is updated.
|
|
945
|
-
*/
|
|
946
|
-
var X32State = class extends node_events.EventEmitter {
|
|
947
|
-
/** Map storing all OSC paths and their current values. */
|
|
948
|
-
state = /* @__PURE__ */ new Map();
|
|
949
|
-
defaultState = /* @__PURE__ */ new Map();
|
|
950
|
-
/**
|
|
951
|
-
* Initializes the state with default values from the schema.
|
|
952
|
-
* @param schema - The schema definition map.
|
|
953
|
-
*/
|
|
954
|
-
constructor(schema) {
|
|
955
|
-
super();
|
|
956
|
-
for (const [addr, def] of Object.entries(schema)) this.defaultState.set(addr, def.default);
|
|
957
|
-
this.reset();
|
|
958
|
-
}
|
|
959
|
-
/**
|
|
960
|
-
* Resets all state parameters to their default values defined in the schema.
|
|
961
|
-
*/
|
|
962
|
-
reset() {
|
|
963
|
-
this.state.clear();
|
|
964
|
-
this.defaultState.forEach((val, key) => {
|
|
965
|
-
this.state.set(key, val);
|
|
966
|
-
});
|
|
967
|
-
}
|
|
968
|
-
/**
|
|
969
|
-
* Retrieves the value of a specific OSC node.
|
|
970
|
-
* @param address - The full OSC address path.
|
|
971
|
-
* @returns The stored value (number or string) or undefined if not found.
|
|
972
|
-
*/
|
|
973
|
-
get(address) {
|
|
974
|
-
return this.state.get(address);
|
|
975
|
-
}
|
|
976
|
-
/**
|
|
977
|
-
* Updates the value of a specific OSC node and notifies subscribers.
|
|
978
|
-
* @param address - The full OSC address path.
|
|
979
|
-
* @param value - The new value to store.
|
|
980
|
-
*/
|
|
981
|
-
set(address, value) {
|
|
982
|
-
this.state.set(address, value);
|
|
983
|
-
this.emit("change", {
|
|
984
|
-
address,
|
|
985
|
-
value
|
|
986
|
-
});
|
|
987
|
-
}
|
|
988
|
-
/**
|
|
989
|
-
* Specialized logic to handle X32 Mute Groups side-effects.
|
|
990
|
-
* When a mute group is toggled, it iterates through all channels
|
|
991
|
-
* assigned to that group and updates their individual mute status.
|
|
992
|
-
* @param groupIdx - The index of the mute group (1-6).
|
|
993
|
-
* @param isOn - The new state of the group master switch (0 or 1).
|
|
994
|
-
*/
|
|
995
|
-
handleMuteGroupChange(groupIdx, isOn) {
|
|
996
|
-
for (let i = 1; i <= 32; i++) {
|
|
997
|
-
const ch = i.toString().padStart(2, "0");
|
|
998
|
-
const grpVal = this.get(`/ch/${ch}/grp/mute`);
|
|
999
|
-
if (typeof grpVal === "number") {
|
|
1000
|
-
if ((grpVal & 1 << groupIdx - 1) !== 0) {
|
|
1001
|
-
const targetMute = isOn === 1 ? 0 : 1;
|
|
1002
|
-
const muteAddr = `/ch/${ch}/mix/on`;
|
|
1003
|
-
this.set(muteAddr, targetMute);
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
};
|
|
1009
|
-
|
|
1010
|
-
//#endregion
|
|
1011
|
-
//#region src/domain/models/X32Node.ts
|
|
1012
|
-
/**
|
|
1013
|
-
* Metadata for a single state node in the X32 schema.
|
|
1014
|
-
* Represents a "Knob" or "Variable" on the console.
|
|
1015
|
-
*/
|
|
1016
|
-
var X32Node = class X32Node {
|
|
1017
|
-
/** Value type (f=float, i=int, s=string). */
|
|
1018
|
-
type;
|
|
1019
|
-
/** Default value for reset. */
|
|
1020
|
-
default;
|
|
1021
|
-
/**
|
|
1022
|
-
* Creates a new X32Node.
|
|
1023
|
-
* @param type - The OSC data type ('f', 'i', 's').
|
|
1024
|
-
* @param defaultValue - The default value.
|
|
1025
|
-
*/
|
|
1026
|
-
constructor(type, defaultValue) {
|
|
1027
|
-
this.type = type;
|
|
1028
|
-
this.default = defaultValue;
|
|
1029
|
-
}
|
|
1030
|
-
/**
|
|
1031
|
-
* Validates if a value is compatible with this node's type.
|
|
1032
|
-
* @param value - The value to check.
|
|
1033
|
-
* @returns True if valid.
|
|
1034
|
-
*/
|
|
1035
|
-
validate(value) {
|
|
1036
|
-
if (this.type === "f") return typeof value === "number";
|
|
1037
|
-
if (this.type === "i") return typeof value === "number";
|
|
1038
|
-
if (this.type === "s") return typeof value === "string";
|
|
1039
|
-
return false;
|
|
1040
|
-
}
|
|
1041
|
-
/**
|
|
1042
|
-
* Factory method to create from a plain object (for compatibility/migration).
|
|
1043
|
-
* @param obj - Plain object.
|
|
1044
|
-
* @param obj.type - OSC data type.
|
|
1045
|
-
* @param obj.default - Default value.
|
|
1046
|
-
* @returns A new X32Node instance.
|
|
1047
|
-
*/
|
|
1048
|
-
static from(obj) {
|
|
1049
|
-
return new X32Node(obj.type, obj.default);
|
|
1050
|
-
}
|
|
1051
|
-
};
|
|
1052
|
-
|
|
1053
|
-
//#endregion
|
|
1054
|
-
//#region src/infrastructure/repositories/InMemoryStateRepository.ts
|
|
1055
|
-
/**
|
|
1056
|
-
* In-memory implementation of the state repository.
|
|
1057
|
-
* Stores the mixer state in volatile memory during the simulator's execution.
|
|
1058
|
-
*/
|
|
1059
|
-
var InMemoryStateRepository = class {
|
|
1060
|
-
state;
|
|
1061
|
-
/**
|
|
1062
|
-
* Creates a new InMemoryStateRepository.
|
|
1063
|
-
* @param logger - Logger service.
|
|
1064
|
-
* @param schemaRegistry - Registry providing the initial state schema.
|
|
1065
|
-
*/
|
|
1066
|
-
constructor(logger, schemaRegistry) {
|
|
1067
|
-
this.logger = logger;
|
|
1068
|
-
this.state = new X32State(schemaRegistry.getSchema());
|
|
1069
|
-
}
|
|
1070
|
-
/**
|
|
1071
|
-
* Returns the current mixer state instance.
|
|
1072
|
-
* @returns The X32State entity.
|
|
1073
|
-
*/
|
|
1074
|
-
getState() {
|
|
1075
|
-
return this.state;
|
|
1076
|
-
}
|
|
1077
|
-
/**
|
|
1078
|
-
* Resets the entire state to its default values.
|
|
1079
|
-
*/
|
|
1080
|
-
reset() {
|
|
1081
|
-
this.logger.info(LogCategory.SYSTEM, "Resetting state to defaults");
|
|
1082
|
-
this.state.reset();
|
|
1083
|
-
}
|
|
1084
|
-
};
|
|
1085
|
-
|
|
1086
|
-
//#endregion
|
|
1087
|
-
//#region src/infrastructure/services/ConsoleLogger.ts
|
|
1088
|
-
/**
|
|
1089
|
-
* Log levels for the application.
|
|
1090
|
-
*/
|
|
1091
|
-
let LogLevel = /* @__PURE__ */ function(LogLevel$1) {
|
|
1092
|
-
LogLevel$1[LogLevel$1["DEBUG"] = 0] = "DEBUG";
|
|
1093
|
-
LogLevel$1[LogLevel$1["INFO"] = 1] = "INFO";
|
|
1094
|
-
LogLevel$1[LogLevel$1["WARN"] = 2] = "WARN";
|
|
1095
|
-
LogLevel$1[LogLevel$1["ERROR"] = 3] = "ERROR";
|
|
1096
|
-
LogLevel$1[LogLevel$1["NONE"] = 4] = "NONE";
|
|
1097
|
-
return LogLevel$1;
|
|
1098
|
-
}({});
|
|
1099
|
-
/**
|
|
1100
|
-
* Enhanced logger with category support and environment-based filtering.
|
|
1101
|
-
*/
|
|
1102
|
-
var ConsoleLogger = class ConsoleLogger {
|
|
1103
|
-
static instance;
|
|
1104
|
-
level = LogLevel.DEBUG;
|
|
1105
|
-
hiddenPatterns = [];
|
|
1106
|
-
enabledCategories = new Set([
|
|
1107
|
-
LogCategory.SYSTEM,
|
|
1108
|
-
LogCategory.OSC_IN,
|
|
1109
|
-
LogCategory.OSC_OUT,
|
|
1110
|
-
LogCategory.DISPATCH,
|
|
1111
|
-
LogCategory.STATE,
|
|
1112
|
-
LogCategory.SUB
|
|
1113
|
-
]);
|
|
1114
|
-
constructor() {
|
|
1115
|
-
if (process.env.HIDDEN_LOG) this.hiddenPatterns = process.env.HIDDEN_LOG.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
1116
|
-
}
|
|
1117
|
-
/**
|
|
1118
|
-
* Gets the singleton instance.
|
|
1119
|
-
* @returns ConsoleLogger instance.
|
|
1120
|
-
*/
|
|
1121
|
-
static getInstance() {
|
|
1122
|
-
if (!ConsoleLogger.instance) ConsoleLogger.instance = new ConsoleLogger();
|
|
1123
|
-
return ConsoleLogger.instance;
|
|
1124
|
-
}
|
|
1125
|
-
/**
|
|
1126
|
-
* Sets the minimum log level.
|
|
1127
|
-
* @param level - LogLevel.
|
|
1128
|
-
*/
|
|
1129
|
-
setLevel(level) {
|
|
1130
|
-
this.level = level;
|
|
1131
|
-
}
|
|
1132
|
-
/**
|
|
1133
|
-
* Enables a category for output.
|
|
1134
|
-
* @param cat - Category name.
|
|
1135
|
-
*/
|
|
1136
|
-
enableCategory(cat) {
|
|
1137
|
-
this.enabledCategories.add(cat);
|
|
1138
|
-
}
|
|
1139
|
-
/**
|
|
1140
|
-
* Disables a category for output.
|
|
1141
|
-
* @param cat - Category name.
|
|
1142
|
-
*/
|
|
1143
|
-
disableCategory(cat) {
|
|
1144
|
-
this.enabledCategories.delete(cat);
|
|
1145
|
-
}
|
|
1146
|
-
/**
|
|
1147
|
-
* Logs a debug message.
|
|
1148
|
-
* @param category - Log category.
|
|
1149
|
-
* @param msg - Message string.
|
|
1150
|
-
* @param data - Optional metadata.
|
|
1151
|
-
*/
|
|
1152
|
-
debug(category, msg, data) {
|
|
1153
|
-
if (this.shouldHide(msg, data)) return;
|
|
1154
|
-
if (this.level <= LogLevel.DEBUG && this.enabledCategories.has(category)) console.log(this.format("DEBUG", category, msg, data));
|
|
1155
|
-
}
|
|
1156
|
-
/**
|
|
1157
|
-
* Logs an info message.
|
|
1158
|
-
* @param category - Log category.
|
|
1159
|
-
* @param msg - Message string.
|
|
1160
|
-
* @param data - Optional metadata.
|
|
1161
|
-
*/
|
|
1162
|
-
info(category, msg, data) {
|
|
1163
|
-
if (this.shouldHide(msg, data)) return;
|
|
1164
|
-
if (this.level <= LogLevel.INFO && this.enabledCategories.has(category)) console.log(this.format("INFO ", category, msg, data));
|
|
1165
|
-
}
|
|
1166
|
-
/**
|
|
1167
|
-
* Logs a warning message.
|
|
1168
|
-
* @param category - Log category.
|
|
1169
|
-
* @param msg - Message string.
|
|
1170
|
-
* @param data - Optional metadata.
|
|
1171
|
-
*/
|
|
1172
|
-
warn(category, msg, data) {
|
|
1173
|
-
if (this.shouldHide(msg, data)) return;
|
|
1174
|
-
if (this.level <= LogLevel.WARN && this.enabledCategories.has(category)) console.log(this.format("WARN ", category, msg, data));
|
|
1175
|
-
}
|
|
1176
|
-
/**
|
|
1177
|
-
* Logs an error message.
|
|
1178
|
-
* @param category - Log category.
|
|
1179
|
-
* @param msg - Message string.
|
|
1180
|
-
* @param err - Optional error object.
|
|
1181
|
-
*/
|
|
1182
|
-
error(category, msg, err) {
|
|
1183
|
-
if (this.shouldHide(msg, err)) return;
|
|
1184
|
-
if (this.level <= LogLevel.ERROR) console.log(this.format("ERROR", category, msg, err));
|
|
1185
|
-
}
|
|
1186
|
-
/**
|
|
1187
|
-
* Checks if a log should be hidden based on patterns.
|
|
1188
|
-
* @param msg - Message.
|
|
1189
|
-
* @param data - Metadata.
|
|
1190
|
-
* @returns True if log should be suppressed.
|
|
1191
|
-
*/
|
|
1192
|
-
shouldHide(msg, data) {
|
|
1193
|
-
if (this.hiddenPatterns.length === 0) return false;
|
|
1194
|
-
if (this.hiddenPatterns.some((p) => msg.includes(p))) return true;
|
|
1195
|
-
if (data !== void 0) {
|
|
1196
|
-
const strData = Buffer.isBuffer(data) ? data.toString("hex") : typeof data === "object" ? JSON.stringify(data) : String(data);
|
|
1197
|
-
if (this.hiddenPatterns.some((p) => strData.includes(p))) return true;
|
|
1198
|
-
}
|
|
1199
|
-
return false;
|
|
1200
|
-
}
|
|
1201
|
-
/**
|
|
1202
|
-
* Formats the log message.
|
|
1203
|
-
* @param level - Level label.
|
|
1204
|
-
* @param category - Category label.
|
|
1205
|
-
* @param msg - Message.
|
|
1206
|
-
* @param data - Metadata.
|
|
1207
|
-
* @returns Formatted string.
|
|
1208
|
-
*/
|
|
1209
|
-
format(level, category, msg, data) {
|
|
1210
|
-
const now = /* @__PURE__ */ new Date();
|
|
1211
|
-
let out = `\x1b[90m[${`${now.getHours().toString().padStart(2, "0")}:${now.getMinutes().toString().padStart(2, "0")}:${now.getSeconds().toString().padStart(2, "0")}.${now.getMilliseconds().toString().padStart(3, "0")}`}]\x1b[0m `;
|
|
1212
|
-
switch (level) {
|
|
1213
|
-
case "DEBUG":
|
|
1214
|
-
out += `\x1b[36m[DEBUG]\x1b[0m`;
|
|
1215
|
-
break;
|
|
1216
|
-
case "INFO ":
|
|
1217
|
-
out += `\x1b[32m[INFO ]\x1b[0m`;
|
|
1218
|
-
break;
|
|
1219
|
-
case "WARN ":
|
|
1220
|
-
out += `\x1b[33m[WARN ]\x1b[0m`;
|
|
1221
|
-
break;
|
|
1222
|
-
case "ERROR":
|
|
1223
|
-
out += `\x1b[31m[ERROR]\x1b[0m`;
|
|
1224
|
-
break;
|
|
1225
|
-
}
|
|
1226
|
-
out += ` \x1b[35m[${category.padEnd(8)}]\x1b[0m ${msg}`;
|
|
1227
|
-
if (data !== void 0) try {
|
|
1228
|
-
if (Buffer.isBuffer(data)) out += ` \x1b[90m<Buffer ${data.length}b>\x1b[0m`;
|
|
1229
|
-
else if (typeof data === "object" && data !== null) out += ` \x1b[90m${JSON.stringify(data)}\x1b[0m`;
|
|
1230
|
-
else out += ` \x1b[90m${data}\x1b[0m`;
|
|
1231
|
-
} catch {
|
|
1232
|
-
out += ` [Circular/Error]`;
|
|
1233
|
-
}
|
|
1234
|
-
return out;
|
|
1235
|
-
}
|
|
1236
|
-
};
|
|
1237
|
-
|
|
1238
|
-
//#endregion
|
|
1239
|
-
//#region src/infrastructure/services/UdpNetworkGateway.ts
|
|
1240
|
-
/**
|
|
1241
|
-
* Node.js UDP implementation of the network gateway.
|
|
1242
|
-
* Handles the low-level socket communication and OSC packet routing.
|
|
1243
|
-
*/
|
|
1244
|
-
var UdpNetworkGateway = class {
|
|
1245
|
-
socket;
|
|
1246
|
-
isRunning = false;
|
|
1247
|
-
packetCallback = null;
|
|
1248
|
-
/**
|
|
1249
|
-
* Creates a new UdpNetworkGateway.
|
|
1250
|
-
* @param logger - Logger service.
|
|
1251
|
-
* @param codec - OSC codec for encoding/decoding.
|
|
1252
|
-
*/
|
|
1253
|
-
constructor(logger, codec) {
|
|
1254
|
-
this.logger = logger;
|
|
1255
|
-
this.codec = codec;
|
|
1256
|
-
this.socket = node_dgram.createSocket("udp4");
|
|
1257
|
-
}
|
|
1258
|
-
/**
|
|
1259
|
-
* Registers a callback to be executed whenever a new OSC packet arrives.
|
|
1260
|
-
* @param callback - Function called with decoded packet and source info.
|
|
1261
|
-
*/
|
|
1262
|
-
onPacket(callback) {
|
|
1263
|
-
this.packetCallback = callback;
|
|
1264
|
-
}
|
|
1265
|
-
/**
|
|
1266
|
-
* Starts the UDP server on the specified port and IP.
|
|
1267
|
-
* @param port - UDP port.
|
|
1268
|
-
* @param ip - IP address to bind to.
|
|
1269
|
-
* @returns Promise resolving when the socket is bound.
|
|
1270
|
-
*/
|
|
1271
|
-
start(port, ip) {
|
|
1272
|
-
return new Promise((resolve, reject) => {
|
|
1273
|
-
this.socket.on("error", (err) => {
|
|
1274
|
-
this.logger.error(LogCategory.SYSTEM, "Socket Error", err);
|
|
1275
|
-
reject(err);
|
|
1276
|
-
});
|
|
1277
|
-
this.socket.on("message", (msg, rinfo) => {
|
|
1278
|
-
try {
|
|
1279
|
-
this.logger.debug(LogCategory.OSC_IN, `Packet received ${msg.length}b`, { ip: rinfo.address });
|
|
1280
|
-
const decoded = this.codec.decode(msg);
|
|
1281
|
-
if (this.packetCallback) this.packetCallback(decoded, {
|
|
1282
|
-
address: rinfo.address,
|
|
1283
|
-
port: rinfo.port
|
|
1284
|
-
});
|
|
1285
|
-
} catch (err) {
|
|
1286
|
-
this.logger.error(LogCategory.OSC_IN, "Decode Error", err instanceof Error ? err : new Error(String(err)));
|
|
1287
|
-
}
|
|
1288
|
-
});
|
|
1289
|
-
this.socket.bind(port, ip, () => {
|
|
1290
|
-
this.logger.info(LogCategory.SYSTEM, `Server bound to ${ip}:${port}`);
|
|
1291
|
-
this.isRunning = true;
|
|
1292
|
-
resolve();
|
|
1293
|
-
});
|
|
1294
|
-
});
|
|
1295
|
-
}
|
|
1296
|
-
/**
|
|
1297
|
-
* Shuts down the UDP server.
|
|
1298
|
-
* @returns Promise resolving when the socket is closed.
|
|
1299
|
-
*/
|
|
1300
|
-
stop() {
|
|
1301
|
-
return new Promise((resolve) => {
|
|
1302
|
-
if (!this.isRunning) return resolve();
|
|
1303
|
-
this.socket.close(() => {
|
|
1304
|
-
this.isRunning = false;
|
|
1305
|
-
this.logger.info(LogCategory.SYSTEM, "Server stopped");
|
|
1306
|
-
resolve();
|
|
1307
|
-
});
|
|
1308
|
-
});
|
|
1309
|
-
}
|
|
1310
|
-
/**
|
|
1311
|
-
* Sends an OSC message to a specific remote client.
|
|
1312
|
-
* @param target - Target client info (IP/port).
|
|
1313
|
-
* @param address - OSC address pattern.
|
|
1314
|
-
* @param args - Array of arguments.
|
|
1315
|
-
*/
|
|
1316
|
-
send(target, address, args) {
|
|
1317
|
-
const buf = this.codec.encode(address, args);
|
|
1318
|
-
const cat = address.startsWith("/meters") ? LogCategory.METER : LogCategory.OSC_OUT;
|
|
1319
|
-
this.logger.debug(cat, `Sending ${address}`, {
|
|
1320
|
-
ip: target.address,
|
|
1321
|
-
args
|
|
1322
|
-
});
|
|
1323
|
-
this.socket.send(buf, target.port, target.address, (err) => {
|
|
1324
|
-
if (err) this.logger.error(LogCategory.OSC_OUT, "Send Error", err);
|
|
1325
|
-
});
|
|
1326
|
-
}
|
|
1327
|
-
};
|
|
1328
|
-
|
|
1329
|
-
//#endregion
|
|
1330
|
-
//#region node_modules/node-osc/lib/Message.mjs
|
|
1331
|
-
const typeTags = {
|
|
1332
|
-
s: "string",
|
|
1333
|
-
f: "float",
|
|
1334
|
-
i: "integer",
|
|
1335
|
-
b: "blob",
|
|
1336
|
-
m: "midi"
|
|
1337
|
-
};
|
|
1338
|
-
/**
|
|
1339
|
-
* Represents a typed argument for an OSC message.
|
|
1340
|
-
*
|
|
1341
|
-
* @class
|
|
1342
|
-
* @private
|
|
1343
|
-
*/
|
|
1344
|
-
var Argument = class {
|
|
1345
|
-
/**
|
|
1346
|
-
* @param {string} type - The type of the argument (string, float, integer, blob, boolean).
|
|
1347
|
-
* @param {*} value - The value of the argument.
|
|
1348
|
-
*/
|
|
1349
|
-
constructor(type, value) {
|
|
1350
|
-
this.type = type;
|
|
1351
|
-
this.value = value;
|
|
1352
|
-
}
|
|
1353
|
-
};
|
|
1354
|
-
/**
|
|
1355
|
-
* Represents an OSC message with an address and arguments.
|
|
1356
|
-
*
|
|
1357
|
-
* OSC messages consist of an address pattern (string starting with '/')
|
|
1358
|
-
* and zero or more arguments of various types.
|
|
1359
|
-
*
|
|
1360
|
-
* @class
|
|
1361
|
-
*
|
|
1362
|
-
* @example
|
|
1363
|
-
* // Create a message with constructor arguments
|
|
1364
|
-
* const msg = new Message('/test', 1, 2, 'hello');
|
|
1365
|
-
*
|
|
1366
|
-
* @example
|
|
1367
|
-
* // Create a message and append arguments
|
|
1368
|
-
* const msg = new Message('/test');
|
|
1369
|
-
* msg.append(1);
|
|
1370
|
-
* msg.append('hello');
|
|
1371
|
-
* msg.append(3.14);
|
|
1372
|
-
*/
|
|
1373
|
-
var Message = class {
|
|
1374
|
-
/**
|
|
1375
|
-
* Create an OSC Message.
|
|
1376
|
-
*
|
|
1377
|
-
* @param {string} address - The OSC address pattern (e.g., '/oscillator/frequency').
|
|
1378
|
-
* @param {...*} args - Optional arguments to include in the message.
|
|
1379
|
-
*
|
|
1380
|
-
* @example
|
|
1381
|
-
* const msg = new Message('/test');
|
|
1382
|
-
*
|
|
1383
|
-
* @example
|
|
1384
|
-
* const msg = new Message('/test', 1, 2, 3);
|
|
1385
|
-
*
|
|
1386
|
-
* @example
|
|
1387
|
-
* const msg = new Message('/synth', 'note', 60, 0.5);
|
|
1388
|
-
*/
|
|
1389
|
-
constructor(address, ...args) {
|
|
1390
|
-
this.oscType = "message";
|
|
1391
|
-
this.address = address;
|
|
1392
|
-
this.args = args;
|
|
1393
|
-
}
|
|
1394
|
-
/**
|
|
1395
|
-
* Append an argument to the message.
|
|
1396
|
-
*
|
|
1397
|
-
* Automatically detects the type based on the JavaScript type:
|
|
1398
|
-
* - Integers are encoded as OSC integers
|
|
1399
|
-
* - Floats are encoded as OSC floats
|
|
1400
|
-
* - Strings are encoded as OSC strings
|
|
1401
|
-
* - Booleans are encoded as OSC booleans
|
|
1402
|
-
* - Buffers are encoded as OSC blobs
|
|
1403
|
-
* - Arrays are recursively appended
|
|
1404
|
-
* - Objects with a 'type' property are used as-is
|
|
1405
|
-
*
|
|
1406
|
-
* @param {*} arg - The argument to append. Can be:
|
|
1407
|
-
* - A primitive value (number, string, boolean)
|
|
1408
|
-
* - A Buffer (encoded as blob)
|
|
1409
|
-
* - An array of values (will be recursively appended)
|
|
1410
|
-
* - An object with 'type' and 'value' properties for explicit type control
|
|
1411
|
-
*
|
|
1412
|
-
* @throws {Error} If the argument type cannot be encoded.
|
|
1413
|
-
*
|
|
1414
|
-
* @example
|
|
1415
|
-
* const msg = new Message('/test');
|
|
1416
|
-
* msg.append(42); // Integer
|
|
1417
|
-
* msg.append(3.14); // Float
|
|
1418
|
-
* msg.append('hello'); // String
|
|
1419
|
-
* msg.append(true); // Boolean
|
|
1420
|
-
*
|
|
1421
|
-
* @example
|
|
1422
|
-
* // Append multiple values at once
|
|
1423
|
-
* msg.append([1, 2, 3]);
|
|
1424
|
-
*
|
|
1425
|
-
* @example
|
|
1426
|
-
* // Explicitly specify type
|
|
1427
|
-
* msg.append({ type: 'float', value: 42 });
|
|
1428
|
-
* msg.append({ type: 'blob', value: Buffer.from('data') });
|
|
1429
|
-
*
|
|
1430
|
-
* @example
|
|
1431
|
-
* // MIDI messages (4 bytes: port, status, data1, data2)
|
|
1432
|
-
* msg.append({ type: 'midi', value: { port: 0, status: 144, data1: 60, data2: 127 } });
|
|
1433
|
-
* msg.append({ type: 'm', value: Buffer.from([0, 144, 60, 127]) });
|
|
1434
|
-
*/
|
|
1435
|
-
append(arg) {
|
|
1436
|
-
let argOut;
|
|
1437
|
-
switch (typeof arg) {
|
|
1438
|
-
case "object":
|
|
1439
|
-
if (Buffer.isBuffer(arg)) this.args.push(arg);
|
|
1440
|
-
else if (arg instanceof Array) arg.forEach((a) => this.append(a));
|
|
1441
|
-
else if (arg.type) {
|
|
1442
|
-
if (typeTags[arg.type]) arg.type = typeTags[arg.type];
|
|
1443
|
-
this.args.push(arg);
|
|
1444
|
-
} else throw new Error(`don't know how to encode object ${arg}`);
|
|
1445
|
-
break;
|
|
1446
|
-
case "number":
|
|
1447
|
-
if (Math.floor(arg) === arg) argOut = new Argument("integer", arg);
|
|
1448
|
-
else argOut = new Argument("float", arg);
|
|
1449
|
-
break;
|
|
1450
|
-
case "string":
|
|
1451
|
-
argOut = new Argument("string", arg);
|
|
1452
|
-
break;
|
|
1453
|
-
case "boolean":
|
|
1454
|
-
argOut = new Argument("boolean", arg);
|
|
1455
|
-
break;
|
|
1456
|
-
default: throw new Error(`don't know how to encode ${arg}`);
|
|
1457
|
-
}
|
|
1458
|
-
if (argOut) this.args.push(argOut);
|
|
1459
|
-
}
|
|
1460
|
-
};
|
|
1461
|
-
var Message_default = Message;
|
|
1462
|
-
|
|
1463
|
-
//#endregion
|
|
1464
|
-
//#region node_modules/node-osc/lib/osc.mjs
|
|
1465
|
-
function padString(str) {
|
|
1466
|
-
const nullTerminated = str + "\0";
|
|
1467
|
-
const padding = (4 - node_buffer.Buffer.byteLength(nullTerminated) % 4) % 4;
|
|
1468
|
-
return nullTerminated + "\0".repeat(padding);
|
|
1469
|
-
}
|
|
1470
|
-
function readString(buffer, offset) {
|
|
1471
|
-
let end = offset;
|
|
1472
|
-
while (end < buffer.length && buffer[end] !== 0) end++;
|
|
1473
|
-
if (end >= buffer.length) throw new Error("Malformed Packet: Missing null terminator for string");
|
|
1474
|
-
return {
|
|
1475
|
-
value: buffer.subarray(offset, end).toString("utf8"),
|
|
1476
|
-
offset: offset + Math.ceil((end - offset + 1) / 4) * 4
|
|
1477
|
-
};
|
|
1478
|
-
}
|
|
1479
|
-
function writeInt32(value) {
|
|
1480
|
-
const buffer = node_buffer.Buffer.alloc(4);
|
|
1481
|
-
buffer.writeInt32BE(value, 0);
|
|
1482
|
-
return buffer;
|
|
1483
|
-
}
|
|
1484
|
-
function readInt32(buffer, offset) {
|
|
1485
|
-
if (offset + 4 > buffer.length) throw new Error("Malformed Packet: Not enough bytes for int32");
|
|
1486
|
-
return {
|
|
1487
|
-
value: buffer.readInt32BE(offset),
|
|
1488
|
-
offset: offset + 4
|
|
1489
|
-
};
|
|
1490
|
-
}
|
|
1491
|
-
function writeFloat32(value) {
|
|
1492
|
-
const buffer = node_buffer.Buffer.alloc(4);
|
|
1493
|
-
buffer.writeFloatBE(value, 0);
|
|
1494
|
-
return buffer;
|
|
1495
|
-
}
|
|
1496
|
-
function readFloat32(buffer, offset) {
|
|
1497
|
-
if (offset + 4 > buffer.length) throw new Error("Malformed Packet: Not enough bytes for float32");
|
|
1498
|
-
return {
|
|
1499
|
-
value: buffer.readFloatBE(offset),
|
|
1500
|
-
offset: offset + 4
|
|
1501
|
-
};
|
|
1502
|
-
}
|
|
1503
|
-
function writeBlob(value) {
|
|
1504
|
-
const length = value.length;
|
|
1505
|
-
const lengthBuffer = writeInt32(length);
|
|
1506
|
-
const padding = 4 - length % 4;
|
|
1507
|
-
const paddingBuffer = node_buffer.Buffer.alloc(padding === 4 ? 0 : padding);
|
|
1508
|
-
return node_buffer.Buffer.concat([
|
|
1509
|
-
lengthBuffer,
|
|
1510
|
-
value,
|
|
1511
|
-
paddingBuffer
|
|
1512
|
-
]);
|
|
1513
|
-
}
|
|
1514
|
-
function readBlob(buffer, offset) {
|
|
1515
|
-
const lengthResult = readInt32(buffer, offset);
|
|
1516
|
-
const length = lengthResult.value;
|
|
1517
|
-
if (length < 0) throw new Error("Malformed Packet: Invalid blob length");
|
|
1518
|
-
if (lengthResult.offset + length > buffer.length) throw new Error("Malformed Packet: Not enough bytes for blob");
|
|
1519
|
-
const data = buffer.subarray(lengthResult.offset, lengthResult.offset + length);
|
|
1520
|
-
const padding = 4 - length % 4;
|
|
1521
|
-
const nextOffset = lengthResult.offset + length + (padding === 4 ? 0 : padding);
|
|
1522
|
-
if (nextOffset > buffer.length) throw new Error("Malformed Packet: Not enough bytes for blob padding");
|
|
1523
|
-
return {
|
|
1524
|
-
value: data,
|
|
1525
|
-
offset: nextOffset
|
|
1526
|
-
};
|
|
1527
|
-
}
|
|
1528
|
-
function writeTimeTag(value) {
|
|
1529
|
-
const buffer = node_buffer.Buffer.alloc(8);
|
|
1530
|
-
if (value === 0 || value === null || value === void 0) {
|
|
1531
|
-
buffer.writeUInt32BE(0, 0);
|
|
1532
|
-
buffer.writeUInt32BE(1, 4);
|
|
1533
|
-
} else if (typeof value === "number") {
|
|
1534
|
-
const seconds = Math.floor(value);
|
|
1535
|
-
const fraction = Math.floor((value - seconds) * 4294967296);
|
|
1536
|
-
buffer.writeUInt32BE(seconds + 2208988800, 0);
|
|
1537
|
-
buffer.writeUInt32BE(fraction, 4);
|
|
1538
|
-
} else {
|
|
1539
|
-
buffer.writeUInt32BE(0, 0);
|
|
1540
|
-
buffer.writeUInt32BE(1, 4);
|
|
1541
|
-
}
|
|
1542
|
-
return buffer;
|
|
1543
|
-
}
|
|
1544
|
-
function readTimeTag(buffer, offset) {
|
|
1545
|
-
if (offset + 8 > buffer.length) throw new Error("Malformed Packet: Not enough bytes for timetag");
|
|
1546
|
-
const seconds = buffer.readUInt32BE(offset);
|
|
1547
|
-
const fraction = buffer.readUInt32BE(offset + 4);
|
|
1548
|
-
let value;
|
|
1549
|
-
if (seconds === 0 && fraction === 1) value = 0;
|
|
1550
|
-
else value = seconds - 2208988800 + fraction / 4294967296;
|
|
1551
|
-
return {
|
|
1552
|
-
value,
|
|
1553
|
-
offset: offset + 8
|
|
1554
|
-
};
|
|
1555
|
-
}
|
|
1556
|
-
function writeMidi(value) {
|
|
1557
|
-
const buffer = node_buffer.Buffer.alloc(4);
|
|
1558
|
-
if (node_buffer.Buffer.isBuffer(value)) {
|
|
1559
|
-
if (value.length !== 4) throw new Error("MIDI message must be exactly 4 bytes");
|
|
1560
|
-
value.copy(buffer);
|
|
1561
|
-
} else if (typeof value === "object" && value !== null) {
|
|
1562
|
-
buffer.writeUInt8(value.port || 0, 0);
|
|
1563
|
-
buffer.writeUInt8(value.status || 0, 1);
|
|
1564
|
-
buffer.writeUInt8(value.data1 || 0, 2);
|
|
1565
|
-
buffer.writeUInt8(value.data2 || 0, 3);
|
|
1566
|
-
} else throw new Error("MIDI value must be a 4-byte Buffer or object with port, status, data1, data2 properties");
|
|
1567
|
-
return buffer;
|
|
1568
|
-
}
|
|
1569
|
-
function readMidi(buffer, offset) {
|
|
1570
|
-
if (offset + 4 > buffer.length) throw new Error("Not enough bytes for MIDI message");
|
|
1571
|
-
return {
|
|
1572
|
-
value: buffer.subarray(offset, offset + 4),
|
|
1573
|
-
offset: offset + 4
|
|
1574
|
-
};
|
|
1575
|
-
}
|
|
1576
|
-
function encodeArgument(arg) {
|
|
1577
|
-
if (typeof arg === "object" && arg.type && arg.value !== void 0) switch (arg.type) {
|
|
1578
|
-
case "i":
|
|
1579
|
-
case "integer": return {
|
|
1580
|
-
tag: "i",
|
|
1581
|
-
data: writeInt32(arg.value)
|
|
1582
|
-
};
|
|
1583
|
-
case "f":
|
|
1584
|
-
case "float": return {
|
|
1585
|
-
tag: "f",
|
|
1586
|
-
data: writeFloat32(arg.value)
|
|
1587
|
-
};
|
|
1588
|
-
case "s":
|
|
1589
|
-
case "string": return {
|
|
1590
|
-
tag: "s",
|
|
1591
|
-
data: node_buffer.Buffer.from(padString(arg.value))
|
|
1592
|
-
};
|
|
1593
|
-
case "b":
|
|
1594
|
-
case "blob": return {
|
|
1595
|
-
tag: "b",
|
|
1596
|
-
data: writeBlob(arg.value)
|
|
1597
|
-
};
|
|
1598
|
-
case "d":
|
|
1599
|
-
case "double": return {
|
|
1600
|
-
tag: "f",
|
|
1601
|
-
data: writeFloat32(arg.value)
|
|
1602
|
-
};
|
|
1603
|
-
case "T": return {
|
|
1604
|
-
tag: "T",
|
|
1605
|
-
data: node_buffer.Buffer.alloc(0)
|
|
1606
|
-
};
|
|
1607
|
-
case "F": return {
|
|
1608
|
-
tag: "F",
|
|
1609
|
-
data: node_buffer.Buffer.alloc(0)
|
|
1610
|
-
};
|
|
1611
|
-
case "boolean": return arg.value ? {
|
|
1612
|
-
tag: "T",
|
|
1613
|
-
data: node_buffer.Buffer.alloc(0)
|
|
1614
|
-
} : {
|
|
1615
|
-
tag: "F",
|
|
1616
|
-
data: node_buffer.Buffer.alloc(0)
|
|
1617
|
-
};
|
|
1618
|
-
case "m":
|
|
1619
|
-
case "midi": return {
|
|
1620
|
-
tag: "m",
|
|
1621
|
-
data: writeMidi(arg.value)
|
|
1622
|
-
};
|
|
1623
|
-
default: throw new Error(`Unknown argument type: ${arg.type}`);
|
|
1624
|
-
}
|
|
1625
|
-
switch (typeof arg) {
|
|
1626
|
-
case "number": if (Number.isInteger(arg)) return {
|
|
1627
|
-
tag: "i",
|
|
1628
|
-
data: writeInt32(arg)
|
|
1629
|
-
};
|
|
1630
|
-
else return {
|
|
1631
|
-
tag: "f",
|
|
1632
|
-
data: writeFloat32(arg)
|
|
1633
|
-
};
|
|
1634
|
-
case "string": return {
|
|
1635
|
-
tag: "s",
|
|
1636
|
-
data: node_buffer.Buffer.from(padString(arg))
|
|
1637
|
-
};
|
|
1638
|
-
case "boolean": return arg ? {
|
|
1639
|
-
tag: "T",
|
|
1640
|
-
data: node_buffer.Buffer.alloc(0)
|
|
1641
|
-
} : {
|
|
1642
|
-
tag: "F",
|
|
1643
|
-
data: node_buffer.Buffer.alloc(0)
|
|
1644
|
-
};
|
|
1645
|
-
default:
|
|
1646
|
-
if (node_buffer.Buffer.isBuffer(arg)) return {
|
|
1647
|
-
tag: "b",
|
|
1648
|
-
data: writeBlob(arg)
|
|
1649
|
-
};
|
|
1650
|
-
throw new Error(`Don't know how to encode argument: ${arg}`);
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
function decodeArgument(tag, buffer, offset) {
|
|
1654
|
-
switch (tag) {
|
|
1655
|
-
case "i": return readInt32(buffer, offset);
|
|
1656
|
-
case "f": return readFloat32(buffer, offset);
|
|
1657
|
-
case "s": return readString(buffer, offset);
|
|
1658
|
-
case "b": return readBlob(buffer, offset);
|
|
1659
|
-
case "T": return {
|
|
1660
|
-
value: true,
|
|
1661
|
-
offset
|
|
1662
|
-
};
|
|
1663
|
-
case "F": return {
|
|
1664
|
-
value: false,
|
|
1665
|
-
offset
|
|
1666
|
-
};
|
|
1667
|
-
case "N": return {
|
|
1668
|
-
value: null,
|
|
1669
|
-
offset
|
|
1670
|
-
};
|
|
1671
|
-
case "m": return readMidi(buffer, offset);
|
|
1672
|
-
default: throw new Error(`I don't understand the argument code ${tag}`);
|
|
1673
|
-
}
|
|
1674
|
-
}
|
|
1675
|
-
/**
|
|
1676
|
-
* Encode an OSC message or bundle to a Buffer.
|
|
1677
|
-
*
|
|
1678
|
-
* This low-level function converts OSC messages and bundles into binary format
|
|
1679
|
-
* for transmission or storage. Useful for sending OSC over custom transports
|
|
1680
|
-
* (WebSocket, TCP, HTTP), storing to files, or implementing custom OSC routers.
|
|
1681
|
-
*
|
|
1682
|
-
* @param {Object} message - OSC message or bundle object with oscType property
|
|
1683
|
-
* @returns {Buffer} The encoded OSC data ready for transmission
|
|
1684
|
-
*
|
|
1685
|
-
* @example
|
|
1686
|
-
* // Encode a message
|
|
1687
|
-
* import { Message, encode } from 'node-osc';
|
|
1688
|
-
*
|
|
1689
|
-
* const message = new Message('/oscillator/frequency', 440);
|
|
1690
|
-
* const buffer = encode(message);
|
|
1691
|
-
* console.log('Encoded bytes:', buffer.length);
|
|
1692
|
-
*
|
|
1693
|
-
* @example
|
|
1694
|
-
* // Encode a bundle
|
|
1695
|
-
* import { Bundle, encode } from 'node-osc';
|
|
1696
|
-
*
|
|
1697
|
-
* const bundle = new Bundle(['/one', 1], ['/two', 2]);
|
|
1698
|
-
* const buffer = encode(bundle);
|
|
1699
|
-
*
|
|
1700
|
-
* @example
|
|
1701
|
-
* // Send over WebSocket
|
|
1702
|
-
* const buffer = encode(message);
|
|
1703
|
-
* websocket.send(buffer);
|
|
1704
|
-
*/
|
|
1705
|
-
function encode(message) {
|
|
1706
|
-
if (message.oscType === "bundle") return encodeBundleToBuffer(message);
|
|
1707
|
-
else return encodeMessageToBuffer(message);
|
|
1708
|
-
}
|
|
1709
|
-
function encodeMessageToBuffer(message) {
|
|
1710
|
-
const address = padString(message.address);
|
|
1711
|
-
const addressBuffer = node_buffer.Buffer.from(address);
|
|
1712
|
-
const encodedArgs = message.args.map(encodeArgument);
|
|
1713
|
-
const typeTags$1 = "," + encodedArgs.map((arg) => arg.tag).join("");
|
|
1714
|
-
const typeTagsBuffer = node_buffer.Buffer.from(padString(typeTags$1));
|
|
1715
|
-
const argumentBuffers = encodedArgs.map((arg) => arg.data);
|
|
1716
|
-
return node_buffer.Buffer.concat([
|
|
1717
|
-
addressBuffer,
|
|
1718
|
-
typeTagsBuffer,
|
|
1719
|
-
...argumentBuffers
|
|
1720
|
-
]);
|
|
1721
|
-
}
|
|
1722
|
-
function encodeBundleToBuffer(bundle) {
|
|
1723
|
-
const bundleString = padString("#bundle");
|
|
1724
|
-
const bundleStringBuffer = node_buffer.Buffer.from(bundleString);
|
|
1725
|
-
const timetagBuffer = writeTimeTag(bundle.timetag);
|
|
1726
|
-
const elementBuffers = bundle.elements.map((element) => {
|
|
1727
|
-
let elementBuffer;
|
|
1728
|
-
if (element.oscType === "bundle") elementBuffer = encodeBundleToBuffer(element);
|
|
1729
|
-
else elementBuffer = encodeMessageToBuffer(element);
|
|
1730
|
-
const sizeBuffer = writeInt32(elementBuffer.length);
|
|
1731
|
-
return node_buffer.Buffer.concat([sizeBuffer, elementBuffer]);
|
|
1732
|
-
});
|
|
1733
|
-
return node_buffer.Buffer.concat([
|
|
1734
|
-
bundleStringBuffer,
|
|
1735
|
-
timetagBuffer,
|
|
1736
|
-
...elementBuffers
|
|
1737
|
-
]);
|
|
1738
|
-
}
|
|
1739
|
-
/**
|
|
1740
|
-
* Decode a Buffer containing OSC data into a message or bundle object.
|
|
1741
|
-
*
|
|
1742
|
-
* This low-level function parses binary OSC data back into JavaScript objects.
|
|
1743
|
-
* Useful for receiving OSC over custom transports, reading from files,
|
|
1744
|
-
* or implementing custom OSC routers.
|
|
1745
|
-
*
|
|
1746
|
-
* @param {Buffer} buffer - The Buffer containing OSC data
|
|
1747
|
-
* @returns {Object} The decoded OSC message or bundle. Messages have
|
|
1748
|
-
* {oscType: 'message', address: string, args: Array}, bundles have
|
|
1749
|
-
* {oscType: 'bundle', timetag: number, elements: Array}
|
|
1750
|
-
* @throws {Error} If the buffer contains malformed OSC data
|
|
1751
|
-
*
|
|
1752
|
-
* @example
|
|
1753
|
-
* // Decode received data
|
|
1754
|
-
* import { decode } from 'node-osc';
|
|
1755
|
-
*
|
|
1756
|
-
* const decoded = decode(buffer);
|
|
1757
|
-
* if (decoded.oscType === 'message') {
|
|
1758
|
-
* console.log('Address:', decoded.address);
|
|
1759
|
-
* console.log('Arguments:', decoded.args);
|
|
1760
|
-
* }
|
|
1761
|
-
*
|
|
1762
|
-
* @example
|
|
1763
|
-
* // Round-trip encode/decode
|
|
1764
|
-
* import { Message, encode, decode } from 'node-osc';
|
|
1765
|
-
*
|
|
1766
|
-
* const original = new Message('/test', 42, 'hello');
|
|
1767
|
-
* const buffer = encode(original);
|
|
1768
|
-
* const decoded = decode(buffer);
|
|
1769
|
-
* console.log(decoded.address); // '/test'
|
|
1770
|
-
*/
|
|
1771
|
-
function decode(buffer) {
|
|
1772
|
-
if (buffer.length >= 8 && buffer.subarray(0, 8).toString() === "#bundle\0") return decodeBundleFromBuffer(buffer);
|
|
1773
|
-
else return decodeMessageFromBuffer(buffer);
|
|
1774
|
-
}
|
|
1775
|
-
function decodeMessageFromBuffer(buffer) {
|
|
1776
|
-
let offset = 0;
|
|
1777
|
-
const addressResult = readString(buffer, offset);
|
|
1778
|
-
const address = addressResult.value;
|
|
1779
|
-
offset = addressResult.offset;
|
|
1780
|
-
const typeTagsResult = readString(buffer, offset);
|
|
1781
|
-
const typeTags$1 = typeTagsResult.value;
|
|
1782
|
-
offset = typeTagsResult.offset;
|
|
1783
|
-
if (!typeTags$1.startsWith(",")) throw new Error("Malformed Packet");
|
|
1784
|
-
const tags = typeTags$1.slice(1);
|
|
1785
|
-
const args = [];
|
|
1786
|
-
for (const tag of tags) {
|
|
1787
|
-
const argResult = decodeArgument(tag, buffer, offset);
|
|
1788
|
-
args.push({ value: argResult.value });
|
|
1789
|
-
offset = argResult.offset;
|
|
1790
|
-
}
|
|
1791
|
-
return {
|
|
1792
|
-
oscType: "message",
|
|
1793
|
-
address,
|
|
1794
|
-
args
|
|
1795
|
-
};
|
|
1796
|
-
}
|
|
1797
|
-
function decodeBundleFromBuffer(buffer) {
|
|
1798
|
-
let offset = 8;
|
|
1799
|
-
const timetagResult = readTimeTag(buffer, offset);
|
|
1800
|
-
const timetag = timetagResult.value;
|
|
1801
|
-
offset = timetagResult.offset;
|
|
1802
|
-
const elements = [];
|
|
1803
|
-
while (offset < buffer.length) {
|
|
1804
|
-
const sizeResult = readInt32(buffer, offset);
|
|
1805
|
-
const size = sizeResult.value;
|
|
1806
|
-
offset = sizeResult.offset;
|
|
1807
|
-
if (size <= 0 || offset + size > buffer.length) throw new Error("Malformed Packet");
|
|
1808
|
-
const element = decode(buffer.subarray(offset, offset + size));
|
|
1809
|
-
elements.push(element);
|
|
1810
|
-
offset += size;
|
|
1811
|
-
}
|
|
1812
|
-
return {
|
|
1813
|
-
oscType: "bundle",
|
|
1814
|
-
timetag,
|
|
1815
|
-
elements
|
|
1816
|
-
};
|
|
1817
|
-
}
|
|
1818
|
-
|
|
1819
|
-
//#endregion
|
|
1820
|
-
//#region src/infrastructure/mappers/OscCodec.ts
|
|
1821
|
-
/**
|
|
1822
|
-
* Handles encoding and decoding of X32 OSC messages.
|
|
1823
|
-
*/
|
|
1824
|
-
var OscCodec = class {
|
|
1825
|
-
constructor(schemaRegistry) {
|
|
1826
|
-
this.schemaRegistry = schemaRegistry;
|
|
1827
|
-
}
|
|
1828
|
-
/**
|
|
1829
|
-
* Decodes a binary OSC message into a packet object.
|
|
1830
|
-
* @param msg - Raw UDP buffer.
|
|
1831
|
-
* @returns Decoded OscPacket.
|
|
1832
|
-
*/
|
|
1833
|
-
decode(msg) {
|
|
1834
|
-
return decode(msg);
|
|
1835
|
-
}
|
|
1836
|
-
/**
|
|
1837
|
-
* Encodes an address and arguments into a binary OSC message.
|
|
1838
|
-
* @param address - OSC address pattern.
|
|
1839
|
-
* @param args - Array of arguments.
|
|
1840
|
-
* @returns Binary buffer.
|
|
1841
|
-
*/
|
|
1842
|
-
encode(address, args) {
|
|
1843
|
-
return encode(this.createMessage(address, args));
|
|
1844
|
-
}
|
|
1845
|
-
/**
|
|
1846
|
-
* Creates a typed node-osc Message based on X32 schema.
|
|
1847
|
-
* @param address - Target address.
|
|
1848
|
-
* @param args - Untyped arguments.
|
|
1849
|
-
* @returns Typed Message.
|
|
1850
|
-
*/
|
|
1851
|
-
createMessage(address, args) {
|
|
1852
|
-
return new Message_default(address, ...args.map((arg) => {
|
|
1853
|
-
if (typeof arg === "object" && arg !== null && "type" in arg && "value" in arg) return arg;
|
|
1854
|
-
if (Buffer.isBuffer(arg)) return arg;
|
|
1855
|
-
const node = this.schemaRegistry.getNode(address);
|
|
1856
|
-
if (node) {
|
|
1857
|
-
if (node.type === "f" && typeof arg === "number") return {
|
|
1858
|
-
type: "f",
|
|
1859
|
-
value: arg
|
|
1860
|
-
};
|
|
1861
|
-
if (node.type === "i" && typeof arg === "number") return {
|
|
1862
|
-
type: "i",
|
|
1863
|
-
value: Math.round(arg)
|
|
1864
|
-
};
|
|
1865
|
-
if (node.type === "s" && typeof arg === "string") return {
|
|
1866
|
-
type: "s",
|
|
1867
|
-
value: arg
|
|
1868
|
-
};
|
|
1869
|
-
}
|
|
1870
|
-
return arg;
|
|
1871
|
-
}));
|
|
1872
|
-
}
|
|
1873
|
-
};
|
|
1874
|
-
|
|
1875
|
-
//#endregion
|
|
1876
|
-
//#region src/domain/services/SchemaFactory.ts
|
|
1877
|
-
/**
|
|
1878
|
-
* Factory service responsible for constructing the X32 OSC Schema.
|
|
1879
|
-
* Encapsulates all the logic for generating channel strips, routing blocks, etc.
|
|
1880
|
-
*/
|
|
1881
|
-
var SchemaFactory = class {
|
|
1882
|
-
/**
|
|
1883
|
-
* Builds the complete X32 OSC Schema.
|
|
1884
|
-
* @returns The constructed schema map.
|
|
1885
|
-
*/
|
|
1886
|
-
createSchema() {
|
|
1887
|
-
const schema = {
|
|
1888
|
-
...this.generateNodes(32, "ch"),
|
|
1889
|
-
...this.generateNodes(16, "bus"),
|
|
1890
|
-
...this.generateNodes(8, "dca"),
|
|
1891
|
-
...this.generateNodes(8, "auxin"),
|
|
1892
|
-
...this.generateNodes(8, "fxrtn"),
|
|
1893
|
-
...this.generateNodes(6, "mtx"),
|
|
1894
|
-
...Object.fromEntries(Array.from({ length: 8 }, (_, i) => [`/fx/${i + 1}/type`, this.node("i", 0)])),
|
|
1895
|
-
...this.generateRange(8, "/fx", "/type", "i", 0),
|
|
1896
|
-
...this.generateRange(8, "/fx", "/source/l", "i", 0),
|
|
1897
|
-
...this.generateRange(8, "/fx", "/source/r", "i", 0),
|
|
1898
|
-
...Object.fromEntries(Array.from({ length: 8 }, (_, slot) => Object.entries(this.generateRange(64, `/fx/${slot + 1}/par`, "", "f", 0, 2, 1))).flat()),
|
|
1899
|
-
...this.generateRange(128, "/headamp", "/gain", "f", 0, 3, 0),
|
|
1900
|
-
...this.generateRange(128, "/headamp", "/phantom", "i", 0, 3, 0),
|
|
1901
|
-
...this.generateRange(6, "/config/mute", "", "i", 0),
|
|
1902
|
-
...this.generateRange(80, "/-stat/solosw", "", "i", 0),
|
|
1903
|
-
"/-stat/selidx": this.node("i", 0),
|
|
1904
|
-
"/-stat/sendsonfader": this.node("i", 0),
|
|
1905
|
-
"/-stat/bussendbank": this.node("i", 0),
|
|
1906
|
-
"/-stat/keysolo": this.node("i", 0),
|
|
1907
|
-
"/-stat/screen/screen": this.node("i", 0),
|
|
1908
|
-
"/-stat/screen/CHAN/page": this.node("i", 0),
|
|
1909
|
-
"/-stat/screen/METER/page": this.node("i", 0),
|
|
1910
|
-
"/-stat/screen/ROUTE/page": this.node("i", 0),
|
|
1911
|
-
"/-stat/screen/SETUP/page": this.node("i", 0),
|
|
1912
|
-
"/-stat/screen/LIBRARY/page": this.node("i", 0),
|
|
1913
|
-
"/-stat/screen/FX/page": this.node("i", 0),
|
|
1914
|
-
"/-stat/screen/MON/page": this.node("i", 0),
|
|
1915
|
-
"/-stat/screen/USB/page": this.node("i", 0),
|
|
1916
|
-
"/-stat/screen/SCENE/page": this.node("i", 0),
|
|
1917
|
-
"/-stat/screen/ASSIGN/page": this.node("i", 0),
|
|
1918
|
-
"/-stat/talk/A": this.node("i", 0),
|
|
1919
|
-
"/-stat/talk/B": this.node("i", 0),
|
|
1920
|
-
"/-stat/osc/on": this.node("i", 0),
|
|
1921
|
-
"/-prefs/autosel": this.node("i", 1),
|
|
1922
|
-
"/-action/setrtasrc": this.node("i", 0),
|
|
1923
|
-
"/-action/playtrack": this.node("i", 0),
|
|
1924
|
-
"/-action/goscene": this.node("i", 0),
|
|
1925
|
-
"/-action/setscene": this.node("i", 0),
|
|
1926
|
-
"/config/routing/AES50A/1-8": this.node("i", 0),
|
|
1927
|
-
"/config/routing/AES50B/1-8": this.node("i", 0),
|
|
1928
|
-
"/config/routing/CARD/1-8": this.node("i", 0),
|
|
1929
|
-
"/config/routing/OUT/1-4": this.node("i", 0),
|
|
1930
|
-
"/-prefs/invertmutes": this.node("i", 0),
|
|
1931
|
-
...this.generateChannelStrip("/main/st", 6, false),
|
|
1932
|
-
...this.generateChannelStrip("/main/m", 6, false),
|
|
1933
|
-
...Object.fromEntries(Array.from({ length: 16 }, (_, i) => [`/config/chlink/${i * 2 + 1}-${i * 2 + 2}`, this.node("i", 0)])),
|
|
1934
|
-
...Object.fromEntries(Array.from({ length: 8 }, (_, i) => [`/config/buslink/${i * 2 + 1}-${i * 2 + 2}`, this.node("i", 0)])),
|
|
1935
|
-
...Object.fromEntries(Array.from({ length: 4 }, (_, i) => [`/config/auxlink/${i * 2 + 1}-${i * 2 + 2}`, this.node("i", 0)])),
|
|
1936
|
-
...Object.fromEntries(Array.from({ length: 4 }, (_, i) => [`/config/fxlink/${i * 2 + 1}-${i * 2 + 2}`, this.node("i", 0)])),
|
|
1937
|
-
...this.generateRange(32, "/config/userrout/in", "", "i", 0),
|
|
1938
|
-
...this.generateRange(48, "/config/userrout/out", "", "i", 0),
|
|
1939
|
-
"/config/solo/level": this.node("f", 0),
|
|
1940
|
-
"/config/solo/source": this.node("i", 0),
|
|
1941
|
-
"/config/solo/sourcetrim": this.node("f", 0),
|
|
1942
|
-
"/config/solo/exclusive": this.node("i", 0),
|
|
1943
|
-
"/config/solo/dim": this.node("i", 0),
|
|
1944
|
-
"/config/solo/dimpfl": this.node("i", 0),
|
|
1945
|
-
"/config/solo/dimatt": this.node("f", 0),
|
|
1946
|
-
"/config/solo/mono": this.node("i", 0),
|
|
1947
|
-
"/config/solo/chmode": this.node("i", 0),
|
|
1948
|
-
"/config/solo/busmode": this.node("i", 0),
|
|
1949
|
-
"/config/solo/dcamode": this.node("i", 0),
|
|
1950
|
-
"/config/solo/masterctrl": this.node("i", 0),
|
|
1951
|
-
"/config/solo/delay": this.node("i", 0),
|
|
1952
|
-
"/config/solo/delaytime": this.node("f", 0),
|
|
1953
|
-
"/config/solo/followsel": this.node("i", 0),
|
|
1954
|
-
"/config/solo/followsolo": this.node("i", 0),
|
|
1955
|
-
"/config/talk/enable": this.node("i", 0),
|
|
1956
|
-
"/config/talk/source": this.node("i", 0),
|
|
1957
|
-
"/config/talk/A/level": this.node("f", 0),
|
|
1958
|
-
"/config/talk/B/level": this.node("f", 0),
|
|
1959
|
-
"/config/talk/A/dim": this.node("i", 0),
|
|
1960
|
-
"/config/talk/B/dim": this.node("i", 0),
|
|
1961
|
-
"/config/talk/A/latch": this.node("i", 0),
|
|
1962
|
-
"/config/talk/B/latch": this.node("i", 0),
|
|
1963
|
-
"/config/talk/A/destmap": this.node("i", 0),
|
|
1964
|
-
"/config/talk/B/destmap": this.node("i", 0),
|
|
1965
|
-
"/config/osc/on": this.node("i", 0),
|
|
1966
|
-
"/config/osc/type": this.node("i", 0),
|
|
1967
|
-
"/config/osc/fsel": this.node("i", 0),
|
|
1968
|
-
"/config/osc/f1": this.node("f", .5),
|
|
1969
|
-
"/config/osc/f2": this.node("f", .5),
|
|
1970
|
-
"/config/osc/level": this.node("f", 0),
|
|
1971
|
-
"/config/osc/dest": this.node("i", 0),
|
|
1972
|
-
...this.generateOutputs("main", 16),
|
|
1973
|
-
...this.generateOutputs("aux", 6),
|
|
1974
|
-
...this.generateOutputs("p16", 16),
|
|
1975
|
-
...this.generateOutputs("aes", 2),
|
|
1976
|
-
...this.generateOutputs("rec", 2)
|
|
1977
|
-
};
|
|
1978
|
-
Object.keys(STATIC_RESPONSES_DATA).forEach((key) => {
|
|
1979
|
-
if (key.startsWith("/-") || key.startsWith("/stat")) {
|
|
1980
|
-
const val = STATIC_RESPONSES_DATA[key][0];
|
|
1981
|
-
const type = typeof val === "string" ? "s" : Number.isInteger(val) ? "i" : "f";
|
|
1982
|
-
schema[key] = this.node(type, val);
|
|
1983
|
-
}
|
|
1984
|
-
});
|
|
1985
|
-
[
|
|
1986
|
-
"/config/routing/IN/1-8",
|
|
1987
|
-
"/config/routing/IN/9-16",
|
|
1988
|
-
"/config/routing/IN/17-24",
|
|
1989
|
-
"/config/routing/IN/25-32",
|
|
1990
|
-
"/config/routing/AUX/1-4",
|
|
1991
|
-
"/config/routing/OUT/1-4",
|
|
1992
|
-
"/config/routing/OUT/5-8",
|
|
1993
|
-
"/config/routing/OUT/9-12",
|
|
1994
|
-
"/config/routing/OUT/13-16",
|
|
1995
|
-
"/config/routing/P16/1-8",
|
|
1996
|
-
"/config/routing/P16/9-16",
|
|
1997
|
-
"/config/routing/CARD/1-8",
|
|
1998
|
-
"/config/routing/CARD/9-16",
|
|
1999
|
-
"/config/routing/CARD/17-24",
|
|
2000
|
-
"/config/routing/CARD/25-32",
|
|
2001
|
-
"/config/routing/AES50A/1-8",
|
|
2002
|
-
"/config/routing/AES50A/9-16",
|
|
2003
|
-
"/config/routing/AES50A/17-24",
|
|
2004
|
-
"/config/routing/AES50A/25-32",
|
|
2005
|
-
"/config/routing/AES50A/33-40",
|
|
2006
|
-
"/config/routing/AES50A/41-48",
|
|
2007
|
-
"/config/routing/AES50B/1-8",
|
|
2008
|
-
"/config/routing/AES50B/9-16",
|
|
2009
|
-
"/config/routing/AES50B/17-24",
|
|
2010
|
-
"/config/routing/AES50B/25-32",
|
|
2011
|
-
"/config/routing/AES50B/33-40",
|
|
2012
|
-
"/config/routing/AES50B/41-48",
|
|
2013
|
-
"/config/routing/PLAY/1-8",
|
|
2014
|
-
"/config/routing/PLAY/9-16",
|
|
2015
|
-
"/config/routing/PLAY/17-24",
|
|
2016
|
-
"/config/routing/PLAY/25-32"
|
|
2017
|
-
].forEach((path) => {
|
|
2018
|
-
schema[path] = this.node("i", 0);
|
|
2019
|
-
});
|
|
2020
|
-
return schema;
|
|
2021
|
-
}
|
|
2022
|
-
node(type, def) {
|
|
2023
|
-
return new X32Node(type, def);
|
|
2024
|
-
}
|
|
2025
|
-
generateChannelStrip(base, eqBands = 4, hasPreamp = false) {
|
|
2026
|
-
const nodes = {};
|
|
2027
|
-
nodes[`${base}/config/name`] = this.node("s", base.split("/").pop()?.toUpperCase() || "");
|
|
2028
|
-
nodes[`${base}/config/icon`] = this.node("i", 1);
|
|
2029
|
-
nodes[`${base}/config/color`] = this.node("i", 1);
|
|
2030
|
-
nodes[`${base}/config/source`] = this.node("i", 1);
|
|
2031
|
-
nodes[`${base}/mix/fader`] = this.node("f", .75);
|
|
2032
|
-
nodes[`${base}/mix/on`] = this.node("i", 0);
|
|
2033
|
-
nodes[`${base}/mix/pan`] = this.node("f", .5);
|
|
2034
|
-
nodes[`${base}/mix/mono`] = this.node("i", 0);
|
|
2035
|
-
nodes[`${base}/mix/mlevel`] = this.node("f", 0);
|
|
2036
|
-
nodes[`${base}/mix/st`] = this.node("i", 1);
|
|
2037
|
-
if (hasPreamp) {
|
|
2038
|
-
nodes[`${base}/preamp/trim`] = this.node("f", .5);
|
|
2039
|
-
nodes[`${base}/preamp/hpon`] = this.node("i", 0);
|
|
2040
|
-
nodes[`${base}/preamp/hpf`] = this.node("f", 0);
|
|
2041
|
-
nodes[`${base}/preamp/phantom`] = this.node("i", 0);
|
|
2042
|
-
nodes[`${base}/preamp/rtnsw`] = this.node("i", 0);
|
|
2043
|
-
nodes[`${base}/preamp/invert`] = this.node("i", 0);
|
|
2044
|
-
}
|
|
2045
|
-
nodes[`${base}/delay/on`] = this.node("i", 0);
|
|
2046
|
-
nodes[`${base}/delay/time`] = this.node("f", 0);
|
|
2047
|
-
nodes[`${base}/insert/on`] = this.node("i", 0);
|
|
2048
|
-
nodes[`${base}/insert/pos`] = this.node("i", 0);
|
|
2049
|
-
nodes[`${base}/insert/sel`] = this.node("i", 0);
|
|
2050
|
-
nodes[`${base}/gate/on`] = this.node("i", 0);
|
|
2051
|
-
nodes[`${base}/gate/mode`] = this.node("i", 0);
|
|
2052
|
-
nodes[`${base}/gate/thr`] = this.node("f", 0);
|
|
2053
|
-
nodes[`${base}/gate/range`] = this.node("f", 0);
|
|
2054
|
-
nodes[`${base}/gate/attack`] = this.node("f", 0);
|
|
2055
|
-
nodes[`${base}/gate/hold`] = this.node("f", 0);
|
|
2056
|
-
nodes[`${base}/gate/release`] = this.node("f", 0);
|
|
2057
|
-
nodes[`${base}/gate/keysrc`] = this.node("i", 0);
|
|
2058
|
-
nodes[`${base}/gate/filter/on`] = this.node("i", 0);
|
|
2059
|
-
nodes[`${base}/gate/filter/type`] = this.node("i", 0);
|
|
2060
|
-
nodes[`${base}/gate/filter/f`] = this.node("f", .5);
|
|
2061
|
-
nodes[`${base}/dyn/on`] = this.node("i", 0);
|
|
2062
|
-
nodes[`${base}/dyn/mode`] = this.node("i", 0);
|
|
2063
|
-
nodes[`${base}/dyn/pos`] = this.node("i", 0);
|
|
2064
|
-
nodes[`${base}/dyn/det`] = this.node("i", 0);
|
|
2065
|
-
nodes[`${base}/dyn/env`] = this.node("i", 0);
|
|
2066
|
-
nodes[`${base}/dyn/thr`] = this.node("f", 0);
|
|
2067
|
-
nodes[`${base}/dyn/ratio`] = this.node("i", 0);
|
|
2068
|
-
nodes[`${base}/dyn/knee`] = this.node("f", 0);
|
|
2069
|
-
nodes[`${base}/dyn/mgain`] = this.node("f", 0);
|
|
2070
|
-
nodes[`${base}/dyn/attack`] = this.node("f", 0);
|
|
2071
|
-
nodes[`${base}/dyn/hold`] = this.node("f", 0);
|
|
2072
|
-
nodes[`${base}/dyn/release`] = this.node("f", 0);
|
|
2073
|
-
nodes[`${base}/dyn/mix`] = this.node("f", 1);
|
|
2074
|
-
nodes[`${base}/dyn/auto`] = this.node("i", 0);
|
|
2075
|
-
nodes[`${base}/dyn/keysrc`] = this.node("i", 0);
|
|
2076
|
-
nodes[`${base}/dyn/filter/on`] = this.node("i", 0);
|
|
2077
|
-
nodes[`${base}/dyn/filter/type`] = this.node("i", 0);
|
|
2078
|
-
nodes[`${base}/dyn/filter/f`] = this.node("f", .5);
|
|
2079
|
-
nodes[`${base}/eq/on`] = this.node("i", 0);
|
|
2080
|
-
nodes[`${base}/eq/mode`] = this.node("i", 0);
|
|
2081
|
-
for (let b = 1; b <= eqBands; b++) {
|
|
2082
|
-
nodes[`${base}/eq/${b}/type`] = this.node("i", 0);
|
|
2083
|
-
nodes[`${base}/eq/${b}/f`] = this.node("f", .5);
|
|
2084
|
-
nodes[`${base}/eq/${b}/g`] = this.node("f", .5);
|
|
2085
|
-
nodes[`${base}/eq/${b}/q`] = this.node("f", .5);
|
|
2086
|
-
}
|
|
2087
|
-
nodes[`${base}/grp/dca`] = this.node("i", 0);
|
|
2088
|
-
nodes[`${base}/grp/mute`] = this.node("i", 0);
|
|
2089
|
-
return nodes;
|
|
2090
|
-
}
|
|
2091
|
-
generateNodes(count, prefix) {
|
|
2092
|
-
const nodes = {};
|
|
2093
|
-
const isChannelOrAux = prefix === "ch" || prefix === "auxin";
|
|
2094
|
-
const eqBands = prefix === "bus" || prefix === "mtx" ? 6 : 4;
|
|
2095
|
-
for (let i = 1; i <= count; i++) {
|
|
2096
|
-
const padId = i.toString().padStart(2, "0");
|
|
2097
|
-
[i.toString(), padId].forEach((id) => {
|
|
2098
|
-
const base = `/${prefix}/${id}`;
|
|
2099
|
-
if (prefix === "dca") {
|
|
2100
|
-
nodes[`${base}/config/name`] = this.node("s", `DCA ${id}`);
|
|
2101
|
-
nodes[`${base}/config/color`] = this.node("i", 1);
|
|
2102
|
-
nodes[`${base}/fader`] = this.node("f", .75);
|
|
2103
|
-
nodes[`${base}/on`] = this.node("i", 0);
|
|
2104
|
-
} else {
|
|
2105
|
-
Object.assign(nodes, this.generateChannelStrip(base, eqBands, isChannelOrAux));
|
|
2106
|
-
if (prefix === "ch" || prefix === "auxin" || prefix === "fxrtn" || prefix === "bus") for (let b = 1; b <= 16; b++) {
|
|
2107
|
-
const busId = b.toString().padStart(2, "0");
|
|
2108
|
-
nodes[`${base}/mix/${busId}/level`] = this.node("f", 0);
|
|
2109
|
-
nodes[`${base}/mix/${busId}/on`] = this.node("i", 0);
|
|
2110
|
-
nodes[`${base}/mix/${busId}/pan`] = this.node("f", .5);
|
|
2111
|
-
nodes[`${base}/mix/${busId}/type`] = this.node("i", 0);
|
|
2112
|
-
}
|
|
2113
|
-
}
|
|
2114
|
-
});
|
|
2115
|
-
}
|
|
2116
|
-
return nodes;
|
|
2117
|
-
}
|
|
2118
|
-
generateRange(count, prefix, suffix, type, def, pad = 2, start = 1) {
|
|
2119
|
-
const nodes = {};
|
|
2120
|
-
for (let i = start; i < start + count; i++) {
|
|
2121
|
-
const id = i.toString().padStart(pad, "0");
|
|
2122
|
-
nodes[`${prefix}/${i}${suffix}`] = this.node(type, def);
|
|
2123
|
-
nodes[`${prefix}/${id}${suffix}`] = this.node(type, def);
|
|
2124
|
-
}
|
|
2125
|
-
return nodes;
|
|
2126
|
-
}
|
|
2127
|
-
generateOutputs(prefix, count) {
|
|
2128
|
-
const nodes = {};
|
|
2129
|
-
for (let i = 1; i <= count; i++) {
|
|
2130
|
-
const base = `/outputs/${prefix}/${i.toString().padStart(2, "0")}`;
|
|
2131
|
-
nodes[`${base}/src`] = this.node("i", 0);
|
|
2132
|
-
nodes[`${base}/pos`] = this.node("i", 0);
|
|
2133
|
-
nodes[`${base}/invert`] = this.node("i", 0);
|
|
2134
|
-
nodes[`${base}/delay/on`] = this.node("i", 0);
|
|
2135
|
-
nodes[`${base}/delay/time`] = this.node("f", 0);
|
|
2136
|
-
if (prefix === "p16") {
|
|
2137
|
-
nodes[`${base}/iQ/group`] = this.node("i", 0);
|
|
2138
|
-
nodes[`${base}/iQ/model`] = this.node("i", 0);
|
|
2139
|
-
nodes[`${base}/iQ/eq`] = this.node("i", 0);
|
|
2140
|
-
nodes[`${base}/iQ/speaker`] = this.node("i", 0);
|
|
2141
|
-
}
|
|
2142
|
-
}
|
|
2143
|
-
return nodes;
|
|
2144
|
-
}
|
|
2145
|
-
};
|
|
2146
|
-
|
|
2147
|
-
//#endregion
|
|
2148
|
-
//#region src/domain/services/SchemaRegistry.ts
|
|
2149
|
-
/**
|
|
2150
|
-
* Service providing access to the X32 OSC Schema.
|
|
2151
|
-
* Acts as the "Registry" of all available console parameters.
|
|
2152
|
-
*/
|
|
2153
|
-
var SchemaRegistry = class {
|
|
2154
|
-
_schema;
|
|
2155
|
-
constructor(schemaFactory) {
|
|
2156
|
-
this.schemaFactory = schemaFactory;
|
|
2157
|
-
this._schema = this.schemaFactory.createSchema();
|
|
2158
|
-
}
|
|
2159
|
-
/**
|
|
2160
|
-
* Retrieves the entire schema map.
|
|
2161
|
-
* @returns The internal schema definition record.
|
|
2162
|
-
*/
|
|
2163
|
-
getSchema() {
|
|
2164
|
-
return this._schema;
|
|
2165
|
-
}
|
|
2166
|
-
/**
|
|
2167
|
-
* Retrieves the node definition for a given path.
|
|
2168
|
-
* @param path - The OSC path.
|
|
2169
|
-
* @returns The X32Node definition or undefined if not found.
|
|
2170
|
-
*/
|
|
2171
|
-
getNode(path) {
|
|
2172
|
-
return this._schema[path];
|
|
2173
|
-
}
|
|
2174
|
-
/**
|
|
2175
|
-
* Checks if a path exists in the schema.
|
|
2176
|
-
* @param path - The path to check.
|
|
2177
|
-
* @returns True if the path is registered.
|
|
2178
|
-
*/
|
|
2179
|
-
has(path) {
|
|
2180
|
-
return path in this._schema;
|
|
2181
|
-
}
|
|
2182
|
-
/**
|
|
2183
|
-
* Returns all paths in the schema.
|
|
2184
|
-
* @returns Array of all registered OSC paths.
|
|
2185
|
-
*/
|
|
2186
|
-
getAllPaths() {
|
|
2187
|
-
return Object.keys(this._schema);
|
|
2188
|
-
}
|
|
2189
|
-
/**
|
|
2190
|
-
* Maps an absolute X32 global index to its specific OSC root path.
|
|
2191
|
-
* Used for batch subscriptions where clients request ranges of channels.
|
|
2192
|
-
* @param index - The absolute integer index.
|
|
2193
|
-
* @returns The root path string or null if index is out of bounds.
|
|
2194
|
-
*/
|
|
2195
|
-
getRootFromIndex(index) {
|
|
2196
|
-
if (index >= 0 && index <= 31) return `/ch/${(index + 1).toString().padStart(2, "0")}`;
|
|
2197
|
-
if (index >= 32 && index <= 39) return `/auxin/${(index - 31).toString().padStart(2, "0")}`;
|
|
2198
|
-
if (index >= 40 && index <= 47) return `/fxrtn/${(index - 39).toString().padStart(2, "0")}`;
|
|
2199
|
-
if (index >= 48 && index <= 63) return `/bus/${(index - 47).toString().padStart(2, "0")}`;
|
|
2200
|
-
if (index >= 64 && index <= 69) return `/mtx/${(index - 63).toString().padStart(2, "0")}`;
|
|
2201
|
-
if (index === 70) return "/main/st";
|
|
2202
|
-
if (index === 71) return "/main/m";
|
|
2203
|
-
if (index >= 72 && index <= 79) return `/dca/${(index - 71).toString().padStart(2, "0")}`;
|
|
2204
|
-
return null;
|
|
2205
|
-
}
|
|
2206
|
-
};
|
|
2207
|
-
|
|
2208
|
-
//#endregion
|
|
2209
|
-
Object.defineProperty(exports, 'ConsoleLogger', {
|
|
2210
|
-
enumerable: true,
|
|
2211
|
-
get: function () {
|
|
2212
|
-
return ConsoleLogger;
|
|
2213
|
-
}
|
|
2214
|
-
});
|
|
2215
|
-
Object.defineProperty(exports, 'InMemoryStateRepository', {
|
|
2216
|
-
enumerable: true,
|
|
2217
|
-
get: function () {
|
|
2218
|
-
return InMemoryStateRepository;
|
|
2219
|
-
}
|
|
2220
|
-
});
|
|
2221
|
-
Object.defineProperty(exports, 'LogCategory', {
|
|
2222
|
-
enumerable: true,
|
|
2223
|
-
get: function () {
|
|
2224
|
-
return LogCategory;
|
|
2225
|
-
}
|
|
2226
|
-
});
|
|
2227
|
-
Object.defineProperty(exports, 'LogLevel', {
|
|
2228
|
-
enumerable: true,
|
|
2229
|
-
get: function () {
|
|
2230
|
-
return LogLevel;
|
|
2231
|
-
}
|
|
2232
|
-
});
|
|
2233
|
-
Object.defineProperty(exports, 'METER_COUNTS', {
|
|
2234
|
-
enumerable: true,
|
|
2235
|
-
get: function () {
|
|
2236
|
-
return METER_COUNTS;
|
|
2237
|
-
}
|
|
2238
|
-
});
|
|
2239
|
-
Object.defineProperty(exports, 'MeterData', {
|
|
2240
|
-
enumerable: true,
|
|
2241
|
-
get: function () {
|
|
2242
|
-
return MeterData;
|
|
2243
|
-
}
|
|
2244
|
-
});
|
|
2245
|
-
Object.defineProperty(exports, 'OscCodec', {
|
|
2246
|
-
enumerable: true,
|
|
2247
|
-
get: function () {
|
|
2248
|
-
return OscCodec;
|
|
2249
|
-
}
|
|
2250
|
-
});
|
|
2251
|
-
Object.defineProperty(exports, 'SchemaFactory', {
|
|
2252
|
-
enumerable: true,
|
|
2253
|
-
get: function () {
|
|
2254
|
-
return SchemaFactory;
|
|
2255
|
-
}
|
|
2256
|
-
});
|
|
2257
|
-
Object.defineProperty(exports, 'SchemaRegistry', {
|
|
2258
|
-
enumerable: true,
|
|
2259
|
-
get: function () {
|
|
2260
|
-
return SchemaRegistry;
|
|
2261
|
-
}
|
|
2262
|
-
});
|
|
2263
|
-
Object.defineProperty(exports, 'SimulationService', {
|
|
2264
|
-
enumerable: true,
|
|
2265
|
-
get: function () {
|
|
2266
|
-
return SimulationService;
|
|
2267
|
-
}
|
|
2268
|
-
});
|
|
2269
|
-
Object.defineProperty(exports, 'SubscriptionManager', {
|
|
2270
|
-
enumerable: true,
|
|
2271
|
-
get: function () {
|
|
2272
|
-
return SubscriptionManager;
|
|
2273
|
-
}
|
|
2274
|
-
});
|
|
2275
|
-
Object.defineProperty(exports, 'UdpNetworkGateway', {
|
|
2276
|
-
enumerable: true,
|
|
2277
|
-
get: function () {
|
|
2278
|
-
return UdpNetworkGateway;
|
|
2279
|
-
}
|
|
2280
|
-
});
|
|
2281
|
-
Object.defineProperty(exports, 'X32Node', {
|
|
2282
|
-
enumerable: true,
|
|
2283
|
-
get: function () {
|
|
2284
|
-
return X32Node;
|
|
2285
|
-
}
|
|
2286
|
-
});
|
|
2287
|
-
Object.defineProperty(exports, 'X32State', {
|
|
2288
|
-
enumerable: true,
|
|
2289
|
-
get: function () {
|
|
2290
|
-
return X32State;
|
|
2291
|
-
}
|
|
2292
|
-
});
|
|
2293
|
-
Object.defineProperty(exports, '__toESM', {
|
|
2294
|
-
enumerable: true,
|
|
2295
|
-
get: function () {
|
|
2296
|
-
return __toESM;
|
|
2297
|
-
}
|
|
2298
|
-
});
|