@hyperframes/studio 0.7.107 → 0.7.108

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 (126) hide show
  1. package/dist/assets/{hyperframes-player-BLrfwq5o.js → hyperframes-player-QqavTWRK.js} +1 -1
  2. package/dist/assets/{index-BA9yhzfR.js → index-BQjXA1pz.js} +1 -1
  3. package/dist/assets/{index-BSBk5srs.js → index-BhHHMprP.js} +1 -1
  4. package/dist/assets/index-DNkh9mbV.css +1 -0
  5. package/dist/assets/index-GqONLcOl.js +428 -0
  6. package/dist/index.d.ts +85 -2
  7. package/dist/index.html +2 -2
  8. package/dist/index.js +17696 -12512
  9. package/dist/index.js.map +1 -1
  10. package/package.json +7 -7
  11. package/src/components/StudioRightPanel.tsx +18 -1
  12. package/src/components/TimelineToolbar.test.tsx +46 -0
  13. package/src/components/TimelineToolbar.tsx +17 -0
  14. package/src/components/editor/PropertyPanel.test.tsx +5 -1
  15. package/src/components/editor/PropertyPanel.tsx +7 -23
  16. package/src/components/editor/PropertyPanelFlat.tsx +25 -0
  17. package/src/components/editor/audioFxSummary.test.ts +75 -0
  18. package/src/components/editor/audioFxSummary.ts +36 -0
  19. package/src/components/editor/audioFxTelemetry.test.ts +129 -0
  20. package/src/components/editor/audioFxTelemetry.ts +230 -0
  21. package/src/components/editor/propertyPanelAudioFxGroup.test.tsx +1830 -0
  22. package/src/components/editor/propertyPanelAudioFxGroup.tsx +299 -0
  23. package/src/components/editor/propertyPanelAudioFxGroupUtils.ts +21 -0
  24. package/src/components/editor/propertyPanelAutomation.test.ts +60 -0
  25. package/src/components/editor/propertyPanelAutomation.ts +97 -0
  26. package/src/components/editor/propertyPanelFlatMediaSection.tsx +37 -9
  27. package/src/components/editor/propertyPanelFlatProps.ts +1 -0
  28. package/src/components/editor/propertyPanelFxAddMenu.tsx +209 -0
  29. package/src/components/editor/propertyPanelFxBandRuler.tsx +72 -0
  30. package/src/components/editor/propertyPanelFxCarveModule.tsx +382 -0
  31. package/src/components/editor/propertyPanelFxControls.test.tsx +115 -0
  32. package/src/components/editor/propertyPanelFxControls.tsx +356 -0
  33. package/src/components/editor/propertyPanelFxEqModule.tsx +196 -0
  34. package/src/components/editor/propertyPanelFxFamily.ts +83 -0
  35. package/src/components/editor/propertyPanelFxNodeOpenBody.tsx +269 -0
  36. package/src/components/editor/propertyPanelFxNodeParams.tsx +112 -0
  37. package/src/components/editor/propertyPanelFxNodeRow.tsx +339 -0
  38. package/src/components/editor/propertyPanelFxPresetMenu.tsx +159 -0
  39. package/src/components/editor/propertyPanelFxPresetRun.tsx +215 -0
  40. package/src/components/editor/propertyPanelFxPresetStyle.test.ts +142 -0
  41. package/src/components/editor/propertyPanelFxPresetStyle.ts +216 -0
  42. package/src/components/editor/propertyPanelFxRackChain.tsx +202 -0
  43. package/src/components/editor/propertyPanelFxSection.test.tsx +1747 -0
  44. package/src/components/editor/propertyPanelFxSection.tsx +550 -0
  45. package/src/components/editor/propertyPanelFxSectionTypes.ts +91 -0
  46. package/src/components/editor/propertyPanelTypes.ts +5 -0
  47. package/src/components/editor/useFxAudition.ts +95 -0
  48. package/src/components/editor/useFxCarve.ts +0 -0
  49. package/src/components/editor/useFxChainObserved.ts +83 -0
  50. package/src/components/editor/useFxLevelling.ts +235 -0
  51. package/src/components/editor/useVolumeAutomation.test.tsx +122 -0
  52. package/src/components/editor/useVolumeAutomation.ts +54 -0
  53. package/src/contexts/DomEditContext.tsx +11 -0
  54. package/src/hooks/useAppHotkeys.test.ts +198 -0
  55. package/src/hooks/useAppHotkeys.ts +30 -3
  56. package/src/hooks/useAutomationSelectionKeyboard.test.tsx +429 -0
  57. package/src/hooks/useAutomationSelectionKeyboard.ts +371 -0
  58. package/src/hooks/useDomEditAttributeCommits.ts +90 -10
  59. package/src/hooks/useDomEditCommits.test.tsx +38 -0
  60. package/src/hooks/useDomEditCommits.ts +2 -0
  61. package/src/hooks/useDomEditSession.ts +2 -0
  62. package/src/hooks/useDomEditTextCommits.ts +2 -0
  63. package/src/hooks/useElementLifecycleOps.ts +3 -0
  64. package/src/hooks/useLivePlayheadTime.ts +49 -0
  65. package/src/hooks/usePreviewPersistence.ts +7 -0
  66. package/src/hooks/useTimelineEditing.ts +3 -0
  67. package/src/player/components/AutomationSelectionMenu.tsx +76 -0
  68. package/src/player/components/AutomationValueInput.tsx +51 -0
  69. package/src/player/components/LayerDisclosureRow.tsx +5 -4
  70. package/src/player/components/Timeline.test.ts +84 -0
  71. package/src/player/components/TimelineAutomationLane.test.tsx +1720 -0
  72. package/src/player/components/TimelineAutomationLane.tsx +674 -0
  73. package/src/player/components/TimelineAutomationLaneSlot.test.tsx +193 -0
  74. package/src/player/components/TimelineLanes.test.tsx +24 -5
  75. package/src/player/components/TimelineLanes.tsx +142 -154
  76. package/src/player/components/TimelineTrackHeader.test.tsx +212 -1
  77. package/src/player/components/TimelineTrackHeader.tsx +166 -6
  78. package/src/player/components/TimelineTrackRow.tsx +8 -1
  79. package/src/player/components/automationClipboard.test.ts +94 -0
  80. package/src/player/components/automationClipboard.ts +136 -0
  81. package/src/player/components/automationGestureKeys.test.ts +49 -0
  82. package/src/player/components/automationGestureKeys.ts +49 -0
  83. package/src/player/components/automationLaneData.test.ts +270 -0
  84. package/src/player/components/automationLaneData.ts +258 -0
  85. package/src/player/components/automationLaneDragMath.ts +194 -0
  86. package/src/player/components/automationLaneGeometry.test.ts +239 -0
  87. package/src/player/components/automationLaneGeometry.ts +287 -0
  88. package/src/player/components/automationLaneHeight.ts +15 -0
  89. package/src/player/components/automationLanePointer.ts +20 -0
  90. package/src/player/components/automationLaneSelection.test.ts +183 -0
  91. package/src/player/components/automationLaneSelection.ts +135 -0
  92. package/src/player/components/automationShapes.test.ts +82 -0
  93. package/src/player/components/automationShapes.ts +70 -0
  94. package/src/player/components/automationSimplify.test.ts +48 -0
  95. package/src/player/components/automationSimplify.ts +51 -0
  96. package/src/player/components/timelineClipGestureHandlers.ts +223 -0
  97. package/src/player/components/timelineLaneProps.ts +19 -0
  98. package/src/player/components/timelineLayout.ts +11 -5
  99. package/src/player/components/useAutomationEdgeStretch.test.ts +27 -0
  100. package/src/player/components/useAutomationEdgeStretch.ts +269 -0
  101. package/src/player/components/useAutomationLaneGestures.ts +537 -0
  102. package/src/player/components/useAutomationLanes.test.tsx +112 -0
  103. package/src/player/components/useAutomationLanes.ts +170 -0
  104. package/src/player/components/useAutomationRangeDrag.ts +114 -0
  105. package/src/player/components/useTimelineTrackLayout.test.ts +107 -1
  106. package/src/player/components/useTimelineTrackLayout.ts +83 -7
  107. package/src/player/hooks/useExpandedTimelineElements.ts +7 -0
  108. package/src/player/hooks/useTimelinePlayer.ts +13 -1
  109. package/src/player/lib/automationStoreSync.test.ts +83 -0
  110. package/src/player/lib/automationStoreSync.ts +56 -0
  111. package/src/player/lib/timelineDOM.test.ts +33 -0
  112. package/src/player/lib/timelineDOM.ts +12 -0
  113. package/src/player/store/automationSelectionSlice.test.ts +30 -0
  114. package/src/player/store/automationSelectionSlice.ts +54 -0
  115. package/src/player/store/playerStore.test.ts +15 -0
  116. package/src/player/store/playerStore.ts +54 -65
  117. package/src/player/store/timelineElement.ts +78 -0
  118. package/src/styles/studio.css +89 -0
  119. package/src/telemetry/agentRuntime.test.ts +45 -0
  120. package/src/telemetry/agentRuntime.ts +62 -0
  121. package/src/telemetry/system.ts +8 -0
  122. package/src/utils/studioFileHistory.test.ts +49 -0
  123. package/src/utils/studioFileHistory.ts +17 -1
  124. package/src/utils/studioTelemetry.ts +16 -10
  125. package/dist/assets/index-dF-CmLZu.js +0 -428
  126. package/dist/assets/index-zQ4JFwwB.css +0 -1
@@ -0,0 +1,674 @@
1
+ /**
2
+ * Breakpoint automation over an audio clip, edited the way a DAW edits it:
3
+ * double-click the line to add a point, drag one to shape it, right-click or
4
+ * Shift+click a point to remove it, Alt-drag the line between two points to bend
5
+ * it, and double-click a point to type an exact value.
6
+ *
7
+ * Modifiers follow Ableton's, because that is the muscle memory an automation
8
+ * lane inherits: Shift locks a drag to one axis and fines the value down, Alt
9
+ * over a segment curves it, and Alt during a point drag ignores the grid.
10
+ *
11
+ * Drag the background to draw a selection box around a set of breakpoints, then
12
+ * Delete to remove them, drag any one of them to move the whole set, or
13
+ * right-click inside the box for shapes over its span.
14
+ *
15
+ * The lane knows nothing about any particular effect. Which parameters it can
16
+ * offer, their ranges, units and whether they read logarithmically all come
17
+ * from the FX registry, so an effect gained upstream needs no change here — the
18
+ * same principle the property panel's controls follow.
19
+ */
20
+
21
+ import {
22
+ useCallback,
23
+ useEffect,
24
+ useMemo,
25
+ useRef,
26
+ useState,
27
+ type MouseEvent as ReactMouseEvent,
28
+ } from "react";
29
+ import {
30
+ resolveAutomationRange,
31
+ sampleAutomationLane,
32
+ type AutomationRange,
33
+ type HfAutomation,
34
+ type HfAutomationLane,
35
+ type HfAutomationPoint,
36
+ } from "@hyperframes/core/audio-automation";
37
+ import { envelopePath, fromUnit, laneFor, PAD_X, toUnit, withLane } from "./automationLaneGeometry";
38
+ import { useAutomationLaneGestures } from "./useAutomationLaneGestures";
39
+ import { AutomationValueInput } from "./AutomationValueInput";
40
+ import { AutomationSelectionMenu } from "./AutomationSelectionMenu";
41
+ import { AUTOMATION_LANE_H } from "./automationLaneHeight";
42
+ import { generateShape, type AutomationShapeId } from "./automationShapes";
43
+ import { simplifyPoints } from "./automationSimplify";
44
+ import { pointInSelection, pointsIn, replaceRange } from "./automationLaneSelection";
45
+ import { getTimelineLaneTop } from "./timelineLayout";
46
+ import { defaultTimelineTheme } from "./timelineTheme";
47
+ import { groupAutomationLanes } from "./automationLaneData";
48
+ import { isAudioTimelineElement } from "../../utils/timelineInspector";
49
+ import { getTimelineElementIdentity } from "../lib/timelineElementHelpers";
50
+ import type { TimelineElement } from "../store/playerStore";
51
+ import type { UseAutomationLanesResult } from "./useAutomationLanes";
52
+
53
+ /**
54
+ * Drawn radius of a breakpoint.
55
+ *
56
+ * Independent of the grab radius, which is how close a pointer has to be to catch
57
+ * one: the two were the same number scaled, and tying them meant a dot could not be
58
+ * made easier to see without also changing what it caught. A touch over half the
59
+ * grab radius reads clearly at lane height without swallowing a dense run.
60
+ */
61
+ const POINT_R = 4.9;
62
+
63
+ /** Separator between stacked lanes — the same token a track row divides with. Read
64
+ * off the default theme rather than threaded as a prop: nothing overrides the
65
+ * timeline theme for lanes today, and a prop for one colour is plumbing to nowhere. */
66
+ const LANE_BORDER = defaultTimelineTheme.rowBorder;
67
+
68
+ /** Selection box on one lane. Value bounds included: a point at the right time
69
+ * but the wrong value is not in it. */
70
+ type SelectionBox = { t0: number; t1: number; v0: number; v1: number };
71
+
72
+ /** Is this breakpoint inside the selection box? The rule itself is shared with
73
+ * Delete and with the group drag, so what is drawn as caught is exactly what
74
+ * those act on; this only adds tolerance for there being no selection at all. */
75
+ function pointInBox(point: HfAutomationPoint, box: SelectionBox | null | undefined): boolean {
76
+ return !!box && pointInSelection(point, box);
77
+ }
78
+
79
+ /** A breakpoint's drawn radius and stroke, pulled out of the render loop so the
80
+ * map callback stays a single JSX return — the ternaries below are what pushed
81
+ * it over the complexity budget when they lived inline. */
82
+ function pointCircleStyle(
83
+ inRange: boolean,
84
+ dragging: boolean,
85
+ ): { radius: number; stroke: string; strokeWidth: number } {
86
+ return {
87
+ radius: POINT_R * (dragging ? 1.3 : inRange ? 1.15 : 1),
88
+ // A white ring rather than a different fill: the fill is the parameter's
89
+ // own colour, and a lane with two envelopes on it is read by colour first.
90
+ stroke: inRange ? "#fff" : "rgba(0,0,0,0.5)",
91
+ strokeWidth: inRange ? 1.5 : 1,
92
+ };
93
+ }
94
+
95
+ /** Pointer shape: a read-only lane can only be selected, a live one edited. */
96
+ function laneCursor(readOnly: boolean | undefined, dragging: boolean, stretching: boolean): string {
97
+ // A stretch handle wins over everything it might also sit above: the handle is
98
+ // a few px wide and always overlaps whatever is under the selection edge, so
99
+ // any other cursor there would advertise a gesture the press will not start.
100
+ if (stretching) return "col-resize";
101
+ if (readOnly) return "pointer";
102
+ return dragging ? "grabbing" : "crosshair";
103
+ }
104
+
105
+ export interface TimelineAutomationLaneProps {
106
+ /** Clip-local duration the lane spans. */
107
+ duration: number;
108
+ widthPx: number;
109
+ leftPx: number;
110
+ topPx: number;
111
+ automation: HfAutomation;
112
+ /** Which lane of that automation this row draws. */
113
+ target: string;
114
+ /** Axis, unit and label for the target, resolved against the chain. */
115
+ range: AutomationRange;
116
+ accentColor: string;
117
+ /** Clip-local seconds of the playhead, or null when it is outside the clip. */
118
+ playheadSec: number | null;
119
+ /** Continuous write while dragging; does not persist. */
120
+ onPreview(automation: HfAutomation): void;
121
+ /** Gesture-end write; this is the one that persists and lands in undo. */
122
+ onCommit(automation: HfAutomation): void;
123
+ /**
124
+ * Clip-local times a dragged point snaps to — the beat grid, shifted into this
125
+ * clip's frame. Its own neighbouring points are added on top.
126
+ */
127
+ snapTimes?: readonly number[];
128
+ /** Editing writes to the selected element, so an unselected clip is read-only. */
129
+ readOnly?: boolean;
130
+ /** Called when a read-only lane is pressed: selects the clip so it goes live. */
131
+ onSelect?(): void;
132
+ /** Active selection box on THIS lane, or null. */
133
+ rangeSelection?: SelectionBox | null | undefined;
134
+ onRangeSelect?: ((t0: number, t1: number, v0: number, v1: number) => void) | undefined;
135
+ onRangeClear?: (() => void) | undefined;
136
+ }
137
+
138
+ export function TimelineAutomationLane({
139
+ duration,
140
+ widthPx,
141
+ leftPx,
142
+ topPx,
143
+ automation,
144
+ target,
145
+ range,
146
+ accentColor,
147
+ playheadSec,
148
+ onPreview,
149
+ onCommit,
150
+ snapTimes,
151
+ readOnly,
152
+ onSelect,
153
+ rangeSelection,
154
+ onRangeSelect,
155
+ onRangeClear,
156
+ }: TimelineAutomationLaneProps) {
157
+ const stored = laneFor(automation, target);
158
+
159
+ const svgRef = useRef<SVGSVGElement | null>(null);
160
+
161
+ /**
162
+ * Points as the user is shaping them, before the edit has come back around.
163
+ *
164
+ * A live write sets the preview attribute but deliberately skips the refresh —
165
+ * that is what keeps dragging from reloading the composition and restarting
166
+ * playback. So the automation prop does not move under the pointer, and
167
+ * without a local draft the point would not either.
168
+ */
169
+ const [draft, setDraft] = useState<{ points: HfAutomationPoint[]; basedOn: HfAutomation } | null>(
170
+ null,
171
+ );
172
+ const lane: HfAutomationLane = useMemo(
173
+ () => (draft ? { target, points: draft.points } : stored),
174
+ [draft, target, stored],
175
+ );
176
+
177
+ // The draft is released when the automation it was drawn over actually
178
+ // changes — the persisted edit landing, or an edit from elsewhere. Releasing
179
+ // it merely because the drag ended would snap the point back to where it
180
+ // started for as long as the write takes to come around.
181
+ useEffect(() => {
182
+ if (draft && draft.basedOn !== automation) setDraft(null);
183
+ }, [automation, draft]);
184
+
185
+ // A different parameter is a different envelope; the draft does not carry over.
186
+ useEffect(() => {
187
+ setDraft(null);
188
+ }, [target]);
189
+
190
+ const h = AUTOMATION_LANE_H;
191
+ const pad = 6;
192
+ const inner = h - pad * 2;
193
+ // Drawing is inset by PAD_X and the svg is widened to match, so screen
194
+ // position still lines up with clip time — the lane just has margins.
195
+ const xOf = useCallback(
196
+ (t: number): number => PAD_X + (duration > 0 ? (t / duration) * widthPx : 0),
197
+ [duration, widthPx],
198
+ );
199
+ const yOf = useCallback(
200
+ (v: number): number => pad + (1 - toUnit(range, v)) * inner,
201
+ [range, inner],
202
+ );
203
+
204
+ /** Pointer position as a clip-local time and a parameter value. */
205
+ const pointAt = useCallback(
206
+ (clientX: number, clientY: number): { t: number; v: number } => {
207
+ const box = svgRef.current?.getBoundingClientRect();
208
+ if (!box || box.width <= 0) return { t: 0, v: range.default ?? range.min };
209
+ const t = Math.min(
210
+ duration,
211
+ Math.max(0, ((clientX - box.left - PAD_X) / widthPx) * duration),
212
+ );
213
+ const unit = 1 - (clientY - box.top - pad) / inner;
214
+ return { t, v: fromUnit(range, unit) };
215
+ },
216
+ [duration, inner, range, widthPx],
217
+ );
218
+
219
+ const path = useMemo(
220
+ () => envelopePath({ lane, range, widthPx, xOf, yOf }),
221
+ [lane, range, widthPx, xOf, yOf],
222
+ );
223
+
224
+ const commitPoints = useCallback(
225
+ (points: HfAutomationLane["points"], persist: boolean): void => {
226
+ // Draw from the draft immediately; the write is what eventually agrees.
227
+ setDraft({ points, basedOn: automation });
228
+ const next = withLane(automation, { target, points });
229
+ if (persist) onCommit(next);
230
+ else onPreview(next);
231
+ },
232
+ [automation, target, onCommit, onPreview],
233
+ );
234
+
235
+ const getBox = useCallback(
236
+ (): DOMRect | null => svgRef.current?.getBoundingClientRect() ?? null,
237
+ [],
238
+ );
239
+ const gestures = useAutomationLaneGestures({
240
+ getBox,
241
+ lane,
242
+ range,
243
+ pointAt,
244
+ xOf,
245
+ yOf,
246
+ commitPoints,
247
+ snapTimes,
248
+ readOnly,
249
+ onSelect,
250
+ onRangeSelect,
251
+ onRangeClear,
252
+ duration,
253
+ rangeSelection,
254
+ });
255
+ const { dragIndex, curveIndex, edgeDrag, edgeHover, hint, editing } = gestures;
256
+
257
+ const removeAt = useCallback(
258
+ (index: number): void => {
259
+ if (readOnly) return;
260
+ commitPoints(
261
+ lane.points.filter((_, i) => i !== index),
262
+ true,
263
+ );
264
+ },
265
+ [lane, commitPoints, readOnly],
266
+ );
267
+
268
+ /** Client-coordinate position of an open selection menu, or null when closed. */
269
+ const [menuAt, setMenuAt] = useState<{ x: number; y: number } | null>(null);
270
+ /**
271
+ * Whether the pointer is over this lane, which is what decides if the
272
+ * breakpoints are drawn.
273
+ *
274
+ * A stack of envelopes across a long clip is hundreds of discs, and at rest the
275
+ * shape of each is the thing worth reading — the handles matter only to someone
276
+ * about to grab one. The line stays visible either way; this hides just the
277
+ * points.
278
+ */
279
+ const [hovered, setHovered] = useState(false);
280
+
281
+ const insertShape = useCallback(
282
+ (shape: AutomationShapeId): void => {
283
+ if (!rangeSelection) return;
284
+ const inner = generateShape({
285
+ shape,
286
+ lane,
287
+ range,
288
+ t0: rangeSelection.t0,
289
+ t1: rangeSelection.t1,
290
+ });
291
+ commitPoints(
292
+ replaceRange({ lane, range, t0: rangeSelection.t0, t1: rangeSelection.t1, inner }),
293
+ true,
294
+ );
295
+ },
296
+ [rangeSelection, lane, range, commitPoints],
297
+ );
298
+
299
+ const simplifySelection = useCallback((): void => {
300
+ if (!rangeSelection) return;
301
+ const inner = simplifyPoints(pointsIn(lane, rangeSelection.t0, rangeSelection.t1), range);
302
+ commitPoints(
303
+ replaceRange({ lane, range, t0: rangeSelection.t0, t1: rangeSelection.t1, inner }),
304
+ true,
305
+ );
306
+ }, [rangeSelection, lane, range, commitPoints]);
307
+
308
+ // A point's own right-click already stops propagation and still deletes;
309
+ // this only fires when the press lands on the background inside the
310
+ // active selection.
311
+ const onSvgContextMenu = useCallback(
312
+ (e: ReactMouseEvent<SVGSVGElement>): void => {
313
+ if (readOnly || !rangeSelection) return;
314
+ // Inside the drawn box, not merely inside its span: the menu's own actions
315
+ // read the span, but a right-click well above or below the box is a press
316
+ // on empty lane as far as the author can see.
317
+ if (!pointInSelection(pointAt(e.clientX, e.clientY), rangeSelection)) return;
318
+ e.preventDefault();
319
+ setMenuAt({ x: e.clientX, y: e.clientY });
320
+ },
321
+ [readOnly, rangeSelection, pointAt],
322
+ );
323
+
324
+ const currentValue =
325
+ lane.points.length > 0 && playheadSec !== null
326
+ ? sampleAutomationLane(lane, playheadSec, range.scale)
327
+ : null;
328
+
329
+ return (
330
+ <div
331
+ // Spans the whole row so the separator below can, but takes no pointer
332
+ // events itself: clips sharing a row each mount one of these over the
333
+ // full width, so a band that accepted the pointer would let whichever
334
+ // clip rendered last swallow every sibling's envelope — hover, drag and
335
+ // all. Only the drawn parts opt back in.
336
+ className="hf-automation-lane pointer-events-none absolute"
337
+ style={{ top: topPx, left: 0, right: 0, height: h }}
338
+ data-automation-lane={target}
339
+ >
340
+ {/* Separator above each lane, in the same colour a track row divides with, so
341
+ a stack of envelopes reads as rows rather than as one tall field. Drawn as
342
+ an overlay rather than a CSS border: the lane's height is fixed and its svg
343
+ is positioned against the same box, so a border would shift the drawing a
344
+ pixel off the geometry every hit test is computed from. */}
345
+ <div
346
+ data-automation-lane-border=""
347
+ className="hf-automation-lane-border pointer-events-none absolute"
348
+ style={{ top: 0, left: 0, right: 0, height: 1, background: LANE_BORDER, zIndex: 1 }}
349
+ />
350
+ {/* No name drawn here: the label column carries it, on the same tree
351
+ connector as the keyframe rows. Painted in the lane it sat on top of the
352
+ envelope it described and scrolled horizontally away from its own row. */}
353
+ <svg
354
+ ref={svgRef}
355
+ className="hf-automation-svg pointer-events-auto absolute"
356
+ style={{
357
+ left: leftPx - PAD_X,
358
+ top: 0,
359
+ width: widthPx + PAD_X * 2,
360
+ height: h,
361
+ cursor: laneCursor(
362
+ readOnly,
363
+ dragIndex !== null || curveIndex !== null,
364
+ edgeDrag !== null || edgeHover,
365
+ ),
366
+ opacity: readOnly ? 0.55 : 1,
367
+ touchAction: "none",
368
+ }}
369
+ width={widthPx + PAD_X * 2}
370
+ height={h}
371
+ onPointerEnter={() => setHovered(true)}
372
+ onPointerLeave={() => setHovered(false)}
373
+ onPointerDown={gestures.onPointerDown}
374
+ onPointerMove={gestures.onPointerMove}
375
+ onPointerUp={gestures.endDrag}
376
+ onPointerCancel={gestures.cancelDrag}
377
+ onDoubleClick={gestures.onDoubleClick}
378
+ onContextMenu={onSvgContextMenu}
379
+ role="group"
380
+ aria-label={`${range.label} automation`}
381
+ >
382
+ <title>
383
+ {readOnly
384
+ ? "Drag a box to select points, which also selects this clip; then double-click to add a point"
385
+ : "Double-click to add a point, drag to shape, double-click a point to type a value, right-click or Shift+click to remove it. Drag the background to draw a box around points, then Delete to remove them or drag one to move them all. Alt-drag the line to curve it. Shift locks an axis mid-drag; Alt ignores the grid."}
386
+ </title>
387
+ {/* No plate behind the envelope: the lane used to darken its clip's width,
388
+ which drew a box inside the row and made a stack of lanes read as tiles
389
+ rather than as rows of one timeline. The row background shows through, and
390
+ the separator above each lane is what divides them now. */}
391
+ {/* Mid rail, so a value reads against something. */}
392
+ <line
393
+ x1={PAD_X}
394
+ x2={PAD_X + widthPx}
395
+ y1={pad + inner / 2}
396
+ y2={pad + inner / 2}
397
+ stroke="rgba(255,255,255,0.08)"
398
+ strokeDasharray="3 4"
399
+ />
400
+ {rangeSelection ? (
401
+ <rect
402
+ data-automation-selection=""
403
+ x={xOf(rangeSelection.t0)}
404
+ // v1 is the upper bound, which is the SMALLER y: the value axis runs
405
+ // up the lane and the screen axis runs down it.
406
+ y={yOf(rangeSelection.v1)}
407
+ width={Math.max(0, xOf(rangeSelection.t1) - xOf(rangeSelection.t0))}
408
+ height={Math.max(0, yOf(rangeSelection.v0) - yOf(rangeSelection.v1))}
409
+ fill={accentColor}
410
+ opacity={0.15}
411
+ // Outlined as well as tinted. A box dragged thin along either axis is
412
+ // nearly invisible as a fill, and the author still has to be able to
413
+ // see what they drew before pressing Delete.
414
+ stroke={accentColor}
415
+ strokeOpacity={0.6}
416
+ pointerEvents="none"
417
+ />
418
+ ) : null}
419
+ <path
420
+ d={path}
421
+ fill="none"
422
+ stroke={accentColor}
423
+ strokeWidth={1.5}
424
+ opacity={lane.points.length === 0 ? 0.35 : 0.95}
425
+ />
426
+ {lane.points.map((p, i) => {
427
+ // Endpoint-inclusive, the same rule Delete uses, so what looks caught by
428
+ // the range is exactly what the range will remove. The tinted rectangle
429
+ // says where the selection is; this says which points it has.
430
+ const inRange = pointInBox(p, rangeSelection);
431
+ const { radius, stroke, strokeWidth } = pointCircleStyle(inRange, i === dragIndex);
432
+ return (
433
+ <circle
434
+ key={`${i}-${p.t}`}
435
+ data-automation-point={i}
436
+ {...(inRange ? { "data-automation-point-in-range": "" } : {})}
437
+ cx={xOf(p.t)}
438
+ cy={yOf(p.v)}
439
+ r={radius}
440
+ fill={accentColor}
441
+ stroke={stroke}
442
+ strokeWidth={strokeWidth}
443
+ // Hidden rather than unmounted, so the hit area survives: a point
444
+ // dragged past the lane's edge fires pointerleave mid-gesture, and a
445
+ // handle that vanishes then would drop the drag. A drag in progress
446
+ // and a selected range both keep them up for the same reason — the
447
+ // range is the subject of a pending Delete, and which points it
448
+ // caught cannot depend on where the mouse is.
449
+ style={{
450
+ cursor: readOnly ? "default" : "grab",
451
+ opacity: hovered || dragIndex !== null || rangeSelection ? 1 : 0,
452
+ }}
453
+ onContextMenu={(e) => {
454
+ e.preventDefault();
455
+ e.stopPropagation();
456
+ removeAt(i);
457
+ }}
458
+ />
459
+ );
460
+ })}
461
+ {playheadSec !== null && currentValue !== null ? (
462
+ <circle
463
+ data-automation-playhead=""
464
+ cx={xOf(playheadSec)}
465
+ cy={yOf(currentValue)}
466
+ r={2.5}
467
+ fill="#fff"
468
+ opacity={0.8}
469
+ pointerEvents="none"
470
+ />
471
+ ) : null}
472
+ </svg>
473
+
474
+ {editing ? (
475
+ <AutomationValueInput
476
+ text={editing.text}
477
+ leftPx={leftPx + xOf(lane.points[editing.index]?.t ?? 0) - PAD_X - 18}
478
+ label={range.label}
479
+ onChange={gestures.setEditingText}
480
+ onCommit={gestures.commitEdit}
481
+ onCancel={gestures.cancelEdit}
482
+ />
483
+ ) : null}
484
+
485
+ {hint ? (
486
+ <div
487
+ className="hf-automation-hint pointer-events-none absolute rounded-[3px] bg-black/80 px-1 py-0.5 font-mono text-[9px] text-white"
488
+ style={{ left: leftPx + 6, top: 2, zIndex: 3 }}
489
+ >
490
+ {hint}
491
+ </div>
492
+ ) : null}
493
+
494
+ {menuAt && rangeSelection ? (
495
+ <AutomationSelectionMenu
496
+ x={menuAt.x}
497
+ y={menuAt.y}
498
+ onClose={() => setMenuAt(null)}
499
+ onInsertShape={insertShape}
500
+ onSimplify={simplifySelection}
501
+ canSimplify={pointsIn(lane, rangeSelection.t0, rangeSelection.t1).length >= 3}
502
+ />
503
+ ) : null}
504
+ </div>
505
+ );
506
+ }
507
+
508
+ /** Which shared rows one clip draws into, and with which of its lanes. */
509
+ interface ClipLaneRow {
510
+ lane: HfAutomationLane;
511
+ rowIndex: number;
512
+ }
513
+
514
+ /**
515
+ * One clip's envelopes, each in the shared row its property owns.
516
+ *
517
+ * Its own component because every clip on the row needs its own binding, its own
518
+ * gestures and its own selection box — a shared row is a shared lane track, not a
519
+ * shared envelope, and two clips' curves must never drag as one thing. Hooks
520
+ * cannot run in a loop, so the loop is over components.
521
+ */
522
+ function ClipAutomationLanes({
523
+ element,
524
+ rows,
525
+ isSelected,
526
+ lanes,
527
+ pps,
528
+ top,
529
+ accentColor,
530
+ currentTime,
531
+ beatTimes,
532
+ }: {
533
+ element: TimelineElement;
534
+ rows: readonly ClipLaneRow[];
535
+ isSelected: boolean;
536
+ lanes: UseAutomationLanesResult;
537
+ pps: number;
538
+ /** y of the first automation row on this track. */
539
+ top: number;
540
+ accentColor: string;
541
+ currentTime: number;
542
+ beatTimes?: readonly number[];
543
+ }) {
544
+ // Beats inside this clip, in the clip's own frame — the lane's times are
545
+ // clip-local, and a beat outside the clip can never be snapped to anyway.
546
+ const snapTimes = useMemo(
547
+ () =>
548
+ (beatTimes ?? [])
549
+ .filter((t) => t >= element.start && t <= element.start + element.duration)
550
+ .map((t) => t - element.start),
551
+ [beatTimes, element.start, element.duration],
552
+ );
553
+ const bound = lanes.bind(element, isSelected);
554
+ // Stale-selection guard: the selected lane's target can vanish out from under
555
+ // it (e.g. its effect got deleted from the chain, dropping the lane), leaving
556
+ // a rectangle selecting nothing. Clear it rather than let it point at a
557
+ // target that no longer draws. Above the empty-rows return, because a clip
558
+ // that draws nothing is exactly when a selection goes stale.
559
+ useEffect(() => {
560
+ const target = bound.selection?.target;
561
+ if (target !== undefined && !bound.lanes.some((lane) => lane.target === target)) {
562
+ bound.onRangeClear();
563
+ }
564
+ }, [bound]);
565
+ if (rows.length === 0) return null;
566
+ const inClip = currentTime >= element.start && currentTime <= element.start + element.duration;
567
+ return (
568
+ <>
569
+ {rows.map(({ lane, rowIndex }) => {
570
+ const range = resolveAutomationRange(lane.target, bound.chain ?? undefined);
571
+ // A lane whose target no longer resolves was already dropped upstream;
572
+ // this is belt and braces so a row can never draw on the wrong axis.
573
+ if (!range) return null;
574
+ return (
575
+ <TimelineAutomationLane
576
+ key={lane.target}
577
+ duration={element.duration}
578
+ widthPx={Math.max(element.duration * pps, 4)}
579
+ leftPx={element.start * pps}
580
+ topPx={top + rowIndex * AUTOMATION_LANE_H}
581
+ automation={bound.automation}
582
+ target={lane.target}
583
+ range={range}
584
+ accentColor={accentColor}
585
+ playheadSec={inClip ? currentTime - element.start : null}
586
+ onPreview={bound.onPreview}
587
+ onCommit={bound.onCommit}
588
+ onSelect={bound.onSelect}
589
+ snapTimes={snapTimes}
590
+ readOnly={bound.readOnly}
591
+ rangeSelection={
592
+ bound.selection?.target === lane.target
593
+ ? {
594
+ t0: bound.selection.t0,
595
+ t1: bound.selection.t1,
596
+ v0: bound.selection.v0,
597
+ v1: bound.selection.v1,
598
+ }
599
+ : null
600
+ }
601
+ onRangeSelect={(t0, t1, v0, v1) => bound.onRangeSelect(lane.target, t0, t1, v0, v1)}
602
+ onRangeClear={bound.onRangeClear}
603
+ />
604
+ );
605
+ })}
606
+ </>
607
+ );
608
+ }
609
+
610
+ export interface TimelineAutomationLaneSlotProps {
611
+ /** Every clip on the track, in row order — not just the selected one. */
612
+ elements: readonly TimelineElement[];
613
+ isSelected: (element: TimelineElement) => boolean;
614
+ lanes: UseAutomationLanesResult;
615
+ pps: number;
616
+ /** Keyframe lanes already stacked above, which automation sits under. */
617
+ laneCount: number;
618
+ accentColor: string;
619
+ /** Composition-time playhead; the slot converts it to clip-local. */
620
+ currentTime: number;
621
+ /** Composition-time beat grid; the slot converts it to clip-local too. */
622
+ beatTimes?: readonly number[];
623
+ }
624
+
625
+ /**
626
+ * Every automated parameter on this TRACK, one lane per row — the way a DAW
627
+ * stacks them, so two envelopes can be read and edited without swapping a
628
+ * control to see either.
629
+ *
630
+ * Rows belong to the track, not to a clip: clips sharing a row share a row per
631
+ * property (see `groupAutomationLanes`), each drawing over its own span, and a
632
+ * clip that does not automate that property leaves its stretch empty. Binding one
633
+ * clip at a time is what made the visible envelopes change with the selection.
634
+ */
635
+ export function TimelineAutomationLaneSlot({
636
+ elements,
637
+ isSelected,
638
+ lanes,
639
+ pps,
640
+ laneCount,
641
+ accentColor,
642
+ currentTime,
643
+ beatTimes,
644
+ }: TimelineAutomationLaneSlotProps) {
645
+ const clips = elements.filter(isAudioTimelineElement);
646
+ const rowsByClip = new Map<string, ClipLaneRow[]>();
647
+ groupAutomationLanes(clips).forEach((group, rowIndex) => {
648
+ for (const entry of group.entries) {
649
+ const key = getTimelineElementIdentity(entry.element);
650
+ const rows = rowsByClip.get(key);
651
+ if (rows) rows.push({ lane: entry.lane, rowIndex });
652
+ else rowsByClip.set(key, [{ lane: entry.lane, rowIndex }]);
653
+ }
654
+ });
655
+ const top = getTimelineLaneTop(laneCount);
656
+ return (
657
+ <>
658
+ {clips.map((element) => (
659
+ <ClipAutomationLanes
660
+ key={getTimelineElementIdentity(element)}
661
+ element={element}
662
+ rows={rowsByClip.get(getTimelineElementIdentity(element)) ?? []}
663
+ isSelected={isSelected(element)}
664
+ lanes={lanes}
665
+ pps={pps}
666
+ top={top}
667
+ accentColor={accentColor}
668
+ currentTime={currentTime}
669
+ beatTimes={beatTimes}
670
+ />
671
+ ))}
672
+ </>
673
+ );
674
+ }