Skip to content

Commit acb4aa4

Browse files
committed
TL14b: a sound's own tracks (fromTracks, clipEdits) move from sdk/timeline read.ts to sounds.ts, which keeps read.ts under its 500 lines
1 parent 26d094c commit acb4aa4

3 files changed

Lines changed: 69 additions & 67 deletions

File tree

‎sdk/timeline/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export * from "./registry"
1111
export * from "./play"
1212
export * from "./captions"
1313
export * from "./anim"
14+
export * from "./sounds"

‎sdk/timeline/src/read.ts‎

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -397,73 +397,6 @@ export function seqEdits(t: Timeline, op: Op): SeqEdit[] | { why: string } {
397397
}
398398
}
399399

400-
// ---------------------------------------------------------------- a sound's own tracks (TL14b)
401-
402-
/** A track of a sound in the feed as its host lists it (raea-feed host/sounds.ts), in seconds of the render. */
403-
export interface SoundTrack {
404-
/** its id in the sound's file */
405-
id: string
406-
/** what its head says */
407-
name: string
408-
/** what it holds: notes (a part played from notes), clips (files placed in time) or lines (words sung or said) */
409-
kind: "notes" | "clips" | "lines"
410-
/** the bus it plays through */
411-
bus: string
412-
/** its clips, each with its span in seconds, what it is, its file, where in the file it starts and its level in dB */
413-
clips: { id: string; from: number; to: number; label: string; src?: string; offset?: number; gainDb?: number }[]
414-
}
415-
/** A clip's span and level, in seconds and dB: what the host writes back for a clip that was moved, trimmed or
416-
* turned up or down (raea-feed host/clips.ts). */
417-
export interface ClipSpan {
418-
/** where it starts, in seconds of the render */
419-
start: number
420-
/** where it ends, in seconds of the render */
421-
end: number
422-
/** where in its file it starts playing, in seconds */
423-
offset: number
424-
/** its level change, in dB (0 as recorded) */
425-
gainDb: number
426-
}
427-
428-
const level = (db: number) => Math.round(10 ** (db / 20) * 1000) / 1000
429-
const dB = (v: number) => Math.round(20 * Math.log10(Math.max(v, 0.001)) * 10) / 10
430-
431-
/** A sound's tracks as a timeline: a sound track each, by its bus; a clip of a file keeps its place in the file
432-
* (its offset) and its level. Notes and lines are clips too, locked here: they are edited where they are written
433-
* (the roll, the words). No magnet: a mix's clips are where they were put. */
434-
export function fromTracks(tracks: SoundTrack[], fps: number): Timeline {
435-
const f = (s: number) => Math.round(s * fps)
436-
return {
437-
...empty(fps),
438-
magnet: false,
439-
tracks: tracks.map((k) => ({
440-
id: k.id,
441-
kind: "sound" as const,
442-
name: k.name,
443-
clips: k.clips
444-
.map((c): Clip => ({ id: c.id, kind: k.kind === "clips" ? "audio" : k.kind, name: c.label, start: f(c.from), length: Math.max(1, f(c.to) - f(c.from)), ...(c.src ? { in: f(c.offset ?? 0), at: c.src, volume: level(c.gainDb ?? 0) } : { locked: k.kind === "notes" ? "edited on its roll" : "edited in its words" }) }))
445-
.sort((a, b) => a.start - b.start),
446-
})),
447-
}
448-
}
449-
450-
/** A clip of a file as the host is told it: where it plays, how far into its file, how loud. */
451-
const spanOf = (c: Clip, fps: number): ClipSpan => ({ start: c.start / fps, end: end(c) / fps, offset: (c.in ?? 0) / fps, gainDb: dB(c.volume ?? 1) })
452-
453-
/** The file clips that differ between the timeline as it was read and as it stands, each with its span before and
454-
* after: what a sound's hand edit carries (its `clips`). A clip that was removed or made here isn't one of these. */
455-
export function clipEdits(read: Timeline, now: Timeline): { id: string; src: string; from: ClipSpan; to: ClipSpan }[] {
456-
const out: { id: string; src: string; from: ClipSpan; to: ClipSpan }[] = []
457-
for (const k of read.tracks)
458-
for (const was of k.clips) {
459-
const is = find(now, was.id)?.clip
460-
if (!was.at || !is) continue
461-
const a = spanOf(was, read.fps), b = spanOf(is, now.fps)
462-
if (a.start !== b.start || a.end !== b.end || a.offset !== b.offset || a.gainDb !== b.gainDb) out.push({ id: was.id, src: was.at, from: a, to: b })
463-
}
464-
return out
465-
}
466-
467400
// ---------------------------------------------------------------- a timeline an item declares (TL0d)
468401

469402
/** A timeline as an agent wrote it on a feed item or a controller's field (its own data: a schedule, a set list, a

‎sdk/timeline/src/sounds.ts‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// A sound's own tracks as a timeline (docs/timeline.feature TL14b): the tracks a sound in the feed lists, read in,
2+
// and the file clips a hand edit moved, trimmed or turned up, read back out for the host to write.
3+
import { type Clip, empty, end, find, type Timeline } from "./model"
4+
5+
/** A track of a sound in the feed as its host lists it (raea-feed host/sounds.ts), in seconds of the render. */
6+
export interface SoundTrack {
7+
/** its id in the sound's file */
8+
id: string
9+
/** what its head says */
10+
name: string
11+
/** what it holds: notes (a part played from notes), clips (files placed in time) or lines (words sung or said) */
12+
kind: "notes" | "clips" | "lines"
13+
/** the bus it plays through */
14+
bus: string
15+
/** its clips, each with its span in seconds, what it is, its file, where in the file it starts and its level in dB */
16+
clips: { id: string; from: number; to: number; label: string; src?: string; offset?: number; gainDb?: number }[]
17+
}
18+
/** A clip's span and level, in seconds and dB: what the host writes back for a clip that was moved, trimmed or
19+
* turned up or down (raea-feed host/clips.ts). */
20+
export interface ClipSpan {
21+
/** where it starts, in seconds of the render */
22+
start: number
23+
/** where it ends, in seconds of the render */
24+
end: number
25+
/** where in its file it starts playing, in seconds */
26+
offset: number
27+
/** its level change, in dB (0 as recorded) */
28+
gainDb: number
29+
}
30+
31+
const level = (db: number) => Math.round(10 ** (db / 20) * 1000) / 1000
32+
const dB = (v: number) => Math.round(20 * Math.log10(Math.max(v, 0.001)) * 10) / 10
33+
34+
/** A sound's tracks as a timeline: a sound track each, by its bus; a clip of a file keeps its place in the file
35+
* (its offset) and its level. Notes and lines are clips too, locked here: they are edited where they are written
36+
* (the roll, the words). No magnet: a mix's clips are where they were put. */
37+
export function fromTracks(tracks: SoundTrack[], fps: number): Timeline {
38+
const f = (s: number) => Math.round(s * fps)
39+
return {
40+
...empty(fps),
41+
magnet: false,
42+
tracks: tracks.map((k) => ({
43+
id: k.id,
44+
kind: "sound" as const,
45+
name: k.name,
46+
clips: k.clips
47+
.map((c): Clip => ({ id: c.id, kind: k.kind === "clips" ? "audio" : k.kind, name: c.label, start: f(c.from), length: Math.max(1, f(c.to) - f(c.from)), ...(c.src ? { in: f(c.offset ?? 0), at: c.src, volume: level(c.gainDb ?? 0) } : { locked: k.kind === "notes" ? "edited on its roll" : "edited in its words" }) }))
48+
.sort((a, b) => a.start - b.start),
49+
})),
50+
}
51+
}
52+
53+
/** A clip of a file as the host is told it: where it plays, how far into its file, how loud. */
54+
const spanOf = (c: Clip, fps: number): ClipSpan => ({ start: c.start / fps, end: end(c) / fps, offset: (c.in ?? 0) / fps, gainDb: dB(c.volume ?? 1) })
55+
56+
/** The file clips that differ between the timeline as it was read and as it stands, each with its span before and
57+
* after: what a sound's hand edit carries (its `clips`). A clip that was removed or made here isn't one of these. */
58+
export function clipEdits(read: Timeline, now: Timeline): { id: string; src: string; from: ClipSpan; to: ClipSpan }[] {
59+
const out: { id: string; src: string; from: ClipSpan; to: ClipSpan }[] = []
60+
for (const k of read.tracks)
61+
for (const was of k.clips) {
62+
const is = find(now, was.id)?.clip
63+
if (!was.at || !is) continue
64+
const a = spanOf(was, read.fps), b = spanOf(is, now.fps)
65+
if (a.start !== b.start || a.end !== b.end || a.offset !== b.offset || a.gainDb !== b.gainDb) out.push({ id: was.id, src: was.at, from: a, to: b })
66+
}
67+
return out
68+
}

0 commit comments

Comments
 (0)