@djodjonx/x32-simulator 0.0.7 → 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.
@@ -1,3389 +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 node_events = require("node:events");
29
- let os = require("os");
30
- os = __toESM(os);
31
- let node_dgram = require("node:dgram");
32
- node_dgram = __toESM(node_dgram);
33
- let node_buffer = require("node:buffer");
34
-
35
- //#region src/domain/ports/ILogger.ts
36
- /**
37
- * Standard log categories for the domain.
38
- */
39
- let LogCategory = /* @__PURE__ */ function(LogCategory$1) {
40
- LogCategory$1["SYSTEM"] = "SYSTEM";
41
- LogCategory$1["OSC_IN"] = "OSC_IN";
42
- LogCategory$1["OSC_OUT"] = "OSC_OUT";
43
- LogCategory$1["DISPATCH"] = "DISPATCH";
44
- LogCategory$1["STATE"] = "STATE";
45
- LogCategory$1["SUB"] = "SUB";
46
- LogCategory$1["METER"] = "METER";
47
- return LogCategory$1;
48
- }({});
49
-
50
- //#endregion
51
- //#region src/application/use-cases/ProcessPacketUseCase.ts
52
- var ProcessPacketUseCase = class {
53
- constructor(messageHandler, gateway, logger) {
54
- this.messageHandler = messageHandler;
55
- this.gateway = gateway;
56
- this.logger = logger;
57
- }
58
- execute(packet, rinfo) {
59
- try {
60
- if (packet.oscType === "bundle") packet.elements?.forEach((el) => this.execute(el, rinfo));
61
- else if (packet.oscType === "message") {
62
- const args = packet.args.map((arg) => {
63
- if (typeof arg === "object" && arg !== null && "value" in arg) return arg.value;
64
- return arg;
65
- });
66
- this.messageHandler.handle({
67
- address: packet.address,
68
- args
69
- }, rinfo).forEach((reply) => {
70
- this.gateway.send(rinfo, reply.address, reply.args);
71
- });
72
- }
73
- } catch (err) {
74
- this.logger?.error(LogCategory.DISPATCH, `Error processing packet from ${rinfo.address}:${rinfo.port}`, err instanceof Error ? err : new Error(String(err)));
75
- }
76
- }
77
- };
78
-
79
- //#endregion
80
- //#region src/application/use-cases/BroadcastUpdatesUseCase.ts
81
- var BroadcastUpdatesUseCase = class {
82
- constructor(subscriptionManager, state, gateway, logger, meterService, schemaRegistry) {
83
- this.subscriptionManager = subscriptionManager;
84
- this.state = state;
85
- this.gateway = gateway;
86
- this.logger = logger;
87
- this.meterService = meterService;
88
- this.schemaRegistry = schemaRegistry;
89
- }
90
- execute() {
91
- this.subscriptionManager.getSubscribers().forEach((sub) => {
92
- if (sub.type === "path" || !sub.alias) {
93
- if (sub.type === "meter" && sub.meterPath) {
94
- const meterData = this.meterService.generateMeterData(sub.meterPath, this.state);
95
- this.gateway.send({
96
- address: sub.address,
97
- port: sub.port
98
- }, sub.meterPath, [meterData.toBlob()]);
99
- }
100
- return;
101
- }
102
- const rinfo = {
103
- address: sub.address,
104
- port: sub.port
105
- };
106
- if (sub.type === "batch" && sub.paths) {
107
- if (sub.paths.length === 1 && sub.paths[0].startsWith("/meters")) {
108
- const meterData = this.meterService.generateMeterData(sub.paths[0], this.state);
109
- this.gateway.send(rinfo, sub.alias, [meterData.toBlob()]);
110
- return;
111
- }
112
- let stride;
113
- const dataSize = sub.paths.length * 4;
114
- const factor = sub.factor || 0;
115
- const count = sub.count || 0;
116
- if (factor > 0) stride = Math.max(factor * 4, dataSize);
117
- else stride = sub.paths.length === 3 ? 16 : dataSize;
118
- const blobSize = count * stride;
119
- if (isNaN(blobSize) || blobSize < 0) {
120
- this.logger.error(LogCategory.SYSTEM, `Invalid blob size`, {
121
- alias: sub.alias,
122
- blobSize,
123
- count,
124
- stride,
125
- factor,
126
- dataSize
127
- });
128
- return;
129
- }
130
- const blob = Buffer.alloc(blobSize);
131
- for (let i = 0; i < count; i++) {
132
- const root = this.schemaRegistry.getRootFromIndex(sub.start + i);
133
- let currentOffset = i * stride;
134
- if (!root) continue;
135
- sub.paths.forEach((s, pIdx) => {
136
- if (pIdx * 4 >= stride) return;
137
- if (s.startsWith("/meters")) blob.writeFloatLE(0, currentOffset);
138
- else {
139
- const target = `${root}${s}`;
140
- const node = this.schemaRegistry.getNode(target);
141
- let val = this.state.get(target);
142
- if (val === void 0) val = node ? node.default : 0;
143
- if (typeof val === "number") if (node && node.type === "f") blob.writeFloatLE(val, currentOffset);
144
- else blob.writeInt32LE(val, currentOffset);
145
- else blob.writeInt32LE(0, currentOffset);
146
- }
147
- currentOffset += 4;
148
- });
149
- }
150
- this.gateway.send(rinfo, sub.alias, [blob]);
151
- } else if (sub.type === "format" && sub.pattern) {
152
- const stride = sub.factor ? sub.factor * 4 : 4;
153
- const start = sub.start || 0;
154
- const count = sub.count || 0;
155
- const totalSize = (start + count) * stride;
156
- if (isNaN(totalSize) || totalSize < 0) return;
157
- const blob = Buffer.alloc(totalSize);
158
- let offset = start * stride;
159
- for (let i = start; i < start + count; i++) {
160
- const id = i.toString().padStart(2, "0");
161
- const target = sub.pattern.replace(/\*\*?/, id);
162
- let val = this.state.get(target);
163
- if (val === void 0) val = 0;
164
- if (typeof val === "number") {
165
- const node = this.schemaRegistry.getNode(target);
166
- if (node && node.type === "f") blob.writeFloatLE(val, offset);
167
- else blob.writeInt32LE(val, offset);
168
- } else blob.writeInt32LE(0, offset);
169
- offset += stride;
170
- }
171
- this.gateway.send(rinfo, sub.alias, [blob]);
172
- }
173
- });
174
- }
175
- broadcastSingleChange(path, value) {
176
- this.subscriptionManager.getSubscribers().forEach((sub) => {
177
- if (path === sub.path || sub.path === "/xremote" || sub.path && sub.path.includes("*") && path.startsWith(sub.path.split("*")[0])) this.gateway.send({
178
- address: sub.address,
179
- port: sub.port
180
- }, path, [value]);
181
- });
182
- }
183
- };
184
-
185
- //#endregion
186
- //#region src/application/use-cases/ManageSessionsUseCase.ts
187
- var ManageSessionsUseCase = class {
188
- constructor(subscriptionManager) {
189
- this.subscriptionManager = subscriptionManager;
190
- }
191
- cleanup() {
192
- this.subscriptionManager.cleanup();
193
- }
194
- };
195
-
196
- //#endregion
197
- //#region src/domain/entities/X32State.ts
198
- /**
199
- * Manages the internal "Digital Twin" state of the X32 console.
200
- * It acts as a single source of truth for all parameters.
201
- * Emits 'change' events whenever a value is updated.
202
- * Uses an injectable repository for storage (memory or persistent).
203
- */
204
- var X32State = class extends node_events.EventEmitter {
205
- defaultState = /* @__PURE__ */ new Map();
206
- /**
207
- * Initializes the state with default values from the schema.
208
- * @param schema - The schema definition map.
209
- * @param repository - The storage repository (injectable).
210
- */
211
- constructor(schema, repository) {
212
- super();
213
- this.repository = repository;
214
- for (const [addr, def] of Object.entries(schema)) this.defaultState.set(addr, def.default);
215
- }
216
- /**
217
- * Initializes the state - loads from repository or resets to defaults.
218
- */
219
- async initialize() {
220
- const stored = await this.repository.load();
221
- if (Object.keys(stored).length === 0) this.reset();
222
- }
223
- /**
224
- * Resets all state parameters to their default values defined in the schema.
225
- */
226
- reset() {
227
- const defaults = {};
228
- this.defaultState.forEach((val, key) => {
229
- defaults[key] = val;
230
- });
231
- this.repository.reset(defaults);
232
- }
233
- /**
234
- * Retrieves the value of a specific OSC node.
235
- * @param address - The full OSC address path.
236
- * @returns The stored value (number or string) or undefined if not found.
237
- */
238
- get(address) {
239
- return this.repository.get(address);
240
- }
241
- /**
242
- * Retrieves all state entries as a plain object.
243
- * @returns A record of all OSC addresses and their current values.
244
- */
245
- getAll() {
246
- return this.repository.getAll();
247
- }
248
- /**
249
- * Updates the value of a specific OSC node and notifies subscribers.
250
- * @param address - The full OSC address path.
251
- * @param value - The new value to store.
252
- */
253
- set(address, value) {
254
- this.repository.set(address, value);
255
- this.emit("change", {
256
- address,
257
- value
258
- });
259
- }
260
- /**
261
- * Flushes pending changes to persistent storage.
262
- */
263
- async flush() {
264
- await this.repository.flush();
265
- }
266
- /**
267
- * Specialized logic to handle X32 Mute Groups side-effects.
268
- * When a mute group is toggled, it iterates through all channels
269
- * assigned to that group and updates their individual mute status.
270
- * @param groupIdx - The index of the mute group (1-6).
271
- * @param isOn - The new state of the group master switch (0 or 1).
272
- */
273
- handleMuteGroupChange(groupIdx, isOn) {
274
- for (let i = 1; i <= 32; i++) {
275
- const ch = i.toString().padStart(2, "0");
276
- const grpVal = this.get(`/ch/${ch}/grp/mute`);
277
- if (typeof grpVal === "number") {
278
- if ((grpVal & 1 << groupIdx - 1) !== 0) {
279
- const targetMute = isOn === 1 ? 0 : 1;
280
- const muteAddr = `/ch/${ch}/mix/on`;
281
- this.set(muteAddr, targetMute);
282
- }
283
- }
284
- }
285
- }
286
- };
287
-
288
- //#endregion
289
- //#region src/domain/models/Config.ts
290
- /**
291
- * Default configuration values for the simulator.
292
- */
293
- const DEFAULT_CONFIG = {
294
- SUBSCRIPTION_TTL_MS: 1e4,
295
- CLEANUP_INTERVAL_MS: 5e3,
296
- BROADCAST_INTERVAL_MS: 100,
297
- DEFAULT_PORT: 10023,
298
- DEFAULT_HOST: "0.0.0.0",
299
- DEFAULT_NAME: "osc-server",
300
- DEFAULT_MODEL: "X32"
301
- };
302
- /**
303
- * Merges user-provided configuration with defaults.
304
- * @param partial - Partial configuration to merge.
305
- * @returns Complete configuration with defaults applied.
306
- */
307
- function mergeConfig(partial) {
308
- return {
309
- ...DEFAULT_CONFIG,
310
- ...partial
311
- };
312
- }
313
-
314
- //#endregion
315
- //#region src/domain/entities/SubscriptionManager.ts
316
- /**
317
- * Manages OSC client subscriptions and their lifecycle.
318
- */
319
- var SubscriptionManager = class {
320
- subscribers = [];
321
- constructor(logger, subscriptionTtlMs = DEFAULT_CONFIG.SUBSCRIPTION_TTL_MS) {
322
- this.logger = logger;
323
- this.subscriptionTtlMs = subscriptionTtlMs;
324
- }
325
- /**
326
- * Cleans up expired subscriptions.
327
- * Standard X32 subscriptions last 10 seconds.
328
- */
329
- cleanup() {
330
- const now = Date.now();
331
- const initialCount = this.subscribers.length;
332
- this.subscribers = this.subscribers.filter((s) => {
333
- const active = s.expires > now;
334
- if (!active) this.logger.debug(LogCategory.SUB, `Expired subscriber`, {
335
- type: s.type,
336
- ip: s.address,
337
- port: s.port,
338
- path: "path" in s ? s.path : s.alias
339
- });
340
- return active;
341
- });
342
- if (this.subscribers.length !== initialCount) this.logger.info(LogCategory.SUB, `Cleanup finished`, {
343
- removed: initialCount - this.subscribers.length,
344
- remaining: this.subscribers.length
345
- });
346
- }
347
- /**
348
- * Gets all active subscribers.
349
- * @returns Array of subscribers.
350
- */
351
- getSubscribers() {
352
- return this.subscribers;
353
- }
354
- /**
355
- * Adds or renews a path-based subscription (e.g. /subscribe or /xremote).
356
- * @param rinfo - Client remote info.
357
- * @param path - Subscription path.
358
- */
359
- addPathSubscriber(rinfo, path) {
360
- const key = `${rinfo.address}:${rinfo.port}:${path}`;
361
- const expires = Date.now() + this.subscriptionTtlMs;
362
- const existing = this.subscribers.find((s) => s.type === "path" && `${s.address}:${s.port}:${s.path}` === key);
363
- if (existing) {
364
- existing.expires = expires;
365
- this.logger.debug(LogCategory.SUB, `Renewed subscription`, {
366
- ip: rinfo.address,
367
- path
368
- });
369
- } else {
370
- this.subscribers.push({
371
- type: "path",
372
- address: rinfo.address,
373
- port: rinfo.port,
374
- path,
375
- expires
376
- });
377
- this.logger.info(LogCategory.SUB, `New subscription`, {
378
- ip: rinfo.address,
379
- path
380
- });
381
- }
382
- }
383
- /**
384
- * Adds or renews a batch subscription.
385
- * @param rinfo - Client remote info.
386
- * @param alias - Response alias.
387
- * @param paths - Target paths.
388
- * @param start - Start index.
389
- * @param count - Count.
390
- * @param factor - Frequency factor.
391
- * @param args - Command arguments.
392
- */
393
- addBatchSubscriber(rinfo, alias, paths, start, count, factor, args) {
394
- const expires = Date.now() + this.subscriptionTtlMs;
395
- this.subscribers = this.subscribers.filter((s) => !(s.type === "batch" && s.alias === alias && s.address === rinfo.address));
396
- this.subscribers.push({
397
- type: "batch",
398
- address: rinfo.address,
399
- port: rinfo.port,
400
- alias,
401
- paths,
402
- start,
403
- count,
404
- factor,
405
- expires,
406
- args
407
- });
408
- this.logger.info(LogCategory.SUB, `Batch subscription`, {
409
- alias,
410
- count: paths.length,
411
- factor,
412
- ip: rinfo.address,
413
- args
414
- });
415
- }
416
- /**
417
- * Adds or renews a format subscription.
418
- * @param rinfo - Client remote info.
419
- * @param alias - Response alias.
420
- * @param pattern - Path pattern.
421
- * @param start - Start index.
422
- * @param count - Count.
423
- * @param factor - Frequency factor.
424
- */
425
- addFormatSubscriber(rinfo, alias, pattern, start, count, factor) {
426
- const expires = Date.now() + this.subscriptionTtlMs;
427
- this.subscribers = this.subscribers.filter((s) => !(s.type === "format" && s.alias === alias && s.address === rinfo.address));
428
- this.subscribers.push({
429
- type: "format",
430
- address: rinfo.address,
431
- port: rinfo.port,
432
- alias,
433
- pattern,
434
- start,
435
- count,
436
- factor,
437
- expires
438
- });
439
- this.logger.info(LogCategory.SUB, `Format subscription`, {
440
- alias,
441
- pattern,
442
- factor,
443
- ip: rinfo.address
444
- });
445
- }
446
- /**
447
- * Adds or renews a high-frequency meter subscription.
448
- * @param rinfo - Client remote info.
449
- * @param meterPath - Target meter path.
450
- */
451
- addMeterSubscriber(rinfo, meterPath) {
452
- const expires = Date.now() + this.subscriptionTtlMs;
453
- const existing = this.subscribers.find((s) => s.type === "meter" && s.meterPath === meterPath && s.address === rinfo.address);
454
- this.subscribers = this.subscribers.filter((s) => !(s.type === "meter" && s.meterPath === meterPath && s.address === rinfo.address));
455
- this.subscribers.push({
456
- type: "meter",
457
- address: rinfo.address,
458
- port: rinfo.port,
459
- meterPath,
460
- expires
461
- });
462
- if (!existing) this.logger.info(LogCategory.SUB, `Meter subscription`, {
463
- path: meterPath,
464
- ip: rinfo.address
465
- });
466
- else this.logger.debug(LogCategory.SUB, `Meter renewal`, {
467
- path: meterPath,
468
- ip: rinfo.address
469
- });
470
- }
471
- /**
472
- * Removes a subscription.
473
- * @param rinfo - Client remote info.
474
- * @param path - Subscription path.
475
- */
476
- removeSubscriber(rinfo, path) {
477
- const initial = this.subscribers.length;
478
- this.subscribers = this.subscribers.filter((s) => !(s.address === rinfo.address && s.port === rinfo.port && s.path === path));
479
- if (this.subscribers.length < initial) this.logger.info(LogCategory.SUB, `Unsubscribed`, {
480
- path,
481
- ip: rinfo.address
482
- });
483
- }
484
- };
485
-
486
- //#endregion
487
- //#region src/domain/services/strategies/NodeDiscoveryStrategy.ts
488
- /**
489
- * Handles the /node command for tree traversal/discovery.
490
- * Returns a list of child nodes for a given path.
491
- */
492
- var NodeDiscoveryStrategy = class {
493
- constructor(schemaRegistry) {
494
- this.schemaRegistry = schemaRegistry;
495
- }
496
- canHandle(address) {
497
- return address === "/node";
498
- }
499
- execute(msg, _source) {
500
- const queryPath = msg.args[0] || "/";
501
- const children = /* @__PURE__ */ new Set();
502
- const prefix = queryPath.endsWith("/") ? queryPath : `${queryPath}/`;
503
- for (const key of this.schemaRegistry.getAllPaths()) if (key.startsWith(prefix)) {
504
- const segment = key.slice(prefix.length).split("/")[0];
505
- if (segment) children.add(segment);
506
- }
507
- return [{
508
- address: "/node",
509
- args: [queryPath, ...children]
510
- }];
511
- }
512
- };
513
-
514
- //#endregion
515
- //#region src/domain/services/strategies/StaticResponseStrategy.ts
516
- /**
517
- * Handles discovery and static information queries (GET only).
518
- * e.g., /status, /xinfo
519
- * Note: Only handles queries without arguments. SET commands pass through to StateAccessStrategy.
520
- */
521
- var StaticResponseStrategy = class {
522
- constructor(serverIp, serverName, serverModel, staticResponseService) {
523
- this.serverIp = serverIp;
524
- this.serverName = serverName;
525
- this.serverModel = serverModel;
526
- this.staticResponseService = staticResponseService;
527
- }
528
- canHandle(address, args) {
529
- if (args && args.length > 0) return false;
530
- return !!this.staticResponseService.getResponse(address);
531
- }
532
- execute(msg, _source) {
533
- const rawResponse = this.staticResponseService.getResponse(msg.address);
534
- if (!rawResponse) return [];
535
- const args = rawResponse.map((arg) => {
536
- if (typeof arg === "string") return arg.replace("{{ip}}", this.serverIp).replace("{{name}}", this.serverName).replace("{{model}}", this.serverModel);
537
- return arg;
538
- });
539
- return [{
540
- address: msg.address,
541
- args
542
- }];
543
- }
544
- };
545
-
546
- //#endregion
547
- //#region src/domain/services/strategies/SubscriptionStrategy.ts
548
- var SubscriptionStrategy = class {
549
- constructor(subscriptionManager, state, logger) {
550
- this.subscriptionManager = subscriptionManager;
551
- this.state = state;
552
- this.logger = logger;
553
- }
554
- canHandle(address) {
555
- return [
556
- "/subscribe",
557
- "/renew",
558
- "/unsubscribe",
559
- "/xremote"
560
- ].includes(address);
561
- }
562
- /**
563
- * Handles Session and Subscription lifecycle.
564
- *
565
- * ROUTES:
566
- * - /xremote: Firehose subscription (requests all console updates for 10s).
567
- * - /subscribe [path]: Requests updates for a specific node path for 10s.
568
- * - /renew [path]: Resets the 10s watchdog timer for a path.
569
- * - /unsubscribe [path]: Stops updates for a path.
570
- * @param msg - Parsed OSC message.
571
- * @param source - Source address and port of the packet.
572
- * @returns Returns the current value of the path upon subscription.
573
- */
574
- execute(msg, source) {
575
- const addr = msg.address;
576
- if (addr === "/xremote") {
577
- this.subscriptionManager.addPathSubscriber(source, "/xremote");
578
- return [{
579
- address: "/xremote",
580
- args: []
581
- }];
582
- }
583
- if (addr === "/unsubscribe") {
584
- this.subscriptionManager.removeSubscriber(source, msg.args[0]);
585
- this.logger.debug(LogCategory.SUB, `[UNSUB] ${msg.args[0]}`);
586
- return [];
587
- }
588
- const target = msg.args[0];
589
- this.subscriptionManager.addPathSubscriber(source, target);
590
- const val = this.state.get(target);
591
- if (val !== void 0) {
592
- this.logger.debug(LogCategory.SUB, `[SUB] ${target} -> ${val}`);
593
- return [{
594
- address: target,
595
- args: [val]
596
- }];
597
- }
598
- return [];
599
- }
600
- };
601
-
602
- //#endregion
603
- //#region src/domain/services/strategies/BatchStrategy.ts
604
- /**
605
- * Handles bulk data subscription requests from advanced clients like X32-Edit or Mixing Station.
606
- *
607
- * SUPPORTED COMMANDS:
608
- * - /formatsubscribe: Requests a range of numbered nodes (e.g. /ch/01-32/mix/fader).
609
- * - /batchsubscribe: Aggregates multiple parameters into a single binary blob response.
610
- */
611
- var BatchStrategy = class {
612
- /**
613
- * Initializes the strategy.
614
- * @param subscriptionManager - Session manager.
615
- * @param logger - Logger instance.
616
- */
617
- constructor(subscriptionManager, logger) {
618
- this.subscriptionManager = subscriptionManager;
619
- this.logger = logger;
620
- }
621
- /** @inheritdoc */
622
- canHandle(address) {
623
- return ["/batchsubscribe", "/formatsubscribe"].includes(address);
624
- }
625
- /** @inheritdoc */
626
- execute(msg, source) {
627
- const addr = msg.address;
628
- if (addr === "/formatsubscribe") {
629
- const alias = msg.args[0];
630
- const pattern = msg.args[1];
631
- const start = msg.args[2];
632
- const end = msg.args[3];
633
- const factor = msg.args[4];
634
- const count = end - start + 1;
635
- this.subscriptionManager.addFormatSubscriber(source, alias, pattern, start, count, factor);
636
- this.logger.debug(LogCategory.SUB, `[FORMAT] ${alias} factor: ${factor}`);
637
- return [];
638
- }
639
- if (addr === "/batchsubscribe") {
640
- const alias = msg.args[0];
641
- const firstIntIndex = msg.args.findIndex((a) => typeof a === "number");
642
- if (firstIntIndex === -1) return [];
643
- const paths = msg.args.slice(1, firstIntIndex);
644
- const intArgs = msg.args.slice(firstIntIndex);
645
- const factor = intArgs.pop();
646
- const cmdArgs = intArgs;
647
- this.subscriptionManager.addBatchSubscriber(source, alias, paths, 0, 1, factor, cmdArgs);
648
- this.logger.debug(LogCategory.SUB, `[BATCH] ${alias} paths: ${JSON.stringify(paths)} args: ${JSON.stringify(cmdArgs)} factor: ${factor}`);
649
- return [];
650
- }
651
- return [];
652
- }
653
- };
654
-
655
- //#endregion
656
- //#region src/domain/services/strategies/MeterStrategy.ts
657
- /**
658
- * Handles high-frequency metering data requests.
659
- * Meters are sent as binary blobs to optimize network bandwidth.
660
- * Supports both direct address requests (/meters/1) and argument-based requests (/meters ,s "/meters/1").
661
- */
662
- var MeterStrategy = class {
663
- /**
664
- * Initializes the strategy.
665
- * @param subscriptionManager - Session manager.
666
- * @param state - Current mixer state.
667
- * @param meterService - Service to generate meter data.
668
- */
669
- constructor(subscriptionManager, state, meterService) {
670
- this.subscriptionManager = subscriptionManager;
671
- this.state = state;
672
- this.meterService = meterService;
673
- }
674
- /** @inheritdoc */
675
- canHandle(address) {
676
- return address.startsWith("/meters");
677
- }
678
- /** @inheritdoc */
679
- execute(msg, source) {
680
- let meterPath = msg.address;
681
- if (msg.address === "/meters" && typeof msg.args[0] === "string" && msg.args[0].startsWith("/meters")) meterPath = msg.args[0];
682
- this.subscriptionManager.addMeterSubscriber(source, meterPath);
683
- const blob = this.meterService.generateMeterData(meterPath, this.state).toBlob();
684
- return [{
685
- address: meterPath,
686
- args: [blob]
687
- }];
688
- }
689
- };
690
-
691
- //#endregion
692
- //#region src/domain/services/strategies/StateAccessStrategy.ts
693
- /**
694
- * General-purpose strategy for reading and writing console parameters.
695
- * acts as the fallback for any command that matches the schema.
696
- *
697
- * LOGIC:
698
- * - If no arguments: Treats as a QUERY (GET) and returns the current value.
699
- * - If arguments provided: Treats as an UPDATE (SET) and stores the new value.
700
- * - Unknown addresses are also stored in permissive mode for compatibility.
701
- */
702
- var StateAccessStrategy = class {
703
- /**
704
- * Initializes the strategy.
705
- * @param state - Current mixer state.
706
- * @param logger - Logger instance.
707
- * @param schemaRegistry - Registry to validate addresses.
708
- * @param permissive - If true, store unknown addresses too (default: true).
709
- */
710
- constructor(state, logger, schemaRegistry, permissive = true) {
711
- this.state = state;
712
- this.logger = logger;
713
- this.schemaRegistry = schemaRegistry;
714
- this.permissive = permissive;
715
- }
716
- /** @inheritdoc */
717
- canHandle(address) {
718
- if (this.schemaRegistry.has(address)) return true;
719
- return this.permissive && address.startsWith("/");
720
- }
721
- /** @inheritdoc */
722
- execute(msg, _source) {
723
- const addr = msg.address;
724
- const node = this.schemaRegistry.getNode(addr);
725
- const isKnown = !!node;
726
- if (msg.args.length === 0) {
727
- const val$1 = this.state.get(addr);
728
- if (val$1 !== void 0) return [{
729
- address: addr,
730
- args: [val$1]
731
- }];
732
- if (!isKnown) this.logger.debug(LogCategory.STATE, `[GET] Unknown address queried: ${addr}`);
733
- return [];
734
- }
735
- const val = msg.args[0];
736
- if (isKnown) {
737
- if (!node.validate(val)) {
738
- this.logger.warn(LogCategory.DISPATCH, `[TYPE ERR] ${addr} expected ${node.type}, got ${typeof val}`);
739
- return [];
740
- }
741
- } else this.logger.warn(LogCategory.STATE, `[UNKNOWN] Storing unknown address: ${addr} = ${val}`);
742
- this.state.set(addr, val);
743
- this.logger.debug(LogCategory.STATE, `[SET] ${addr} -> ${val}`);
744
- if (addr.startsWith("/config/mute/")) {
745
- const groupIdx = parseInt(addr.split("/").pop(), 10);
746
- if (!isNaN(groupIdx)) this.state.handleMuteGroupChange(groupIdx, val);
747
- }
748
- if (addr === "/-action/undopt" && val === 1) {
749
- const timeStr = (/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", { hour12: false });
750
- this.state.set("/-undo/time", timeStr);
751
- this.logger.debug(LogCategory.STATE, `[UNDO] Checkpoint created at ${timeStr}`);
752
- }
753
- return [];
754
- }
755
- };
756
-
757
- //#endregion
758
- //#region src/domain/services/strategies/ShowDumpStrategy.ts
759
- /**
760
- * Handles the /showdump command which requests a full state dump.
761
- * Used by X32-Edit during synchronization to retrieve all console parameters.
762
- */
763
- var ShowDumpStrategy = class {
764
- constructor(state, logger) {
765
- this.state = state;
766
- this.logger = logger;
767
- }
768
- /** @inheritdoc */
769
- canHandle(address) {
770
- return address === "/showdump";
771
- }
772
- /** @inheritdoc */
773
- execute(_msg, _source) {
774
- this.logger.debug(LogCategory.DISPATCH, "[SHOWDUMP] Full state dump requested");
775
- const replies = [];
776
- const allState = this.state.getAll();
777
- for (const [address, value] of Object.entries(allState)) replies.push({
778
- address,
779
- args: [value]
780
- });
781
- this.logger.debug(LogCategory.DISPATCH, `[SHOWDUMP] Sending ${replies.length} state entries`);
782
- return replies;
783
- }
784
- };
785
-
786
- //#endregion
787
- //#region src/domain/services/strategies/SceneDataStrategy.ts
788
- /**
789
- * Maps scene file format (batch values) to individual OSC addresses.
790
- * The X32 scene format sends multiple values for a parent address.
791
- * Example: /ch/01/mix ON -0.2 ON -100 OFF -oo
792
- * Maps to: /ch/01/mix/on, /ch/01/mix/fader, /ch/01/mix/st, /ch/01/mix/pan, /ch/01/mix/mono, /ch/01/mix/mlevel
793
- */
794
- const SCENE_MAPPINGS = {
795
- "headamp": ["gain", "phantom"],
796
- "config": [
797
- "name",
798
- "icon",
799
- "color",
800
- "source"
801
- ],
802
- "delay": ["on", "time"],
803
- "preamp": [
804
- "trim",
805
- "invert",
806
- "hpon",
807
- "hpslope",
808
- "hpf"
809
- ],
810
- "gate": [
811
- "on",
812
- "mode",
813
- "thr",
814
- "range",
815
- "attack",
816
- "hold",
817
- "release",
818
- "keysrc"
819
- ],
820
- "gate/filter": [
821
- "on",
822
- "type",
823
- "f"
824
- ],
825
- "dyn": [
826
- "on",
827
- "mode",
828
- "det",
829
- "env",
830
- "thr",
831
- "ratio",
832
- "knee",
833
- "mgain",
834
- "attack",
835
- "hold",
836
- "release",
837
- "pos",
838
- "keysrc",
839
- "mix",
840
- "auto"
841
- ],
842
- "dyn/filter": [
843
- "on",
844
- "type",
845
- "f"
846
- ],
847
- "insert": [
848
- "on",
849
- "pos",
850
- "sel"
851
- ],
852
- "eq": ["on"],
853
- "eq/1": [
854
- "type",
855
- "f",
856
- "g",
857
- "q"
858
- ],
859
- "eq/2": [
860
- "type",
861
- "f",
862
- "g",
863
- "q"
864
- ],
865
- "eq/3": [
866
- "type",
867
- "f",
868
- "g",
869
- "q"
870
- ],
871
- "eq/4": [
872
- "type",
873
- "f",
874
- "g",
875
- "q"
876
- ],
877
- "eq/5": [
878
- "type",
879
- "f",
880
- "g",
881
- "q"
882
- ],
883
- "eq/6": [
884
- "type",
885
- "f",
886
- "g",
887
- "q"
888
- ],
889
- "mix": [
890
- "on",
891
- "fader",
892
- "st",
893
- "pan",
894
- "mono",
895
- "mlevel"
896
- ],
897
- "mix/01": [
898
- "on",
899
- "level",
900
- "pan",
901
- "type",
902
- "panFollow"
903
- ],
904
- "mix/02": ["on", "level"],
905
- "mix/03": [
906
- "on",
907
- "level",
908
- "pan",
909
- "type",
910
- "panFollow"
911
- ],
912
- "mix/04": ["on", "level"],
913
- "mix/05": [
914
- "on",
915
- "level",
916
- "pan",
917
- "type",
918
- "panFollow"
919
- ],
920
- "mix/06": ["on", "level"],
921
- "mix/07": [
922
- "on",
923
- "level",
924
- "pan",
925
- "type",
926
- "panFollow"
927
- ],
928
- "mix/08": ["on", "level"],
929
- "mix/09": [
930
- "on",
931
- "level",
932
- "pan",
933
- "type",
934
- "panFollow"
935
- ],
936
- "mix/10": ["on", "level"],
937
- "mix/11": [
938
- "on",
939
- "level",
940
- "pan",
941
- "type",
942
- "panFollow"
943
- ],
944
- "mix/12": ["on", "level"],
945
- "mix/13": [
946
- "on",
947
- "level",
948
- "pan",
949
- "type",
950
- "panFollow"
951
- ],
952
- "mix/14": ["on", "level"],
953
- "mix/15": [
954
- "on",
955
- "level",
956
- "pan",
957
- "type",
958
- "panFollow"
959
- ],
960
- "mix/16": ["on", "level"],
961
- "grp": ["dca", "mute"],
962
- "automix": ["group", "weight"],
963
- "chlink": [
964
- "1-2",
965
- "3-4",
966
- "5-6",
967
- "7-8",
968
- "9-10",
969
- "11-12",
970
- "13-14",
971
- "15-16",
972
- "17-18",
973
- "19-20",
974
- "21-22",
975
- "23-24",
976
- "25-26",
977
- "27-28",
978
- "29-30",
979
- "31-32"
980
- ],
981
- "auxlink": [
982
- "1-2",
983
- "3-4",
984
- "5-6",
985
- "7-8"
986
- ],
987
- "fxlink": [
988
- "1-2",
989
- "3-4",
990
- "5-6",
991
- "7-8"
992
- ],
993
- "buslink": [
994
- "1-2",
995
- "3-4",
996
- "5-6",
997
- "7-8",
998
- "9-10",
999
- "11-12",
1000
- "13-14",
1001
- "15-16"
1002
- ],
1003
- "mtxlink": [
1004
- "1-2",
1005
- "3-4",
1006
- "5-6"
1007
- ],
1008
- "mute": [
1009
- "1",
1010
- "2",
1011
- "3",
1012
- "4",
1013
- "5",
1014
- "6"
1015
- ],
1016
- "linkcfg": [
1017
- "hadly",
1018
- "eq",
1019
- "dyn",
1020
- "fdrmute"
1021
- ],
1022
- "mono": ["mode", "link"],
1023
- "solo": [
1024
- "level",
1025
- "source",
1026
- "sourcetrim",
1027
- "chmode",
1028
- "busmode",
1029
- "dcamode",
1030
- "exclusive",
1031
- "followsel",
1032
- "followsolo",
1033
- "dimatt",
1034
- "dim",
1035
- "mono",
1036
- "delay",
1037
- "delaytime",
1038
- "masterctrl",
1039
- "mute",
1040
- "dimmute"
1041
- ],
1042
- "talk": ["enable", "source"],
1043
- "talk/A": [
1044
- "level",
1045
- "dim",
1046
- "latch",
1047
- "destmap"
1048
- ],
1049
- "talk/B": [
1050
- "level",
1051
- "dim",
1052
- "latch",
1053
- "destmap"
1054
- ],
1055
- "osc": [
1056
- "level",
1057
- "f1",
1058
- "f2",
1059
- "type",
1060
- "dest"
1061
- ],
1062
- "tape": [
1063
- "gainL",
1064
- "gainR",
1065
- "autoplay"
1066
- ],
1067
- "amixenable": ["X", "Y"],
1068
- "dp48": [
1069
- "broadcast",
1070
- "bundles",
1071
- "assign"
1072
- ],
1073
- "dp48/assign": Array.from({ length: 48 }, (_, i) => String(i + 1)),
1074
- "dp48/link": Array.from({ length: 24 }, (_, i) => String(i + 1)),
1075
- "dp48/grpname": Array.from({ length: 12 }, (_, i) => String(i + 1)),
1076
- "userrout/out": Array.from({ length: 48 }, (_, i) => String(i + 1)),
1077
- "userrout/in": Array.from({ length: 32 }, (_, i) => String(i + 1)),
1078
- "routing": ["routswitch"],
1079
- "routing/IN": [
1080
- "1-8",
1081
- "9-16",
1082
- "17-24",
1083
- "25-32",
1084
- "AUX"
1085
- ],
1086
- "routing/AES50A": [
1087
- "1-8",
1088
- "9-16",
1089
- "17-24",
1090
- "25-32",
1091
- "33-40",
1092
- "41-48"
1093
- ],
1094
- "routing/AES50B": [
1095
- "1-8",
1096
- "9-16",
1097
- "17-24",
1098
- "25-32",
1099
- "33-40",
1100
- "41-48"
1101
- ],
1102
- "routing/CARD": [
1103
- "1-8",
1104
- "9-16",
1105
- "17-24",
1106
- "25-32"
1107
- ],
1108
- "routing/OUT": [
1109
- "1-4",
1110
- "5-8",
1111
- "9-12",
1112
- "13-16"
1113
- ],
1114
- "routing/PLAY": [
1115
- "1-8",
1116
- "9-16",
1117
- "17-24",
1118
- "25-32",
1119
- "AUX"
1120
- ],
1121
- "userctrl/A": ["color"],
1122
- "userctrl/A/enc": [
1123
- "1",
1124
- "2",
1125
- "3",
1126
- "4"
1127
- ],
1128
- "userctrl/A/btn": [
1129
- "1",
1130
- "2",
1131
- "3",
1132
- "4",
1133
- "5",
1134
- "6",
1135
- "7",
1136
- "8"
1137
- ],
1138
- "userctrl/B": ["color"],
1139
- "userctrl/B/enc": [
1140
- "1",
1141
- "2",
1142
- "3",
1143
- "4"
1144
- ],
1145
- "userctrl/B/btn": [
1146
- "1",
1147
- "2",
1148
- "3",
1149
- "4",
1150
- "5",
1151
- "6",
1152
- "7",
1153
- "8"
1154
- ],
1155
- "userctrl/C": ["color"],
1156
- "userctrl/C/enc": [
1157
- "1",
1158
- "2",
1159
- "3",
1160
- "4"
1161
- ],
1162
- "userctrl/C/btn": [
1163
- "1",
1164
- "2",
1165
- "3",
1166
- "4",
1167
- "5",
1168
- "6",
1169
- "7",
1170
- "8",
1171
- "9",
1172
- "10",
1173
- "11",
1174
- "12"
1175
- ],
1176
- "dca": ["on", "fader"],
1177
- "bus/config": [
1178
- "name",
1179
- "icon",
1180
- "color"
1181
- ],
1182
- "bus/mix": [
1183
- "on",
1184
- "fader",
1185
- "st",
1186
- "pan",
1187
- "mono",
1188
- "mlevel"
1189
- ],
1190
- "main/st/config": [
1191
- "name",
1192
- "icon",
1193
- "color"
1194
- ],
1195
- "main/st/mix": [
1196
- "on",
1197
- "fader",
1198
- "st",
1199
- "pan"
1200
- ],
1201
- "main/m/config": [
1202
- "name",
1203
- "icon",
1204
- "color"
1205
- ],
1206
- "main/m/mix": ["on", "fader"],
1207
- "fx/source": ["inL", "inR"],
1208
- "fx": ["type"],
1209
- "fx/par": Array.from({ length: 64 }, (_, i) => String(i + 1)),
1210
- "outputs/main": [
1211
- "src",
1212
- "pos",
1213
- "invert"
1214
- ],
1215
- "outputs/main/delay": ["on", "time"],
1216
- "outputs/aux": [
1217
- "src",
1218
- "pos",
1219
- "invert"
1220
- ],
1221
- "outputs/p16": [
1222
- "src",
1223
- "pos",
1224
- "invert"
1225
- ],
1226
- "outputs/p16/iQ": [
1227
- "model",
1228
- "eqset",
1229
- "sound"
1230
- ],
1231
- "outputs/aes": [
1232
- "src",
1233
- "pos",
1234
- "invert"
1235
- ],
1236
- "outputs/rec": [
1237
- "src",
1238
- "pos",
1239
- "invert"
1240
- ]
1241
- };
1242
- /**
1243
- * Converts scene file values to proper OSC types.
1244
- */
1245
- function parseSceneValue(val) {
1246
- if (val === "ON") return 1;
1247
- if (val === "OFF") return 0;
1248
- if (val === "-oo" || val === "-inf") return -90;
1249
- if (val === "+oo" || val === "+inf") return 90;
1250
- if (val.startsWith("%")) return parseInt(val.slice(1), 2);
1251
- const freqMatch = val.match(/^(\d+)k(\d+)$/);
1252
- if (freqMatch) return parseFloat(freqMatch[1] + "." + freqMatch[2]) * 1e3;
1253
- if (val.startsWith("+") || val.startsWith("-")) {
1254
- const num$1 = parseFloat(val);
1255
- if (!isNaN(num$1)) return num$1;
1256
- }
1257
- const num = parseFloat(val);
1258
- if (!isNaN(num)) return num;
1259
- const int = parseInt(val, 10);
1260
- if (!isNaN(int)) return int;
1261
- return val.replace(/^"|"$/g, "");
1262
- }
1263
- /**
1264
- * Strategy to handle X32 scene file format (batch multi-value commands).
1265
- * Expands parent addresses with multiple values into individual parameter sets.
1266
- */
1267
- var SceneDataStrategy = class {
1268
- constructor(state, logger) {
1269
- this.state = state;
1270
- this.logger = logger;
1271
- }
1272
- canHandle(address, args) {
1273
- if (!args || args.length === 0) return false;
1274
- if (args.length === 1) {
1275
- if (address.match(/^\/fx\/\d$/)) return true;
1276
- return false;
1277
- }
1278
- if (args.length === 2) {
1279
- if (address.match(/^\/dca\/\d$/)) return true;
1280
- }
1281
- return this.findMapping(address) !== null;
1282
- }
1283
- execute(msg, _source) {
1284
- const { address, args } = msg;
1285
- const mapping = this.findMapping(address);
1286
- if (!mapping) return [];
1287
- const { basePath, fields } = mapping;
1288
- this.logger.debug(LogCategory.STATE, `[SCENE] Expanding batch command`, {
1289
- address,
1290
- argCount: args.length,
1291
- fields: fields.length
1292
- });
1293
- for (let i = 0; i < args.length && i < fields.length; i++) {
1294
- const fieldName = fields[i];
1295
- const rawValue = args[i];
1296
- const value = typeof rawValue === "string" ? parseSceneValue(rawValue) : rawValue;
1297
- const fullPath = `${basePath}/${fieldName}`;
1298
- this.state.set(fullPath, value);
1299
- this.logger.debug(LogCategory.STATE, `[SCENE] Set ${fullPath} = ${value}`);
1300
- }
1301
- return [];
1302
- }
1303
- findMapping(address) {
1304
- if (address.match(/^\/headamp\/\d{3}$/) && SCENE_MAPPINGS["headamp"]) return {
1305
- basePath: address,
1306
- fields: SCENE_MAPPINGS["headamp"]
1307
- };
1308
- if (address.match(/^\/fx\/\d\/source$/) && SCENE_MAPPINGS["fx/source"]) return {
1309
- basePath: address,
1310
- fields: SCENE_MAPPINGS["fx/source"]
1311
- };
1312
- if (address.match(/^\/fx\/\d\/par$/) && SCENE_MAPPINGS["fx/par"]) return {
1313
- basePath: address,
1314
- fields: SCENE_MAPPINGS["fx/par"]
1315
- };
1316
- if (address.match(/^\/fx\/\d$/) && SCENE_MAPPINGS["fx"]) return {
1317
- basePath: address,
1318
- fields: SCENE_MAPPINGS["fx"]
1319
- };
1320
- if (address.match(/^\/dca\/\d$/) && SCENE_MAPPINGS["dca"]) return {
1321
- basePath: address,
1322
- fields: SCENE_MAPPINGS["dca"]
1323
- };
1324
- if (address.match(/^\/dca\/\d\/config$/)) return {
1325
- basePath: address,
1326
- fields: [
1327
- "name",
1328
- "icon",
1329
- "color"
1330
- ]
1331
- };
1332
- if (address.match(/^\/outputs\/main\/\d{2}\/delay$/) && SCENE_MAPPINGS["outputs/main/delay"]) return {
1333
- basePath: address,
1334
- fields: SCENE_MAPPINGS["outputs/main/delay"]
1335
- };
1336
- if (address.match(/^\/outputs\/p16\/\d{2}\/iQ$/) && SCENE_MAPPINGS["outputs/p16/iQ"]) return {
1337
- basePath: address,
1338
- fields: SCENE_MAPPINGS["outputs/p16/iQ"]
1339
- };
1340
- if (address.match(/^\/outputs\/main\/\d{2}$/) && SCENE_MAPPINGS["outputs/main"]) return {
1341
- basePath: address,
1342
- fields: SCENE_MAPPINGS["outputs/main"]
1343
- };
1344
- if (address.match(/^\/outputs\/aux\/\d{2}$/) && SCENE_MAPPINGS["outputs/aux"]) return {
1345
- basePath: address,
1346
- fields: SCENE_MAPPINGS["outputs/aux"]
1347
- };
1348
- if (address.match(/^\/outputs\/p16\/\d{2}$/) && SCENE_MAPPINGS["outputs/p16"]) return {
1349
- basePath: address,
1350
- fields: SCENE_MAPPINGS["outputs/p16"]
1351
- };
1352
- if (address.match(/^\/outputs\/aes\/\d{2}$/) && SCENE_MAPPINGS["outputs/aes"]) return {
1353
- basePath: address,
1354
- fields: SCENE_MAPPINGS["outputs/aes"]
1355
- };
1356
- if (address.match(/^\/outputs\/rec\/\d{2}$/) && SCENE_MAPPINGS["outputs/rec"]) return {
1357
- basePath: address,
1358
- fields: SCENE_MAPPINGS["outputs/rec"]
1359
- };
1360
- if (address.startsWith("/config/")) {
1361
- const suffix = address.replace("/config/", "");
1362
- if (SCENE_MAPPINGS[suffix]) return {
1363
- basePath: address,
1364
- fields: SCENE_MAPPINGS[suffix]
1365
- };
1366
- }
1367
- for (const [pattern, fields] of Object.entries(SCENE_MAPPINGS)) {
1368
- if (address.endsWith("/" + pattern)) return {
1369
- basePath: address,
1370
- fields
1371
- };
1372
- if ((/* @__PURE__ */ new RegExp(`/${pattern.replace(/\//g, "/")}$`)).test(address)) return {
1373
- basePath: address,
1374
- fields
1375
- };
1376
- }
1377
- const numberedPathMatch = address.match(/^\/\w+\/\d+\/(.+)$/);
1378
- if (numberedPathMatch) {
1379
- const suffix = numberedPathMatch[1];
1380
- if (SCENE_MAPPINGS[suffix]) return {
1381
- basePath: address,
1382
- fields: SCENE_MAPPINGS[suffix]
1383
- };
1384
- }
1385
- return null;
1386
- }
1387
- };
1388
-
1389
- //#endregion
1390
- //#region src/domain/services/OscMessageHandler.ts
1391
- /**
1392
- * The central dispatcher for incoming OSC messages.
1393
- * Uses a Chain of Responsibility (Strategy pattern) to delegate handling.
1394
- * Order of strategies is critical for correct prioritization.
1395
- */
1396
- var OscMessageHandler = class {
1397
- /** List of active command strategies. */
1398
- strategies;
1399
- /**
1400
- * Initializes the handler with all available strategies.
1401
- * @param state - Global mixer state.
1402
- * @param subscriptionManager - Active client sessions.
1403
- * @param logger - Logger instance.
1404
- * @param serverIp - Host IP reported in handshakes.
1405
- * @param serverName - Console name reported in handshakes.
1406
- * @param serverModel - Console model reported in handshakes.
1407
- * @param meterService - Service for metering.
1408
- * @param schemaRegistry - Service for schema validation.
1409
- * @param staticResponseService - Service for static responses.
1410
- */
1411
- constructor(state, subscriptionManager, logger, serverIp, serverName, serverModel, meterService, schemaRegistry, staticResponseService) {
1412
- this.logger = logger;
1413
- this.meterService = meterService;
1414
- this.schemaRegistry = schemaRegistry;
1415
- this.staticResponseService = staticResponseService;
1416
- this.strategies = [
1417
- new NodeDiscoveryStrategy(this.schemaRegistry),
1418
- new SubscriptionStrategy(subscriptionManager, state, logger),
1419
- new BatchStrategy(subscriptionManager, logger),
1420
- new MeterStrategy(subscriptionManager, state, this.meterService),
1421
- new ShowDumpStrategy(state, logger),
1422
- new SceneDataStrategy(state, logger),
1423
- new StaticResponseStrategy(serverIp, serverName, serverModel, this.staticResponseService),
1424
- new StateAccessStrategy(state, logger, this.schemaRegistry)
1425
- ];
1426
- }
1427
- /**
1428
- * Dispatches an incoming message to the first matching strategy.
1429
- * @param msg - Parsed OSC message.
1430
- * @param source - Source address and port of the packet.
1431
- * @returns Array of replies generated by the strategy.
1432
- */
1433
- handle(msg, source) {
1434
- let addr = msg.address;
1435
- let args = msg.args;
1436
- if (addr === "/" && args.length === 1 && typeof args[0] === "string") {
1437
- const parts = args[0].trim().match(/(?:[^\s"]+|"[^"]*")+/g) || [];
1438
- if (parts.length > 0 && parts[0]) {
1439
- let innerAddr = parts[0];
1440
- if (!innerAddr.startsWith("/")) innerAddr = "/" + innerAddr;
1441
- const innerArgs = parts.slice(1).map((arg) => {
1442
- let val = arg.replace(/^"|"$/g, "");
1443
- if (/^-?\d+$/.test(val)) return parseInt(val, 10);
1444
- if (/^-?\d+\.\d+$/.test(val)) return parseFloat(val);
1445
- return val;
1446
- });
1447
- this.logger.debug(LogCategory.DISPATCH, `Unwrapped X32-Edit command: ${innerAddr}`, { innerArgs });
1448
- return this.handle({
1449
- address: innerAddr,
1450
- args: innerArgs
1451
- }, source);
1452
- }
1453
- }
1454
- if (!addr.startsWith("/meters")) this.logger.debug(LogCategory.DISPATCH, `Handling`, {
1455
- addr,
1456
- args
1457
- });
1458
- for (const strategy of this.strategies) if (strategy.canHandle(addr, args)) {
1459
- const replies = strategy.execute({
1460
- address: addr,
1461
- args
1462
- }, source);
1463
- if (replies.length > 0) this.logger.debug(LogCategory.DISPATCH, `Strategy ${strategy.constructor.name} replied`, { count: replies.length });
1464
- return replies;
1465
- }
1466
- this.logger.warn(LogCategory.DISPATCH, `Unknown Command`, {
1467
- addr,
1468
- args,
1469
- ip: source.address
1470
- });
1471
- return [];
1472
- }
1473
- };
1474
-
1475
- //#endregion
1476
- //#region src/domain/models/MeterData.ts
1477
- /**
1478
- * Represents a set of meter values for a specific meter path.
1479
- * Handles the storage of float values and serialization to X32-specific binary blobs.
1480
- */
1481
- var MeterData = class {
1482
- _path;
1483
- _values;
1484
- /**
1485
- * Creates a new MeterData instance.
1486
- * @param path - The meter OSC path (e.g., "/meters/1").
1487
- * @param values - The array of float values (0.0 - 1.0 or similar).
1488
- */
1489
- constructor(path, values) {
1490
- this._path = path;
1491
- this._values = values;
1492
- }
1493
- /**
1494
- * Gets the meter path.
1495
- */
1496
- get path() {
1497
- return this._path;
1498
- }
1499
- /**
1500
- * Gets the values.
1501
- */
1502
- get values() {
1503
- return [...this._values];
1504
- }
1505
- /**
1506
- * Generates an optimized binary blob for X32 meters (mixed endianness).
1507
- * Structure: [Size (Int32BE)] [Count (Int32LE)] [Float1 (LE)] [Float2 (LE)] ...
1508
- * @returns Buffer containing the OSC blob.
1509
- */
1510
- toBlob() {
1511
- const count = this._values.length;
1512
- const totalSize = 8 + count * 4;
1513
- const blob = Buffer.alloc(totalSize);
1514
- blob.writeInt32BE(totalSize, 0);
1515
- blob.writeInt32LE(count, 4);
1516
- for (let i = 0; i < count; i++) blob.writeFloatLE(this._values[i], 8 + i * 4);
1517
- return blob;
1518
- }
1519
- };
1520
-
1521
- //#endregion
1522
- //#region src/domain/models/MeterConfig.ts
1523
- /**
1524
- * Configuration for meter counts per path.
1525
- */
1526
- const METER_COUNTS = {
1527
- "/meters/0": 70,
1528
- "/meters/1": 96,
1529
- "/meters/2": 49,
1530
- "/meters/3": 22,
1531
- "/meters/4": 82,
1532
- "/meters/5": 27,
1533
- "/meters/6": 4,
1534
- "/meters/7": 16,
1535
- "/meters/8": 6,
1536
- "/meters/9": 32,
1537
- "/meters/10": 32,
1538
- "/meters/11": 5,
1539
- "/meters/12": 4,
1540
- "/meters/13": 48,
1541
- "/meters/14": 80,
1542
- "/meters/15": 50,
1543
- "/meters/16": 48
1544
- };
1545
-
1546
- //#endregion
1547
- //#region src/domain/services/MeterService.ts
1548
- /**
1549
- * Service responsible for generating meter values and data.
1550
- * Mimics the physics/audio engine of the X32.
1551
- */
1552
- var MeterService = class {
1553
- /**
1554
- * Generates a MeterData object for a given path.
1555
- * @param path - The meter OSC path (e.g., "/meters/1").
1556
- * @param state - The current X32 state (for correlating faders to meters).
1557
- * @returns MeterData object containing the values.
1558
- */
1559
- generateMeterData(path, state) {
1560
- const count = METER_COUNTS[path];
1561
- if (count === void 0) return new MeterData(path, []);
1562
- const values = [];
1563
- for (let i = 0; i < count; i++) {
1564
- let val = Math.random() * .05;
1565
- if (state && path === "/meters/1") {
1566
- if (i < 32) {
1567
- const faderPath = `/ch/${(i + 1).toString().padStart(2, "0")}/mix/fader`;
1568
- const fader = state.get(faderPath);
1569
- if (typeof fader === "number") val = fader > .01 ? fader * (.9 + Math.random() * .1) : 0;
1570
- }
1571
- }
1572
- values.push(val);
1573
- }
1574
- return new MeterData(path, values);
1575
- }
1576
- };
1577
-
1578
- //#endregion
1579
- //#region src/domain/services/StaticResponseService.ts
1580
- /**
1581
- * Static OSC responses for X32 Discovery and System status.
1582
- * These are read-only informational endpoints that return system info.
1583
- * All other parameters are handled by StateAccessStrategy from the schema.
1584
- */
1585
- const STATIC_RESPONSES_DATA = {
1586
- "/xinfo": [
1587
- "{{ip}}",
1588
- "{{name}}",
1589
- "{{model}}",
1590
- "4.06"
1591
- ],
1592
- "/info": [
1593
- "V2.05",
1594
- "{{name}}",
1595
- "{{model}}",
1596
- "4.06"
1597
- ],
1598
- "/status": [
1599
- "active",
1600
- "{{ip}}",
1601
- "{{name}}"
1602
- ]
1603
- };
1604
- /**
1605
- * Service providing static system responses.
1606
- * Mimics the fixed firmware responses of the X32.
1607
- */
1608
- var StaticResponseService = class {
1609
- responses = STATIC_RESPONSES_DATA;
1610
- /**
1611
- * Retrieves a static response for a given path.
1612
- * @param path - The OSC path.
1613
- * @returns The response arguments or undefined.
1614
- */
1615
- getResponse(path) {
1616
- return this.responses[path];
1617
- }
1618
- };
1619
-
1620
- //#endregion
1621
- //#region src/application/use-cases/SimulationService.ts
1622
- /**
1623
- * Gets the first non-internal IPv4 address found on this machine.
1624
- * @returns Detected IP or localhost.
1625
- */
1626
- function getLocalIp() {
1627
- const interfaces = os.networkInterfaces();
1628
- for (const name of Object.keys(interfaces)) for (const iface of interfaces[name]) if (iface.family === "IPv4" && !iface.internal) return iface.address;
1629
- return "127.0.0.1";
1630
- }
1631
- /**
1632
- * The core service that manages the X32 simulation, including networking,
1633
- * state management, and OSC message handling.
1634
- */
1635
- var SimulationService = class {
1636
- subscriptionManager;
1637
- messageHandler;
1638
- state;
1639
- processPacket;
1640
- broadcastUpdates;
1641
- manageSessions;
1642
- meterService;
1643
- staticResponseService;
1644
- config;
1645
- updateInterval = null;
1646
- cleanupInterval = null;
1647
- /**
1648
- * Creates a new SimulationService instance.
1649
- * @param gateway - The network gateway for OSC communication.
1650
- * @param logger - The logger service.
1651
- * @param stateRepository - The repository for state persistence.
1652
- * @param schemaRegistry - The registry for X32 OSC schema.
1653
- * @param port - UDP port to listen on (default from config).
1654
- * @param ip - IP address to bind to (default from config).
1655
- * @param name - Reported console name.
1656
- * @param model - Reported console model.
1657
- * @param configOverrides - Optional configuration overrides.
1658
- */
1659
- constructor(gateway, logger, stateRepository, schemaRegistry, port = DEFAULT_CONFIG.DEFAULT_PORT, ip = DEFAULT_CONFIG.DEFAULT_HOST, name = DEFAULT_CONFIG.DEFAULT_NAME, model = DEFAULT_CONFIG.DEFAULT_MODEL, configOverrides) {
1660
- this.gateway = gateway;
1661
- this.logger = logger;
1662
- this.stateRepository = stateRepository;
1663
- this.schemaRegistry = schemaRegistry;
1664
- this.port = port;
1665
- this.ip = ip;
1666
- this.config = mergeConfig(configOverrides);
1667
- this.state = new X32State(schemaRegistry.getSchema(), stateRepository);
1668
- this.subscriptionManager = new SubscriptionManager(logger, this.config.SUBSCRIPTION_TTL_MS);
1669
- this.meterService = new MeterService();
1670
- this.staticResponseService = new StaticResponseService();
1671
- const reportedIp = this.ip === "0.0.0.0" ? getLocalIp() : this.ip;
1672
- this.messageHandler = new OscMessageHandler(this.state, this.subscriptionManager, logger, reportedIp, name, model, this.meterService, this.schemaRegistry, this.staticResponseService);
1673
- this.processPacket = new ProcessPacketUseCase(this.messageHandler, gateway, logger);
1674
- this.broadcastUpdates = new BroadcastUpdatesUseCase(this.subscriptionManager, this.state, gateway, logger, this.meterService, this.schemaRegistry);
1675
- this.manageSessions = new ManageSessionsUseCase(this.subscriptionManager);
1676
- this.state.on("change", (evt) => {
1677
- this.logger.info(LogCategory.STATE, `State Changed`, evt);
1678
- this.broadcastUpdates.broadcastSingleChange(evt.address, evt.value);
1679
- });
1680
- this.gateway.onPacket((packet, source) => this.processPacket.execute(packet, source));
1681
- }
1682
- /**
1683
- * Starts the simulator server and internal loops.
1684
- */
1685
- async start() {
1686
- await this.state.initialize();
1687
- await this.gateway.start(this.port, this.ip);
1688
- this.cleanupInterval = setInterval(() => {
1689
- this.manageSessions.cleanup();
1690
- }, this.config.CLEANUP_INTERVAL_MS);
1691
- this.updateInterval = setInterval(() => {
1692
- this.broadcastUpdates.execute();
1693
- }, this.config.BROADCAST_INTERVAL_MS);
1694
- }
1695
- /**
1696
- * Stops the simulator server and stops all internal loops.
1697
- */
1698
- async stop() {
1699
- if (this.updateInterval) clearInterval(this.updateInterval);
1700
- if (this.cleanupInterval) clearInterval(this.cleanupInterval);
1701
- await this.state.flush();
1702
- await this.gateway.stop();
1703
- }
1704
- /**
1705
- * Resets the mixer state to default values.
1706
- */
1707
- resetState() {
1708
- this.state.reset();
1709
- }
1710
- /**
1711
- * Forces a save of the current state to storage.
1712
- */
1713
- async saveState() {
1714
- await this.state.flush();
1715
- }
1716
- };
1717
-
1718
- //#endregion
1719
- //#region src/domain/models/X32Node.ts
1720
- /**
1721
- * Metadata for a single state node in the X32 schema.
1722
- * Represents a "Knob" or "Variable" on the console.
1723
- */
1724
- var X32Node = class X32Node {
1725
- /** Value type (f=float, i=int, s=string). */
1726
- type;
1727
- /** Default value for reset. */
1728
- default;
1729
- /** Optional validation constraints. */
1730
- options;
1731
- /**
1732
- * Creates a new X32Node.
1733
- * @param type - The OSC data type ('f', 'i', 's').
1734
- * @param defaultValue - The default value.
1735
- * @param options - Optional validation constraints.
1736
- */
1737
- constructor(type, defaultValue, options) {
1738
- this.type = type;
1739
- this.default = defaultValue;
1740
- this.options = options;
1741
- }
1742
- /**
1743
- * Validates if a value is compatible with this node's type.
1744
- * @param value - The value to check.
1745
- * @param strict - If true, also validates against min/max constraints.
1746
- * @returns True if valid.
1747
- */
1748
- validate(value, strict = false) {
1749
- if (this.type === "f" && typeof value !== "number") return false;
1750
- if (this.type === "i" && typeof value !== "number") return false;
1751
- if (this.type === "s" && typeof value !== "string") return false;
1752
- if (strict && this.options && typeof value === "number") {
1753
- if (this.options.min !== void 0 && value < this.options.min) return false;
1754
- if (this.options.max !== void 0 && value > this.options.max) return false;
1755
- if (this.type === "i" && this.options.strictInteger && !Number.isInteger(value)) return false;
1756
- }
1757
- return true;
1758
- }
1759
- /**
1760
- * Factory method to create from a plain object (for compatibility/migration).
1761
- * @param obj - Plain object.
1762
- * @param obj.type - OSC data type.
1763
- * @param obj.default - Default value.
1764
- * @param obj.options - Optional validation constraints.
1765
- * @returns A new X32Node instance.
1766
- */
1767
- static from(obj) {
1768
- return new X32Node(obj.type, obj.default, obj.options);
1769
- }
1770
- };
1771
-
1772
- //#endregion
1773
- //#region src/infrastructure/repositories/InMemoryStateRepository.ts
1774
- /**
1775
- * In-memory state repository.
1776
- * Stores state in a Map, no persistence across restarts.
1777
- * This is the default and fastest option.
1778
- */
1779
- var InMemoryStateRepository = class {
1780
- state = /* @__PURE__ */ new Map();
1781
- /**
1782
- * Loads state from memory.
1783
- * For in-memory storage, this returns current state.
1784
- */
1785
- async load() {
1786
- return this.getAll();
1787
- }
1788
- /**
1789
- * Saves state to memory.
1790
- * For in-memory storage, this replaces current state.
1791
- */
1792
- async save(state) {
1793
- this.state.clear();
1794
- for (const [key, value] of Object.entries(state)) this.state.set(key, value);
1795
- }
1796
- /**
1797
- * Gets a single value from memory.
1798
- */
1799
- get(address) {
1800
- return this.state.get(address);
1801
- }
1802
- /**
1803
- * Sets a single value in memory.
1804
- */
1805
- set(address, value) {
1806
- this.state.set(address, value);
1807
- }
1808
- /**
1809
- * Gets all entries from memory.
1810
- */
1811
- getAll() {
1812
- const result = {};
1813
- this.state.forEach((value, key) => {
1814
- result[key] = value;
1815
- });
1816
- return result;
1817
- }
1818
- /**
1819
- * Resets state to provided defaults.
1820
- */
1821
- reset(defaults) {
1822
- this.state.clear();
1823
- for (const [key, value] of Object.entries(defaults)) this.state.set(key, value);
1824
- }
1825
- /**
1826
- * No-op for in-memory storage.
1827
- */
1828
- async flush() {}
1829
- };
1830
-
1831
- //#endregion
1832
- //#region src/infrastructure/services/ConsoleLogger.ts
1833
- /**
1834
- * Log levels for the application.
1835
- */
1836
- let LogLevel = /* @__PURE__ */ function(LogLevel$1) {
1837
- LogLevel$1[LogLevel$1["DEBUG"] = 0] = "DEBUG";
1838
- LogLevel$1[LogLevel$1["INFO"] = 1] = "INFO";
1839
- LogLevel$1[LogLevel$1["WARN"] = 2] = "WARN";
1840
- LogLevel$1[LogLevel$1["ERROR"] = 3] = "ERROR";
1841
- LogLevel$1[LogLevel$1["NONE"] = 4] = "NONE";
1842
- return LogLevel$1;
1843
- }({});
1844
- /**
1845
- * Enhanced logger with category support and environment-based filtering.
1846
- */
1847
- var ConsoleLogger = class ConsoleLogger {
1848
- static instance;
1849
- level = LogLevel.DEBUG;
1850
- hiddenPatterns = [];
1851
- enabledCategories = new Set([
1852
- LogCategory.SYSTEM,
1853
- LogCategory.OSC_IN,
1854
- LogCategory.OSC_OUT,
1855
- LogCategory.DISPATCH,
1856
- LogCategory.STATE,
1857
- LogCategory.SUB
1858
- ]);
1859
- constructor() {
1860
- if (process.env.HIDDEN_LOG) this.hiddenPatterns = process.env.HIDDEN_LOG.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
1861
- }
1862
- /**
1863
- * Gets the singleton instance.
1864
- * @returns ConsoleLogger instance.
1865
- */
1866
- static getInstance() {
1867
- if (!ConsoleLogger.instance) ConsoleLogger.instance = new ConsoleLogger();
1868
- return ConsoleLogger.instance;
1869
- }
1870
- /**
1871
- * Sets the minimum log level.
1872
- * @param level - LogLevel.
1873
- */
1874
- setLevel(level) {
1875
- this.level = level;
1876
- }
1877
- /**
1878
- * Enables a category for output.
1879
- * @param cat - Category name.
1880
- */
1881
- enableCategory(cat) {
1882
- this.enabledCategories.add(cat);
1883
- }
1884
- /**
1885
- * Disables a category for output.
1886
- * @param cat - Category name.
1887
- */
1888
- disableCategory(cat) {
1889
- this.enabledCategories.delete(cat);
1890
- }
1891
- /**
1892
- * Logs a debug message.
1893
- * @param category - Log category.
1894
- * @param msg - Message string.
1895
- * @param data - Optional metadata.
1896
- */
1897
- debug(category, msg, data) {
1898
- if (this.shouldHide(msg, data)) return;
1899
- if (this.level <= LogLevel.DEBUG && this.enabledCategories.has(category)) console.log(this.format("DEBUG", category, msg, data));
1900
- }
1901
- /**
1902
- * Logs an info message.
1903
- * @param category - Log category.
1904
- * @param msg - Message string.
1905
- * @param data - Optional metadata.
1906
- */
1907
- info(category, msg, data) {
1908
- if (this.shouldHide(msg, data)) return;
1909
- if (this.level <= LogLevel.INFO && this.enabledCategories.has(category)) console.log(this.format("INFO ", category, msg, data));
1910
- }
1911
- /**
1912
- * Logs a warning message.
1913
- * @param category - Log category.
1914
- * @param msg - Message string.
1915
- * @param data - Optional metadata.
1916
- */
1917
- warn(category, msg, data) {
1918
- if (this.shouldHide(msg, data)) return;
1919
- if (this.level <= LogLevel.WARN && this.enabledCategories.has(category)) console.log(this.format("WARN ", category, msg, data));
1920
- }
1921
- /**
1922
- * Logs an error message.
1923
- * @param category - Log category.
1924
- * @param msg - Message string.
1925
- * @param err - Optional error object.
1926
- */
1927
- error(category, msg, err) {
1928
- if (this.shouldHide(msg, err)) return;
1929
- if (this.level <= LogLevel.ERROR) console.log(this.format("ERROR", category, msg, err));
1930
- }
1931
- /**
1932
- * Checks if a log should be hidden based on patterns.
1933
- * @param msg - Message.
1934
- * @param data - Metadata.
1935
- * @returns True if log should be suppressed.
1936
- */
1937
- shouldHide(msg, data) {
1938
- if (this.hiddenPatterns.length === 0) return false;
1939
- if (this.hiddenPatterns.some((p) => msg.includes(p))) return true;
1940
- if (data !== void 0) {
1941
- const strData = Buffer.isBuffer(data) ? data.toString("hex") : typeof data === "object" ? JSON.stringify(data) : String(data);
1942
- if (this.hiddenPatterns.some((p) => strData.includes(p))) return true;
1943
- }
1944
- return false;
1945
- }
1946
- /**
1947
- * Formats the log message.
1948
- * @param level - Level label.
1949
- * @param category - Category label.
1950
- * @param msg - Message.
1951
- * @param data - Metadata.
1952
- * @returns Formatted string.
1953
- */
1954
- format(level, category, msg, data) {
1955
- const now = /* @__PURE__ */ new Date();
1956
- 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 `;
1957
- switch (level) {
1958
- case "DEBUG":
1959
- out += `\x1b[36m[DEBUG]\x1b[0m`;
1960
- break;
1961
- case "INFO ":
1962
- out += `\x1b[32m[INFO ]\x1b[0m`;
1963
- break;
1964
- case "WARN ":
1965
- out += `\x1b[33m[WARN ]\x1b[0m`;
1966
- break;
1967
- case "ERROR":
1968
- out += `\x1b[31m[ERROR]\x1b[0m`;
1969
- break;
1970
- }
1971
- out += ` \x1b[35m[${category.padEnd(8)}]\x1b[0m ${msg}`;
1972
- if (data !== void 0) try {
1973
- if (Buffer.isBuffer(data)) out += ` \x1b[90m<Buffer ${data.length}b>\x1b[0m`;
1974
- else if (typeof data === "object" && data !== null) out += ` \x1b[90m${JSON.stringify(data)}\x1b[0m`;
1975
- else out += ` \x1b[90m${data}\x1b[0m`;
1976
- } catch {
1977
- out += ` [Circular/Error]`;
1978
- }
1979
- return out;
1980
- }
1981
- };
1982
-
1983
- //#endregion
1984
- //#region src/infrastructure/services/UdpNetworkGateway.ts
1985
- /**
1986
- * Node.js UDP implementation of the network gateway.
1987
- * Handles the low-level socket communication and OSC packet routing.
1988
- */
1989
- var UdpNetworkGateway = class {
1990
- socket;
1991
- isRunning = false;
1992
- packetCallback = null;
1993
- /**
1994
- * Creates a new UdpNetworkGateway.
1995
- * @param logger - Logger service.
1996
- * @param codec - OSC codec for encoding/decoding.
1997
- */
1998
- constructor(logger, codec) {
1999
- this.logger = logger;
2000
- this.codec = codec;
2001
- this.socket = node_dgram.createSocket("udp4");
2002
- }
2003
- /**
2004
- * Registers a callback to be executed whenever a new OSC packet arrives.
2005
- * @param callback - Function called with decoded packet and source info.
2006
- */
2007
- onPacket(callback) {
2008
- this.packetCallback = callback;
2009
- }
2010
- /**
2011
- * Starts the UDP server on the specified port and IP.
2012
- * @param port - UDP port.
2013
- * @param ip - IP address to bind to.
2014
- * @returns Promise resolving when the socket is bound.
2015
- */
2016
- start(port, ip) {
2017
- return new Promise((resolve, reject) => {
2018
- this.socket.on("error", (err) => {
2019
- this.logger.error(LogCategory.SYSTEM, "Socket Error", err);
2020
- reject(err);
2021
- });
2022
- this.socket.on("message", (msg, rinfo) => {
2023
- try {
2024
- this.logger.debug(LogCategory.OSC_IN, `Packet received ${msg.length}b`, { ip: rinfo.address });
2025
- const decoded = this.codec.decode(msg);
2026
- if (this.packetCallback) this.packetCallback(decoded, {
2027
- address: rinfo.address,
2028
- port: rinfo.port
2029
- });
2030
- } catch (err) {
2031
- this.logger.error(LogCategory.OSC_IN, "Decode Error", err instanceof Error ? err : new Error(String(err)));
2032
- }
2033
- });
2034
- this.socket.bind(port, ip, () => {
2035
- this.logger.info(LogCategory.SYSTEM, `Server bound to ${ip}:${port}`);
2036
- this.isRunning = true;
2037
- resolve();
2038
- });
2039
- });
2040
- }
2041
- /**
2042
- * Shuts down the UDP server.
2043
- * @returns Promise resolving when the socket is closed.
2044
- */
2045
- stop() {
2046
- return new Promise((resolve) => {
2047
- if (!this.isRunning) return resolve();
2048
- this.socket.close(() => {
2049
- this.isRunning = false;
2050
- this.logger.info(LogCategory.SYSTEM, "Server stopped");
2051
- resolve();
2052
- });
2053
- });
2054
- }
2055
- /**
2056
- * Sends an OSC message to a specific remote client.
2057
- * @param target - Target client info (IP/port).
2058
- * @param address - OSC address pattern.
2059
- * @param args - Array of arguments.
2060
- */
2061
- send(target, address, args) {
2062
- const buf = this.codec.encode(address, args);
2063
- const cat = address.startsWith("/meters") ? LogCategory.METER : LogCategory.OSC_OUT;
2064
- this.logger.debug(cat, `Sending ${address}`, {
2065
- ip: target.address,
2066
- args
2067
- });
2068
- this.socket.send(buf, target.port, target.address, (err) => {
2069
- if (err) this.logger.error(LogCategory.OSC_OUT, "Send Error", err);
2070
- });
2071
- }
2072
- };
2073
-
2074
- //#endregion
2075
- //#region node_modules/node-osc/lib/Message.mjs
2076
- const typeTags = {
2077
- s: "string",
2078
- f: "float",
2079
- i: "integer",
2080
- b: "blob",
2081
- m: "midi"
2082
- };
2083
- /**
2084
- * Represents a typed argument for an OSC message.
2085
- *
2086
- * @class
2087
- * @private
2088
- */
2089
- var Argument = class {
2090
- /**
2091
- * @param {string} type - The type of the argument (string, float, integer, blob, boolean).
2092
- * @param {*} value - The value of the argument.
2093
- */
2094
- constructor(type, value) {
2095
- this.type = type;
2096
- this.value = value;
2097
- }
2098
- };
2099
- /**
2100
- * Represents an OSC message with an address and arguments.
2101
- *
2102
- * OSC messages consist of an address pattern (string starting with '/')
2103
- * and zero or more arguments of various types.
2104
- *
2105
- * @class
2106
- *
2107
- * @example
2108
- * // Create a message with constructor arguments
2109
- * const msg = new Message('/test', 1, 2, 'hello');
2110
- *
2111
- * @example
2112
- * // Create a message and append arguments
2113
- * const msg = new Message('/test');
2114
- * msg.append(1);
2115
- * msg.append('hello');
2116
- * msg.append(3.14);
2117
- */
2118
- var Message = class {
2119
- /**
2120
- * Create an OSC Message.
2121
- *
2122
- * @param {string} address - The OSC address pattern (e.g., '/oscillator/frequency').
2123
- * @param {...*} args - Optional arguments to include in the message.
2124
- *
2125
- * @example
2126
- * const msg = new Message('/test');
2127
- *
2128
- * @example
2129
- * const msg = new Message('/test', 1, 2, 3);
2130
- *
2131
- * @example
2132
- * const msg = new Message('/synth', 'note', 60, 0.5);
2133
- */
2134
- constructor(address, ...args) {
2135
- this.oscType = "message";
2136
- this.address = address;
2137
- this.args = args;
2138
- }
2139
- /**
2140
- * Append an argument to the message.
2141
- *
2142
- * Automatically detects the type based on the JavaScript type:
2143
- * - Integers are encoded as OSC integers
2144
- * - Floats are encoded as OSC floats
2145
- * - Strings are encoded as OSC strings
2146
- * - Booleans are encoded as OSC booleans
2147
- * - Buffers are encoded as OSC blobs
2148
- * - Arrays are recursively appended
2149
- * - Objects with a 'type' property are used as-is
2150
- *
2151
- * @param {*} arg - The argument to append. Can be:
2152
- * - A primitive value (number, string, boolean)
2153
- * - A Buffer (encoded as blob)
2154
- * - An array of values (will be recursively appended)
2155
- * - An object with 'type' and 'value' properties for explicit type control
2156
- *
2157
- * @throws {Error} If the argument type cannot be encoded.
2158
- *
2159
- * @example
2160
- * const msg = new Message('/test');
2161
- * msg.append(42); // Integer
2162
- * msg.append(3.14); // Float
2163
- * msg.append('hello'); // String
2164
- * msg.append(true); // Boolean
2165
- *
2166
- * @example
2167
- * // Append multiple values at once
2168
- * msg.append([1, 2, 3]);
2169
- *
2170
- * @example
2171
- * // Explicitly specify type
2172
- * msg.append({ type: 'float', value: 42 });
2173
- * msg.append({ type: 'blob', value: Buffer.from('data') });
2174
- *
2175
- * @example
2176
- * // MIDI messages (4 bytes: port, status, data1, data2)
2177
- * msg.append({ type: 'midi', value: { port: 0, status: 144, data1: 60, data2: 127 } });
2178
- * msg.append({ type: 'm', value: Buffer.from([0, 144, 60, 127]) });
2179
- */
2180
- append(arg) {
2181
- let argOut;
2182
- switch (typeof arg) {
2183
- case "object":
2184
- if (Buffer.isBuffer(arg)) this.args.push(arg);
2185
- else if (arg instanceof Array) arg.forEach((a) => this.append(a));
2186
- else if (arg.type) {
2187
- if (typeTags[arg.type]) arg.type = typeTags[arg.type];
2188
- this.args.push(arg);
2189
- } else throw new Error(`don't know how to encode object ${arg}`);
2190
- break;
2191
- case "number":
2192
- if (Math.floor(arg) === arg) argOut = new Argument("integer", arg);
2193
- else argOut = new Argument("float", arg);
2194
- break;
2195
- case "string":
2196
- argOut = new Argument("string", arg);
2197
- break;
2198
- case "boolean":
2199
- argOut = new Argument("boolean", arg);
2200
- break;
2201
- default: throw new Error(`don't know how to encode ${arg}`);
2202
- }
2203
- if (argOut) this.args.push(argOut);
2204
- }
2205
- };
2206
- var Message_default = Message;
2207
-
2208
- //#endregion
2209
- //#region node_modules/node-osc/lib/osc.mjs
2210
- function padString(str) {
2211
- const nullTerminated = str + "\0";
2212
- const padding = (4 - node_buffer.Buffer.byteLength(nullTerminated) % 4) % 4;
2213
- return nullTerminated + "\0".repeat(padding);
2214
- }
2215
- function readString(buffer, offset) {
2216
- let end = offset;
2217
- while (end < buffer.length && buffer[end] !== 0) end++;
2218
- if (end >= buffer.length) throw new Error("Malformed Packet: Missing null terminator for string");
2219
- return {
2220
- value: buffer.subarray(offset, end).toString("utf8"),
2221
- offset: offset + Math.ceil((end - offset + 1) / 4) * 4
2222
- };
2223
- }
2224
- function writeInt32(value) {
2225
- const buffer = node_buffer.Buffer.alloc(4);
2226
- buffer.writeInt32BE(value, 0);
2227
- return buffer;
2228
- }
2229
- function readInt32(buffer, offset) {
2230
- if (offset + 4 > buffer.length) throw new Error("Malformed Packet: Not enough bytes for int32");
2231
- return {
2232
- value: buffer.readInt32BE(offset),
2233
- offset: offset + 4
2234
- };
2235
- }
2236
- function writeFloat32(value) {
2237
- const buffer = node_buffer.Buffer.alloc(4);
2238
- buffer.writeFloatBE(value, 0);
2239
- return buffer;
2240
- }
2241
- function readFloat32(buffer, offset) {
2242
- if (offset + 4 > buffer.length) throw new Error("Malformed Packet: Not enough bytes for float32");
2243
- return {
2244
- value: buffer.readFloatBE(offset),
2245
- offset: offset + 4
2246
- };
2247
- }
2248
- function writeBlob(value) {
2249
- const length = value.length;
2250
- const lengthBuffer = writeInt32(length);
2251
- const padding = 4 - length % 4;
2252
- const paddingBuffer = node_buffer.Buffer.alloc(padding === 4 ? 0 : padding);
2253
- return node_buffer.Buffer.concat([
2254
- lengthBuffer,
2255
- value,
2256
- paddingBuffer
2257
- ]);
2258
- }
2259
- function readBlob(buffer, offset) {
2260
- const lengthResult = readInt32(buffer, offset);
2261
- const length = lengthResult.value;
2262
- if (length < 0) throw new Error("Malformed Packet: Invalid blob length");
2263
- if (lengthResult.offset + length > buffer.length) throw new Error("Malformed Packet: Not enough bytes for blob");
2264
- const data = buffer.subarray(lengthResult.offset, lengthResult.offset + length);
2265
- const padding = 4 - length % 4;
2266
- const nextOffset = lengthResult.offset + length + (padding === 4 ? 0 : padding);
2267
- if (nextOffset > buffer.length) throw new Error("Malformed Packet: Not enough bytes for blob padding");
2268
- return {
2269
- value: data,
2270
- offset: nextOffset
2271
- };
2272
- }
2273
- function writeTimeTag(value) {
2274
- const buffer = node_buffer.Buffer.alloc(8);
2275
- if (value === 0 || value === null || value === void 0) {
2276
- buffer.writeUInt32BE(0, 0);
2277
- buffer.writeUInt32BE(1, 4);
2278
- } else if (typeof value === "number") {
2279
- const seconds = Math.floor(value);
2280
- const fraction = Math.floor((value - seconds) * 4294967296);
2281
- buffer.writeUInt32BE(seconds + 2208988800, 0);
2282
- buffer.writeUInt32BE(fraction, 4);
2283
- } else {
2284
- buffer.writeUInt32BE(0, 0);
2285
- buffer.writeUInt32BE(1, 4);
2286
- }
2287
- return buffer;
2288
- }
2289
- function readTimeTag(buffer, offset) {
2290
- if (offset + 8 > buffer.length) throw new Error("Malformed Packet: Not enough bytes for timetag");
2291
- const seconds = buffer.readUInt32BE(offset);
2292
- const fraction = buffer.readUInt32BE(offset + 4);
2293
- let value;
2294
- if (seconds === 0 && fraction === 1) value = 0;
2295
- else value = seconds - 2208988800 + fraction / 4294967296;
2296
- return {
2297
- value,
2298
- offset: offset + 8
2299
- };
2300
- }
2301
- function writeMidi(value) {
2302
- const buffer = node_buffer.Buffer.alloc(4);
2303
- if (node_buffer.Buffer.isBuffer(value)) {
2304
- if (value.length !== 4) throw new Error("MIDI message must be exactly 4 bytes");
2305
- value.copy(buffer);
2306
- } else if (typeof value === "object" && value !== null) {
2307
- buffer.writeUInt8(value.port || 0, 0);
2308
- buffer.writeUInt8(value.status || 0, 1);
2309
- buffer.writeUInt8(value.data1 || 0, 2);
2310
- buffer.writeUInt8(value.data2 || 0, 3);
2311
- } else throw new Error("MIDI value must be a 4-byte Buffer or object with port, status, data1, data2 properties");
2312
- return buffer;
2313
- }
2314
- function readMidi(buffer, offset) {
2315
- if (offset + 4 > buffer.length) throw new Error("Not enough bytes for MIDI message");
2316
- return {
2317
- value: buffer.subarray(offset, offset + 4),
2318
- offset: offset + 4
2319
- };
2320
- }
2321
- function encodeArgument(arg) {
2322
- if (typeof arg === "object" && arg.type && arg.value !== void 0) switch (arg.type) {
2323
- case "i":
2324
- case "integer": return {
2325
- tag: "i",
2326
- data: writeInt32(arg.value)
2327
- };
2328
- case "f":
2329
- case "float": return {
2330
- tag: "f",
2331
- data: writeFloat32(arg.value)
2332
- };
2333
- case "s":
2334
- case "string": return {
2335
- tag: "s",
2336
- data: node_buffer.Buffer.from(padString(arg.value))
2337
- };
2338
- case "b":
2339
- case "blob": return {
2340
- tag: "b",
2341
- data: writeBlob(arg.value)
2342
- };
2343
- case "d":
2344
- case "double": return {
2345
- tag: "f",
2346
- data: writeFloat32(arg.value)
2347
- };
2348
- case "T": return {
2349
- tag: "T",
2350
- data: node_buffer.Buffer.alloc(0)
2351
- };
2352
- case "F": return {
2353
- tag: "F",
2354
- data: node_buffer.Buffer.alloc(0)
2355
- };
2356
- case "boolean": return arg.value ? {
2357
- tag: "T",
2358
- data: node_buffer.Buffer.alloc(0)
2359
- } : {
2360
- tag: "F",
2361
- data: node_buffer.Buffer.alloc(0)
2362
- };
2363
- case "m":
2364
- case "midi": return {
2365
- tag: "m",
2366
- data: writeMidi(arg.value)
2367
- };
2368
- default: throw new Error(`Unknown argument type: ${arg.type}`);
2369
- }
2370
- switch (typeof arg) {
2371
- case "number": if (Number.isInteger(arg)) return {
2372
- tag: "i",
2373
- data: writeInt32(arg)
2374
- };
2375
- else return {
2376
- tag: "f",
2377
- data: writeFloat32(arg)
2378
- };
2379
- case "string": return {
2380
- tag: "s",
2381
- data: node_buffer.Buffer.from(padString(arg))
2382
- };
2383
- case "boolean": return arg ? {
2384
- tag: "T",
2385
- data: node_buffer.Buffer.alloc(0)
2386
- } : {
2387
- tag: "F",
2388
- data: node_buffer.Buffer.alloc(0)
2389
- };
2390
- default:
2391
- if (node_buffer.Buffer.isBuffer(arg)) return {
2392
- tag: "b",
2393
- data: writeBlob(arg)
2394
- };
2395
- throw new Error(`Don't know how to encode argument: ${arg}`);
2396
- }
2397
- }
2398
- function decodeArgument(tag, buffer, offset) {
2399
- switch (tag) {
2400
- case "i": return readInt32(buffer, offset);
2401
- case "f": return readFloat32(buffer, offset);
2402
- case "s": return readString(buffer, offset);
2403
- case "b": return readBlob(buffer, offset);
2404
- case "T": return {
2405
- value: true,
2406
- offset
2407
- };
2408
- case "F": return {
2409
- value: false,
2410
- offset
2411
- };
2412
- case "N": return {
2413
- value: null,
2414
- offset
2415
- };
2416
- case "m": return readMidi(buffer, offset);
2417
- default: throw new Error(`I don't understand the argument code ${tag}`);
2418
- }
2419
- }
2420
- /**
2421
- * Encode an OSC message or bundle to a Buffer.
2422
- *
2423
- * This low-level function converts OSC messages and bundles into binary format
2424
- * for transmission or storage. Useful for sending OSC over custom transports
2425
- * (WebSocket, TCP, HTTP), storing to files, or implementing custom OSC routers.
2426
- *
2427
- * @param {Object} message - OSC message or bundle object with oscType property
2428
- * @returns {Buffer} The encoded OSC data ready for transmission
2429
- *
2430
- * @example
2431
- * // Encode a message
2432
- * import { Message, encode } from 'node-osc';
2433
- *
2434
- * const message = new Message('/oscillator/frequency', 440);
2435
- * const buffer = encode(message);
2436
- * console.log('Encoded bytes:', buffer.length);
2437
- *
2438
- * @example
2439
- * // Encode a bundle
2440
- * import { Bundle, encode } from 'node-osc';
2441
- *
2442
- * const bundle = new Bundle(['/one', 1], ['/two', 2]);
2443
- * const buffer = encode(bundle);
2444
- *
2445
- * @example
2446
- * // Send over WebSocket
2447
- * const buffer = encode(message);
2448
- * websocket.send(buffer);
2449
- */
2450
- function encode(message) {
2451
- if (message.oscType === "bundle") return encodeBundleToBuffer(message);
2452
- else return encodeMessageToBuffer(message);
2453
- }
2454
- function encodeMessageToBuffer(message) {
2455
- const address = padString(message.address);
2456
- const addressBuffer = node_buffer.Buffer.from(address);
2457
- const encodedArgs = message.args.map(encodeArgument);
2458
- const typeTags$1 = "," + encodedArgs.map((arg) => arg.tag).join("");
2459
- const typeTagsBuffer = node_buffer.Buffer.from(padString(typeTags$1));
2460
- const argumentBuffers = encodedArgs.map((arg) => arg.data);
2461
- return node_buffer.Buffer.concat([
2462
- addressBuffer,
2463
- typeTagsBuffer,
2464
- ...argumentBuffers
2465
- ]);
2466
- }
2467
- function encodeBundleToBuffer(bundle) {
2468
- const bundleString = padString("#bundle");
2469
- const bundleStringBuffer = node_buffer.Buffer.from(bundleString);
2470
- const timetagBuffer = writeTimeTag(bundle.timetag);
2471
- const elementBuffers = bundle.elements.map((element) => {
2472
- let elementBuffer;
2473
- if (element.oscType === "bundle") elementBuffer = encodeBundleToBuffer(element);
2474
- else elementBuffer = encodeMessageToBuffer(element);
2475
- const sizeBuffer = writeInt32(elementBuffer.length);
2476
- return node_buffer.Buffer.concat([sizeBuffer, elementBuffer]);
2477
- });
2478
- return node_buffer.Buffer.concat([
2479
- bundleStringBuffer,
2480
- timetagBuffer,
2481
- ...elementBuffers
2482
- ]);
2483
- }
2484
- /**
2485
- * Decode a Buffer containing OSC data into a message or bundle object.
2486
- *
2487
- * This low-level function parses binary OSC data back into JavaScript objects.
2488
- * Useful for receiving OSC over custom transports, reading from files,
2489
- * or implementing custom OSC routers.
2490
- *
2491
- * @param {Buffer} buffer - The Buffer containing OSC data
2492
- * @returns {Object} The decoded OSC message or bundle. Messages have
2493
- * {oscType: 'message', address: string, args: Array}, bundles have
2494
- * {oscType: 'bundle', timetag: number, elements: Array}
2495
- * @throws {Error} If the buffer contains malformed OSC data
2496
- *
2497
- * @example
2498
- * // Decode received data
2499
- * import { decode } from 'node-osc';
2500
- *
2501
- * const decoded = decode(buffer);
2502
- * if (decoded.oscType === 'message') {
2503
- * console.log('Address:', decoded.address);
2504
- * console.log('Arguments:', decoded.args);
2505
- * }
2506
- *
2507
- * @example
2508
- * // Round-trip encode/decode
2509
- * import { Message, encode, decode } from 'node-osc';
2510
- *
2511
- * const original = new Message('/test', 42, 'hello');
2512
- * const buffer = encode(original);
2513
- * const decoded = decode(buffer);
2514
- * console.log(decoded.address); // '/test'
2515
- */
2516
- function decode(buffer) {
2517
- if (buffer.length >= 8 && buffer.subarray(0, 8).toString() === "#bundle\0") return decodeBundleFromBuffer(buffer);
2518
- else return decodeMessageFromBuffer(buffer);
2519
- }
2520
- function decodeMessageFromBuffer(buffer) {
2521
- let offset = 0;
2522
- const addressResult = readString(buffer, offset);
2523
- const address = addressResult.value;
2524
- offset = addressResult.offset;
2525
- const typeTagsResult = readString(buffer, offset);
2526
- const typeTags$1 = typeTagsResult.value;
2527
- offset = typeTagsResult.offset;
2528
- if (!typeTags$1.startsWith(",")) throw new Error("Malformed Packet");
2529
- const tags = typeTags$1.slice(1);
2530
- const args = [];
2531
- for (const tag of tags) {
2532
- const argResult = decodeArgument(tag, buffer, offset);
2533
- args.push({ value: argResult.value });
2534
- offset = argResult.offset;
2535
- }
2536
- return {
2537
- oscType: "message",
2538
- address,
2539
- args
2540
- };
2541
- }
2542
- function decodeBundleFromBuffer(buffer) {
2543
- let offset = 8;
2544
- const timetagResult = readTimeTag(buffer, offset);
2545
- const timetag = timetagResult.value;
2546
- offset = timetagResult.offset;
2547
- const elements = [];
2548
- while (offset < buffer.length) {
2549
- const sizeResult = readInt32(buffer, offset);
2550
- const size = sizeResult.value;
2551
- offset = sizeResult.offset;
2552
- if (size <= 0 || offset + size > buffer.length) throw new Error("Malformed Packet");
2553
- const element = decode(buffer.subarray(offset, offset + size));
2554
- elements.push(element);
2555
- offset += size;
2556
- }
2557
- return {
2558
- oscType: "bundle",
2559
- timetag,
2560
- elements
2561
- };
2562
- }
2563
-
2564
- //#endregion
2565
- //#region src/infrastructure/mappers/OscCodec.ts
2566
- /**
2567
- * Handles encoding and decoding of X32 OSC messages.
2568
- */
2569
- var OscCodec = class {
2570
- constructor(schemaRegistry) {
2571
- this.schemaRegistry = schemaRegistry;
2572
- }
2573
- /**
2574
- * Decodes a binary OSC message into a packet object.
2575
- * @param msg - Raw UDP buffer.
2576
- * @returns Decoded OscPacket.
2577
- */
2578
- decode(msg) {
2579
- return decode(msg);
2580
- }
2581
- /**
2582
- * Encodes an address and arguments into a binary OSC message.
2583
- * @param address - OSC address pattern.
2584
- * @param args - Array of arguments.
2585
- * @returns Binary buffer.
2586
- */
2587
- encode(address, args) {
2588
- return encode(this.createMessage(address, args));
2589
- }
2590
- /**
2591
- * Creates a typed node-osc Message based on X32 schema.
2592
- * @param address - Target address.
2593
- * @param args - Untyped arguments.
2594
- * @returns Typed Message.
2595
- */
2596
- createMessage(address, args) {
2597
- return new Message_default(address, ...args.map((arg) => {
2598
- if (typeof arg === "object" && arg !== null && "type" in arg && "value" in arg) return arg;
2599
- if (Buffer.isBuffer(arg)) return arg;
2600
- const node = this.schemaRegistry.getNode(address);
2601
- if (node) {
2602
- if (node.type === "f" && typeof arg === "number") return {
2603
- type: "f",
2604
- value: arg
2605
- };
2606
- if (node.type === "i" && typeof arg === "number") return {
2607
- type: "i",
2608
- value: Math.round(arg)
2609
- };
2610
- if (node.type === "s" && typeof arg === "string") return {
2611
- type: "s",
2612
- value: arg
2613
- };
2614
- }
2615
- return arg;
2616
- }));
2617
- }
2618
- };
2619
-
2620
- //#endregion
2621
- //#region src/domain/services/SchemaFactory.ts
2622
- /**
2623
- * Factory service responsible for constructing the X32 OSC Schema.
2624
- * Encapsulates all the logic for generating channel strips, routing blocks, etc.
2625
- */
2626
- var SchemaFactory = class {
2627
- /**
2628
- * Builds the complete X32 OSC Schema.
2629
- * @returns The constructed schema map.
2630
- */
2631
- createSchema() {
2632
- const schema = {
2633
- ...this.generateNodes(32, "ch"),
2634
- ...this.generateNodes(16, "bus"),
2635
- ...this.generateNodes(8, "dca"),
2636
- ...this.generateNodes(8, "auxin"),
2637
- ...this.generateNodes(8, "fxrtn"),
2638
- ...this.generateNodes(6, "mtx"),
2639
- ...Object.fromEntries(Array.from({ length: 8 }, (_, i) => [`/fx/${i + 1}/type`, this.node("i", 0)])),
2640
- ...this.generateRange(8, "/fx", "/type", "i", 0),
2641
- ...this.generateRange(8, "/fx", "/source/l", "i", 0),
2642
- ...this.generateRange(8, "/fx", "/source/r", "i", 0),
2643
- ...Object.fromEntries(Array.from({ length: 8 }, (_, slot) => Object.entries(this.generateRange(64, `/fx/${slot + 1}/par`, "", "f", 0, 2, 1))).flat()),
2644
- ...this.generateRange(128, "/headamp", "/gain", "f", 0, 3, 0),
2645
- ...this.generateRange(128, "/headamp", "/phantom", "i", 0, 3, 0),
2646
- ...this.generateRange(6, "/config/mute", "", "i", 0),
2647
- ...this.generateRange(80, "/-stat/solosw", "", "i", 0, 2, 1),
2648
- "/-stat/selidx": this.node("i", 0),
2649
- "/-stat/chfaderbank": this.node("i", 0),
2650
- "/-stat/grpfaderbank": this.node("i", 0),
2651
- "/-stat/sendsonfader": this.node("i", 0),
2652
- "/-stat/bussendbank": this.node("i", 0),
2653
- "/-stat/eqband": this.node("i", 0),
2654
- "/-stat/keysolo": this.node("i", 0),
2655
- "/-stat/userbank": this.node("i", 0),
2656
- "/-stat/autosave": this.node("i", 0),
2657
- "/-stat/lock": this.node("i", 0),
2658
- "/-stat/usbmounted": this.node("i", 0),
2659
- "/-stat/remote": this.node("i", 0),
2660
- "/-stat/rtamodeeq": this.node("i", 0),
2661
- "/-stat/rtamodegeq": this.node("i", 0),
2662
- "/-stat/rtaeqpre": this.node("i", 0),
2663
- "/-stat/rtageqpost": this.node("i", 0),
2664
- "/-stat/rtasource": this.node("i", 0),
2665
- "/-stat/xcardtype": this.node("i", 0),
2666
- "/-stat/xcardsync": this.node("i", 0),
2667
- "/-stat/geqonfdr": this.node("i", 0),
2668
- "/-stat/geqpos": this.node("i", 0),
2669
- "/-stat/screen/screen": this.node("i", 0),
2670
- "/-stat/screen/mutegrp": this.node("i", 0),
2671
- "/-stat/screen/utils": this.node("i", 0),
2672
- "/-stat/screen/CHAN/page": this.node("i", 0),
2673
- "/-stat/screen/METER/page": this.node("i", 0),
2674
- "/-stat/screen/ROUTE/page": this.node("i", 0),
2675
- "/-stat/screen/SETUP/page": this.node("i", 0),
2676
- "/-stat/screen/LIB/page": this.node("i", 0),
2677
- "/-stat/screen/LIBRARY/page": this.node("i", 0),
2678
- "/-stat/screen/FX/page": this.node("i", 0),
2679
- "/-stat/screen/MON/page": this.node("i", 0),
2680
- "/-stat/screen/USB/page": this.node("i", 0),
2681
- "/-stat/screen/SCENE/page": this.node("i", 0),
2682
- "/-stat/screen/ASSIGN/page": this.node("i", 0),
2683
- "/-stat/aes50/state": this.node("i", 0),
2684
- "/-stat/aes50/A": this.node("i", 0),
2685
- "/-stat/aes50/B": this.node("i", 0),
2686
- "/-stat/aes50/stats/A": this.node("i", 0),
2687
- "/-stat/aes50/stats/B": this.node("i", 0),
2688
- "/-stat/tape/state": this.node("i", 0),
2689
- "/-stat/tape/file": this.node("s", ""),
2690
- "/-stat/tape/etime": this.node("i", 0),
2691
- "/-stat/tape/rtime": this.node("i", 0),
2692
- "/-stat/urec/state": this.node("i", 0),
2693
- "/-stat/urec/etime": this.node("i", 0),
2694
- "/-stat/urec/rtime": this.node("i", 0),
2695
- "/-stat/talk/A": this.node("i", 0),
2696
- "/-stat/talk/B": this.node("i", 0),
2697
- "/-stat/osc/on": this.node("i", 0),
2698
- "/-action/setip": this.node("i", 0),
2699
- "/-action/setclock": this.node("i", 0),
2700
- "/-action/initall": this.node("i", 0),
2701
- "/-action/initlib": this.node("i", 0),
2702
- "/-action/initshow": this.node("i", 0),
2703
- "/-action/savestate": this.node("i", 0),
2704
- "/-action/undopt": this.node("i", 0),
2705
- "/-action/doundo": this.node("i", 0),
2706
- "/-action/playtrack": this.node("i", 0),
2707
- "/-action/newscreen": this.node("i", 0),
2708
- "/-action/clearsolo": this.node("i", 0),
2709
- "/-action/setprebus": this.node("i", 0),
2710
- "/-action/setsrate": this.node("i", 0),
2711
- "/-action/setrtasrc": this.node("i", 0),
2712
- "/-action/recselect": this.node("i", 0),
2713
- "/-action/gocue": this.node("i", 0),
2714
- "/-action/goscene": this.node("i", 0),
2715
- "/-action/setscene": this.node("i", 0),
2716
- "/-action/gosnippet": this.node("i", 0),
2717
- "/-action/selsession": this.node("i", 0),
2718
- "/-action/delsession": this.node("i", 0),
2719
- "/-action/selmarker": this.node("i", 0),
2720
- "/-action/delmarker": this.node("i", 0),
2721
- "/-action/savemarker": this.node("i", 0),
2722
- "/-action/addmarker": this.node("i", 0),
2723
- "/-action/selposition": this.node("i", 0),
2724
- "/-action/clearalert": this.node("i", 0),
2725
- "/-action/formatcard": this.node("i", 0),
2726
- "/-undo/time": this.node("s", ""),
2727
- "/-show": this.node("i", 0),
2728
- "/-show/prepos": this.node("i", 0),
2729
- "/-show/prepos/current": this.node("i", 0),
2730
- "/-show/showfile": this.node("s", ""),
2731
- "/-show/showfile/inputs": this.node("i", 0),
2732
- "/-show/showfile/mxsends": this.node("i", 0),
2733
- "/-show/showfile/mxbuses": this.node("i", 0),
2734
- "/-show/showfile/console": this.node("i", 0),
2735
- "/-show/showfile/chan16": this.node("i", 0),
2736
- "/-show/showfile/chan32": this.node("i", 0),
2737
- "/-show/showfile/return": this.node("i", 0),
2738
- "/-show/showfile/buses": this.node("i", 0),
2739
- "/-show/showfile/lrmtxdca": this.node("i", 0),
2740
- "/-show/showfile/effects": this.node("i", 0),
2741
- ...this.generateShowfileCues(),
2742
- ...this.generateShowfileScenes(),
2743
- ...this.generateShowfileSnippets(),
2744
- "/-usb/path": this.node("s", ""),
2745
- "/-usb/title": this.node("s", ""),
2746
- "/-usb/dir": this.node("i", 0),
2747
- "/-usb/dirpos": this.node("i", 0),
2748
- "/-usb/maxpos": this.node("i", 0),
2749
- ...this.generateUSBDir(),
2750
- "/-urec/sessionmax": this.node("i", 0),
2751
- "/-urec/markermax": this.node("i", 0),
2752
- "/-urec/sessionlen": this.node("i", 0),
2753
- "/-urec/sessionpos": this.node("i", 0),
2754
- "/-urec/markerpos": this.node("i", 0),
2755
- "/-urec/batterystate": this.node("i", 0),
2756
- "/-urec/srate": this.node("i", 0),
2757
- "/-urec/tracks": this.node("i", 0),
2758
- "/-urec/sessionspan": this.node("i", 0),
2759
- "/-urec/sessionoffs": this.node("i", 0),
2760
- "/-urec/sd1state": this.node("i", 0),
2761
- "/-urec/sd2state": this.node("i", 0),
2762
- "/-urec/sd1info": this.node("s", ""),
2763
- "/-urec/sd2info": this.node("s", ""),
2764
- "/-urec/errormessage": this.node("s", ""),
2765
- "/-urec/errorcode": this.node("i", 0),
2766
- ...this.generateURecSessions(),
2767
- ...this.generateLibraries(),
2768
- "/-insert": this.node("i", 0),
2769
- "/-prefs/style": this.node("i", 0),
2770
- "/-prefs/bright": this.node("i", 50),
2771
- "/-prefs/lcdcont": this.node("i", 50),
2772
- "/-prefs/ledbright": this.node("i", 50),
2773
- "/-prefs/lamp": this.node("i", 50),
2774
- "/-prefs/lampon": this.node("i", 0),
2775
- "/-prefs/clockrate": this.node("i", 0),
2776
- "/-prefs/clocksource": this.node("i", 0),
2777
- "/-prefs/confirm_general": this.node("i", 1),
2778
- "/-prefs/confirm_overwrite": this.node("i", 1),
2779
- "/-prefs/confirm_sceneload": this.node("i", 1),
2780
- "/-prefs/viewrtn": this.node("i", 0),
2781
- "/-prefs/selfollowsbank": this.node("i", 0),
2782
- "/-prefs/scene_advance": this.node("i", 0),
2783
- "/-prefs/safe_masterlevels": this.node("i", 0),
2784
- "/-prefs/haflags": this.node("i", 0),
2785
- "/-prefs/autosel": this.node("i", 1),
2786
- "/-prefs/show_control": this.node("i", 0),
2787
- "/-prefs/clockmode": this.node("i", 0),
2788
- "/-prefs/hardmute": this.node("i", 0),
2789
- "/-prefs/dcamute": this.node("i", 0),
2790
- "/-prefs/invertmutes": this.node("i", 0),
2791
- "/-prefs/name": this.node("s", "X32-Simulator"),
2792
- "/-prefs/rec_control": this.node("i", 0),
2793
- "/-prefs/fastFaders": this.node("i", 0),
2794
- "/-prefs/ip": this.node("s", ""),
2795
- "/-prefs/ip/dhcp": this.node("i", 0),
2796
- "/-prefs/ip/addr": this.node("s", "192.168.1.1"),
2797
- "/-prefs/ip/mask": this.node("s", "255.255.255.0"),
2798
- "/-prefs/ip/gateway": this.node("s", "192.168.1.1"),
2799
- "/-prefs/remote": this.node("i", 0),
2800
- "/-prefs/remote/enable": this.node("i", 0),
2801
- "/-prefs/remote/protocol": this.node("i", 0),
2802
- "/-prefs/remote/port": this.node("i", 10023),
2803
- "/-prefs/remote/ioenable": this.node("i", 0),
2804
- "/-prefs/card": this.node("i", 0),
2805
- "/-prefs/card/UFifc": this.node("i", 0),
2806
- "/-prefs/card/UFmode": this.node("i", 0),
2807
- "/-prefs/card/USBmode": this.node("i", 0),
2808
- "/-prefs/card/ADATwc": this.node("i", 0),
2809
- "/-prefs/card/ADATsync": this.node("i", 0),
2810
- "/-prefs/card/MADImode": this.node("i", 0),
2811
- "/-prefs/card/MADIin": this.node("i", 0),
2812
- "/-prefs/card/MADIout": this.node("i", 0),
2813
- "/-prefs/card/MADIsrc": this.node("i", 0),
2814
- "/-prefs/card/URECtracks": this.node("i", 0),
2815
- "/-prefs/card/URECplayb": this.node("i", 0),
2816
- "/-prefs/card/URECrout": this.node("i", 0),
2817
- "/-prefs/card/URECsdsel": this.node("i", 0),
2818
- "/-prefs/rta": this.node("i", 0),
2819
- "/-prefs/rta/visibility": this.node("s", "70%"),
2820
- "/-prefs/rta/gain": this.node("f", 0),
2821
- "/-prefs/rta/autogain": this.node("i", 0),
2822
- "/-prefs/rta/source": this.node("i", 0),
2823
- "/-prefs/rta/pos": this.node("i", 0),
2824
- "/-prefs/rta/mode": this.node("i", 0),
2825
- "/-prefs/rta/option": this.node("i", 0),
2826
- "/-prefs/rta/det": this.node("i", 0),
2827
- "/-prefs/rta/decay": this.node("i", 0),
2828
- "/-prefs/rta/peakhold": this.node("i", 0),
2829
- ...this.generatePrefsIQ(),
2830
- "/-prefs/key/layout": this.node("i", 0),
2831
- ...this.generateRange(100, "/-prefs/key", "", "i", 0, 2, 0),
2832
- "/config/routing/AES50A/1-8": this.node("i", 0),
2833
- "/config/routing/AES50B/1-8": this.node("i", 0),
2834
- "/config/routing/CARD/1-8": this.node("i", 0),
2835
- "/config/routing/OUT/1-4": this.node("i", 0),
2836
- ...this.generateChannelStrip("/main/st", 6, false),
2837
- ...this.generateChannelStrip("/main/m", 6, false),
2838
- ...Object.fromEntries(Array.from({ length: 16 }, (_, i) => [`/config/chlink/${i * 2 + 1}-${i * 2 + 2}`, this.node("i", 0)])),
2839
- ...Object.fromEntries(Array.from({ length: 8 }, (_, i) => [`/config/buslink/${i * 2 + 1}-${i * 2 + 2}`, this.node("i", 0)])),
2840
- ...Object.fromEntries(Array.from({ length: 4 }, (_, i) => [`/config/auxlink/${i * 2 + 1}-${i * 2 + 2}`, this.node("i", 0)])),
2841
- ...Object.fromEntries(Array.from({ length: 4 }, (_, i) => [`/config/fxlink/${i * 2 + 1}-${i * 2 + 2}`, this.node("i", 0)])),
2842
- ...Object.fromEntries(Array.from({ length: 3 }, (_, i) => [`/config/mtxlink/${i * 2 + 1}-${i * 2 + 2}`, this.node("i", 0)])),
2843
- "/config/linkcfg/hadly": this.node("i", 0),
2844
- "/config/linkcfg/eq": this.node("i", 0),
2845
- "/config/linkcfg/dyn": this.node("i", 0),
2846
- "/config/linkcfg/fdrmute": this.node("i", 0),
2847
- "/config/mono/mode": this.node("i", 0),
2848
- "/config/mono/link": this.node("i", 0),
2849
- "/config/tape/autoplay": this.node("i", 0),
2850
- "/config/tape/gainL": this.node("f", .5),
2851
- "/config/tape/gainR": this.node("f", .5),
2852
- "/config/amixenable/X": this.node("i", 0),
2853
- "/config/amixenable/Y": this.node("i", 0),
2854
- ...this.generateUserCtrl(),
2855
- "/config/routing/routswitch": this.node("i", 0),
2856
- ...this.generateRange(32, "/config/userrout/in", "", "i", 0),
2857
- ...this.generateRange(48, "/config/userrout/out", "", "i", 0),
2858
- "/config/solo/level": this.node("f", 0),
2859
- "/config/solo/source": this.node("i", 0),
2860
- "/config/solo/sourcetrim": this.node("f", 0),
2861
- "/config/solo/exclusive": this.node("i", 0),
2862
- "/config/solo/dim": this.node("i", 0),
2863
- "/config/solo/dimpfl": this.node("i", 0),
2864
- "/config/solo/dimatt": this.node("f", 0),
2865
- "/config/solo/mono": this.node("i", 0),
2866
- "/config/solo/chmode": this.node("i", 0),
2867
- "/config/solo/busmode": this.node("i", 0),
2868
- "/config/solo/dcamode": this.node("i", 0),
2869
- "/config/solo/masterctrl": this.node("i", 0),
2870
- "/config/solo/delay": this.node("i", 0),
2871
- "/config/solo/delaytime": this.node("f", 0),
2872
- "/config/solo/followsel": this.node("i", 0),
2873
- "/config/solo/followsolo": this.node("i", 0),
2874
- "/config/talk/enable": this.node("i", 0),
2875
- "/config/talk/source": this.node("i", 0),
2876
- "/config/talk/A/level": this.node("f", 0),
2877
- "/config/talk/B/level": this.node("f", 0),
2878
- "/config/talk/A/dim": this.node("i", 0),
2879
- "/config/talk/B/dim": this.node("i", 0),
2880
- "/config/talk/A/latch": this.node("i", 0),
2881
- "/config/talk/B/latch": this.node("i", 0),
2882
- "/config/talk/A/destmap": this.node("i", 0),
2883
- "/config/talk/B/destmap": this.node("i", 0),
2884
- "/config/osc/on": this.node("i", 0),
2885
- "/config/osc/type": this.node("i", 0),
2886
- "/config/osc/fsel": this.node("i", 0),
2887
- "/config/osc/f1": this.node("f", .5),
2888
- "/config/osc/f2": this.node("f", .5),
2889
- "/config/osc/level": this.node("f", 0),
2890
- "/config/osc/dest": this.node("i", 0),
2891
- ...this.generateDP48Config(),
2892
- ...this.generateOutputs("main", 16),
2893
- ...this.generateOutputs("aux", 6),
2894
- ...this.generateOutputs("p16", 16),
2895
- ...this.generateOutputs("aes", 2),
2896
- ...this.generateOutputs("rec", 2)
2897
- };
2898
- Object.keys(STATIC_RESPONSES_DATA).forEach((key) => {
2899
- if (key.startsWith("/-")) {
2900
- const val = STATIC_RESPONSES_DATA[key][0];
2901
- const type = typeof val === "string" ? "s" : Number.isInteger(val) ? "i" : "f";
2902
- schema[key] = this.node(type, val);
2903
- }
2904
- });
2905
- [
2906
- "/config/routing/IN/1-8",
2907
- "/config/routing/IN/9-16",
2908
- "/config/routing/IN/17-24",
2909
- "/config/routing/IN/25-32",
2910
- "/config/routing/AUX/1-4",
2911
- "/config/routing/OUT/1-4",
2912
- "/config/routing/OUT/5-8",
2913
- "/config/routing/OUT/9-12",
2914
- "/config/routing/OUT/13-16",
2915
- "/config/routing/P16/1-8",
2916
- "/config/routing/P16/9-16",
2917
- "/config/routing/CARD/1-8",
2918
- "/config/routing/CARD/9-16",
2919
- "/config/routing/CARD/17-24",
2920
- "/config/routing/CARD/25-32",
2921
- "/config/routing/AES50A/1-8",
2922
- "/config/routing/AES50A/9-16",
2923
- "/config/routing/AES50A/17-24",
2924
- "/config/routing/AES50A/25-32",
2925
- "/config/routing/AES50A/33-40",
2926
- "/config/routing/AES50A/41-48",
2927
- "/config/routing/AES50B/1-8",
2928
- "/config/routing/AES50B/9-16",
2929
- "/config/routing/AES50B/17-24",
2930
- "/config/routing/AES50B/25-32",
2931
- "/config/routing/AES50B/33-40",
2932
- "/config/routing/AES50B/41-48",
2933
- "/config/routing/PLAY/1-8",
2934
- "/config/routing/PLAY/9-16",
2935
- "/config/routing/PLAY/17-24",
2936
- "/config/routing/PLAY/25-32"
2937
- ].forEach((path) => {
2938
- schema[path] = this.node("i", 0);
2939
- });
2940
- return schema;
2941
- }
2942
- node(type, def) {
2943
- return new X32Node(type, def);
2944
- }
2945
- generateChannelStrip(base, eqBands = 4, hasPreamp = false) {
2946
- const nodes = {};
2947
- nodes[`${base}/config/name`] = this.node("s", base.split("/").pop()?.toUpperCase() || "");
2948
- nodes[`${base}/config/icon`] = this.node("i", 1);
2949
- nodes[`${base}/config/color`] = this.node("i", 1);
2950
- nodes[`${base}/config/source`] = this.node("i", 1);
2951
- nodes[`${base}/mix/fader`] = this.node("f", .75);
2952
- nodes[`${base}/mix/on`] = this.node("i", 0);
2953
- nodes[`${base}/mix/pan`] = this.node("f", .5);
2954
- nodes[`${base}/mix/mono`] = this.node("i", 0);
2955
- nodes[`${base}/mix/mlevel`] = this.node("f", 0);
2956
- nodes[`${base}/mix/st`] = this.node("i", 1);
2957
- if (hasPreamp) {
2958
- nodes[`${base}/preamp/trim`] = this.node("f", .5);
2959
- nodes[`${base}/preamp/hpon`] = this.node("i", 0);
2960
- nodes[`${base}/preamp/hpf`] = this.node("f", 0);
2961
- nodes[`${base}/preamp/phantom`] = this.node("i", 0);
2962
- nodes[`${base}/preamp/rtnsw`] = this.node("i", 0);
2963
- nodes[`${base}/preamp/invert`] = this.node("i", 0);
2964
- }
2965
- nodes[`${base}/delay/on`] = this.node("i", 0);
2966
- nodes[`${base}/delay/time`] = this.node("f", 0);
2967
- nodes[`${base}/insert/on`] = this.node("i", 0);
2968
- nodes[`${base}/insert/pos`] = this.node("i", 0);
2969
- nodes[`${base}/insert/sel`] = this.node("i", 0);
2970
- nodes[`${base}/gate/on`] = this.node("i", 0);
2971
- nodes[`${base}/gate/mode`] = this.node("i", 0);
2972
- nodes[`${base}/gate/thr`] = this.node("f", 0);
2973
- nodes[`${base}/gate/range`] = this.node("f", 0);
2974
- nodes[`${base}/gate/attack`] = this.node("f", 0);
2975
- nodes[`${base}/gate/hold`] = this.node("f", 0);
2976
- nodes[`${base}/gate/release`] = this.node("f", 0);
2977
- nodes[`${base}/gate/keysrc`] = this.node("i", 0);
2978
- nodes[`${base}/gate/filter/on`] = this.node("i", 0);
2979
- nodes[`${base}/gate/filter/type`] = this.node("i", 0);
2980
- nodes[`${base}/gate/filter/f`] = this.node("f", .5);
2981
- nodes[`${base}/dyn/on`] = this.node("i", 0);
2982
- nodes[`${base}/dyn/mode`] = this.node("i", 0);
2983
- nodes[`${base}/dyn/pos`] = this.node("i", 0);
2984
- nodes[`${base}/dyn/det`] = this.node("i", 0);
2985
- nodes[`${base}/dyn/env`] = this.node("i", 0);
2986
- nodes[`${base}/dyn/thr`] = this.node("f", 0);
2987
- nodes[`${base}/dyn/ratio`] = this.node("i", 0);
2988
- nodes[`${base}/dyn/knee`] = this.node("f", 0);
2989
- nodes[`${base}/dyn/mgain`] = this.node("f", 0);
2990
- nodes[`${base}/dyn/attack`] = this.node("f", 0);
2991
- nodes[`${base}/dyn/hold`] = this.node("f", 0);
2992
- nodes[`${base}/dyn/release`] = this.node("f", 0);
2993
- nodes[`${base}/dyn/mix`] = this.node("f", 1);
2994
- nodes[`${base}/dyn/auto`] = this.node("i", 0);
2995
- nodes[`${base}/dyn/keysrc`] = this.node("i", 0);
2996
- nodes[`${base}/dyn/filter/on`] = this.node("i", 0);
2997
- nodes[`${base}/dyn/filter/type`] = this.node("i", 0);
2998
- nodes[`${base}/dyn/filter/f`] = this.node("f", .5);
2999
- nodes[`${base}/eq/on`] = this.node("i", 0);
3000
- nodes[`${base}/eq/mode`] = this.node("i", 0);
3001
- for (let b = 1; b <= eqBands; b++) {
3002
- nodes[`${base}/eq/${b}/type`] = this.node("i", 0);
3003
- nodes[`${base}/eq/${b}/f`] = this.node("f", .5);
3004
- nodes[`${base}/eq/${b}/g`] = this.node("f", .5);
3005
- nodes[`${base}/eq/${b}/q`] = this.node("f", .5);
3006
- }
3007
- nodes[`${base}/grp/dca`] = this.node("i", 0);
3008
- nodes[`${base}/grp/mute`] = this.node("i", 0);
3009
- return nodes;
3010
- }
3011
- generateNodes(count, prefix) {
3012
- const nodes = {};
3013
- const isChannelOrAux = prefix === "ch" || prefix === "auxin";
3014
- const hasMtxPreamp = prefix === "mtx";
3015
- const eqBands = prefix === "bus" || prefix === "mtx" ? 6 : 4;
3016
- for (let i = 1; i <= count; i++) {
3017
- const padId = i.toString().padStart(2, "0");
3018
- [i.toString(), padId].forEach((id) => {
3019
- const base = `/${prefix}/${id}`;
3020
- if (prefix === "dca") {
3021
- nodes[`${base}/config/name`] = this.node("s", `DCA ${id}`);
3022
- nodes[`${base}/config/color`] = this.node("i", 1);
3023
- nodes[`${base}/fader`] = this.node("f", .75);
3024
- nodes[`${base}/on`] = this.node("i", 0);
3025
- } else {
3026
- Object.assign(nodes, this.generateChannelStrip(base, eqBands, isChannelOrAux || hasMtxPreamp));
3027
- if (prefix === "ch" || prefix === "auxin" || prefix === "fxrtn" || prefix === "bus") for (let b = 1; b <= 16; b++) {
3028
- const busId = b.toString().padStart(2, "0");
3029
- nodes[`${base}/mix/${busId}/level`] = this.node("f", 0);
3030
- nodes[`${base}/mix/${busId}/on`] = this.node("i", 0);
3031
- nodes[`${base}/mix/${busId}/pan`] = this.node("f", .5);
3032
- nodes[`${base}/mix/${busId}/type`] = this.node("i", 0);
3033
- }
3034
- if (prefix === "ch") {
3035
- nodes[`${base}/automix`] = this.node("i", 0);
3036
- nodes[`${base}/automix/group`] = this.node("i", 0);
3037
- nodes[`${base}/automix/weight`] = this.node("f", 0);
3038
- }
3039
- }
3040
- });
3041
- }
3042
- return nodes;
3043
- }
3044
- generateRange(count, prefix, suffix, type, def, pad = 2, start = 1) {
3045
- const nodes = {};
3046
- for (let i = start; i < start + count; i++) {
3047
- const id = i.toString().padStart(pad, "0");
3048
- nodes[`${prefix}/${i}${suffix}`] = this.node(type, def);
3049
- nodes[`${prefix}/${id}${suffix}`] = this.node(type, def);
3050
- }
3051
- return nodes;
3052
- }
3053
- generateOutputs(prefix, count) {
3054
- const nodes = {};
3055
- for (let i = 1; i <= count; i++) {
3056
- const base = `/outputs/${prefix}/${i.toString().padStart(2, "0")}`;
3057
- nodes[`${base}/src`] = this.node("i", 0);
3058
- nodes[`${base}/pos`] = this.node("i", 0);
3059
- nodes[`${base}/invert`] = this.node("i", 0);
3060
- nodes[`${base}/delay/on`] = this.node("i", 0);
3061
- nodes[`${base}/delay/time`] = this.node("f", 0);
3062
- if (prefix === "p16") {
3063
- nodes[`${base}/iQ/group`] = this.node("i", 0);
3064
- nodes[`${base}/iQ/model`] = this.node("i", 0);
3065
- nodes[`${base}/iQ/eq`] = this.node("i", 0);
3066
- nodes[`${base}/iQ/speaker`] = this.node("i", 0);
3067
- }
3068
- }
3069
- return nodes;
3070
- }
3071
- /**
3072
- * Generates showfile cue entries (100 cues: 000-099)
3073
- */
3074
- generateShowfileCues() {
3075
- const nodes = {};
3076
- for (let i = 0; i < 100; i++) {
3077
- const base = `/-show/showfile/cue/${i.toString().padStart(3, "0")}`;
3078
- nodes[base] = this.node("s", "");
3079
- nodes[`${base}/numb`] = this.node("i", 0);
3080
- nodes[`${base}/name`] = this.node("s", "");
3081
- nodes[`${base}/skip`] = this.node("i", 0);
3082
- nodes[`${base}/scene`] = this.node("i", 0);
3083
- nodes[`${base}/bit`] = this.node("i", 0);
3084
- nodes[`${base}/miditype`] = this.node("i", 0);
3085
- nodes[`${base}/midichan`] = this.node("i", 0);
3086
- nodes[`${base}/midipara1`] = this.node("i", 0);
3087
- nodes[`${base}/midipara2`] = this.node("i", 0);
3088
- }
3089
- return nodes;
3090
- }
3091
- /**
3092
- * Generates showfile scene entries (100 scenes: 000-099)
3093
- */
3094
- generateShowfileScenes() {
3095
- const nodes = {};
3096
- for (let i = 0; i < 100; i++) {
3097
- const base = `/-show/showfile/scene/${i.toString().padStart(3, "0")}`;
3098
- nodes[base] = this.node("s", "");
3099
- nodes[`${base}/name`] = this.node("s", "");
3100
- nodes[`${base}/notes`] = this.node("s", "");
3101
- nodes[`${base}/safes`] = this.node("i", 0);
3102
- nodes[`${base}/hasdata`] = this.node("i", 0);
3103
- }
3104
- return nodes;
3105
- }
3106
- /**
3107
- * Generates showfile snippet entries (100 snippets: 000-099)
3108
- */
3109
- generateShowfileSnippets() {
3110
- const nodes = {};
3111
- for (let i = 0; i < 100; i++) {
3112
- const base = `/-show/showfile/snippet/${i.toString().padStart(3, "0")}`;
3113
- nodes[base] = this.node("s", "");
3114
- nodes[`${base}/name`] = this.node("s", "");
3115
- nodes[`${base}/eventtyp`] = this.node("i", 0);
3116
- nodes[`${base}/channels`] = this.node("i", 0);
3117
- nodes[`${base}/auxbuses`] = this.node("i", 0);
3118
- nodes[`${base}/maingrps`] = this.node("i", 0);
3119
- nodes[`${base}/hasdata`] = this.node("i", 0);
3120
- }
3121
- return nodes;
3122
- }
3123
- /**
3124
- * Generates preferences iQ entries (16 entries: 01-16)
3125
- */
3126
- generatePrefsIQ() {
3127
- const nodes = {};
3128
- for (let i = 1; i <= 16; i++) {
3129
- const base = `/-prefs/iQ/${i.toString().padStart(2, "0")}`;
3130
- nodes[base] = this.node("i", 0);
3131
- nodes[`${base}/iQmodel`] = this.node("i", 0);
3132
- nodes[`${base}/iQeqset`] = this.node("i", 0);
3133
- nodes[`${base}/iQsound`] = this.node("i", 0);
3134
- }
3135
- return nodes;
3136
- }
3137
- /**
3138
- * Generates DP48 Personal Monitor config entries (48 channels)
3139
- */
3140
- generateDP48Config() {
3141
- const nodes = {};
3142
- for (let i = 1; i <= 48; i++) {
3143
- const id = i.toString().padStart(2, "0");
3144
- nodes[`/config/dp48/link/${id}`] = this.node("i", 0);
3145
- }
3146
- nodes["/config/dp48/assign"] = this.node("i", 0);
3147
- nodes["/config/dp48/grpname/01"] = this.node("s", "");
3148
- nodes["/config/dp48/grpname/02"] = this.node("s", "");
3149
- nodes["/config/dp48/grpname/03"] = this.node("s", "");
3150
- nodes["/config/dp48/grpname/04"] = this.node("s", "");
3151
- nodes["/config/dp48/grpname/05"] = this.node("s", "");
3152
- nodes["/config/dp48/grpname/06"] = this.node("s", "");
3153
- nodes["/config/dp48/grpname/07"] = this.node("s", "");
3154
- nodes["/config/dp48/grpname/08"] = this.node("s", "");
3155
- nodes["/config/dp48/grpname/09"] = this.node("s", "");
3156
- nodes["/config/dp48/grpname/10"] = this.node("s", "");
3157
- nodes["/config/dp48/grpname/11"] = this.node("s", "");
3158
- nodes["/config/dp48/grpname/12"] = this.node("s", "");
3159
- return nodes;
3160
- }
3161
- /**
3162
- * Generates USB directory entries (1000 entries: 000-999)
3163
- */
3164
- generateUSBDir() {
3165
- const nodes = {};
3166
- for (let i = 0; i < 1e3; i++) {
3167
- const id = i.toString().padStart(3, "0");
3168
- nodes[`/-usb/dir/${id}`] = this.node("s", "");
3169
- nodes[`/-usb/dir/${id}/name`] = this.node("s", "");
3170
- }
3171
- return nodes;
3172
- }
3173
- /**
3174
- * Generates USB recording session and marker entries
3175
- */
3176
- generateURecSessions() {
3177
- const nodes = {};
3178
- for (let i = 1; i <= 100; i++) {
3179
- const id = i.toString().padStart(3, "0");
3180
- nodes[`/-urec/session/${id}/name`] = this.node("s", "");
3181
- nodes[`/-urec/marker/${id}/time`] = this.node("i", 0);
3182
- }
3183
- return nodes;
3184
- }
3185
- /**
3186
- * Generates library entries (ch, fx, r, mon - 100 each)
3187
- */
3188
- generateLibraries() {
3189
- const nodes = {};
3190
- for (const lib of [
3191
- "ch",
3192
- "fx",
3193
- "r",
3194
- "mon"
3195
- ]) {
3196
- nodes[`/-libs/${lib}`] = this.node("i", 0);
3197
- for (let i = 1; i <= 100; i++) {
3198
- const base = `/-libs/${lib}/${i.toString().padStart(3, "0")}`;
3199
- nodes[base] = this.node("s", "");
3200
- nodes[`${base}/pos`] = this.node("i", 0);
3201
- nodes[`${base}/name`] = this.node("s", "");
3202
- nodes[`${base}/flags`] = this.node("i", 0);
3203
- nodes[`${base}/hasdata`] = this.node("i", 0);
3204
- }
3205
- }
3206
- return nodes;
3207
- }
3208
- /**
3209
- * Generates user control entries (A, B, C with enc and btn)
3210
- */
3211
- generateUserCtrl() {
3212
- const nodes = {};
3213
- for (const bank of [
3214
- "A",
3215
- "B",
3216
- "C"
3217
- ]) {
3218
- nodes[`/config/userctrl/${bank}`] = this.node("i", 0);
3219
- for (let i = 1; i <= 4; i++) nodes[`/config/userctrl/${bank}/enc/${i}`] = this.node("i", 0);
3220
- for (let i = 1; i <= 12; i++) nodes[`/config/userctrl/${bank}/btn/${i}`] = this.node("i", 0);
3221
- }
3222
- return nodes;
3223
- }
3224
- };
3225
-
3226
- //#endregion
3227
- //#region src/domain/services/SchemaRegistry.ts
3228
- /**
3229
- * Service providing access to the X32 OSC Schema.
3230
- * Acts as the "Registry" of all available console parameters.
3231
- */
3232
- var SchemaRegistry = class {
3233
- _schema;
3234
- constructor(schemaFactory) {
3235
- this.schemaFactory = schemaFactory;
3236
- this._schema = this.schemaFactory.createSchema();
3237
- }
3238
- /**
3239
- * Retrieves the entire schema map.
3240
- * @returns The internal schema definition record.
3241
- */
3242
- getSchema() {
3243
- return this._schema;
3244
- }
3245
- /**
3246
- * Retrieves the node definition for a given path.
3247
- * @param path - The OSC path.
3248
- * @returns The X32Node definition or undefined if not found.
3249
- */
3250
- getNode(path) {
3251
- return this._schema[path];
3252
- }
3253
- /**
3254
- * Checks if a path exists in the schema.
3255
- * @param path - The path to check.
3256
- * @returns True if the path is registered.
3257
- */
3258
- has(path) {
3259
- return path in this._schema;
3260
- }
3261
- /**
3262
- * Returns all paths in the schema.
3263
- * @returns Array of all registered OSC paths.
3264
- */
3265
- getAllPaths() {
3266
- return Object.keys(this._schema);
3267
- }
3268
- /**
3269
- * Maps an absolute X32 global index to its specific OSC root path.
3270
- * Used for batch subscriptions where clients request ranges of channels.
3271
- * @param index - The absolute integer index.
3272
- * @returns The root path string or null if index is out of bounds.
3273
- */
3274
- getRootFromIndex(index) {
3275
- if (index >= 0 && index <= 31) return `/ch/${(index + 1).toString().padStart(2, "0")}`;
3276
- if (index >= 32 && index <= 39) return `/auxin/${(index - 31).toString().padStart(2, "0")}`;
3277
- if (index >= 40 && index <= 47) return `/fxrtn/${(index - 39).toString().padStart(2, "0")}`;
3278
- if (index >= 48 && index <= 63) return `/bus/${(index - 47).toString().padStart(2, "0")}`;
3279
- if (index >= 64 && index <= 69) return `/mtx/${(index - 63).toString().padStart(2, "0")}`;
3280
- if (index === 70) return "/main/st";
3281
- if (index === 71) return "/main/m";
3282
- if (index >= 72 && index <= 79) return `/dca/${(index - 71).toString().padStart(2, "0")}`;
3283
- return null;
3284
- }
3285
- };
3286
-
3287
- //#endregion
3288
- Object.defineProperty(exports, 'ConsoleLogger', {
3289
- enumerable: true,
3290
- get: function () {
3291
- return ConsoleLogger;
3292
- }
3293
- });
3294
- Object.defineProperty(exports, 'DEFAULT_CONFIG', {
3295
- enumerable: true,
3296
- get: function () {
3297
- return DEFAULT_CONFIG;
3298
- }
3299
- });
3300
- Object.defineProperty(exports, 'InMemoryStateRepository', {
3301
- enumerable: true,
3302
- get: function () {
3303
- return InMemoryStateRepository;
3304
- }
3305
- });
3306
- Object.defineProperty(exports, 'LogCategory', {
3307
- enumerable: true,
3308
- get: function () {
3309
- return LogCategory;
3310
- }
3311
- });
3312
- Object.defineProperty(exports, 'LogLevel', {
3313
- enumerable: true,
3314
- get: function () {
3315
- return LogLevel;
3316
- }
3317
- });
3318
- Object.defineProperty(exports, 'METER_COUNTS', {
3319
- enumerable: true,
3320
- get: function () {
3321
- return METER_COUNTS;
3322
- }
3323
- });
3324
- Object.defineProperty(exports, 'MeterData', {
3325
- enumerable: true,
3326
- get: function () {
3327
- return MeterData;
3328
- }
3329
- });
3330
- Object.defineProperty(exports, 'OscCodec', {
3331
- enumerable: true,
3332
- get: function () {
3333
- return OscCodec;
3334
- }
3335
- });
3336
- Object.defineProperty(exports, 'SchemaFactory', {
3337
- enumerable: true,
3338
- get: function () {
3339
- return SchemaFactory;
3340
- }
3341
- });
3342
- Object.defineProperty(exports, 'SchemaRegistry', {
3343
- enumerable: true,
3344
- get: function () {
3345
- return SchemaRegistry;
3346
- }
3347
- });
3348
- Object.defineProperty(exports, 'SimulationService', {
3349
- enumerable: true,
3350
- get: function () {
3351
- return SimulationService;
3352
- }
3353
- });
3354
- Object.defineProperty(exports, 'SubscriptionManager', {
3355
- enumerable: true,
3356
- get: function () {
3357
- return SubscriptionManager;
3358
- }
3359
- });
3360
- Object.defineProperty(exports, 'UdpNetworkGateway', {
3361
- enumerable: true,
3362
- get: function () {
3363
- return UdpNetworkGateway;
3364
- }
3365
- });
3366
- Object.defineProperty(exports, 'X32Node', {
3367
- enumerable: true,
3368
- get: function () {
3369
- return X32Node;
3370
- }
3371
- });
3372
- Object.defineProperty(exports, 'X32State', {
3373
- enumerable: true,
3374
- get: function () {
3375
- return X32State;
3376
- }
3377
- });
3378
- Object.defineProperty(exports, '__toESM', {
3379
- enumerable: true,
3380
- get: function () {
3381
- return __toESM;
3382
- }
3383
- });
3384
- Object.defineProperty(exports, 'mergeConfig', {
3385
- enumerable: true,
3386
- get: function () {
3387
- return mergeConfig;
3388
- }
3389
- });