@hyperframes/core 0.8.214 → 0.8.216

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.
@@ -49,3 +49,9 @@ export declare function bandFramesOf(signal: AudioSignal): BandFrames;
49
49
  export declare function rhythm(signal: AudioSignal): Rhythm;
50
50
  /** `rhythm`, yielding between short pieces of work. */
51
51
  export declare function rhythmSteps(signal: AudioSignal): Steps<Rhythm>;
52
+ export interface BeatEvidence {
53
+ confidence: number;
54
+ lift: number;
55
+ }
56
+ /** Steady-beat confidence over six seconds around each time, and its onset's lift there, at any level. */
57
+ export declare function localBeatEvidence(signal: AudioSignal, times: readonly number[], beatSeconds?: number): BeatEvidence[];
@@ -422,3 +422,27 @@ export function* rhythmSteps(signal) {
422
422
  entry.rhythm ??= yield* rhythmOf(entry.frames);
423
423
  return entry.rhythm;
424
424
  }
425
+ const SPAN_SECONDS = 6;
426
+ /** Steady-beat confidence over six seconds around each time, and its onset's lift there, at any level. */
427
+ export function localBeatEvidence(signal, times, beatSeconds) {
428
+ const { broad, fps } = onsetCurves(bandFramesOf(signal));
429
+ const half = Math.round((SPAN_SECONDS / 2) * fps);
430
+ const whole = beatSeconds ?? medianInterval(times) ?? 0;
431
+ if (whole * fps < 2)
432
+ return times.map(() => ({ confidence: 0, lift: 0 }));
433
+ const local = smoothed(broad, whole * fps);
434
+ return times.map((t) => {
435
+ const centre = Math.round((t - ONSET_LAG_SECONDS) * fps);
436
+ const from = Math.max(0, centre - half);
437
+ const to = Math.min(broad.length, centre + half);
438
+ const near = times.filter((other) => Math.abs(other - t) * fps <= half);
439
+ const lag = Math.round((beatSeconds ?? medianInterval(near) ?? whole) * fps);
440
+ const ac = autocorrelation(broad.subarray(from, to), lag + 1);
441
+ const clarity = Math.max(ac[lag - 1] ?? 0, ac[lag] ?? 0, ac[lag + 1] ?? 0);
442
+ const span = local.subarray(from, to);
443
+ const mean = span.reduce((sum, v) => sum + v, 0) / (span.length || 1);
444
+ const peak = Math.max(...[-2, -1, 0, 1, 2].map((d) => local[centre + d] ?? 0));
445
+ const lift = mean > 0 ? peak / mean - 1 : 0;
446
+ return { confidence: beatConfidence(clarity, lift), lift };
447
+ });
448
+ }
@@ -14,10 +14,12 @@ type GroupLookupRoot = Pick<Document, "getElementById"> | null | undefined;
14
14
  */
15
15
  export declare function colorGroupOf(el: Element): string | null;
16
16
  /**
17
- * The `<hf-color-group>` for an id, or null. Tag-checked so an unrelated
17
+ * The `<hf-color-group>` for an id, or null. Ids are unique only per
18
+ * composition file, so a member's own composition is searched first, as audio
19
+ * groups pair per composition; then the document. Tag-checked so an unrelated
18
20
  * element sharing the id is never read as a lane's grade.
19
21
  */
20
- export declare function resolveColorGroupElement(root: GroupLookupRoot, groupId: string): Element | null;
22
+ export declare function resolveColorGroupElement(root: GroupLookupRoot, groupId: string, member?: Element): Element | null;
21
23
  /**
22
24
  * The grade that applies to `el`: its own `data-color-grading` when present,
23
25
  * else its group element's, else null. A group id with no element is ungrouped.
@@ -22,10 +22,18 @@ export function colorGroupOf(el) {
22
22
  return el.getAttribute(HF_COLOR_GROUP_ATTR) || null;
23
23
  }
24
24
  /**
25
- * The `<hf-color-group>` for an id, or null. Tag-checked so an unrelated
25
+ * The `<hf-color-group>` for an id, or null. Ids are unique only per
26
+ * composition file, so a member's own composition is searched first, as audio
27
+ * groups pair per composition; then the document. Tag-checked so an unrelated
26
28
  * element sharing the id is never read as a lane's grade.
27
29
  */
28
- export function resolveColorGroupElement(root, groupId) {
30
+ export function resolveColorGroupElement(root, groupId, member) {
31
+ const scope = typeof member?.closest === "function" ? member.closest("[data-composition-id]") : null;
32
+ const scoped = scope
33
+ ? Array.from(scope.getElementsByTagName(HF_COLOR_GROUP_TAG)).find((g) => g.id === groupId)
34
+ : undefined;
35
+ if (scoped)
36
+ return scoped;
29
37
  const el = root?.getElementById(groupId) ?? null;
30
38
  return el?.tagName.toLowerCase() === HF_COLOR_GROUP_TAG ? el : null;
31
39
  }
@@ -40,7 +48,7 @@ export function effectiveColorGrading(el, root) {
40
48
  const groupId = colorGroupOf(el);
41
49
  if (!groupId)
42
50
  return null;
43
- return resolveColorGroupElement(root, groupId)?.getAttribute(HF_COLOR_GRADING_ATTR) ?? null;
51
+ return resolveColorGroupElement(root, groupId, el)?.getAttribute(HF_COLOR_GRADING_ATTR) ?? null;
44
52
  }
45
53
  /**
46
54
  * Make `<hf-color-group>` inert, once per document: an unknown custom element
@@ -0,0 +1,4 @@
1
+ /** Whether `fetch` follows the proxy variables (`NODE_USE_ENV_PROXY=1` or `--use-env-proxy`). */
2
+ export declare function envProxyEnabled(env?: NodeJS.ProcessEnv, execArgv?: readonly string[]): boolean;
3
+ /** Whether `fetch` reaches the network through `HTTPS_PROXY`, which then does the name resolution. */
4
+ export declare function fetchGoesThroughEnvProxy(env?: NodeJS.ProcessEnv, execArgv?: readonly string[]): boolean;
@@ -0,0 +1,9 @@
1
+ /** Whether `fetch` follows the proxy variables (`NODE_USE_ENV_PROXY=1` or `--use-env-proxy`). */
2
+ export function envProxyEnabled(env = process.env, execArgv = process.execArgv) {
3
+ const flags = [...execArgv, ...(env["NODE_OPTIONS"]?.split(/\s+/u) ?? [])];
4
+ return env["NODE_USE_ENV_PROXY"] === "1" || flags.includes("--use-env-proxy");
5
+ }
6
+ /** Whether `fetch` reaches the network through `HTTPS_PROXY`, which then does the name resolution. */
7
+ export function fetchGoesThroughEnvProxy(env = process.env, execArgv = process.execArgv) {
8
+ return (Boolean((env["HTTPS_PROXY"] ?? env["https_proxy"])?.trim()) && envProxyEnabled(env, execArgv));
9
+ }