Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apps/mobile/src/ext/flows/ui/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<FlowBody | null>(null);
const change = (fn: (b: FlowBody) => FlowBody) => {
if (locked) return;
const next = fn(latest.current.body);
Expand Down Expand Up @@ -405,7 +407,10 @@ export function FlowEditor({ flow, back }: { flow: LocalFlow; back: () => void }
<View style={s.form}>
<Text style={s.label}>Name</Text>
<Input value={name} maxLength={120} editable={!locked} onChangeText={rename} />
<Slider label="Length" value={body.durationMs} min={1000} max={600_000} step={1000} format={fmtSeconds} disabled={locked} onChange={(ms) => 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. */}
<Slider label="Length" value={body.durationMs} min={1000} max={600_000} step={1000} format={fmtSeconds} disabled={locked}
onDragStart={() => { lengthFrom.current = latest.current.body; }} onDragEnd={() => { lengthFrom.current = null; }}
onChange={(ms) => change((b) => setDuration(lengthFrom.current ?? b, ms))} />
<Toggle label="Loop" meta="Starts again at the end" value={body.loop} disabled={locked} onChange={(loop) => change((b) => ({ ...b, loop }))} />
<Toggle label="Live" meta="While stopped, the lights show the flow at the playhead" value={live} onChange={setLive} />
</View>
Expand Down
14 changes: 9 additions & 5 deletions apps/mobile/src/ui/forms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
Expand Down
17 changes: 15 additions & 2 deletions apps/studio/src/ext/flows/FlowsApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -621,8 +634,8 @@ function FlowEditor({ f, projectId, active, list, onNew, onGone }: { f: FileRec;
const props = (
<div className="fl-props">
<label className="hw-ctl"><small>Name</small><TextInput size="sm" value={nameDraft ?? f.name} disabled={readonly} maxLength={120} onInput={(e) => typeName(e.currentTarget.value)} onBlur={() => saveName()} onKeyDown={(e) => { if (e.key === "Enter") saveName(); }} /></label>
<label className="hw-ctl"><small>Length (s)</small><NumberInput size="sm" value={body.durationMs / 1000} step={1} min={1} max={FLOW_MAX_MS / 1000} disabled={readonly}
onChange={(v: number) => { if (v > 0) change((b) => { const d = Math.min(FLOW_MAX_MS, Math.max(1000, snap(v * 1000))); return { ...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)) }; }); }} /></label>
<label className="hw-ctl"><small>Length (s)</small>{/* Taken on Enter or on leaving the field, never while typing: a shorter length cuts what lies past it, and "20" typed over "30" passes through 2 seconds. */}
<NumberInput size="sm" commitOnBlur value={body.durationMs / 1000} step={1} min={1} max={FLOW_MAX_MS / 1000} disabled={readonly} onChange={setLength} /></label>
<Switch checked={body.loop} disabled={readonly} onChange={(on: boolean) => change((b) => ({ ...b, loop: on }))}>Loop</Switch>
<div className="hw-row">
<Button size="sm" variant="secondary" icon="copy" onClick={() => void duplicate()}>Duplicate</Button>
Expand Down
2 changes: 1 addition & 1 deletion docs/features/flows.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading