rvlib-shipkit 2.20.0 → 2.22.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.
Files changed (156) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/package.json +1 -1
  3. package/src/asks/asks-queue.ts +8 -7
  4. package/src/assets/kits/identity-kit.ts +158 -2
  5. package/src/checks/SK004-gitignore-policy.check.ts +6 -3
  6. package/src/cli/cmd_Bump.ts +3 -3
  7. package/src/cli/cmd_GlobalProcesses.ts +2 -107
  8. package/src/cli/cmd_Home.ts +1 -1
  9. package/src/cli/cmd_Overview.ts +2 -1
  10. package/src/cli/cmd_Rec.ts +349 -0
  11. package/src/cli/cmd_Releases.ts +42 -3
  12. package/src/cli/cmd_Review.ts +22 -13
  13. package/src/cli/cmd_Secret.ts +10 -3
  14. package/src/cli/cmd_Sign.ts +24 -0
  15. package/src/cli/cmd_Social.ts +57 -8
  16. package/src/cli/cmd_Sound.ts +17 -4
  17. package/src/cli/cmd_Trailer.ts +67 -1
  18. package/src/cli/family-pages.ts +1 -0
  19. package/src/cli/registry.ts +6 -1
  20. package/src/collections/collection-types.ts +1 -1
  21. package/src/collections/review.ts +23 -4
  22. package/src/core/agent-spawn.ts +4 -17
  23. package/src/core/code-lines.ts +49 -0
  24. package/src/core/discover-checks.ts +27 -3
  25. package/src/core/hard-reset.ts +34 -0
  26. package/src/core/layout.ts +6 -0
  27. package/src/core/raw-access.ts +3 -13
  28. package/src/core/throwaway-worktree.ts +72 -0
  29. package/src/home/app-sign.ts +98 -0
  30. package/src/home/gui-app/ShipkitGui.swift +35 -0
  31. package/src/home/gui-app.ts +31 -11
  32. package/src/home/home-routes.ts +6 -0
  33. package/src/home/pm-switch.ts +112 -0
  34. package/src/home/serve-web.ts +1 -1
  35. package/src/identities/identities.ts +17 -6
  36. package/src/media-kinds.ts +5 -3
  37. package/src/media-store/forget.ts +54 -0
  38. package/src/media-store/put.ts +4 -3
  39. package/src/media-store/space.ts +63 -24
  40. package/src/messages/brief.ts +3 -3
  41. package/src/messages/score.ts +2 -0
  42. package/src/recordings/delete.ts +19 -0
  43. package/src/recordings/edit.ts +231 -0
  44. package/src/recordings/load.ts +37 -0
  45. package/src/recordings/marks-draw.ts +111 -0
  46. package/src/recordings/marks-png.ts +25 -0
  47. package/src/recordings/marks.ts +138 -0
  48. package/src/recordings/media-kind.ts +67 -0
  49. package/src/recordings/model.ts +170 -0
  50. package/src/recordings/open.ts +33 -0
  51. package/src/recordings/place.ts +89 -0
  52. package/src/recordings/presets.ts +99 -0
  53. package/src/recordings/recorder-app/Capture.swift +510 -0
  54. package/src/recordings/recorder-app/Clip.swift +107 -0
  55. package/src/recordings/recorder-app/Editor.swift +39 -0
  56. package/src/recordings/recorder-app/Tray.swift +298 -0
  57. package/src/recordings/recorder-app/main.swift +859 -0
  58. package/src/recordings/recorder-app.ts +46 -0
  59. package/src/recordings/recorder.shipkit.ts +11 -0
  60. package/src/recordings/routes.ts +140 -0
  61. package/src/recordings/run-recorder.ts +40 -0
  62. package/src/recordings/share.ts +107 -0
  63. package/src/recordings/take.ts +146 -0
  64. package/src/recordings/view.ts +40 -0
  65. package/src/release/gate-checkout.ts +74 -0
  66. package/src/release/release-scope.ts +35 -26
  67. package/src/release/run-bump.ts +79 -37
  68. package/src/release/run-release.ts +67 -53
  69. package/src/releases/add.ts +38 -5
  70. package/src/releases/before.ts +31 -0
  71. package/src/releases/from-card.ts +105 -20
  72. package/src/releases/model.ts +100 -18
  73. package/src/releases/pictures.ts +29 -8
  74. package/src/repo-config.ts +7 -3
  75. package/src/review/http.ts +1 -1
  76. package/src/review/model.ts +12 -2
  77. package/src/review/stage-card.ts +1 -1
  78. package/src/review/store.ts +12 -2
  79. package/src/review/trailer-desk.ts +20 -0
  80. package/src/review/trailer-model.ts +67 -0
  81. package/src/review/trailer-routes.ts +98 -1
  82. package/src/review/trailer-voices.ts +144 -0
  83. package/src/review/watchers.ts +58 -1
  84. package/src/secrets/manager.ts +18 -1
  85. package/src/serve/hub-app/benign-errors.ts +22 -0
  86. package/src/serve/hub-app/hash-route.ts +27 -15
  87. package/src/serve/hub-app/home-st.ts +23 -5
  88. package/src/serve/hub-app/home.html +1 -0
  89. package/src/serve/hub-app/hub-app.tsx +8 -1
  90. package/src/serve/hub-app/icons.tsx +2 -0
  91. package/src/serve/hub-app/palette-st.ts +1 -0
  92. package/src/serve/hub-app/project-list.css +7 -2
  93. package/src/serve/hub-app/project-list.tsx +10 -0
  94. package/src/serve/hub-app/projects-svc.ts +17 -7
  95. package/src/serve/hub-app/recordings-st.ts +641 -0
  96. package/src/serve/hub-app/recordings-view.tsx +504 -0
  97. package/src/serve/hub-app/recordings.css +82 -0
  98. package/src/serve/hub-app/releases/releases-page.tsx +121 -28
  99. package/src/serve/hub-app/releases/releases-st.ts +46 -4
  100. package/src/serve/hub-app/releases.css +30 -3
  101. package/src/serve/hub-app/repo-sections.ts +1 -1
  102. package/src/serve/hub-app/repo-st.ts +16 -11
  103. package/src/serve/hub-app/review/clip-st.ts +3 -1
  104. package/src/serve/hub-app/review/kit.tsx +3 -3
  105. package/src/serve/hub-app/review/trailer-page.tsx +32 -6
  106. package/src/serve/hub-app/review/trailer-st.ts +184 -8
  107. package/src/serve/hub-app/review/trailer-timeline.tsx +39 -4
  108. package/src/serve/hub-app/review/trailer-voices-st.ts +370 -0
  109. package/src/serve/hub-app/review/trailer-voices.tsx +574 -0
  110. package/src/serve/hub-app/review.css +90 -0
  111. package/src/serve/hub-app/social/comms-page.tsx +10 -5
  112. package/src/serve/hub-app/social/next-release.tsx +118 -0
  113. package/src/serve/hub-app/social/post-card.tsx +31 -3
  114. package/src/serve/hub-app/social/social-model.ts +6 -0
  115. package/src/serve/hub-app/social/social-st.ts +50 -1
  116. package/src/serve/hub-app/social.css +12 -0
  117. package/src/serve/hub-app/tree-build.ts +2 -0
  118. package/src/serve/project-gutter-route.ts +8 -0
  119. package/src/serve/project-gutter.ts +4 -2
  120. package/src/shipkit.ts +2 -2
  121. package/src/shot/box.ts +49 -22
  122. package/src/shot/browser-slot.ts +13 -3
  123. package/src/shot/client.ts +1 -1
  124. package/src/shot/film-box.ts +193 -117
  125. package/src/shot/shooter.ts +20 -8
  126. package/src/smoke/run-smoke.ts +8 -6
  127. package/src/social/compose.ts +14 -0
  128. package/src/social/desk-index.ts +49 -8
  129. package/src/social/discord-layout.ts +6 -2
  130. package/src/social/drafts.ts +1 -1
  131. package/src/social/kinds.ts +3 -2
  132. package/src/social/load.ts +42 -9
  133. package/src/social/publish/index.ts +27 -10
  134. package/src/social/publish/secret.ts +12 -4
  135. package/src/social/release-card.ts +69 -0
  136. package/src/social/release-stage.ts +173 -30
  137. package/src/social/routes.ts +7 -1
  138. package/src/social/stage.ts +45 -22
  139. package/src/trailer/bed.ts +111 -0
  140. package/src/trailer/build.ts +81 -38
  141. package/src/trailer/ffmpeg.ts +14 -0
  142. package/src/trailer/grammar.ts +32 -4
  143. package/src/trailer/graph.ts +12 -1
  144. package/src/trailer/look.ts +7 -0
  145. package/src/trailer/shot-plan.ts +75 -0
  146. package/src/trailer/shot-state.ts +191 -0
  147. package/src/trailer/sound/audio.ts +28 -0
  148. package/src/trailer/sound/brand.ts +53 -3
  149. package/src/trailer/sound/gen.ts +61 -2
  150. package/src/trailer/sound/index.ts +25 -11
  151. package/src/trailer/sound/presets.ts +86 -5
  152. package/src/trailer/sound/run.ts +1 -1
  153. package/src/trailer/sound/takes.ts +94 -0
  154. package/src/trailer/titles.ts +36 -0
  155. package/src/trailer/url.ts +1 -1
  156. package/src/veille/chrome.ts +6 -3
@@ -0,0 +1,574 @@
1
+ // the trailer page's Voices (wiki tools/trailer/trailer-sound.md, Your own voice): the open line in the middle, what the
2
+ // cut plays now and his take, its clip below, the record button; every line of the trailer on the right, his to
3
+ // record first. While he records, the clip plays from its shot's start without sound and the cue lights where the
4
+ // line starts
5
+ import { observer } from 'mobx-react-lite'
6
+ import { useEffect, useRef, useState } from 'react'
7
+ import { clock, PASSAGE_PAD, type VoiceLine, type VoiceUse } from '../../../review/trailer-model.ts'
8
+ import { editorHref } from '../check-words.ts'
9
+ import type { TrailerSt } from './trailer-st.ts'
10
+ import { stateOfLine, type VoicesSt, type VoiceState } from './trailer-voices-st.ts'
11
+
12
+ const STATE_WORD: Record<VoiceState, string> = { waiting: 'to record', recorded: 'recorded', other: 'another voice' }
13
+
14
+ /** the line's words with its tags as small directions: `[excited]` says how, never what */
15
+ const Spoken = ({ text }: { text: string }) => (
16
+ <>
17
+ {text.split(/(\[[^\]]*\])/).map((p, i) =>
18
+ /^\[.*\]$/.test(p) ? <span key={i} className="tv-tag">{p.slice(1, -1)}</span> : <span key={i}>{p}</span>,
19
+ )}
20
+ </>
21
+ )
22
+
23
+ /** the Voices button of the cut list: the count of lines waiting for him */
24
+ export const VoicesButton = observer(({ tr }: { tr: TrailerSt }) => {
25
+ const v = tr.voices
26
+ const n = tr.trailer ? (v.counts[tr.trailer.id] ?? 0) : v.count
27
+ return (
28
+ <button className={`tr-cutrow tv-button${v.on ? ' on' : ''}`} onClick={() => v.show(!v.on)}
29
+ title={`every voice line of the trailer: listen, see its clip, record your own (R)${n > 0 ? `. ${n} of its lines are yours to read and not recorded yet: the cut plays a stand-in voice until you record them` : ''}`}>
30
+ <span style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start' }}>
31
+ <span>🎙 Voice lines</span>
32
+ {n > 0 ? <span className="tr-dim tr-small">{n} not recorded by you yet</span> : null}
33
+ </span>
34
+ </button>
35
+ )
36
+ })
37
+
38
+ export const VoicesList = observer(({ tr }: { tr: TrailerSt }) => {
39
+ const v = tr.voices
40
+ const ls = v.lines
41
+ const open = v.line
42
+ return (
43
+ <div className="tv-list rv-scroll">
44
+ <div className="tr-noteshead"><b>Voice lines</b><span className="sp" /><span className="tv-dim">{ls.length} text{ls.length === 1 ? '' : 's'}</span></div>
45
+ {v.desk?.errors.map((e) => <div key={e} className="rv-err">{e}</div>)}
46
+ {ls.map((l) => {
47
+ const s = stateOfLine(l)
48
+ return (
49
+ <button key={l.key} className={`tv-row${open?.key === l.key ? ' on' : ''}`} onClick={() => v.pick(l.key)}>
50
+ <span className={`tv-dot ${s}`} title={STATE_WORD[s]} />
51
+ <span className="tv-rowtext">{l.words}</span>
52
+ {l.uses.length > 1 ? <span className="tv-dim" title={l.uses.map((u) => `${u.cut} · ${u.shot}`).join('\n')}>×{l.uses.length}</span> : null}
53
+ </button>
54
+ )
55
+ })}
56
+ {v.desk && ls.length === 0 ? <div className="rv-empty">No voice line in this trailer: a shot says one with voice "&lt;line&gt;".</div> : null}
57
+ </div>
58
+ )
59
+ })
60
+
61
+ export const VoiceOpen = observer(({ tr }: { tr: TrailerSt }) => {
62
+ const v = tr.voices
63
+ const l = v.line
64
+ if (v.error && !v.desk) return <div className="rv-err">{v.error}</div>
65
+ if (!v.desk) return <div className="rv-empty"><span className="spin" /> reading the voice lines…</div>
66
+ return (
67
+ <div className="tv-open">
68
+ {v.error ? <div className="rv-err">{v.error}</div> : null}
69
+ {!v.desk.recorder ? (
70
+ <div className="rv-empty">
71
+ No voice of yours in the brand yet. Add one to trailer.voices in .shipkit/identity/brand.ts, <code>{"me: { record: 'Your name', standin: '<a voice>' }"}</code>, then write <code>by me</code> on the lines you read.
72
+ </div>
73
+ ) : (
74
+ <div className="tv-dim" title={`the switch is takes on the ${v.desk.recorder.voice} voice in .shipkit/identity/brand.ts; both versions stay kept`}>
75
+ The cuts play {v.desk.recorder.takes ? `${v.desk.recorder.who}'s takes where there is one` : `the standin on every line, ${v.desk.recorder.who}'s takes kept`} (takes: {String(v.desk.recorder.takes)} in the brand)
76
+ </div>
77
+ )}
78
+ {l ? <LineCard v={v} l={l} key={l.key} /> : <div className="rv-empty">No voice line in this trailer.</div>}
79
+ </div>
80
+ )
81
+ })
82
+
83
+ const LineCard = observer(({ v, l }: { v: VoicesSt; l: VoiceLine }) => {
84
+ const s = stateOfLine(l)
85
+ const use = v.useOf(l)
86
+ const rec = v.recording?.key === l.key ? v.recording : null
87
+ const saving = v.saving === l.key
88
+ const take = v.takeUrl(l)
89
+ const who = v.desk?.recorder?.who ?? 'you'
90
+ const [now, setNow] = useState(Date.now())
91
+ useEffect(() => {
92
+ if (!rec) return
93
+ const t = setInterval(() => setNow(Date.now()), 100)
94
+ return () => clearInterval(t)
95
+ }, [rec])
96
+ return (
97
+ <>
98
+ <div className="tv-head">
99
+ <span className={`tv-pill ${s}`}>{STATE_WORD[s]}</span>
100
+ {s === 'other' ? <span className="tv-dim">the cut reads it with {use?.reader}; your take is kept, and plays once its line says by {l.voice ?? 'your voice'}</span> : null}
101
+ {l.uses.length > 1 ? <span className="tv-dim">said {l.uses.length} times, one take for all</span> : null}
102
+ </div>
103
+ <blockquote className="tv-text"><Spoken text={l.text} /></blockquote>
104
+ <div className="tv-audio">
105
+ <span className="tv-label">In the cut now</span>
106
+ <span className="tv-dim">{use ? use.reader : 'no use'}{use && !use.made ? ' (sk trailer makes it)' : ''}</span>
107
+ <span className="sp" />
108
+ {take && !rec ? <button className="tv-small" onClick={() => void v.drop(l)} title="delete your take of these words">Delete your take</button> : null}
109
+ </div>
110
+ <div className="tv-actions">
111
+ {rec ? (
112
+ <>
113
+ <button className="tv-rec on" onClick={() => void v.stop()} title="stop and keep the take (R)">■ Stop and keep</button>
114
+ <button onClick={() => void v.cancel()} title="drop this recording (Esc)">Cancel</button>
115
+ <span className="tv-meter"><span style={{ width: `${Math.min(100, Math.round(rec.level * 100))}%` }} /></span>
116
+ <span className="tv-time">{((now - rec.since) / 1000).toFixed(1)} s</span>
117
+ </>
118
+ ) : (
119
+ <>
120
+ <button className="tv-rec" disabled={saving || !l.voice} onClick={() => void v.record(l.key)} title={l.voice ? `record ${who} reading it (R): the clip plays without sound, the cue lights where the line starts` : 'no voice of yours in the brand'}>
121
+ {saving ? 'Keeping…' : take ? '● Record again' : '● Record'}
122
+ </button>
123
+ <button onClick={() => v.next()} title="the next line (N)">Next</button>
124
+ </>
125
+ )}
126
+ </div>
127
+ <label className="tv-mic" title="the input your takes record from, kept by this browser">
128
+ <span className="tv-label">Microphone</span>
129
+ <select value={v.micId} disabled={rec !== null} onChange={(e) => v.pickMic(e.currentTarget.value)} onFocus={() => void v.loadMics()}>
130
+ <option value="">the system's default</option>
131
+ {v.mics.map((m) => <option key={m.id} value={m.id}>{m.label}</option>)}
132
+ </select>
133
+ </label>
134
+ {use ? <LinePlayer v={v} l={l} use={use} recording={rec !== null} key={`${l.key}:${use.cut}:${use.line}`} /> : null}
135
+ <div className="tv-uses">
136
+ {l.uses.map((u) => (
137
+ <a key={`${u.cut}:${u.line}`} href={editorHref(v.root, `${u.file}:${u.line}`) ?? undefined} title="open the line in the editor">
138
+ {u.cut} · {u.shot} · {clock(u.at)} · line {u.line}{u.mine ? '' : ` · ${u.reader}`}
139
+ </a>
140
+ ))}
141
+ </div>
142
+ </>
143
+ )
144
+ })
145
+
146
+ /** one sound's samples, decoded once a url: what its lane draws */
147
+ type Wave = { data: Float32Array; seconds: number; peak: number }
148
+ const waves = new Map<string, Promise<Wave>>()
149
+ let decoder: AudioContext | null = null
150
+ function waveOf(url: string): Promise<Wave> {
151
+ let w = waves.get(url)
152
+ if (!w) {
153
+ w = fetch(url)
154
+ .then((r) => (r.ok ? r.arrayBuffer() : Promise.reject(new Error(`HTTP ${r.status}`))))
155
+ .then((b) => (decoder ??= new AudioContext()).decodeAudioData(b))
156
+ .then((a) => {
157
+ const data = a.getChannelData(0)
158
+ let peak = 0
159
+ for (const x of data) peak = Math.max(peak, Math.abs(x))
160
+ return { data, seconds: a.duration, peak }
161
+ })
162
+ w.catch(() => waves.delete(url))
163
+ waves.set(url, w)
164
+ }
165
+ return w
166
+ }
167
+
168
+ /** a media element played: a pause or a new source before it starts rejects its promise with AbortError, which is
169
+ * the normal course of a play cut short, never an error to show; any other refusal is said in the console */
170
+ function playQuiet(el: HTMLMediaElement): void {
171
+ el.play().catch((e: Error) => {
172
+ if (e.name !== 'AbortError') console.warn(`the clip could not play: ${e.name}: ${e.message}`)
173
+ })
174
+ }
175
+
176
+ /** a lane: the reference (the voice that stands in, else what the cut plays) or his take. `draw` is the file its
177
+ * shape is drawn from, placed at `at` on the line's time with `mask` (its own seconds) tinted; `play` the file heard,
178
+ * which starts at the line's 0 (his take: the made line, its mask and offset in it) */
179
+ type Lane = { id: 'ref' | 'take'; label: string; draw: string; play: string | null; at: number; mask: Range[]; tone: string }
180
+ type Range = [number, number]
181
+ /** one empty mask for every lane with none: a new array each frame would redraw its shape at every cursor move */
182
+ const NO_MASK: Range[] = []
183
+ /** a lane played alone, from a time; the clip is a video of its own */
184
+ type Mode = { lane: Lane['id']; from: number } | null
185
+ type Brush = 'mute' | 'keep'
186
+
187
+ /** a brush stroke on a mask: mute adds the range, keep takes it out */
188
+ function brushed(mask: readonly Range[], r: Range, brush: Brush): Range[] {
189
+ const [a, b] = r[0] <= r[1] ? r : [r[1], r[0]]
190
+ if (brush === 'mute') return [...mask, [a, b]]
191
+ return mask.flatMap(([x, y]): Range[] => (y <= a || x >= b ? [[x, y]] : [...(x < a ? [[x, a] as Range] : []), ...(y > b ? [[b, y] as Range] : [])]))
192
+ }
193
+
194
+ /** the line's sounds as waveforms on one time scale, 0 where the line starts in the cut, a cursor on whatever plays
195
+ * (a lane alone, a lane over the clip and its music, his recording), the next line's start marked; his take dragged
196
+ * to its place and its noises painted out on the bar under it; the shot below */
197
+ const LinePlayer = observer(({ v, l, use, recording }: { v: VoicesSt; l: VoiceLine; use: VoiceUse; recording: boolean }) => {
198
+ const ref = use.standin ? (use.standin.made ? v.madeUrlOf(use.standin.made) : null) : v.madeUrl(use)
199
+ const raw = v.takeUrl(l)
200
+ // a drag or a stroke in progress, drawn before it is kept
201
+ const [drag, setDrag] = useState(0)
202
+ const [stroke, setStroke] = useState<{ r: Range; brush: Brush } | null>(null)
203
+ const [brush, setBrush] = useState<Brush>('mute')
204
+ const t = l.take
205
+ const mask = t ? (stroke ? brushed(t.mask, stroke.r, stroke.brush) : t.mask) : NO_MASK
206
+ const lanes: Lane[] = [
207
+ ...(ref ? [{ id: 'ref' as const, label: use.standin?.name ?? use.reader, draw: ref, play: ref, at: 0, mask: NO_MASK, tone: 'var(--dim)' }] : []),
208
+ // his take plays only as the cut will: the made line, his drag and masks in it; while it is being made,
209
+ // nothing plays, never the raw recording without them
210
+ ...(t && raw ? [{ id: 'take' as const, label: t.made ? 'your take' : 'your take (making…)', draw: raw, play: t.made ? v.madeUrlOf(t.made) : null, at: t.offset + drag, mask, tone: 'var(--accent)' }] : []),
211
+ ]
212
+ const [shapes, setShapes] = useState<Record<string, Wave | 'error'>>({})
213
+ useEffect(() => {
214
+ let live = true
215
+ for (const ln of lanes) if (!(ln.draw in shapes)) void waveOf(ln.draw).then((w) => live && setShapes((s) => ({ ...s, [ln.draw]: w })), () => live && setShapes((s) => ({ ...s, [ln.draw]: 'error' })))
216
+ return () => void (live = false)
217
+ }, [ref, raw])
218
+ const lengths = lanes.flatMap((ln) => {
219
+ const w = shapes[ln.draw]
220
+ return w && w !== 'error' ? [ln.at + w.seconds] : []
221
+ })
222
+ const span = Math.max(1, Math.min(use.room, 12), ...lengths) + 0.25
223
+ const keep = (edit: { offset: number | null; mask: Range[] }): void => void v.editTake(l, edit).finally(() => (setDrag(0), setStroke(null)))
224
+ const [mode, setMode] = useState<Mode>(null)
225
+ const [cursor, setCursor] = useState<number | null>(null)
226
+ const [cue, setCue] = useState(false)
227
+ const video = useRef<HTMLVideoElement>(null)
228
+ const voice = useRef<Record<string, HTMLAudioElement | null>>({})
229
+ // the passage: the line's picture from PASSAGE_PAD before it, its bed and the version he hears, one file, one clock
230
+ const hear = lanes.some((ln) => ln.id === v.hear) ? v.hear : (lanes[0]?.id ?? 'ref')
231
+ const lead = Math.min(PASSAGE_PAD, use.at)
232
+ // his version waits for its made line; a passage the hub refuses says why under the frame, never a dead player
233
+ const waiting = !recording && hear === 'take' && !t?.made
234
+ const src = waiting ? null : v.passageUrl(l, use, recording ? 'none' : hear)
235
+ const [clipError, setClipError] = useState<string | null>(null)
236
+ // the clip plays at his level, a new clip of the line too; a lane alone takes it as it starts
237
+ const level = v.level
238
+ useEffect(() => {
239
+ if (video.current) video.current.volume = level
240
+ for (const a of Object.values(voice.current)) if (a) a.volume = Math.min(1, use.volume) * level
241
+ }, [level, src])
242
+ useEffect(() => setClipError(null), [src])
243
+ const sayWhy = (url: string): void =>
244
+ void fetch(url)
245
+ .then(async (r) => (r.ok ? 'the clip could not play in this window' : (((await r.json().catch(() => ({}))) as { error?: string }).error ?? `HTTP ${r.status}`)))
246
+ .catch((e: Error) => e.message)
247
+ .then((why) => setClipError(why))
248
+ // a lane alone: from its start or a click, its time is the cursor; it stops at its end
249
+ useEffect(() => {
250
+ const lane = mode ? voice.current[mode.lane] : null
251
+ if (!lane || !mode) return
252
+ video.current?.pause()
253
+ lane.currentTime = mode.from
254
+ lane.volume = Math.min(1, use.volume) * v.level
255
+ playQuiet(lane)
256
+ let raf = 0
257
+ const tick = (): void => {
258
+ setCursor(lane.currentTime)
259
+ if (lane.ended || lane.paused) return setMode(null)
260
+ raf = requestAnimationFrame(tick)
261
+ }
262
+ raf = requestAnimationFrame(tick)
263
+ return () => {
264
+ cancelAnimationFrame(raf)
265
+ lane.pause()
266
+ }
267
+ }, [mode])
268
+ // the passage playing: its time less the lead is the cursor; while he records it plays silent from its start, the cue lit where the line starts
269
+ const [clipOn, setClipOn] = useState(false)
270
+ // the part of the passage that plays: its in and out points (seconds of the passage), looped when he asks
271
+ const [length, setLength] = useState(0)
272
+ const [range, setRange] = useState<Range | null>(null)
273
+ const [at, setAt] = useState(0)
274
+ const span2 = (): Range => range ?? [0, length]
275
+ const bounds = useRef<{ r: Range; loop: boolean }>({ r: [0, 0], loop: false })
276
+ bounds.current = { r: span2(), loop: v.loop }
277
+ // a recording plays the silent passage once from its start; this effect alone starts and stops the video for it,
278
+ // keyed on the recording and the passage's url only: a play or pause event never runs it again
279
+ useEffect(() => {
280
+ const vid = video.current
281
+ if (!vid || !recording) return
282
+ vid.muted = true
283
+ vid.currentTime = 0
284
+ playQuiet(vid)
285
+ return () => {
286
+ vid.pause()
287
+ vid.muted = false
288
+ }
289
+ }, [recording, src])
290
+ // the cursor, the playhead and the range's ends while the clip plays: it reads the video, and pauses it only at
291
+ // the out point; it never starts it
292
+ useEffect(() => {
293
+ const vid = video.current
294
+ if (!vid || (!recording && !clipOn)) return
295
+ let raf = 0
296
+ const tick = (): void => {
297
+ const [a, b] = bounds.current.r
298
+ // at the out point: back to the in point when it loops, else it stops there
299
+ if (!recording && b > a && vid.currentTime >= b - 0.01) {
300
+ if (bounds.current.loop) vid.currentTime = a
301
+ else {
302
+ vid.pause()
303
+ vid.currentTime = b
304
+ }
305
+ }
306
+ setAt(vid.currentTime)
307
+ setCursor(vid.currentTime - lead)
308
+ setCue(recording && vid.currentTime >= lead - 0.05 && vid.currentTime < lead + 1.2)
309
+ raf = requestAnimationFrame(tick)
310
+ }
311
+ raf = requestAnimationFrame(tick)
312
+ return () => {
313
+ cancelAnimationFrame(raf)
314
+ setCue(false)
315
+ }
316
+ }, [recording, clipOn, src])
317
+ const playing = (id: Lane['id']): boolean => mode?.lane === id
318
+ const toggle = (id: Lane['id'], from = 0): void => setMode(playing(id) && from === 0 ? null : { lane: id, from })
319
+ return (
320
+ <div className="tv-clip">
321
+ <div className="tv-waves">
322
+ {lanes.map((ln) => (
323
+ <div key={ln.id} className="tv-lane">
324
+ <button className="tv-small" disabled={recording || !ln.play} onClick={() => toggle(ln.id)} title={`play ${ln.label} alone; a click on its shape plays it from there`}>{playing(ln.id) ? '■' : '▶'}</button>
325
+ <span className="tv-lanename" style={{ color: ln.tone }}>{ln.label}</span>
326
+ <WaveCanvas wave={shapes[ln.draw]} span={span} tone={ln.tone} at={ln.at} mask={ln.mask}
327
+ onPick={(x) => !recording && ln.play !== null && setMode({ lane: ln.id, from: x })}
328
+ {...(ln.id === 'take' && t && !recording ? { onDrag: (dx: number) => setDrag(dx), onDrop: (dx: number) => keep({ offset: t.offset + dx, mask: t.mask }) } : {})} />
329
+ {ln.play ? <audio ref={(a) => void (voice.current[ln.id] = a)} src={ln.play} preload="auto" /> : null}
330
+ </div>
331
+ ))}
332
+ {t && raw ? (
333
+ <div className="tv-lane">
334
+ <span />
335
+ <span className="tv-brushes">
336
+ <button className={`tv-brush mute${brush === 'mute' ? ' on' : ''}`} onClick={() => setBrush('mute')} title="paint over a noise to mute it">mute</button>
337
+ <button className={`tv-brush keep${brush === 'keep' ? ' on' : ''}`} onClick={() => setBrush('keep')} title="paint over a muted part to hear it again">keep</button>
338
+ </span>
339
+ <MaskBar span={span} at={t.offset + drag} mask={mask} disabled={recording}
340
+ onStroke={(r) => setStroke({ r, brush })}
341
+ onDone={(r) => keep({ offset: t.offset, mask: brushed(t.mask, r, brush) })} />
342
+ </div>
343
+ ) : null}
344
+ {lanes.length === 0 ? <div className="tv-dim">no sound of this line is made yet: sk trailer makes it</div> : null}
345
+ <div className="tv-overlay">
346
+ <Ruler span={span} />
347
+ {use.room < span ? <div className="tv-room" style={{ left: `${(use.room / span) * 100}%` }} title={`the next line starts ${use.room.toFixed(2)} s after this one`}><span>next line</span></div> : null}
348
+ {cursor !== null && cursor >= 0 && cursor <= span ? <div className="tv-cursor" style={{ left: `${(cursor / span) * 100}%` }} /> : null}
349
+ </div>
350
+ </div>
351
+ {t ? (
352
+ <div className="tv-cliphead tv-dim">
353
+ <span>your take starts {(t.offset + drag) >= 0 ? `${(t.offset + drag).toFixed(2)} s after` : `${(-(t.offset + drag)).toFixed(2)} s into the recording at`} the line's start{t.dragged ? '' : ', at its first sound'}{t.mask.length > 0 ? ` · ${t.mask.length} part${t.mask.length > 1 ? 's' : ''} muted` : ''}</span>
354
+ <span className="tv-dim">drag the shape to move it, paint the bar to mute a noise</span>
355
+ <span className="sp" />
356
+ {v.saving === l.key ? <span className="spin" title="the line is made again" /> : null}
357
+ {t.dragged || t.mask.length > 0 ? <button className="tv-small" disabled={recording} onClick={() => keep({ offset: null, mask: [] })} title="back to the take as recorded: at its first sound, nothing muted">Reset</button> : null}
358
+ </div>
359
+ ) : null}
360
+ <div className="tv-cliphead">
361
+ <span className="tv-label">The clip</span>
362
+ <span className="tv-dim">{use.cut} · {use.shot} · {lead.toFixed(1)} s before the line to {PASSAGE_PAD} s after, with the cut's music{cursor !== null ? ` · ${cursor >= 0 ? '+' : ''}${cursor.toFixed(2)} s` : ''}</span>
363
+ <span className="sp" />
364
+ {lanes.length > 1 ? (
365
+ <span className="tv-hear" title="the version of the line the clip plays">
366
+ {lanes.map((ln) => (
367
+ <button key={ln.id} className={hear === ln.id ? 'on' : ''} disabled={recording} onClick={() => v.setHear(ln.id)}>{ln.id === 'take' ? 'my voice' : ln.label}</button>
368
+ ))}
369
+ </span>
370
+ ) : null}
371
+ </div>
372
+ {src ? (
373
+ <div className="tv-frame">
374
+ {/* no native controls: the play bar under it is the clip's own, and WebKit's controls fail to load their
375
+ icons in the app window, three console errors at every load */}
376
+ <video ref={video} key={src} src={src} playsInline preload="auto"
377
+ onClick={(e) => (recording ? undefined : e.currentTarget.paused ? playQuiet(e.currentTarget) : e.currentTarget.pause())}
378
+ onError={() => sayWhy(src)}
379
+ onLoadedMetadata={(e) => setLength(e.currentTarget.duration || 0)}
380
+ onPlay={(e) => {
381
+ setMode(null)
382
+ setClipOn(true)
383
+ // a play outside the range starts at its in point
384
+ const [a, b] = bounds.current.r
385
+ if (!recording && b > a && (e.currentTarget.currentTime < a - 0.01 || e.currentTarget.currentTime >= b - 0.05)) e.currentTarget.currentTime = a
386
+ }}
387
+ onPause={() => setClipOn(false)} onEnded={(e) => {
388
+ if (!bounds.current.loop || recording) return setClipOn(false)
389
+ e.currentTarget.currentTime = bounds.current.r[0]
390
+ playQuiet(e.currentTarget)
391
+ }} />
392
+ {cue ? <div className="tv-cue">speak</div> : null}
393
+ </div>
394
+ ) : (
395
+ <div className="rv-empty">{waiting ? <><span className="spin" /> your take is being made with your drag and masks: its clip shows in a moment</> : `The cut ${use.cut} has no render yet: sk trailer renders it, then its clip shows here.`}</div>
396
+ )}
397
+ {clipError ? <div className="rv-err">the clip: {clipError}</div> : null}
398
+ {src && length > 0 ? (
399
+ <div className="tv-range">
400
+ <button className="tv-small" disabled={recording} onClick={() => {
401
+ const vid = video.current
402
+ if (!vid) return
403
+ if (vid.paused) playQuiet(vid)
404
+ else vid.pause()
405
+ }} title="play the range (space plays the video too)">{clipOn ? '■' : '▶'}</button>
406
+ <button className={`tv-small tv-loop${v.loop ? ' on' : ''}`} disabled={recording} onClick={() => v.setLoop(!v.loop)} title="loop the range">⟲ loop</button>
407
+ <span className="tv-volume" title={`volume ${Math.round(v.level * 100)} %, kept by this browser`}>
408
+ <button className="tv-small" onClick={() => v.toggleMute()} title={v.muted ? 'sound on' : 'mute'}>{v.level === 0 ? '🔇' : v.level < 0.5 ? '🔉' : '🔊'}</button>
409
+ <input type="range" min={0} max={1} step={0.01} value={v.level} onChange={(e) => v.setVolume(Number(e.currentTarget.value))} />
410
+ </span>
411
+ <RangeBar length={length} range={span2()} at={at} lead={lead} disabled={recording}
412
+ onRange={(r) => setRange(r[0] <= 0.005 && r[1] >= length - 0.005 ? null : r)}
413
+ onSeek={(t) => {
414
+ if (video.current) video.current.currentTime = t
415
+ setAt(t)
416
+ setCursor(t - lead)
417
+ }} />
418
+ <span className="tv-time">{span2()[0].toFixed(2)}–{span2()[1].toFixed(2)} s</span>
419
+ {range ? <button className="tv-small" onClick={() => setRange(null)} title="play the whole passage again">whole</button> : null}
420
+ </div>
421
+ ) : null}
422
+ </div>
423
+ )
424
+ })
425
+
426
+ /** the passage's play bar: the range that plays between two handles he drags, the rest dimmed, the line's start
427
+ * marked, the playhead; a click outside the handles seeks there */
428
+ const RangeBar = ({ length, range, at, lead, disabled, onRange, onSeek }: { length: number; range: Range; at: number; lead: number; disabled: boolean; onRange: (r: Range) => void; onSeek: (t: number) => void }) => {
429
+ const grab = useRef<0 | 1 | null>(null)
430
+ const pct = (t: number): string => `${(Math.max(0, Math.min(length, t)) / length) * 100}%`
431
+ const timeOf = (el: Element, x: number): number => Math.max(0, Math.min(length, timeAt(el, x, length)))
432
+ return (
433
+ <div className={`tv-rangebar${disabled ? ' off' : ''}`}
434
+ onPointerDown={(e) => {
435
+ if (disabled) return
436
+ const t = timeOf(e.currentTarget, e.clientX)
437
+ const near = (h: number): boolean => Math.abs(((t - h) / length) * e.currentTarget.getBoundingClientRect().width) < 10
438
+ grab.current = near(range[0]) ? 0 : near(range[1]) ? 1 : null
439
+ if (grab.current === null) return onSeek(t)
440
+ e.currentTarget.setPointerCapture(e.pointerId)
441
+ }}
442
+ onPointerMove={(e) => {
443
+ if (grab.current === null) return
444
+ const t = timeOf(e.currentTarget, e.clientX)
445
+ onRange(grab.current === 0 ? [Math.min(t, range[1] - 0.05), range[1]] : [range[0], Math.max(t, range[0] + 0.05)])
446
+ }}
447
+ onPointerUp={() => void (grab.current = null)}>
448
+ <span className="tv-rangeon" style={{ left: pct(range[0]), width: `calc(${pct(range[1])} - ${pct(range[0])})` }} />
449
+ <span className="tv-rangeline" style={{ left: pct(lead) }} title="the line starts here" />
450
+ <span className="tv-rangehead" style={{ left: pct(at) }} />
451
+ <span className="tv-handle" style={{ left: pct(range[0]) }} title="drag: where the play starts" />
452
+ <span className="tv-handle" style={{ left: pct(range[1]) }} title="drag: where the play ends" />
453
+ </div>
454
+ )
455
+ }
456
+
457
+ /** seconds marks under the lanes: every 0.5 s, labelled every second */
458
+ const Ruler = ({ span }: { span: number }) => (
459
+ <>
460
+ {Array.from({ length: Math.floor(span / 0.5) + 1 }, (_, i) => i * 0.5).map((t) => (
461
+ <div key={t} className={`tv-tick${t % 1 === 0 ? ' whole' : ''}`} style={{ left: `${(t / span) * 100}%` }}>{t % 1 === 0 ? `${t}s` : ''}</div>
462
+ ))}
463
+ </>
464
+ )
465
+
466
+ /** a css colour token's value on an element */
467
+ const tokenOf = (el: Element, tone: string): string => (tone.startsWith('var(') ? getComputedStyle(el).getPropertyValue(tone.slice(4, -1)).trim() || '#888' : tone)
468
+
469
+ /** seconds on the line's time under a pointer over a lane's column */
470
+ const timeAt = (el: Element, clientX: number, span: number): number => {
471
+ const r = el.getBoundingClientRect()
472
+ return ((clientX - r.left) / r.width) * span
473
+ }
474
+
475
+ /** one lane's shape: the peak of each pixel column, both sides of the axis, its own 0 at `at` on the line's time, its
476
+ * masked parts drawn in red; before the line's 0, what the cut never plays, faded. A click says the time under it; a
477
+ * drag (with onDrag) moves it, its seconds said live and kept on release */
478
+ const WaveCanvas = ({ wave, span, tone, at, mask, onPick, onDrag, onDrop }: { wave: Wave | 'error' | undefined; span: number; tone: string; at: number; mask: readonly Range[]; onPick: (t: number) => void; onDrag?: (dx: number) => void; onDrop?: (dx: number) => void }) => {
479
+ const box = useRef<HTMLCanvasElement>(null)
480
+ const press = useRef<{ x: number; t: number; moved: boolean } | null>(null)
481
+ useEffect(() => {
482
+ const c = box.current
483
+ if (!c) return
484
+ const draw = (): void => {
485
+ const dpr = window.devicePixelRatio || 1
486
+ const w = Math.max(1, Math.round(c.clientWidth * dpr))
487
+ const h = Math.max(1, Math.round(c.clientHeight * dpr))
488
+ c.width = w
489
+ c.height = h
490
+ const g = c.getContext('2d')
491
+ if (!g) return
492
+ g.clearRect(0, 0, w, h)
493
+ g.fillStyle = getComputedStyle(c).color
494
+ g.fillRect(0, Math.floor(h / 2), w, 1)
495
+ if (!wave || wave === 'error') return
496
+ const rate = wave.data.length / wave.seconds
497
+ // each lane at its own loudest: a quiet recording's shape reads as clearly as a made line's
498
+ const gain = 1 / Math.max(1e-4, wave.peak)
499
+ const ink = tokenOf(c, tone)
500
+ const red = tokenOf(c, 'var(--red)')
501
+ for (let x = 0; x < w; x++) {
502
+ // the sound's own seconds under this column
503
+ const s0 = ((x / w) * span) - at
504
+ const s1 = (((x + 1) / w) * span) - at
505
+ if (s1 <= 0 || s0 >= wave.seconds) continue
506
+ const a = Math.max(0, Math.floor(s0 * rate))
507
+ const b = Math.min(wave.data.length, Math.floor(s1 * rate))
508
+ let peak = 0
509
+ for (let i = a; i < b; i++) peak = Math.max(peak, Math.abs(wave.data[i]!))
510
+ const y = Math.max(1, Math.min(1, peak * gain) * h * 0.95)
511
+ const muted = mask.some(([m0, m1]) => s0 < m1 && s1 > m0)
512
+ g.globalAlpha = (x / w) * span < 0 ? 0.25 : 1
513
+ g.fillStyle = muted ? red : ink
514
+ g.fillRect(x, (h - y) / 2, 1, y)
515
+ }
516
+ g.globalAlpha = 1
517
+ }
518
+ draw()
519
+ const ro = new ResizeObserver(draw)
520
+ ro.observe(c)
521
+ return () => ro.disconnect()
522
+ }, [wave, span, tone, at, mask])
523
+ return (
524
+ <canvas ref={box} className={`tv-wave${onDrag ? ' drags' : ''}`} title={wave === 'error' ? 'this sound could not be read' : undefined}
525
+ onPointerDown={(e) => {
526
+ e.currentTarget.setPointerCapture(e.pointerId)
527
+ press.current = { x: e.clientX, t: timeAt(e.currentTarget, e.clientX, span), moved: false }
528
+ }}
529
+ onPointerMove={(e) => {
530
+ const p = press.current
531
+ if (!p || !onDrag) return
532
+ if (!p.moved && Math.abs(e.clientX - p.x) < 4) return
533
+ p.moved = true
534
+ onDrag(timeAt(e.currentTarget, e.clientX, span) - p.t)
535
+ }}
536
+ onPointerUp={(e) => {
537
+ const p = press.current
538
+ press.current = null
539
+ if (!p) return
540
+ if (p.moved && onDrop) onDrop(timeAt(e.currentTarget, e.clientX, span) - p.t)
541
+ else onPick(Math.max(0, p.t))
542
+ }} />
543
+ )
544
+ }
545
+
546
+ /** the bar under his take: its muted parts in red, a stroke painted with the brush, kept on release. Its seconds are
547
+ * the line's; the ranges it hands back are the recording's own, so a later drag keeps them on the same sounds */
548
+ const MaskBar = ({ span, at, mask, disabled, onStroke, onDone }: { span: number; at: number; mask: readonly Range[]; disabled: boolean; onStroke: (r: Range) => void; onDone: (r: Range) => void }) => {
549
+ const from = useRef<number | null>(null)
550
+ const own = (el: Element, x: number): number => Math.max(0, timeAt(el, x, span) - at)
551
+ return (
552
+ <div className={`tv-maskbar${disabled ? ' off' : ''}`} title="paint over a noise to mute it (the mute brush), or over a muted part to hear it again (keep)"
553
+ onPointerDown={(e) => {
554
+ if (disabled) return
555
+ e.currentTarget.setPointerCapture(e.pointerId)
556
+ from.current = own(e.currentTarget, e.clientX)
557
+ onStroke([from.current, from.current])
558
+ }}
559
+ onPointerMove={(e) => {
560
+ if (from.current === null) return
561
+ onStroke([from.current, own(e.currentTarget, e.clientX)])
562
+ }}
563
+ onPointerUp={(e) => {
564
+ if (from.current === null) return
565
+ const r: Range = [from.current, own(e.currentTarget, e.clientX)]
566
+ from.current = null
567
+ onDone(r)
568
+ }}>
569
+ {mask.map(([a, b]) => (
570
+ <span key={`${a}-${b}`} className="tv-masked" style={{ left: `${((a + at) / span) * 100}%`, width: `${((b - a) / span) * 100}%` }} />
571
+ ))}
572
+ </div>
573
+ )
574
+ }