feat: implement param popup with curve drag, range sliders, and freeze toggle (f15)
Add ParamPopup component with full parameter controls: - Curve canvas with vertical drag to adjust response curve - Dual min/max range sliders with visual fill bar - Freeze/unfreeze toggle that captures current value - Param override system in ML store with curve/range/freeze state - 19 Playwright e2e tests covering VAL-PARAM-001 through VAL-PARAM-004 Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
parent
e8175d926c
commit
c147df55f2
7 changed files with 1149 additions and 53 deletions
|
|
@ -101,12 +101,32 @@ Unified event system replacing EventBus + CustomEvents. Topics with `equals: fal
|
|||
- Reactively rebuilds when `outputCount()` changes (mode switch triggers `<For>` re-render)
|
||||
- Visual mode uses curated colors/names (VISUAL_PARAM_COLORS/VISUAL_PARAM_NAMES); other modes use hue-based color generation
|
||||
- Drag-to-set: pointer capture on cell, drag updates output value directly via `iml.setOutput()` + `_updateOutputs()`
|
||||
- Click-to-popup: short click (no drag) opens param popup (name, value, color bar, close button)
|
||||
- Click-to-popup: short click (no drag) opens ParamPopup component with full controls
|
||||
- Tooltip on hover: shows "ParamName: value" positioned below hovered cell
|
||||
- Per-cell event handler factory `createCellHandlers()` captures element reference for pointer events
|
||||
- ML store exposes `_updateOutputs(Float32Array)` for direct output signal update from drag
|
||||
- CSS: glass morphism strip, per-bar colored fill, brightness filter on hover, drag cursor
|
||||
|
||||
### ParamPopup Component (`components/visual/ParamPopup.tsx`) — IMPLEMENTED
|
||||
- Full param control popup opened by clicking heatmap cell
|
||||
- Header: parameter name (colored), current value, close button
|
||||
- Curve row: 36×36 canvas with response curve drawn, vertical drag adjusts curve factor [0,1]
|
||||
- Range row: dual min/max range sliders with visual fill bar, enforce min ≤ max
|
||||
- Freeze row: toggle button freezes parameter at fixed value, shows value slider when frozen
|
||||
- Reads/writes overrides via ML store `getParamOverride()`/`setParamOverride()`
|
||||
- Curve math: `applyCurve(value, factor)` with exponential mapping (0.5 = linear)
|
||||
- Positions below clicked heatmap cell, centered, clamped to viewport edges
|
||||
- Closes on × button click or Escape key
|
||||
|
||||
### Param Override System (`core/param-overrides.ts`) — IMPLEMENTED
|
||||
- Per-parameter overrides: `{ curve: 0.5, min: 0, max: 1, frozen: false, fixedValue: 0.5 }`
|
||||
- `applyCurve(value, curveFactor)`: exponential response curve, 0.5 = linear (identity)
|
||||
- `applyOverride(rawValue, override)`: applies curve + min/max range mapping
|
||||
- `applyOverrideWithFreeze(rawValue, override)`: respects frozen state
|
||||
- `drawCurveOnCanvas(ctx, curveFactor, color, w, h)`: renders response curve on canvas
|
||||
- ML store maintains `paramOverrides[]` array, resized on mode switch (preserves existing overrides)
|
||||
- Store methods: `getParamOverride(i)`, `setParamOverride(i, key, value)`, `getAllOverrides()`, `getOverriddenOutput(i)`, `applyAllOutputs(Float32Array)`
|
||||
|
||||
### Output Store (`stores/output-store.ts`) — NOT YET IMPLEMENTED
|
||||
- Output mode (visual/synth/midi-cc/audio-canvas)
|
||||
- Per-mode overrides arrays
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
* Each bar width is proportional to its corresponding ML output value [0,1].
|
||||
* Bars update reactively when outputs change.
|
||||
* Drag on a bar sets the parameter value.
|
||||
* Click on a bar opens a param popup.
|
||||
* Click on a bar opens a param popup with curve/range/freeze controls.
|
||||
* Rebuilds when mode switches (output count changes).
|
||||
*
|
||||
* Transplanted behavior from playground/js/a-app.js buildHeatmap/updateHeatmap.
|
||||
|
|
@ -16,6 +16,7 @@ import {
|
|||
Show,
|
||||
} from 'solid-js';
|
||||
import type { MLStore } from '../../stores/ml-store';
|
||||
import ParamPopup from './ParamPopup';
|
||||
import './heatmap-strip.css';
|
||||
|
||||
// ─── Visual parameter names and colors ──────────────────────────────
|
||||
|
|
@ -257,38 +258,14 @@ export default function HeatmapStrip(props: HeatmapStripProps) {
|
|||
{tooltipText()}
|
||||
</div>
|
||||
<Show when={popup()}>
|
||||
{(p) => {
|
||||
const outputs = props.mlStore.outputs();
|
||||
const value = outputs[p().paramIndex] ?? 0;
|
||||
const names = getParamNames();
|
||||
const name = names[p().paramIndex] ?? `p${p().paramIndex}`;
|
||||
const colors = getParamColors();
|
||||
const color = colors[p().paramIndex] ?? defaultParamColor(p().paramIndex);
|
||||
const barWidth = `${Math.max(2, Math.round(value * 100))}%`;
|
||||
|
||||
return (
|
||||
<div
|
||||
class="param-popup"
|
||||
id="param-popup"
|
||||
style={{
|
||||
left: `${Math.max(8, Math.min(p().cellRect.left, window.innerWidth - 220))}px`,
|
||||
top: `${p().cellRect.bottom + 4}px`,
|
||||
}}
|
||||
>
|
||||
<div class="param-popup-header">
|
||||
<span class="param-popup-name">{name}</span>
|
||||
<span class="param-popup-value">{value.toFixed(3)}</span>
|
||||
<button class="param-popup-close" onClick={closePopup}>×</button>
|
||||
</div>
|
||||
<div class="param-popup-bar">
|
||||
<div
|
||||
class="param-popup-bar-fill"
|
||||
style={{ width: barWidth, background: color }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
{(p) => (
|
||||
<ParamPopup
|
||||
mlStore={props.mlStore}
|
||||
paramIndex={p().paramIndex}
|
||||
cellRect={p().cellRect}
|
||||
onClose={closePopup}
|
||||
/>
|
||||
)}
|
||||
</Show>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
300
src/components/visual/ParamPopup.tsx
Normal file
300
src/components/visual/ParamPopup.tsx
Normal file
|
|
@ -0,0 +1,300 @@
|
|||
/**
|
||||
* ParamPopup — Popup control panel for a single ML output parameter.
|
||||
*
|
||||
* Shows parameter name, current value, and controls:
|
||||
* - Curve canvas: vertical drag adjusts response curve
|
||||
* - Min/Max range sliders: dual range controls
|
||||
* - Freeze toggle: locks parameter at a fixed value
|
||||
*
|
||||
* Ported from playground/js/a-app.js showParamPopup().
|
||||
*/
|
||||
|
||||
import {
|
||||
createSignal,
|
||||
onMount,
|
||||
onCleanup,
|
||||
Show,
|
||||
} from 'solid-js';
|
||||
import type { MLStore } from '../../stores/ml-store';
|
||||
import {
|
||||
type ParamOverride,
|
||||
createDefaultOverride,
|
||||
applyCurve,
|
||||
drawCurveOnCanvas,
|
||||
} from '../../core/param-overrides';
|
||||
import {
|
||||
VISUAL_PARAM_NAMES,
|
||||
VISUAL_PARAM_COLORS,
|
||||
} from './HeatmapStrip';
|
||||
|
||||
/** Default color for synth/MIDI/audio-canvas params (generated per-index) */
|
||||
function defaultParamColor(index: number): string {
|
||||
const hue = (index * 37) % 360;
|
||||
return `hsl(${hue}, 70%, 55%)`;
|
||||
}
|
||||
|
||||
// ─── Props ──────────────────────────────────────────────────────────
|
||||
|
||||
export interface ParamPopupProps {
|
||||
/** ML store for reading/writing overrides */
|
||||
mlStore: MLStore;
|
||||
/** Parameter index */
|
||||
paramIndex: number;
|
||||
/** Cell rect for positioning */
|
||||
cellRect: DOMRect;
|
||||
/** Close callback */
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
// ─── Component ──────────────────────────────────────────────────────
|
||||
|
||||
export default function ParamPopup(props: ParamPopupProps) {
|
||||
const [curveValue, setCurveValue] = createSignal(0.5);
|
||||
const [minValue, setMinValue] = createSignal(0);
|
||||
const [maxValue, setMaxValue] = createSignal(1);
|
||||
const [frozen, setFrozen] = createSignal(false);
|
||||
const [fixedValue, setFixedValue] = createSignal(0.5);
|
||||
|
||||
let curveCanvasRef: HTMLCanvasElement | undefined;
|
||||
let curveDragging = false;
|
||||
let curveStartY = 0;
|
||||
let curveStartVal = 0;
|
||||
|
||||
// Initialize from store
|
||||
const ov = () => props.mlStore.getParamOverride(props.paramIndex);
|
||||
|
||||
onMount(() => {
|
||||
const o = ov();
|
||||
setCurveValue(o.curve);
|
||||
setMinValue(o.min);
|
||||
setMaxValue(o.max);
|
||||
setFrozen(o.frozen);
|
||||
setFixedValue(o.fixedValue);
|
||||
|
||||
// Draw initial curve
|
||||
if (curveCanvasRef) {
|
||||
const ctx = curveCanvasRef.getContext('2d')!;
|
||||
drawCurveOnCanvas(ctx, o.curve, getColor(), curveCanvasRef.width, curveCanvasRef.height);
|
||||
}
|
||||
|
||||
// Close on Escape
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') props.onClose();
|
||||
};
|
||||
document.addEventListener('keydown', onKey);
|
||||
onCleanup(() => document.removeEventListener('keydown', onKey));
|
||||
});
|
||||
|
||||
// ─── Helpers ───
|
||||
|
||||
function getColor(): string {
|
||||
const mode = props.mlStore.state.outputMode;
|
||||
if (mode === 'visual') {
|
||||
return VISUAL_PARAM_COLORS[props.paramIndex] ?? defaultParamColor(props.paramIndex);
|
||||
}
|
||||
return defaultParamColor(props.paramIndex);
|
||||
}
|
||||
|
||||
function getName(): string {
|
||||
const mode = props.mlStore.state.outputMode;
|
||||
const count = props.mlStore.outputCount();
|
||||
if (mode === 'visual') return VISUAL_PARAM_NAMES[props.paramIndex] ?? `p${props.paramIndex}`;
|
||||
return `p${props.paramIndex}`;
|
||||
}
|
||||
|
||||
function getCurrentValue(): number {
|
||||
const outputs = props.mlStore.outputs();
|
||||
return outputs[props.paramIndex] ?? 0;
|
||||
}
|
||||
|
||||
function redrawCurve() {
|
||||
if (!curveCanvasRef) return;
|
||||
const ctx = curveCanvasRef.getContext('2d')!;
|
||||
drawCurveOnCanvas(ctx, curveValue(), getColor(), curveCanvasRef.width, curveCanvasRef.height);
|
||||
}
|
||||
|
||||
// ─── Curve drag handler ───
|
||||
|
||||
function onCurvePointerDown(e: PointerEvent) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (!curveCanvasRef) return;
|
||||
curveCanvasRef.setPointerCapture(e.pointerId);
|
||||
curveDragging = true;
|
||||
curveStartY = e.clientY;
|
||||
curveStartVal = curveValue();
|
||||
}
|
||||
|
||||
function onCurvePointerMove(e: PointerEvent) {
|
||||
if (!curveDragging || !curveCanvasRef) return;
|
||||
e.preventDefault();
|
||||
// Drag down = higher curve, drag up = lower curve
|
||||
const dy = e.clientY - curveStartY;
|
||||
const newVal = Math.max(0, Math.min(1, curveStartVal + dy / 80));
|
||||
setCurveValue(newVal);
|
||||
props.mlStore.setParamOverride(props.paramIndex, 'curve', newVal);
|
||||
redrawCurve();
|
||||
}
|
||||
|
||||
function onCurvePointerUp() {
|
||||
curveDragging = false;
|
||||
}
|
||||
|
||||
function onCurvePointerCancel() {
|
||||
curveDragging = false;
|
||||
}
|
||||
|
||||
// ─── Range slider handlers ───
|
||||
|
||||
function onMinInput(e: Event) {
|
||||
const val = parseFloat((e.target as HTMLInputElement).value);
|
||||
setMinValue(val);
|
||||
// Enforce min <= max
|
||||
if (val > maxValue()) {
|
||||
setMaxValue(val);
|
||||
props.mlStore.setParamOverride(props.paramIndex, 'max', val);
|
||||
}
|
||||
props.mlStore.setParamOverride(props.paramIndex, 'min', val);
|
||||
}
|
||||
|
||||
function onMaxInput(e: Event) {
|
||||
const val = parseFloat((e.target as HTMLInputElement).value);
|
||||
setMaxValue(val);
|
||||
// Enforce max >= min
|
||||
if (val < minValue()) {
|
||||
setMinValue(val);
|
||||
props.mlStore.setParamOverride(props.paramIndex, 'min', val);
|
||||
}
|
||||
props.mlStore.setParamOverride(props.paramIndex, 'max', val);
|
||||
}
|
||||
|
||||
// ─── Freeze toggle ───
|
||||
|
||||
function toggleFreeze() {
|
||||
const newFrozen = !frozen();
|
||||
setFrozen(newFrozen);
|
||||
props.mlStore.setParamOverride(props.paramIndex, 'frozen', newFrozen);
|
||||
|
||||
// When freezing, capture the current output value
|
||||
if (newFrozen) {
|
||||
const currentVal = getCurrentValue();
|
||||
setFixedValue(currentVal);
|
||||
props.mlStore.setParamOverride(props.paramIndex, 'fixedValue', currentVal);
|
||||
}
|
||||
}
|
||||
|
||||
function onFixedValueInput(e: Event) {
|
||||
const val = parseFloat((e.target as HTMLInputElement).value);
|
||||
setFixedValue(val);
|
||||
props.mlStore.setParamOverride(props.paramIndex, 'fixedValue', val);
|
||||
}
|
||||
|
||||
// ─── Positioning ───
|
||||
|
||||
const popupWidth = 260;
|
||||
const left = () => {
|
||||
const centered = props.cellRect.left + props.cellRect.width / 2 - popupWidth / 2;
|
||||
return Math.max(4, Math.min(centered, window.innerWidth - popupWidth - 4));
|
||||
};
|
||||
const top = () => props.cellRect.bottom + 4;
|
||||
|
||||
// ─── Range fill positioning ───
|
||||
|
||||
const rangeFillLeft = () => `${minValue() * 100}%`;
|
||||
const rangeFillWidth = () => `${(maxValue() - minValue()) * 100}%`;
|
||||
|
||||
return (
|
||||
<div
|
||||
class="param-popup visible"
|
||||
id="param-popup"
|
||||
style={{
|
||||
left: `${left()}px`,
|
||||
top: `${top()}px`,
|
||||
width: `${popupWidth}px`,
|
||||
}}
|
||||
>
|
||||
{/* Header: param name + value + close */}
|
||||
<div class="pp-header">
|
||||
<span class="pp-name" style={{ color: getColor() }}>{getName()}</span>
|
||||
<span class="pp-value">{getCurrentValue().toFixed(3)}</span>
|
||||
<button class="pp-close" onClick={props.onClose}>×</button>
|
||||
</div>
|
||||
|
||||
<div class="pp-body">
|
||||
{/* Curve row */}
|
||||
<div class="pp-row">
|
||||
<span class="pp-label">Curve</span>
|
||||
<canvas
|
||||
ref={curveCanvasRef}
|
||||
class="pp-curve-canvas"
|
||||
width={36}
|
||||
height={36}
|
||||
onPointerDown={onCurvePointerDown}
|
||||
onPointerMove={onCurvePointerMove}
|
||||
onPointerUp={onCurvePointerUp}
|
||||
onPointerCancel={onCurvePointerCancel}
|
||||
/>
|
||||
<span class="pp-val">{curveValue().toFixed(2)}</span>
|
||||
</div>
|
||||
|
||||
{/* Range row */}
|
||||
<div class="pp-row">
|
||||
<span class="pp-label">Range</span>
|
||||
<div class="pp-range-wrap">
|
||||
<div
|
||||
class="pp-range-fill"
|
||||
style={{
|
||||
left: rangeFillLeft(),
|
||||
width: rangeFillWidth(),
|
||||
}}
|
||||
/>
|
||||
<input
|
||||
type="range"
|
||||
class="pp-range-input pp-range-min"
|
||||
min="0"
|
||||
max="1"
|
||||
step="0.01"
|
||||
value={minValue()}
|
||||
onInput={onMinInput}
|
||||
/>
|
||||
<input
|
||||
type="range"
|
||||
class="pp-range-input pp-range-max"
|
||||
min="0"
|
||||
max="1"
|
||||
step="0.01"
|
||||
value={maxValue()}
|
||||
onInput={onMaxInput}
|
||||
/>
|
||||
</div>
|
||||
<span class="pp-val">{minValue().toFixed(2)}–{maxValue().toFixed(2)}</span>
|
||||
</div>
|
||||
|
||||
{/* Freeze row */}
|
||||
<div class="pp-row pp-freeze-row">
|
||||
<button
|
||||
class={`pp-freeze-btn${frozen() ? ' frozen' : ''}`}
|
||||
onClick={toggleFreeze}
|
||||
title={frozen() ? 'Unfreeze — re-enable NISPS control' : 'Freeze — lock value, disable NISPS'}
|
||||
>
|
||||
{frozen() ? 'Frozen' : 'Freeze'}
|
||||
</button>
|
||||
<Show when={frozen()}>
|
||||
<input
|
||||
type="range"
|
||||
class="pp-val-slider"
|
||||
min="0"
|
||||
max="1"
|
||||
step="0.01"
|
||||
value={fixedValue()}
|
||||
onInput={onFixedValueInput}
|
||||
/>
|
||||
</Show>
|
||||
<Show when={frozen()}>
|
||||
<span class="pp-val">{fixedValue().toFixed(2)}</span>
|
||||
</Show>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -82,28 +82,38 @@
|
|||
padding: 10px 12px;
|
||||
min-width: 200px;
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
|
||||
opacity: 0;
|
||||
transition: opacity 0.15s;
|
||||
pointer-events: none;
|
||||
font-family: var(--font-mono, 'JetBrains Mono', monospace);
|
||||
}
|
||||
|
||||
.param-popup-header {
|
||||
.param-popup.visible {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
/* Header: param name + value + close button */
|
||||
.pp-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.param-popup-name {
|
||||
.pp-name {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: #fff;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.param-popup-value {
|
||||
.pp-value {
|
||||
font-size: 11px;
|
||||
color: var(--accent, #00d4ff);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.param-popup-close {
|
||||
.pp-close {
|
||||
background: none;
|
||||
border: none;
|
||||
color: #888;
|
||||
|
|
@ -111,24 +121,178 @@
|
|||
cursor: pointer;
|
||||
padding: 0 2px;
|
||||
line-height: 1;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.param-popup-close:hover {
|
||||
.pp-close:hover {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.param-popup-bar {
|
||||
width: 100%;
|
||||
height: 6px;
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
border-radius: 3px;
|
||||
margin-top: 6px;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
/* Body: controls */
|
||||
.pp-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.param-popup-bar-fill {
|
||||
height: 100%;
|
||||
border-radius: 3px;
|
||||
transition: width 0.15s;
|
||||
/* Generic row layout */
|
||||
.pp-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.pp-label {
|
||||
font-size: 10px;
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
min-width: 36px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.pp-val {
|
||||
font-size: 10px;
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
font-variant-numeric: tabular-nums;
|
||||
min-width: 48px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
/* Curve canvas */
|
||||
.pp-curve-canvas {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
cursor: ns-resize;
|
||||
touch-action: none;
|
||||
}
|
||||
|
||||
/* Range slider wrap (dual min/max) */
|
||||
.pp-range-wrap {
|
||||
flex: 1;
|
||||
position: relative;
|
||||
height: 20px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.pp-range-fill {
|
||||
position: absolute;
|
||||
height: 4px;
|
||||
background: var(--accent, #00d4ff);
|
||||
border-radius: 2px;
|
||||
opacity: 0.4;
|
||||
pointer-events: none;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
|
||||
.pp-range-input {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 4px;
|
||||
-webkit-appearance: none;
|
||||
appearance: none;
|
||||
background: transparent;
|
||||
pointer-events: none;
|
||||
margin: 0;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
|
||||
.pp-range-input::-webkit-slider-thumb {
|
||||
-webkit-appearance: none;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
background: var(--accent, #00d4ff);
|
||||
cursor: pointer;
|
||||
pointer-events: auto;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.pp-range-input::-moz-range-thumb {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
background: var(--accent, #00d4ff);
|
||||
cursor: pointer;
|
||||
pointer-events: auto;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.pp-range-input.pp-range-min::-webkit-slider-thumb {
|
||||
background: #ff6a00;
|
||||
}
|
||||
|
||||
.pp-range-input.pp-range-max::-webkit-slider-thumb {
|
||||
background: #00ccff;
|
||||
}
|
||||
|
||||
.pp-range-input.pp-range-min::-moz-range-thumb {
|
||||
background: #ff6a00;
|
||||
}
|
||||
|
||||
.pp-range-input.pp-range-max::-moz-range-thumb {
|
||||
background: #00ccff;
|
||||
}
|
||||
|
||||
/* Freeze row */
|
||||
.pp-freeze-row {
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.pp-freeze-btn {
|
||||
font-size: 10px;
|
||||
padding: 3px 8px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.15);
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
cursor: pointer;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
font-family: inherit;
|
||||
transition: all 0.15s;
|
||||
}
|
||||
|
||||
.pp-freeze-btn:hover {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.pp-freeze-btn.frozen {
|
||||
background: rgba(0, 212, 255, 0.15);
|
||||
border-color: rgba(0, 212, 255, 0.4);
|
||||
color: #00d4ff;
|
||||
}
|
||||
|
||||
.pp-val-slider {
|
||||
flex: 1;
|
||||
height: 4px;
|
||||
-webkit-appearance: none;
|
||||
appearance: none;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 2px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.pp-val-slider::-webkit-slider-thumb {
|
||||
-webkit-appearance: none;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
background: #00d4ff;
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.pp-val-slider::-moz-range-thumb {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
background: #00d4ff;
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
}
|
||||
|
|
|
|||
122
src/core/param-overrides.ts
Normal file
122
src/core/param-overrides.ts
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
/**
|
||||
* Param Overrides — per-parameter curve/min/max/freeze controls.
|
||||
*
|
||||
* Ported from playground/js/synth/param-map.js (applyCurve, applyGroupOverride)
|
||||
* and playground/js/a-app.js (visualOverrides array pattern).
|
||||
*
|
||||
* Each parameter can have its output shaped by:
|
||||
* curve: [0,1] — 0.5 = linear, <0.5 = compress low end, >0.5 = expand
|
||||
* min/max: [0,1] — output range mapping
|
||||
* frozen: boolean — if true, output holds fixedValue
|
||||
* fixedValue: [0,1] — the value used when frozen
|
||||
*/
|
||||
|
||||
// ─── Types ──────────────────────────────────────────────────────────
|
||||
|
||||
export interface ParamOverride {
|
||||
/** Response curve factor [0,1]. 0.5 = linear */
|
||||
curve: number;
|
||||
/** Output range minimum [0,1] */
|
||||
min: number;
|
||||
/** Output range maximum [0,1] */
|
||||
max: number;
|
||||
/** Whether the parameter is frozen (held at fixedValue) */
|
||||
frozen: boolean;
|
||||
/** The value to hold when frozen [0,1] */
|
||||
fixedValue: number;
|
||||
}
|
||||
|
||||
/** Create a default override with no transformation */
|
||||
export function createDefaultOverride(): ParamOverride {
|
||||
return {
|
||||
curve: 0.5,
|
||||
min: 0,
|
||||
max: 1,
|
||||
frozen: false,
|
||||
fixedValue: 0.5,
|
||||
};
|
||||
}
|
||||
|
||||
/** Create an array of default overrides */
|
||||
export function createDefaultOverrides(count: number): ParamOverride[] {
|
||||
return Array.from({ length: count }, () => createDefaultOverride());
|
||||
}
|
||||
|
||||
// ─── Curve Math ─────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Apply a response curve to a value.
|
||||
* @param value Input value [0,1]
|
||||
* @param curveFactor Curve factor [0,1] — 0.5 = linear (no change)
|
||||
* @returns Curved value [0,1]
|
||||
*/
|
||||
export function applyCurve(value: number, curveFactor: number): number {
|
||||
if (curveFactor === 0.5) return value;
|
||||
const exponent = Math.pow(2, 4 * (curveFactor - 0.5));
|
||||
return Math.pow(Math.max(0, Math.min(1, value)), exponent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply full override transformation: curve + min/max range.
|
||||
* @param rawValue Raw ML output [0,1]
|
||||
* @param override Override settings
|
||||
* @returns Transformed value
|
||||
*/
|
||||
export function applyOverride(rawValue: number, override: ParamOverride): number {
|
||||
const curved = applyCurve(rawValue, override.curve);
|
||||
return override.min + curved * (override.max - override.min);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply override to a raw value, respecting frozen state.
|
||||
* If frozen, returns fixedValue; otherwise applies curve + range.
|
||||
*/
|
||||
export function applyOverrideWithFreeze(rawValue: number, override: ParamOverride): number {
|
||||
if (override.frozen) return override.fixedValue;
|
||||
return applyOverride(rawValue, override);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a response curve on a canvas element.
|
||||
* @param ctx Canvas 2D context
|
||||
* @param curveFactor Curve factor [0,1]
|
||||
* @param color Stroke color
|
||||
* @param w Canvas width
|
||||
* @param h Canvas height
|
||||
*/
|
||||
export function drawCurveOnCanvas(
|
||||
ctx: CanvasRenderingContext2D,
|
||||
curveFactor: number,
|
||||
color: string,
|
||||
w: number,
|
||||
h: number,
|
||||
): void {
|
||||
ctx.clearRect(0, 0, w, h);
|
||||
|
||||
// Background
|
||||
ctx.fillStyle = 'rgba(255,255,255,0.03)';
|
||||
ctx.fillRect(0, 0, w, h);
|
||||
|
||||
// Linear reference line
|
||||
ctx.strokeStyle = 'rgba(255,255,255,0.1)';
|
||||
ctx.lineWidth = 1;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(0, h);
|
||||
ctx.lineTo(w, 0);
|
||||
ctx.stroke();
|
||||
|
||||
// Curve
|
||||
ctx.strokeStyle = color;
|
||||
ctx.lineWidth = Math.min(2, w / 16);
|
||||
ctx.beginPath();
|
||||
const steps = 30;
|
||||
for (let i = 0; i <= steps; i++) {
|
||||
const t = i / steps;
|
||||
const v = applyCurve(t, curveFactor);
|
||||
const px = t * w;
|
||||
const py = (1 - v) * h;
|
||||
if (i === 0) ctx.moveTo(px, py);
|
||||
else ctx.lineTo(px, py);
|
||||
}
|
||||
ctx.stroke();
|
||||
}
|
||||
|
|
@ -14,6 +14,12 @@ import { createSignal, onCleanup } from 'solid-js';
|
|||
import { createStore } from 'solid-js/store';
|
||||
import { WasmIML } from '../core/iml';
|
||||
import type { SignalBus } from '../bus/signal-bus';
|
||||
import {
|
||||
createDefaultOverrides,
|
||||
createDefaultOverride,
|
||||
applyOverrideWithFreeze,
|
||||
type ParamOverride,
|
||||
} from '../core/param-overrides';
|
||||
|
||||
// ─── Constants ────────────────────────────────────────────────────────
|
||||
|
||||
|
|
@ -161,6 +167,18 @@ export interface MLStore {
|
|||
/** Internal: update outputs signal from external source (e.g. heatmap drag) */
|
||||
_updateOutputs(newOutputs: Float32Array): void;
|
||||
|
||||
// ─── Param overrides ───
|
||||
/** Get the override for a specific parameter index */
|
||||
getParamOverride(paramIndex: number): ParamOverride;
|
||||
/** Update a property of a param override */
|
||||
setParamOverride(paramIndex: number, key: keyof ParamOverride, value: number | boolean): void;
|
||||
/** Get all current overrides (for save/restore) */
|
||||
getAllOverrides(): ParamOverride[];
|
||||
/** Get the overridden output value for a parameter (respects freeze/curve/range) */
|
||||
getOverriddenOutput(paramIndex: number): number;
|
||||
/** Apply all overrides to raw outputs, returning a new array */
|
||||
applyAllOverrides(rawOutputs: Float32Array): Float32Array;
|
||||
|
||||
// Lifecycle
|
||||
dispose(): void;
|
||||
}
|
||||
|
|
@ -192,6 +210,9 @@ export async function createMLStore(bus: SignalBus): Promise<MLStore> {
|
|||
// Reactive undo depth signal for UI button state
|
||||
const [undoDepthSignal, setUndoDepthSignal] = createSignal<number>(0);
|
||||
|
||||
// Param overrides — mutable array (not reactive itself, accessed via getParamOverride)
|
||||
let paramOverrides: ParamOverride[] = createDefaultOverrides(initialCount);
|
||||
|
||||
// IML instances — module-scope opaque handles (not reactive)
|
||||
let imlJoy: WasmIML | null = null;
|
||||
let imlHand: WasmIML | null = null;
|
||||
|
|
@ -302,6 +323,14 @@ export async function createMLStore(bus: SignalBus): Promise<MLStore> {
|
|||
outputsTopic.emit(newOutputs);
|
||||
outputCountTopic.emit(newCount);
|
||||
|
||||
// Resize param overrides array to match new output count
|
||||
const oldOverrides = paramOverrides;
|
||||
paramOverrides = createDefaultOverrides(newCount);
|
||||
// Preserve existing overrides where possible
|
||||
for (let i = 0; i < Math.min(oldOverrides.length, newCount); i++) {
|
||||
paramOverrides[i] = { ...oldOverrides[i] };
|
||||
}
|
||||
|
||||
console.log(`[NISPS] MLP resized to ${newCount} outputs (joystick IML warm-started)`);
|
||||
}
|
||||
|
||||
|
|
@ -527,6 +556,40 @@ export async function createMLStore(bus: SignalBus): Promise<MLStore> {
|
|||
_updateOutputs(newOutputs);
|
||||
},
|
||||
|
||||
// ─── Param overrides ───
|
||||
|
||||
getParamOverride: (paramIndex: number): ParamOverride => {
|
||||
if (paramIndex < 0 || paramIndex >= paramOverrides.length) {
|
||||
return createDefaultOverride();
|
||||
}
|
||||
return paramOverrides[paramIndex];
|
||||
},
|
||||
|
||||
setParamOverride: (paramIndex: number, key: keyof ParamOverride, value: number | boolean): void => {
|
||||
if (paramIndex < 0 || paramIndex >= paramOverrides.length) return;
|
||||
(paramOverrides[paramIndex] as any)[key] = value;
|
||||
},
|
||||
|
||||
getAllOverrides: (): ParamOverride[] => {
|
||||
return paramOverrides.map(o => ({ ...o }));
|
||||
},
|
||||
|
||||
getOverriddenOutput: (paramIndex: number): number => {
|
||||
const rawOutputs = outputs();
|
||||
const raw = rawOutputs[paramIndex] ?? 0;
|
||||
const ov = paramOverrides[paramIndex] ?? createDefaultOverride();
|
||||
return applyOverrideWithFreeze(raw, ov);
|
||||
},
|
||||
|
||||
applyAllOverrides: (rawOutputs: Float32Array): Float32Array => {
|
||||
const result = new Float32Array(rawOutputs.length);
|
||||
for (let i = 0; i < rawOutputs.length; i++) {
|
||||
const ov = paramOverrides[i] ?? createDefaultOverride();
|
||||
result[i] = applyOverrideWithFreeze(rawOutputs[i], ov);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
dispose: () => {
|
||||
imlJoy?.destroy();
|
||||
imlHand?.destroy();
|
||||
|
|
|
|||
450
tests/solidjs/param-popup.spec.ts
Normal file
450
tests/solidjs/param-popup.spec.ts
Normal file
|
|
@ -0,0 +1,450 @@
|
|||
/**
|
||||
* e2e tests for f15-param-popup.
|
||||
* Validates:
|
||||
* VAL-PARAM-001: Popup displays param info (name, value, range controls)
|
||||
* VAL-PARAM-002: Curve drag adjusts parameter response curve
|
||||
* VAL-PARAM-003: Min/max range sliders set bounds
|
||||
* VAL-PARAM-004: Freeze/unfreeze toggle holds parameter at fixed value
|
||||
*/
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { loadSolidApp } from './helpers';
|
||||
|
||||
test.describe('Param Popup', () => {
|
||||
|
||||
/**
|
||||
* Helper: open param popup by clicking a heatmap cell.
|
||||
* Returns the popup locator.
|
||||
*/
|
||||
async function openPopup(page: import('@playwright/test').Page, cellIndex = 0) {
|
||||
const cell = page.locator('#heatmap-cells .heatmap-cell').nth(cellIndex);
|
||||
await expect(cell).toBeVisible();
|
||||
const box = await cell.boundingBox();
|
||||
expect(box).not.toBeNull();
|
||||
// Short click in center
|
||||
await page.mouse.click(box!.x + box!.width / 2, box!.y + box!.height / 2);
|
||||
const popup = page.locator('#param-popup');
|
||||
await expect(popup).toBeVisible({ timeout: 3000 });
|
||||
return popup;
|
||||
}
|
||||
|
||||
// ─── VAL-PARAM-001: Popup displays param info ───
|
||||
|
||||
test('VAL-PARAM-001a: popup shows parameter name', async ({ page }) => {
|
||||
await loadSolidApp(page);
|
||||
|
||||
const popup = await openPopup(page, 0);
|
||||
|
||||
// Should have a pp-name element with text
|
||||
const name = popup.locator('.pp-name');
|
||||
await expect(name).toBeVisible();
|
||||
const nameText = await name.textContent();
|
||||
expect(nameText).toBeTruthy();
|
||||
expect(nameText!.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test('VAL-PARAM-001b: popup shows current parameter value', async ({ page }) => {
|
||||
await loadSolidApp(page);
|
||||
|
||||
const popup = await openPopup(page, 0);
|
||||
|
||||
// Should have a pp-value element showing numeric value
|
||||
const value = popup.locator('.pp-value');
|
||||
await expect(value).toBeVisible();
|
||||
const valueText = await value.textContent();
|
||||
expect(valueText).toBeTruthy();
|
||||
// Should be a numeric string like "0.523"
|
||||
expect(parseFloat(valueText!)).toBeGreaterThanOrEqual(0);
|
||||
expect(parseFloat(valueText!)).toBeLessThanOrEqual(1);
|
||||
});
|
||||
|
||||
test('VAL-PARAM-001c: popup has curve canvas, range sliders, and freeze button', async ({ page }) => {
|
||||
await loadSolidApp(page);
|
||||
|
||||
const popup = await openPopup(page, 0);
|
||||
|
||||
// Curve canvas
|
||||
const curveCanvas = popup.locator('.pp-curve-canvas');
|
||||
await expect(curveCanvas).toBeVisible();
|
||||
|
||||
// Curve value display
|
||||
const curveVal = popup.locator('.pp-row').first().locator('.pp-val');
|
||||
await expect(curveVal).toBeVisible();
|
||||
|
||||
// Range sliders (min and max)
|
||||
const minSlider = popup.locator('.pp-range-min');
|
||||
await expect(minSlider).toBeVisible();
|
||||
const maxSlider = popup.locator('.pp-range-max');
|
||||
await expect(maxSlider).toBeVisible();
|
||||
|
||||
// Freeze button
|
||||
const freezeBtn = popup.locator('.pp-freeze-btn');
|
||||
await expect(freezeBtn).toBeVisible();
|
||||
});
|
||||
|
||||
test('VAL-PARAM-001d: popup shows visual mode param names', async ({ page }) => {
|
||||
await loadSolidApp(page);
|
||||
|
||||
// Click first cell (should show "Flow" in visual mode)
|
||||
const popup = await openPopup(page, 0);
|
||||
const name = popup.locator('.pp-name');
|
||||
const nameText = await name.textContent();
|
||||
expect(nameText).toBe('Flow');
|
||||
});
|
||||
|
||||
test('VAL-PARAM-001e: popup has close button that dismisses it', async ({ page }) => {
|
||||
await loadSolidApp(page);
|
||||
|
||||
const popup = await openPopup(page, 0);
|
||||
await expect(popup).toBeVisible();
|
||||
|
||||
// Click close button
|
||||
const closeBtn = popup.locator('.pp-close');
|
||||
await closeBtn.click();
|
||||
|
||||
// Popup should be hidden
|
||||
await expect(popup).not.toBeVisible({ timeout: 2000 });
|
||||
});
|
||||
|
||||
// ─── VAL-PARAM-002: Curve drag adjusts parameter ───
|
||||
|
||||
test('VAL-PARAM-002a: curve canvas is visible and interactive', async ({ page }) => {
|
||||
await loadSolidApp(page);
|
||||
|
||||
const popup = await openPopup(page, 0);
|
||||
const curveCanvas = popup.locator('.pp-curve-canvas');
|
||||
await expect(curveCanvas).toBeVisible();
|
||||
|
||||
// Should have ns-resize cursor style
|
||||
const cursor = await curveCanvas.evaluate(el => getComputedStyle(el).cursor);
|
||||
expect(cursor).toContain('ns-resize');
|
||||
});
|
||||
|
||||
test('VAL-PARAM-002b: vertical drag on curve canvas changes curve value', async ({ page }) => {
|
||||
await loadSolidApp(page);
|
||||
|
||||
const popup = await openPopup(page, 0);
|
||||
|
||||
// Get initial curve value
|
||||
const curveValEl = popup.locator('.pp-row').first().locator('.pp-val');
|
||||
const initialCurveText = await curveValEl.textContent();
|
||||
const initialCurve = parseFloat(initialCurveText!);
|
||||
|
||||
// Drag down on curve canvas to increase curve
|
||||
const curveCanvas = popup.locator('.pp-curve-canvas');
|
||||
const box = await curveCanvas.boundingBox();
|
||||
expect(box).not.toBeNull();
|
||||
|
||||
// Simulate pointer drag down (increase curve)
|
||||
await page.mouse.move(box!.x + box!.width / 2, box!.y + box!.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(box!.x + box!.width / 2, box!.y + box!.height / 2 + 40, { steps: 5 });
|
||||
await page.mouse.up();
|
||||
|
||||
// Curve value should have changed
|
||||
const newCurveText = await curveValEl.textContent();
|
||||
const newCurve = parseFloat(newCurveText!);
|
||||
// Dragging down should increase curve factor
|
||||
expect(newCurve).toBeGreaterThan(initialCurve);
|
||||
});
|
||||
|
||||
test('VAL-PARAM-002c: curve value is stored in override', async ({ page }) => {
|
||||
await loadSolidApp(page);
|
||||
|
||||
const popup = await openPopup(page, 0);
|
||||
|
||||
// Get initial curve value from the display
|
||||
const curveValEl = popup.locator('.pp-row').first().locator('.pp-val');
|
||||
const curveText = await curveValEl.textContent();
|
||||
const curveValue = parseFloat(curveText!);
|
||||
|
||||
// Check that the store's override matches
|
||||
const storeCurve = await page.evaluate(() => {
|
||||
const store = (window as any).__nispsStore;
|
||||
const ov = store.getParamOverride(0);
|
||||
return ov.curve;
|
||||
});
|
||||
|
||||
expect(storeCurve).toBeCloseTo(curveValue, 1);
|
||||
});
|
||||
|
||||
// ─── VAL-PARAM-003: Min/max range sliders ───
|
||||
|
||||
test('VAL-PARAM-003a: range sliders default to 0-1', async ({ page }) => {
|
||||
await loadSolidApp(page);
|
||||
|
||||
const popup = await openPopup(page, 0);
|
||||
|
||||
// Range value display should show 0.00–1.00
|
||||
const rangeRows = popup.locator('.pp-row');
|
||||
// Second row is the range row (first is curve)
|
||||
const rangeRow = rangeRows.nth(1);
|
||||
const rangeVal = rangeRow.locator('.pp-val');
|
||||
const rangeText = await rangeVal.textContent();
|
||||
expect(rangeText).toContain('0.00');
|
||||
expect(rangeText).toContain('1.00');
|
||||
});
|
||||
|
||||
test('VAL-PARAM-003b: adjusting min slider updates range display', async ({ page }) => {
|
||||
await loadSolidApp(page);
|
||||
|
||||
const popup = await openPopup(page, 0);
|
||||
|
||||
// Use programmatic approach to change min slider
|
||||
const result = await page.evaluate(() => {
|
||||
const store = (window as any).__nispsStore;
|
||||
// Set min to 0.3 via the slider
|
||||
const minSlider = document.querySelector('.pp-range-min') as HTMLInputElement;
|
||||
if (!minSlider) return { success: false, error: 'no min slider' };
|
||||
|
||||
// Set value and dispatch input event
|
||||
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
|
||||
window.HTMLInputElement.prototype, 'value'
|
||||
)?.set;
|
||||
nativeInputValueSetter?.call(minSlider, '0.3');
|
||||
minSlider.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
|
||||
return { success: true };
|
||||
});
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
|
||||
// Check that the range display updated
|
||||
const rangeRows = popup.locator('.pp-row');
|
||||
const rangeRow = rangeRows.nth(1);
|
||||
const rangeVal = rangeRow.locator('.pp-val');
|
||||
const rangeText = await rangeVal.textContent();
|
||||
expect(rangeText).toContain('0.30');
|
||||
});
|
||||
|
||||
test('VAL-PARAM-003c: adjusting max slider updates range display', async ({ page }) => {
|
||||
await loadSolidApp(page);
|
||||
|
||||
const popup = await openPopup(page, 0);
|
||||
|
||||
// Set max slider to 0.7 programmatically
|
||||
const result = await page.evaluate(() => {
|
||||
const maxSlider = document.querySelector('.pp-range-max') as HTMLInputElement;
|
||||
if (!maxSlider) return { success: false, error: 'no max slider' };
|
||||
|
||||
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
|
||||
window.HTMLInputElement.prototype, 'value'
|
||||
)?.set;
|
||||
nativeInputValueSetter?.call(maxSlider, '0.7');
|
||||
maxSlider.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
|
||||
return { success: true };
|
||||
});
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
|
||||
// Check range display
|
||||
const rangeRows = popup.locator('.pp-row');
|
||||
const rangeRow = rangeRows.nth(1);
|
||||
const rangeVal = rangeRow.locator('.pp-val');
|
||||
const rangeText = await rangeVal.textContent();
|
||||
expect(rangeText).toContain('0.70');
|
||||
});
|
||||
|
||||
test('VAL-PARAM-003d: min cannot exceed max', async ({ page }) => {
|
||||
await loadSolidApp(page);
|
||||
|
||||
const popup = await openPopup(page, 0);
|
||||
|
||||
// Set max to 0.3 first
|
||||
await page.evaluate(() => {
|
||||
const maxSlider = document.querySelector('.pp-range-max') as HTMLInputElement;
|
||||
const setter = Object.getOwnPropertyDescriptor(
|
||||
window.HTMLInputElement.prototype, 'value'
|
||||
)?.set;
|
||||
setter?.call(maxSlider, '0.3');
|
||||
maxSlider.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
});
|
||||
|
||||
// Now try to set min to 0.5 (should be clamped to max)
|
||||
await page.evaluate(() => {
|
||||
const minSlider = document.querySelector('.pp-range-min') as HTMLInputElement;
|
||||
const setter = Object.getOwnPropertyDescriptor(
|
||||
window.HTMLInputElement.prototype, 'value'
|
||||
)?.set;
|
||||
setter?.call(minSlider, '0.5');
|
||||
minSlider.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
});
|
||||
|
||||
// Check override in store — min should be >= max
|
||||
const ov = await page.evaluate(() => {
|
||||
const store = (window as any).__nispsStore;
|
||||
return store.getParamOverride(0);
|
||||
});
|
||||
|
||||
// Min should have been clamped to max (0.3)
|
||||
expect(ov.min).toBeLessThanOrEqual(ov.max);
|
||||
});
|
||||
|
||||
test('VAL-PARAM-003e: range values are stored in override', async ({ page }) => {
|
||||
await loadSolidApp(page);
|
||||
|
||||
await openPopup(page, 0);
|
||||
|
||||
// Set min via slider
|
||||
await page.evaluate(() => {
|
||||
const store = (window as any).__nispsStore;
|
||||
store.setParamOverride(0, 'min', 0.2);
|
||||
store.setParamOverride(0, 'max', 0.8);
|
||||
});
|
||||
|
||||
// Verify stored values
|
||||
const ov = await page.evaluate(() => {
|
||||
const store = (window as any).__nispsStore;
|
||||
return store.getParamOverride(0);
|
||||
});
|
||||
|
||||
expect(ov.min).toBeCloseTo(0.2, 1);
|
||||
expect(ov.max).toBeCloseTo(0.8, 1);
|
||||
});
|
||||
|
||||
// ─── VAL-PARAM-004: Freeze/unfreeze toggle ───
|
||||
|
||||
test('VAL-PARAM-004a: freeze button toggles state', async ({ page }) => {
|
||||
await loadSolidApp(page);
|
||||
|
||||
const popup = await openPopup(page, 0);
|
||||
const freezeBtn = popup.locator('.pp-freeze-btn');
|
||||
await expect(freezeBtn).toBeVisible();
|
||||
|
||||
// Initially shows "Freeze" (not frozen)
|
||||
const initialText = await freezeBtn.textContent();
|
||||
expect(initialText).toBe('Freeze');
|
||||
|
||||
// Click to freeze
|
||||
await freezeBtn.click();
|
||||
|
||||
// Now should show "Frozen" and have frozen class
|
||||
const frozenText = await freezeBtn.textContent();
|
||||
expect(frozenText).toBe('Frozen');
|
||||
const hasFrozenClass = await freezeBtn.evaluate(el => el.classList.contains('frozen'));
|
||||
expect(hasFrozenClass).toBe(true);
|
||||
});
|
||||
|
||||
test('VAL-PARAM-004b: freeze toggle captures current output value', async ({ page }) => {
|
||||
await loadSolidApp(page);
|
||||
|
||||
const popup = await openPopup(page, 0);
|
||||
|
||||
// Get current output value
|
||||
const currentValue = await page.evaluate(() => {
|
||||
const probe = (window as any).__nisps;
|
||||
return probe.getOutputs()[0];
|
||||
});
|
||||
|
||||
// Click freeze
|
||||
const freezeBtn = popup.locator('.pp-freeze-btn');
|
||||
await freezeBtn.click();
|
||||
|
||||
// Check that the override has frozen=true and fixedValue equals current output
|
||||
const ov = await page.evaluate(() => {
|
||||
const store = (window as any).__nispsStore;
|
||||
return store.getParamOverride(0);
|
||||
});
|
||||
|
||||
expect(ov.frozen).toBe(true);
|
||||
expect(ov.fixedValue).toBeCloseTo(currentValue, 2);
|
||||
});
|
||||
|
||||
test('VAL-PARAM-004c: frozen parameter shows value slider', async ({ page }) => {
|
||||
await loadSolidApp(page);
|
||||
|
||||
const popup = await openPopup(page, 0);
|
||||
|
||||
// Initially no val slider
|
||||
const valSliderBefore = popup.locator('.pp-val-slider');
|
||||
// Slider should not be visible when not frozen
|
||||
const sliderVisibleBefore = await valSliderBefore.count();
|
||||
expect(sliderVisibleBefore).toBe(0);
|
||||
|
||||
// Freeze
|
||||
const freezeBtn = popup.locator('.pp-freeze-btn');
|
||||
await freezeBtn.click();
|
||||
|
||||
// Now slider should appear
|
||||
const valSliderAfter = popup.locator('.pp-val-slider');
|
||||
await expect(valSliderAfter).toBeVisible({ timeout: 2000 });
|
||||
});
|
||||
|
||||
test('VAL-PARAM-004d: unfreeze restores non-frozen state', async ({ page }) => {
|
||||
await loadSolidApp(page);
|
||||
|
||||
const popup = await openPopup(page, 0);
|
||||
const freezeBtn = popup.locator('.pp-freeze-btn');
|
||||
|
||||
// Freeze
|
||||
await freezeBtn.click();
|
||||
let ov = await page.evaluate(() => {
|
||||
const store = (window as any).__nispsStore;
|
||||
return store.getParamOverride(0);
|
||||
});
|
||||
expect(ov.frozen).toBe(true);
|
||||
|
||||
// Unfreeze
|
||||
await freezeBtn.click();
|
||||
ov = await page.evaluate(() => {
|
||||
const store = (window as any).__nispsStore;
|
||||
return store.getParamOverride(0);
|
||||
});
|
||||
expect(ov.frozen).toBe(false);
|
||||
|
||||
// Button text should say "Freeze" again
|
||||
const text = await freezeBtn.textContent();
|
||||
expect(text).toBe('Freeze');
|
||||
});
|
||||
|
||||
test('VAL-PARAM-004e: getOverriddenOutput returns fixedValue when frozen', async ({ page }) => {
|
||||
await loadSolidApp(page);
|
||||
|
||||
await openPopup(page, 0);
|
||||
|
||||
// Set frozen state and fixed value via store
|
||||
await page.evaluate(() => {
|
||||
const store = (window as any).__nispsStore;
|
||||
store.setParamOverride(0, 'frozen', true);
|
||||
store.setParamOverride(0, 'fixedValue', 0.75);
|
||||
});
|
||||
|
||||
// getOverriddenOutput should return the fixed value
|
||||
const overriddenValue = await page.evaluate(() => {
|
||||
const store = (window as any).__nispsStore;
|
||||
return store.getOverriddenOutput(0);
|
||||
});
|
||||
|
||||
expect(overriddenValue).toBeCloseTo(0.75, 1);
|
||||
});
|
||||
|
||||
test('VAL-PARAM-004f: adjusting fixed value slider updates frozen value', async ({ page }) => {
|
||||
await loadSolidApp(page);
|
||||
|
||||
const popup = await openPopup(page, 0);
|
||||
|
||||
// Freeze first
|
||||
const freezeBtn = popup.locator('.pp-freeze-btn');
|
||||
await freezeBtn.click();
|
||||
|
||||
// Adjust fixed value slider
|
||||
await page.evaluate(() => {
|
||||
const valSlider = document.querySelector('.pp-val-slider') as HTMLInputElement;
|
||||
if (!valSlider) return;
|
||||
const setter = Object.getOwnPropertyDescriptor(
|
||||
window.HTMLInputElement.prototype, 'value'
|
||||
)?.set;
|
||||
setter?.call(valSlider, '0.6');
|
||||
valSlider.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
});
|
||||
|
||||
// Check override stored
|
||||
const ov = await page.evaluate(() => {
|
||||
const store = (window as any).__nispsStore;
|
||||
return store.getParamOverride(0);
|
||||
});
|
||||
|
||||
expect(ov.frozen).toBe(true);
|
||||
expect(ov.fixedValue).toBeCloseTo(0.6, 1);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue