@buffered-audio/nodes 0.18.2 → 0.19.0

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/cli.js CHANGED
@@ -4,11 +4,11 @@ import { existsSync, readFileSync } from 'fs';
4
4
  import { resolve } from 'path';
5
5
  import { SourceNode, validateGraphDefinition, createRenderJobs, BufferedSourceStream } from '@buffered-audio/core';
6
6
 
7
- var labelOf = (node) => node.id ? `${node.nodeName}#${node.id}` : node.nodeName;
7
+ var labelOf = (identity) => identity.nodeId !== void 0 ? `${identity.nodeName}#${identity.nodeId}` : `${identity.nodeName}#${identity.streamId}`;
8
8
  function sourceLabel(job) {
9
- for (const [node, streams] of job.streams) {
10
- if (streams.some((stream) => stream instanceof BufferedSourceStream)) {
11
- return labelOf({ nodeName: node.constructor.nodeName, id: node.id });
9
+ for (const streams of job.streams.values()) {
10
+ for (const stream of streams) {
11
+ if (stream instanceof BufferedSourceStream) return labelOf(stream.identity);
12
12
  }
13
13
  }
14
14
  return void 0;
@@ -39,26 +39,26 @@ function parseParams(entries) {
39
39
  }
40
40
  return Object.fromEntries(parameters);
41
41
  }
42
- function stamp() {
43
- const now = /* @__PURE__ */ new Date();
42
+ function stamp(createdAt) {
43
+ const date = new Date(createdAt);
44
44
  const pad = (value) => String(value).padStart(2, "0");
45
- return `${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}`;
45
+ return `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
46
46
  }
47
47
  function createEventSink() {
48
48
  const totals = /* @__PURE__ */ new Map();
49
49
  const subscribe = (events) => {
50
- events.on("started", (node) => {
51
- process.stdout.write(`${stamp()} [${labelOf(node)}] started
50
+ events.on("started", (node, payload) => {
51
+ process.stdout.write(`${stamp(payload.createdAt)} [${labelOf(node)}] started
52
52
  `);
53
53
  });
54
54
  events.on("progress", (node, payload) => {
55
55
  const label = labelOf(node);
56
56
  if (payload.framesTotal !== void 0) {
57
57
  const percent = Math.round(payload.framesDone / payload.framesTotal * 100);
58
- process.stdout.write(`${stamp()} [${label}] ${payload.phase} ${percent}%
58
+ process.stdout.write(`${stamp(payload.createdAt)} [${label}] ${payload.phase} ${percent}%
59
59
  `);
60
60
  } else {
61
- process.stdout.write(`${stamp()} [${label}] ${payload.phase} frames=${payload.framesDone}
61
+ process.stdout.write(`${stamp(payload.createdAt)} [${label}] ${payload.phase} frames=${payload.framesDone}
62
62
  `);
63
63
  }
64
64
  });
@@ -66,24 +66,23 @@ function createEventSink() {
66
66
  const data = payload.data ? Object.entries(payload.data).map(([key, value]) => `${key}=${String(value)}`) : [];
67
67
  const parts = [payload.message, ...data].join(" ");
68
68
  const prefix = payload.level === "warn" ? "warn: " : "";
69
- process.stdout.write(`${stamp()} ${prefix}[${labelOf(node)}] ${parts}
69
+ process.stdout.write(`${stamp(payload.createdAt)} ${prefix}[${labelOf(node)}] ${parts}
70
70
  `);
71
71
  });
72
72
  events.on("finished", (node, payload) => {
73
- totals.set(node, { framesDone: payload.framesDone, processingMs: payload.processingMs });
73
+ totals.set(node.streamId, { label: labelOf(node), framesDone: payload.framesDone, processingMs: payload.processingMs });
74
74
  const ms = payload.processingMs !== void 0 ? ` ms=${Math.round(payload.processingMs)}` : "";
75
- process.stdout.write(`${stamp()} [${labelOf(node)}] finished frames=${payload.framesDone}${ms}
75
+ process.stdout.write(`${stamp(payload.createdAt)} [${labelOf(node)}] finished frames=${payload.framesDone}${ms}
76
76
  `);
77
77
  });
78
78
  };
79
79
  const printSummary = (jobs) => {
80
- for (const [node, { framesDone, processingMs }] of totals) {
81
- const label = labelOf(node);
80
+ for (const { label, framesDone, processingMs } of totals.values()) {
82
81
  if (processingMs !== void 0) {
83
- process.stdout.write(`${stamp()} [${label}] processed ${framesDone} frames in ${Math.round(processingMs)}ms
82
+ process.stdout.write(`${stamp(Date.now())} [${label}] processed ${framesDone} frames in ${Math.round(processingMs)}ms
84
83
  `);
85
84
  } else {
86
- process.stdout.write(`${stamp()} [${label}] processed ${framesDone} frames
85
+ process.stdout.write(`${stamp(Date.now())} [${label}] processed ${framesDone} frames
87
86
  `);
88
87
  }
89
88
  }
@@ -91,7 +90,7 @@ function createEventSink() {
91
90
  const timing = job.timing;
92
91
  if (!timing) continue;
93
92
  const label = sourceLabel(job) ?? "source";
94
- process.stdout.write(`${stamp()} [${label}] total ${(timing.totalMs / 1e3).toFixed(1)}s, ${timing.realTimeMultiplier.toFixed(1)}x RT
93
+ process.stdout.write(`${stamp(Date.now())} [${label}] total ${(timing.totalMs / 1e3).toFixed(1)}s, ${timing.realTimeMultiplier.toFixed(1)}x RT
95
94
  `);
96
95
  }
97
96
  };