@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.
package/dist/server.cjs CHANGED
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env node
2
- const require_SchemaRegistry = require('./SchemaRegistry-Ddy5AEKs.cjs');
2
+ const require_SchemaRegistry = require('./SchemaRegistry-aSJvYTM7.cjs');
3
3
  let node_readline = require("node:readline");
4
4
  node_readline = require_SchemaRegistry.__toESM(node_readline);
5
5
  let node_fs = require("node:fs");
6
6
  node_fs = require_SchemaRegistry.__toESM(node_fs);
7
7
  let node_path = require("node:path");
8
8
  node_path = require_SchemaRegistry.__toESM(node_path);
9
+ let node_crypto = require("node:crypto");
9
10
  let node_fs_promises = require("node:fs/promises");
10
11
 
11
12
  //#region src/infrastructure/repositories/JsonFileStateRepository.ts
@@ -121,12 +122,14 @@ var JsonFileStateRepository = class {
121
122
  async flush() {
122
123
  if (!this.dirty || this.saving) return;
123
124
  this.saving = true;
125
+ const tmpPath = `${this.filePath}.${process.pid}.${(0, node_crypto.randomBytes)(4).toString("hex")}.tmp`;
124
126
  try {
125
127
  const data = this.getAll();
126
- const json = JSON.stringify(data, null, 2);
127
- await (0, node_fs_promises.writeFile)(this.filePath, json, "utf-8");
128
+ await (0, node_fs_promises.writeFile)(tmpPath, JSON.stringify(data, null, 2), "utf-8");
129
+ await (0, node_fs_promises.rename)(tmpPath, this.filePath);
128
130
  this.dirty = false;
129
131
  } catch (error) {
132
+ await (0, node_fs_promises.rm)(tmpPath, { force: true });
130
133
  console.error(`[JsonFileStateRepository] Failed to save state to ${this.filePath}:`, error);
131
134
  } finally {
132
135
  this.saving = false;
@@ -160,6 +163,28 @@ function createStateRepository(config) {
160
163
 
161
164
  //#endregion
162
165
  //#region src/presentation/cli/server.ts
166
+ const CONSOLE_MODELS = new Set([
167
+ "X32",
168
+ "X32RACK",
169
+ "X32C",
170
+ "X32P",
171
+ "X32CORE",
172
+ "M32",
173
+ "M32C",
174
+ "M32R"
175
+ ]);
176
+ const MODEL_LIST = "X32, X32RACK, X32C, X32P, X32CORE, M32, M32C, or M32R";
177
+ const FIRMWARE_PATTERN = /^\d+\.\d+$/;
178
+ const IPV4_OCTET = "(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)";
179
+ const IPV4_PATTERN = /* @__PURE__ */ new RegExp(`^${IPV4_OCTET}(?:\\.${IPV4_OCTET}){3}$`);
180
+ const fail = (message) => {
181
+ throw new Error(message);
182
+ };
183
+ const readOption = (args, index, flag) => {
184
+ const next = args[index + 1];
185
+ if (next === void 0 || next.startsWith("-")) fail(`Missing value for ${flag}.`);
186
+ return next;
187
+ };
163
188
  const loadEnv = () => {
164
189
  try {
165
190
  const envPath = node_path.resolve(process.cwd(), ".env");
@@ -182,6 +207,13 @@ const parseArgs = (argv) => {
182
207
  let cliHost;
183
208
  let storageType = "memory";
184
209
  let stateFilePath;
210
+ let cliName;
211
+ let cliModel;
212
+ let cliFirmware;
213
+ let cliAdvertiseIp;
214
+ let cliLogLevel;
215
+ let cliPermissive = false;
216
+ let cliMeterMode;
185
217
  for (let i = 0; i < args.length; i++) {
186
218
  const arg = args[i];
187
219
  if (arg === "--port" || arg === "-p") {
@@ -200,6 +232,42 @@ const parseArgs = (argv) => {
200
232
  continue;
201
233
  }
202
234
  }
235
+ if (arg === "--name") {
236
+ cliName = readOption(args, i, arg);
237
+ i++;
238
+ continue;
239
+ }
240
+ if (arg === "--model") {
241
+ const model$1 = readOption(args, i, arg);
242
+ if (!CONSOLE_MODELS.has(model$1)) fail(`Unknown model "${model$1}". Expected ${MODEL_LIST}.`);
243
+ cliModel = model$1;
244
+ i++;
245
+ continue;
246
+ }
247
+ if (arg === "--firmware") {
248
+ const firmware$1 = readOption(args, i, arg);
249
+ if (!FIRMWARE_PATTERN.test(firmware$1)) fail(`Invalid firmware "${firmware$1}". Expected <digits>.<digits>, for example 4.06.`);
250
+ cliFirmware = firmware$1;
251
+ i++;
252
+ continue;
253
+ }
254
+ if (arg === "--log-level") {
255
+ cliLogLevel = require_SchemaRegistry.parseLogLevel(readOption(args, i, arg));
256
+ i++;
257
+ continue;
258
+ }
259
+ if (arg === "--meters") {
260
+ cliMeterMode = require_SchemaRegistry.parseMeterMode(readOption(args, i, arg));
261
+ i++;
262
+ continue;
263
+ }
264
+ if (arg === "--advertise-ip") {
265
+ const advertiseIp = readOption(args, i, arg);
266
+ if (!IPV4_PATTERN.test(advertiseIp)) fail(`Invalid advertise IP "${advertiseIp}". Expected an IPv4 address.`);
267
+ cliAdvertiseIp = advertiseIp;
268
+ i++;
269
+ continue;
270
+ }
203
271
  if (arg === "--storage" || arg === "-s") {
204
272
  const next = args[i + 1];
205
273
  if (next && (next === "memory" || next === "json")) {
@@ -215,20 +283,39 @@ const parseArgs = (argv) => {
215
283
  i++;
216
284
  }
217
285
  }
286
+ if (arg === "--permissive") {
287
+ cliPermissive = true;
288
+ continue;
289
+ }
218
290
  if (arg === "--help") {
219
291
  console.log(`
220
292
  X32 Simulator - Usage:
221
293
  x32-simulator [options]
222
294
 
223
295
  Options:
224
- -p, --port <port> UDP port to listen on (default: 10023)
225
- -h, --host <ip> IP address to bind to (default: 0.0.0.0)
226
- -s, --storage <type> Storage type: 'memory' or 'json' (default: memory)
227
- -f, --state-file <file> Path to JSON state file (implies --storage json)
228
- --help Show this help message
296
+ -p, --port <port> UDP port to listen on (default: 10023)
297
+ -h, --host <ip> IP address to bind to (default: 0.0.0.0)
298
+ --name <string> Console name reported by /xinfo (default: osc-server)
299
+ --model <model> ${MODEL_LIST} (default: X32)
300
+ --firmware <d.d> Firmware digits.digits (default: 4.06)
301
+ --advertise-ip <ipv4> IP announced when bound to 0.0.0.0
302
+ --log-level <level> debug, info, warn or error (default: info)
303
+ --meters <mode> silent, fixed, or noise (default: silent)
304
+ --permissive Store a Set sent to an unknown address
305
+ -s, --storage <type> Storage type: 'memory' or 'json' (default: memory)
306
+ -f, --state-file <file> Path to JSON state file (implies --storage json)
307
+ --help Show this help message
308
+
309
+ Terminal:
310
+ reset Reset every parameter to its default and notify clients
311
+ set <address> <text> Set a parameter from scene text, for example set /ch/01/mix/fader -10
312
+ get <address> Print a parameter in scene text
313
+ save Flush the state file
314
+ exit Stop the server
229
315
 
230
316
  Examples:
231
317
  x32-simulator --port 10023 --host 192.168.1.100
318
+ x32-simulator --model X32RACK --name TestRack --firmware 4.06
232
319
  x32-simulator --storage json --state-file ./x32-state.json
233
320
  x32-simulator -p 10023 -f ./my-mixer-state.json
234
321
  `);
@@ -237,24 +324,104 @@ Examples:
237
324
  if (!cliHost && /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(arg)) cliHost = arg;
238
325
  if (!cliPort && /^\d+$/.test(arg)) cliPort = parseInt(arg, 10);
239
326
  }
327
+ const PORT = cliPort || parseInt(process.env.X32_PORT || "10023", 10);
328
+ const HOST = cliHost || process.env.X32_IP || "0.0.0.0";
329
+ const name = cliName ?? require_SchemaRegistry.DEFAULT_CONFIG.DEFAULT_NAME;
330
+ const model = cliModel ?? require_SchemaRegistry.DEFAULT_CONFIG.DEFAULT_MODEL;
331
+ const firmware = cliFirmware ?? require_SchemaRegistry.DEFAULT_FIRMWARE;
332
+ const logLevel = cliLogLevel ?? require_SchemaRegistry.LogLevel.INFO;
240
333
  return {
241
- PORT: cliPort || parseInt(process.env.X32_PORT || "10023", 10),
242
- HOST: cliHost || process.env.X32_IP || "0.0.0.0",
334
+ PORT,
335
+ HOST,
243
336
  storageType,
244
- stateFilePath
337
+ stateFilePath,
338
+ name,
339
+ model,
340
+ firmware,
341
+ advertiseIp: cliAdvertiseIp,
342
+ logLevel,
343
+ permissive: cliPermissive,
344
+ meterMode: cliMeterMode
245
345
  };
246
346
  };
347
+ /** Keeps `{ PERMISSIVE }` alone when `--meters` is omitted, so the default stays `silent`. */
348
+ const meterConfig = (permissive, meterMode) => {
349
+ const config = { PERMISSIVE: permissive };
350
+ if (meterMode !== void 0) config.METER_MODE = meterMode;
351
+ return config;
352
+ };
353
+ /**
354
+ * `set` converts scene text with {@link textToOsc}. `get` prints scene text.
355
+ * Unknown addresses and bad tokens are reported. They do not change the state.
356
+ */
357
+ const runParamCommand = (word, line, schemaRegistry, service) => {
358
+ const match = /^(?:set|get)\s+(\S+)(?:\s+([\s\S]+))?$/i.exec(line);
359
+ const address = match?.[1];
360
+ if (!address) {
361
+ console.log(`Unknown address ${line}`);
362
+ return;
363
+ }
364
+ const node = schemaRegistry.getNode(address);
365
+ if (!node) {
366
+ console.log(`Unknown address ${address}`);
367
+ return;
368
+ }
369
+ if (word === "get") {
370
+ try {
371
+ const value = service.getParameter(address);
372
+ if (value === void 0) {
373
+ console.log(address);
374
+ return;
375
+ }
376
+ const shown = node.param ? require_SchemaRegistry.oscToText(node.param, value) : String(value);
377
+ console.log(`${address} ${shown}`);
378
+ } catch (err) {
379
+ console.log(err instanceof Error ? err.message : String(err));
380
+ }
381
+ return;
382
+ }
383
+ const text = match?.[2]?.trim();
384
+ if (!text) {
385
+ console.log(`Invalid value for ${address}`);
386
+ return;
387
+ }
388
+ let osc;
389
+ if (node.param) osc = require_SchemaRegistry.textToOsc(node.param, text);
390
+ else if (node.type === "s") osc = text;
391
+ else {
392
+ const numeric = Number(text);
393
+ osc = Number.isFinite(numeric) ? numeric : null;
394
+ }
395
+ if (osc === null) {
396
+ console.log(`Invalid value for ${address}`);
397
+ return;
398
+ }
399
+ try {
400
+ service.setParameter(address, osc);
401
+ } catch (err) {
402
+ console.log(err instanceof Error ? err.message : String(err));
403
+ }
404
+ };
247
405
  const bootstrap = async () => {
248
406
  loadEnv();
249
- const { PORT, HOST, storageType, stateFilePath } = parseArgs(process.argv);
407
+ let parsed;
408
+ try {
409
+ parsed = parseArgs(process.argv);
410
+ } catch (err) {
411
+ const message = err instanceof Error ? err.message : String(err);
412
+ console.error(message);
413
+ process.exit(1);
414
+ return;
415
+ }
416
+ const { PORT, HOST, storageType, stateFilePath, name, model, firmware, advertiseIp, logLevel, permissive, meterMode } = parsed;
250
417
  const logger = require_SchemaRegistry.ConsoleLogger.getInstance();
251
- logger.setLevel(require_SchemaRegistry.LogLevel.DEBUG);
418
+ logger.setLevel(logLevel);
252
419
  const schemaRegistry = new require_SchemaRegistry.SchemaRegistry(new require_SchemaRegistry.SchemaFactory());
253
420
  const service = new require_SchemaRegistry.SimulationService(new require_SchemaRegistry.UdpNetworkGateway(logger, new require_SchemaRegistry.OscCodec(schemaRegistry)), logger, createStateRepository({
254
421
  type: storageType,
255
422
  filePath: stateFilePath,
256
423
  autoSaveInterval: 5e3
257
- }), schemaRegistry, PORT, HOST);
424
+ }), schemaRegistry, PORT, HOST, name, model, meterConfig(permissive, meterMode), firmware, advertiseIp);
258
425
  try {
259
426
  await service.start();
260
427
  const storageInfo = storageType === "json" ? `JSON (${stateFilePath})` : "In-Memory";
@@ -266,10 +433,18 @@ const bootstrap = async () => {
266
433
  • Port: ${PORT}
267
434
  • Protocol: UDP (Strict X32 Schema)
268
435
  • Storage: ${storageInfo}
269
- • Logging: ENHANCED (DEBUG)
436
+ • Logging: ${[
437
+ "debug",
438
+ "info",
439
+ "warn",
440
+ "error",
441
+ "none"
442
+ ][logLevel]}
270
443
 
271
444
  👉 Type "exit" or "stop" to shut down.
272
445
  👉 Type "reset" to reset faders to default.
446
+ 👉 Type "set <address> <text>" to move a control, for example set /ch/01/mix/fader -10.
447
+ 👉 Type "get <address>" to print a control.
273
448
  👉 Type "save" to force save state (JSON mode).
274
449
  `);
275
450
  } catch (err) {
@@ -299,27 +474,29 @@ const bootstrap = async () => {
299
474
  input: process.stdin,
300
475
  output: process.stdout
301
476
  }).on("line", async (input) => {
302
- const command = input.trim().toLowerCase();
303
- switch (command) {
304
- case "exit":
305
- case "stop":
306
- case "quit":
307
- console.log("Shutting down...");
308
- await service.stop();
309
- process.exit(0);
310
- break;
311
- case "reset":
312
- service.resetState();
313
- console.log("✨ Console state reset to defaults.");
314
- break;
315
- case "save":
316
- await service.saveState();
317
- console.log("💾 State saved to storage.");
318
- break;
319
- default:
320
- if (command) console.log(`Unknown command: "${command}"`);
321
- break;
477
+ const line = input.trim();
478
+ const word = (line.split(/\s+/, 1)[0] ?? "").toLowerCase();
479
+ if (word === "exit" || word === "stop" || word === "quit") {
480
+ console.log("Shutting down...");
481
+ await service.stop();
482
+ process.exit(0);
483
+ return;
484
+ }
485
+ if (word === "reset") {
486
+ service.resetState();
487
+ console.log("✨ Console state reset to defaults.");
488
+ return;
489
+ }
490
+ if (word === "save") {
491
+ await service.saveState();
492
+ console.log("💾 State saved to storage.");
493
+ return;
494
+ }
495
+ if (word === "set" || word === "get") {
496
+ runParamCommand(word, line, schemaRegistry, service);
497
+ return;
322
498
  }
499
+ if (line) console.log(`Unknown command: "${line}"`);
323
500
  });
324
501
  process.on("SIGINT", async () => {
325
502
  console.log("\n(SIGINT received)");
package/dist/server.mjs CHANGED
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { a as ConsoleLogger, i as UdpNetworkGateway, l as SimulationService, n as SchemaFactory, o as LogLevel, r as OscCodec, s as InMemoryStateRepository, t as SchemaRegistry } from "./SchemaRegistry-BBzyicoy.mjs";
2
+ import { _ as oscToText, a as ConsoleLogger, b as DEFAULT_FIRMWARE, c as InMemoryStateRepository, i as UdpNetworkGateway, m as parseMeterMode, n as SchemaFactory, o as LogLevel, r as OscCodec, s as parseLogLevel, t as SchemaRegistry, u as SimulationService, v as textToOsc, y as DEFAULT_CONFIG } from "./SchemaRegistry-ffv4HZRa.mjs";
3
3
  import * as readline from "node:readline";
4
4
  import * as fs from "node:fs";
5
5
  import { constants } from "node:fs";
6
6
  import * as path from "node:path";
7
- import { access, readFile, writeFile } from "node:fs/promises";
7
+ import { randomBytes } from "node:crypto";
8
+ import { access, readFile, rename, rm, writeFile } from "node:fs/promises";
8
9
 
9
10
  //#region src/infrastructure/repositories/JsonFileStateRepository.ts
10
11
  /**
@@ -119,12 +120,14 @@ var JsonFileStateRepository = class {
119
120
  async flush() {
120
121
  if (!this.dirty || this.saving) return;
121
122
  this.saving = true;
123
+ const tmpPath = `${this.filePath}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
122
124
  try {
123
125
  const data = this.getAll();
124
- const json = JSON.stringify(data, null, 2);
125
- await writeFile(this.filePath, json, "utf-8");
126
+ await writeFile(tmpPath, JSON.stringify(data, null, 2), "utf-8");
127
+ await rename(tmpPath, this.filePath);
126
128
  this.dirty = false;
127
129
  } catch (error) {
130
+ await rm(tmpPath, { force: true });
128
131
  console.error(`[JsonFileStateRepository] Failed to save state to ${this.filePath}:`, error);
129
132
  } finally {
130
133
  this.saving = false;
@@ -158,6 +161,28 @@ function createStateRepository(config) {
158
161
 
159
162
  //#endregion
160
163
  //#region src/presentation/cli/server.ts
164
+ const CONSOLE_MODELS = new Set([
165
+ "X32",
166
+ "X32RACK",
167
+ "X32C",
168
+ "X32P",
169
+ "X32CORE",
170
+ "M32",
171
+ "M32C",
172
+ "M32R"
173
+ ]);
174
+ const MODEL_LIST = "X32, X32RACK, X32C, X32P, X32CORE, M32, M32C, or M32R";
175
+ const FIRMWARE_PATTERN = /^\d+\.\d+$/;
176
+ const IPV4_OCTET = "(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)";
177
+ const IPV4_PATTERN = /* @__PURE__ */ new RegExp(`^${IPV4_OCTET}(?:\\.${IPV4_OCTET}){3}$`);
178
+ const fail = (message) => {
179
+ throw new Error(message);
180
+ };
181
+ const readOption = (args, index, flag) => {
182
+ const next = args[index + 1];
183
+ if (next === void 0 || next.startsWith("-")) fail(`Missing value for ${flag}.`);
184
+ return next;
185
+ };
161
186
  const loadEnv = () => {
162
187
  try {
163
188
  const envPath = path.resolve(process.cwd(), ".env");
@@ -180,6 +205,13 @@ const parseArgs = (argv) => {
180
205
  let cliHost;
181
206
  let storageType = "memory";
182
207
  let stateFilePath;
208
+ let cliName;
209
+ let cliModel;
210
+ let cliFirmware;
211
+ let cliAdvertiseIp;
212
+ let cliLogLevel;
213
+ let cliPermissive = false;
214
+ let cliMeterMode;
183
215
  for (let i = 0; i < args.length; i++) {
184
216
  const arg = args[i];
185
217
  if (arg === "--port" || arg === "-p") {
@@ -198,6 +230,42 @@ const parseArgs = (argv) => {
198
230
  continue;
199
231
  }
200
232
  }
233
+ if (arg === "--name") {
234
+ cliName = readOption(args, i, arg);
235
+ i++;
236
+ continue;
237
+ }
238
+ if (arg === "--model") {
239
+ const model$1 = readOption(args, i, arg);
240
+ if (!CONSOLE_MODELS.has(model$1)) fail(`Unknown model "${model$1}". Expected ${MODEL_LIST}.`);
241
+ cliModel = model$1;
242
+ i++;
243
+ continue;
244
+ }
245
+ if (arg === "--firmware") {
246
+ const firmware$1 = readOption(args, i, arg);
247
+ if (!FIRMWARE_PATTERN.test(firmware$1)) fail(`Invalid firmware "${firmware$1}". Expected <digits>.<digits>, for example 4.06.`);
248
+ cliFirmware = firmware$1;
249
+ i++;
250
+ continue;
251
+ }
252
+ if (arg === "--log-level") {
253
+ cliLogLevel = parseLogLevel(readOption(args, i, arg));
254
+ i++;
255
+ continue;
256
+ }
257
+ if (arg === "--meters") {
258
+ cliMeterMode = parseMeterMode(readOption(args, i, arg));
259
+ i++;
260
+ continue;
261
+ }
262
+ if (arg === "--advertise-ip") {
263
+ const advertiseIp = readOption(args, i, arg);
264
+ if (!IPV4_PATTERN.test(advertiseIp)) fail(`Invalid advertise IP "${advertiseIp}". Expected an IPv4 address.`);
265
+ cliAdvertiseIp = advertiseIp;
266
+ i++;
267
+ continue;
268
+ }
201
269
  if (arg === "--storage" || arg === "-s") {
202
270
  const next = args[i + 1];
203
271
  if (next && (next === "memory" || next === "json")) {
@@ -213,20 +281,39 @@ const parseArgs = (argv) => {
213
281
  i++;
214
282
  }
215
283
  }
284
+ if (arg === "--permissive") {
285
+ cliPermissive = true;
286
+ continue;
287
+ }
216
288
  if (arg === "--help") {
217
289
  console.log(`
218
290
  X32 Simulator - Usage:
219
291
  x32-simulator [options]
220
292
 
221
293
  Options:
222
- -p, --port <port> UDP port to listen on (default: 10023)
223
- -h, --host <ip> IP address to bind to (default: 0.0.0.0)
224
- -s, --storage <type> Storage type: 'memory' or 'json' (default: memory)
225
- -f, --state-file <file> Path to JSON state file (implies --storage json)
226
- --help Show this help message
294
+ -p, --port <port> UDP port to listen on (default: 10023)
295
+ -h, --host <ip> IP address to bind to (default: 0.0.0.0)
296
+ --name <string> Console name reported by /xinfo (default: osc-server)
297
+ --model <model> ${MODEL_LIST} (default: X32)
298
+ --firmware <d.d> Firmware digits.digits (default: 4.06)
299
+ --advertise-ip <ipv4> IP announced when bound to 0.0.0.0
300
+ --log-level <level> debug, info, warn or error (default: info)
301
+ --meters <mode> silent, fixed, or noise (default: silent)
302
+ --permissive Store a Set sent to an unknown address
303
+ -s, --storage <type> Storage type: 'memory' or 'json' (default: memory)
304
+ -f, --state-file <file> Path to JSON state file (implies --storage json)
305
+ --help Show this help message
306
+
307
+ Terminal:
308
+ reset Reset every parameter to its default and notify clients
309
+ set <address> <text> Set a parameter from scene text, for example set /ch/01/mix/fader -10
310
+ get <address> Print a parameter in scene text
311
+ save Flush the state file
312
+ exit Stop the server
227
313
 
228
314
  Examples:
229
315
  x32-simulator --port 10023 --host 192.168.1.100
316
+ x32-simulator --model X32RACK --name TestRack --firmware 4.06
230
317
  x32-simulator --storage json --state-file ./x32-state.json
231
318
  x32-simulator -p 10023 -f ./my-mixer-state.json
232
319
  `);
@@ -235,24 +322,104 @@ Examples:
235
322
  if (!cliHost && /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(arg)) cliHost = arg;
236
323
  if (!cliPort && /^\d+$/.test(arg)) cliPort = parseInt(arg, 10);
237
324
  }
325
+ const PORT = cliPort || parseInt(process.env.X32_PORT || "10023", 10);
326
+ const HOST = cliHost || process.env.X32_IP || "0.0.0.0";
327
+ const name = cliName ?? DEFAULT_CONFIG.DEFAULT_NAME;
328
+ const model = cliModel ?? DEFAULT_CONFIG.DEFAULT_MODEL;
329
+ const firmware = cliFirmware ?? DEFAULT_FIRMWARE;
330
+ const logLevel = cliLogLevel ?? LogLevel.INFO;
238
331
  return {
239
- PORT: cliPort || parseInt(process.env.X32_PORT || "10023", 10),
240
- HOST: cliHost || process.env.X32_IP || "0.0.0.0",
332
+ PORT,
333
+ HOST,
241
334
  storageType,
242
- stateFilePath
335
+ stateFilePath,
336
+ name,
337
+ model,
338
+ firmware,
339
+ advertiseIp: cliAdvertiseIp,
340
+ logLevel,
341
+ permissive: cliPermissive,
342
+ meterMode: cliMeterMode
243
343
  };
244
344
  };
345
+ /** Keeps `{ PERMISSIVE }` alone when `--meters` is omitted, so the default stays `silent`. */
346
+ const meterConfig = (permissive, meterMode) => {
347
+ const config = { PERMISSIVE: permissive };
348
+ if (meterMode !== void 0) config.METER_MODE = meterMode;
349
+ return config;
350
+ };
351
+ /**
352
+ * `set` converts scene text with {@link textToOsc}. `get` prints scene text.
353
+ * Unknown addresses and bad tokens are reported. They do not change the state.
354
+ */
355
+ const runParamCommand = (word, line, schemaRegistry, service) => {
356
+ const match = /^(?:set|get)\s+(\S+)(?:\s+([\s\S]+))?$/i.exec(line);
357
+ const address = match?.[1];
358
+ if (!address) {
359
+ console.log(`Unknown address ${line}`);
360
+ return;
361
+ }
362
+ const node = schemaRegistry.getNode(address);
363
+ if (!node) {
364
+ console.log(`Unknown address ${address}`);
365
+ return;
366
+ }
367
+ if (word === "get") {
368
+ try {
369
+ const value = service.getParameter(address);
370
+ if (value === void 0) {
371
+ console.log(address);
372
+ return;
373
+ }
374
+ const shown = node.param ? oscToText(node.param, value) : String(value);
375
+ console.log(`${address} ${shown}`);
376
+ } catch (err) {
377
+ console.log(err instanceof Error ? err.message : String(err));
378
+ }
379
+ return;
380
+ }
381
+ const text = match?.[2]?.trim();
382
+ if (!text) {
383
+ console.log(`Invalid value for ${address}`);
384
+ return;
385
+ }
386
+ let osc;
387
+ if (node.param) osc = textToOsc(node.param, text);
388
+ else if (node.type === "s") osc = text;
389
+ else {
390
+ const numeric = Number(text);
391
+ osc = Number.isFinite(numeric) ? numeric : null;
392
+ }
393
+ if (osc === null) {
394
+ console.log(`Invalid value for ${address}`);
395
+ return;
396
+ }
397
+ try {
398
+ service.setParameter(address, osc);
399
+ } catch (err) {
400
+ console.log(err instanceof Error ? err.message : String(err));
401
+ }
402
+ };
245
403
  const bootstrap = async () => {
246
404
  loadEnv();
247
- const { PORT, HOST, storageType, stateFilePath } = parseArgs(process.argv);
405
+ let parsed;
406
+ try {
407
+ parsed = parseArgs(process.argv);
408
+ } catch (err) {
409
+ const message = err instanceof Error ? err.message : String(err);
410
+ console.error(message);
411
+ process.exit(1);
412
+ return;
413
+ }
414
+ const { PORT, HOST, storageType, stateFilePath, name, model, firmware, advertiseIp, logLevel, permissive, meterMode } = parsed;
248
415
  const logger = ConsoleLogger.getInstance();
249
- logger.setLevel(LogLevel.DEBUG);
416
+ logger.setLevel(logLevel);
250
417
  const schemaRegistry = new SchemaRegistry(new SchemaFactory());
251
418
  const service = new SimulationService(new UdpNetworkGateway(logger, new OscCodec(schemaRegistry)), logger, createStateRepository({
252
419
  type: storageType,
253
420
  filePath: stateFilePath,
254
421
  autoSaveInterval: 5e3
255
- }), schemaRegistry, PORT, HOST);
422
+ }), schemaRegistry, PORT, HOST, name, model, meterConfig(permissive, meterMode), firmware, advertiseIp);
256
423
  try {
257
424
  await service.start();
258
425
  const storageInfo = storageType === "json" ? `JSON (${stateFilePath})` : "In-Memory";
@@ -264,10 +431,18 @@ const bootstrap = async () => {
264
431
  • Port: ${PORT}
265
432
  • Protocol: UDP (Strict X32 Schema)
266
433
  • Storage: ${storageInfo}
267
- • Logging: ENHANCED (DEBUG)
434
+ • Logging: ${[
435
+ "debug",
436
+ "info",
437
+ "warn",
438
+ "error",
439
+ "none"
440
+ ][logLevel]}
268
441
 
269
442
  👉 Type "exit" or "stop" to shut down.
270
443
  👉 Type "reset" to reset faders to default.
444
+ 👉 Type "set <address> <text>" to move a control, for example set /ch/01/mix/fader -10.
445
+ 👉 Type "get <address>" to print a control.
271
446
  👉 Type "save" to force save state (JSON mode).
272
447
  `);
273
448
  } catch (err) {
@@ -297,27 +472,29 @@ const bootstrap = async () => {
297
472
  input: process.stdin,
298
473
  output: process.stdout
299
474
  }).on("line", async (input) => {
300
- const command = input.trim().toLowerCase();
301
- switch (command) {
302
- case "exit":
303
- case "stop":
304
- case "quit":
305
- console.log("Shutting down...");
306
- await service.stop();
307
- process.exit(0);
308
- break;
309
- case "reset":
310
- service.resetState();
311
- console.log("✨ Console state reset to defaults.");
312
- break;
313
- case "save":
314
- await service.saveState();
315
- console.log("💾 State saved to storage.");
316
- break;
317
- default:
318
- if (command) console.log(`Unknown command: "${command}"`);
319
- break;
475
+ const line = input.trim();
476
+ const word = (line.split(/\s+/, 1)[0] ?? "").toLowerCase();
477
+ if (word === "exit" || word === "stop" || word === "quit") {
478
+ console.log("Shutting down...");
479
+ await service.stop();
480
+ process.exit(0);
481
+ return;
482
+ }
483
+ if (word === "reset") {
484
+ service.resetState();
485
+ console.log("✨ Console state reset to defaults.");
486
+ return;
487
+ }
488
+ if (word === "save") {
489
+ await service.saveState();
490
+ console.log("💾 State saved to storage.");
491
+ return;
492
+ }
493
+ if (word === "set" || word === "get") {
494
+ runParamCommand(word, line, schemaRegistry, service);
495
+ return;
320
496
  }
497
+ if (line) console.log(`Unknown command: "${line}"`);
321
498
  });
322
499
  process.on("SIGINT", async () => {
323
500
  console.log("\n(SIGINT received)");