diff --git a/apps/mobile/src/ext/flows/ui/Editor.tsx b/apps/mobile/src/ext/flows/ui/Editor.tsx index bde3276b..3ab038ab 100644 --- a/apps/mobile/src/ext/flows/ui/Editor.tsx +++ b/apps/mobile/src/ext/flows/ui/Editor.tsx @@ -155,6 +155,8 @@ export function FlowEditor({ flow, back }: { flow: LocalFlow; back: () => void } // ---------- Changes: kept at once, sent by the store ---------- const latest = useRef({ body, name }); latest.current = { body, name }; + /** The flow as it was when a drag of the length began (null: no drag). */ + const lengthFrom = useRef(null); const change = (fn: (b: FlowBody) => FlowBody) => { if (locked) return; const next = fn(latest.current.body); @@ -405,7 +407,10 @@ export function FlowEditor({ flow, back }: { flow: LocalFlow; back: () => void } Name - change((b) => setDuration(b, ms))} /> + {/* While the thumb is dragged the length is cut from the flow as it was when the drag began: passing a shorter length on the way takes nothing for good. */} + { lengthFrom.current = latest.current.body; }} onDragEnd={() => { lengthFrom.current = null; }} + onChange={(ms) => change((b) => setDuration(lengthFrom.current ?? b, ms))} /> change((b) => ({ ...b, loop }))} /> diff --git a/apps/mobile/src/ui/forms.tsx b/apps/mobile/src/ui/forms.tsx index 788de534..295261a7 100644 --- a/apps/mobile/src/ui/forms.tsx +++ b/apps/mobile/src/ui/forms.tsx @@ -115,13 +115,15 @@ export function ChipCell({ children }: { children: ReactNode }) { /** * A value on a track: drag anywhere on it, or step with − and + for an exact value (on set, in * gloves). Hand-written on PanResponder like components/gestures.ts. `onChange` fires on every - * step while dragging; callers that send it somewhere coalesce (fixtures/queue.ts). + * step while dragging; callers that send it somewhere coalesce (fixtures/queue.ts). `onDragStart` and + * `onDragEnd`: for a value whose steps on the way must not each take effect (a flow's length cuts what + * lies past it). */ -export function Slider({ label, value, min, max, step = 1, format = String, onChange, disabled }: { label: string; value: number; min: number; max: number; step?: number; format?: (v: number) => string; onChange: (v: number) => void; disabled?: boolean }) { +export function Slider({ label, value, min, max, step = 1, format = String, onChange, onDragStart, onDragEnd, disabled }: { label: string; value: number; min: number; max: number; step?: number; format?: (v: number) => string; onChange: (v: number) => void; onDragStart?: () => void; onDragEnd?: () => void; disabled?: boolean }) { const s = useSliderStyles(); const [width, setWidth] = useState(0); - const r = useRef({ min, max, step, width, onChange, disabled, x0: 0, last: value }); - r.current = { ...r.current, min, max, step, width, onChange, disabled, last: value }; + const r = useRef({ min, max, step, width, onChange, onDragStart, onDragEnd, disabled, x0: 0, last: value }); + r.current = { ...r.current, min, max, step, width, onChange, onDragStart, onDragEnd, disabled, last: value }; const snap = (v: number) => { const { min: lo, max: hi, step: st } = r.current; return Math.min(hi, Math.max(lo, Math.round((v - lo) / st) * st + lo)); @@ -139,8 +141,10 @@ export function Slider({ label, value, min, max, step = 1, format = String, onCh onMoveShouldSetPanResponder: () => !r.current.disabled, // A slider inside a scroll view keeps the drag once it has it. onPanResponderTerminationRequest: () => false, - onPanResponderGrant: (e) => { r.current.x0 = e.nativeEvent.locationX; emit(at(r.current.x0)); }, + onPanResponderGrant: (e) => { r.current.onDragStart?.(); r.current.x0 = e.nativeEvent.locationX; emit(at(r.current.x0)); }, onPanResponderMove: (_, g) => emit(at(r.current.x0 + g.dx)), + onPanResponderRelease: () => r.current.onDragEnd?.(), + onPanResponderTerminate: () => r.current.onDragEnd?.(), }).panHandlers, []); const frac = max > min ? (Math.min(max, Math.max(min, value)) - min) / (max - min) : 0; const run = Math.max(0, width - THUMB); diff --git a/apps/studio/src/ext/flows/FlowsApp.tsx b/apps/studio/src/ext/flows/FlowsApp.tsx index c8d9359f..06788bdf 100644 --- a/apps/studio/src/ext/flows/FlowsApp.tsx +++ b/apps/studio/src/ext/flows/FlowsApp.tsx @@ -150,6 +150,19 @@ function FlowEditor({ f, projectId, active, list, onNew, onGone }: { f: FileRec; lastStep.current = now; apply(b); }; + /** A new length; what a shorter one cuts off is said, with the way back. */ + const setLength = (seconds: number) => { + if (!(seconds > 0)) return; + const before = latest.current, d = Math.min(FLOW_MAX_MS, Math.max(1000, snap(seconds * 1000))); + if (d === before.durationMs) return; + const keys = before.tracks.reduce((n, t) => n + t.keyframes.filter((k) => k.at > d).length, 0), marks = (before.markers ?? []).filter((m) => m.at > d).length; + // A step of its own, so Undo brings back exactly what the cut took. + lastStep.current = 0; + change((b) => ({ ...b, durationMs: d, tracks: b.tracks.map((t) => ({ ...t, keyframes: t.keyframes.filter((k) => k.at <= d) })), markers: (b.markers ?? []).filter((m) => m.at <= d).map((m) => (m.end !== undefined && m.end > d ? { ...m, end: d } : m)) })); + lastStep.current = 0; + const cut = [keys && `${keys} keyframe${keys === 1 ? "" : "s"}`, marks && `${marks} marker${marks === 1 ? "" : "s"}`].filter(Boolean).join(" and "); + if (cut) toast(`${cut} after ${fmtSeconds(d)} removed with the shorter length`, { tone: "info", action: { label: "Undo", onClick: () => { undo(); } } }); + }; const undo = () => { if (readonly) return false; const b = past.current.pop(); if (!b) return false; future.current.push(latest.current); lastStep.current = 0; apply(b); }; const redo = () => { if (readonly) return false; const b = future.current.pop(); if (!b) return false; past.current.push(latest.current); lastStep.current = 0; apply(b); }; useEffect(() => { past.current = []; future.current = []; }, [lock.editing]); @@ -621,8 +634,8 @@ function FlowEditor({ f, projectId, active, list, onNew, onGone }: { f: FileRec; const props = (
- + change((b) => ({ ...b, loop: on }))}>Loop
diff --git a/docs/features/flows.md b/docs/features/flows.md index cd7a413a..02dac211 100644 --- a/docs/features/flows.md +++ b/docs/features/flows.md @@ -52,7 +52,7 @@ A client saves the flow and names the revision it saved (`updated_at`): `run { f ## In the Studio (`apps/studio/src/ext/flows/`) -The app **Flows** (one window for the project's flows): the list of flows in a panel, with the chosen one's name (saved once typing settles, about 0.7 s, or on Enter or leaving the field; not on every key), length, loop, Duplicate and Delete under it; the tracks in the middle; what is chosen in the other panel. The panels are the Dock's: move, size, collapse, stack as tabs. **Edit** / **Stop editing** as on a timeline; while someone else edits, it is read-only and follows their changes. +The app **Flows** (one window for the project's flows): the list of flows in a panel, with the chosen one's name (saved once typing settles, about 0.7 s, or on Enter or leaving the field; not on every key), length (taken on Enter, on leaving the field or with the arrows, never while typing: a shorter length removes the keyframes and markers past it, and a toast says how many, with Undo), loop, Duplicate and Delete under it; the tracks in the middle; what is chosen in the other panel. The panels are the Dock's: move, size, collapse, stack as tabs. **Edit** / **Stop editing** as on a timeline; while someone else edits, it is read-only and follows their changes. - **Groups** (#518): a mesh light track's panel (a click on its label) has **Group**: No group, the flow's groups, or **New group** (named "Group N"); with a group, its **name** and **Remove the group** (the tracks stay). A group's tracks always **stand together**: put into a group, a track moves next to the group's other tracks; a drag never changes what is in a group (`moveTracks`): a grouped track's grip reorders it only within its group, the **head's grip** moves the whole group, and a track in no group or a group is dropped between blocks, never into a group (the Group field moves a track between groups). Above them a **head** with its grip, the group's name (renamed there) and a remove button, and a **bracket** from the head down beside their labels. Where the group goes out as one message (same time, same change on all of its tracks, `groupLinks`), a **link** runs down across its lanes with a dot in the head; keyframes at the same time that do different things get none. - **Tracks**: Add a track picks a light model or the camera; a track's device is picked on its label (only devices of that model, one track per device; a device that is gone shows so). Under it, the **device at a glance** (#426, `packages/ext-hardware/src/status.ts`; on the device's labels too): its connection as a coloured dot with a word (Connected, Connecting, Not in range, No proxy, Asleep…) and what it runs on: the charge of its own battery (the MC; a charging mark on external power) or of the battery set for it in Devices (the NEEWER lights' "Runs on"), a dash while no charge was heard; **Socket** for a light that takes a battery and has none set; nothing for a camera. The bulb **mutes** a track (left out of playback and Live); the palette sets its colour (8, or none); the bin **removes** the track after a confirmation (#426; the name is edited on the label itself). A click on the label off its controls, or on the type under the name, opens the **track's panel** (its group, back to the common height, removal); so does a light picked on the stage. The grip at the left **reorders** tracks by dragging: the lanes show the order a drop there gives while dragging (by the rules of groups, below), the other rows slide to make room and the dragged row follows the pointer; the device list is in counting order (2 before 10); the lower edge of a label makes that track taller or lower.