feat: add training drawer with dock, buttons, status line, and loss plot (f08)
Build training drawer UI for milestone training-rl:
- Dock component with 6 icons (Train, Mode, Synth, NISPS, FX, Help)
- TrainingDrawer with Add Example, Train, Clear Ex, Clear All, Randomize
- StatusLine showing 'N examples · loss/noise' reactively
- Loss plot canvas with training history visualization
- ML store: add noiseLevel, exampleCountSignal, lastLossSignal, clearAll, addExample
- Debug probe: add clearAll() and getLossHistory() methods
- 22 Playwright e2e tests covering VAL-TRAIN-001 through VAL-TRAIN-009
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
2026-04-07 19:37:27 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* TrainingDrawer — Drawer panel with training controls.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Contains:
|
|
|
|
|
|
* - Add Example button (captures current input/output as training example)
|
|
|
|
|
|
* - Train button (triggers async training)
|
|
|
|
|
|
* - Clear Ex button (clears examples only)
|
|
|
|
|
|
* - Clear All button (clears everything including loss history)
|
|
|
|
|
|
* - Randomize button (randomizes weights)
|
2026-04-07 20:28:17 +02:00
|
|
|
|
* - Visual preset chips (load predefined examples + train)
|
feat: add training drawer with dock, buttons, status line, and loss plot (f08)
Build training drawer UI for milestone training-rl:
- Dock component with 6 icons (Train, Mode, Synth, NISPS, FX, Help)
- TrainingDrawer with Add Example, Train, Clear Ex, Clear All, Randomize
- StatusLine showing 'N examples · loss/noise' reactively
- Loss plot canvas with training history visualization
- ML store: add noiseLevel, exampleCountSignal, lastLossSignal, clearAll, addExample
- Debug probe: add clearAll() and getLossHistory() methods
- 22 Playwright e2e tests covering VAL-TRAIN-001 through VAL-TRAIN-009
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
2026-04-07 19:37:27 +02:00
|
|
|
|
* - Loss plot canvas (shows loss history)
|
|
|
|
|
|
*
|
|
|
|
|
|
* Status line is rendered separately at the bottom of the screen.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
|
createSignal,
|
|
|
|
|
|
onCleanup,
|
2026-04-07 20:28:17 +02:00
|
|
|
|
For,
|
feat: add training drawer with dock, buttons, status line, and loss plot (f08)
Build training drawer UI for milestone training-rl:
- Dock component with 6 icons (Train, Mode, Synth, NISPS, FX, Help)
- TrainingDrawer with Add Example, Train, Clear Ex, Clear All, Randomize
- StatusLine showing 'N examples · loss/noise' reactively
- Loss plot canvas with training history visualization
- ML store: add noiseLevel, exampleCountSignal, lastLossSignal, clearAll, addExample
- Debug probe: add clearAll() and getLossHistory() methods
- 22 Playwright e2e tests covering VAL-TRAIN-001 through VAL-TRAIN-009
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
2026-04-07 19:37:27 +02:00
|
|
|
|
} from 'solid-js';
|
|
|
|
|
|
import type { MLStore } from '../../stores/ml-store';
|
2026-04-07 20:28:17 +02:00
|
|
|
|
import { VISUAL_PRESET_NAMES, VISUAL_PRESET_LABELS } from '../../stores/ml-store';
|
feat: add training drawer with dock, buttons, status line, and loss plot (f08)
Build training drawer UI for milestone training-rl:
- Dock component with 6 icons (Train, Mode, Synth, NISPS, FX, Help)
- TrainingDrawer with Add Example, Train, Clear Ex, Clear All, Randomize
- StatusLine showing 'N examples · loss/noise' reactively
- Loss plot canvas with training history visualization
- ML store: add noiseLevel, exampleCountSignal, lastLossSignal, clearAll, addExample
- Debug probe: add clearAll() and getLossHistory() methods
- 22 Playwright e2e tests covering VAL-TRAIN-001 through VAL-TRAIN-009
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
2026-04-07 19:37:27 +02:00
|
|
|
|
import './drawer.css';
|
|
|
|
|
|
|
|
|
|
|
|
export interface TrainingDrawerProps {
|
|
|
|
|
|
mlStore: MLStore;
|
|
|
|
|
|
visible: boolean;
|
|
|
|
|
|
onClose: () => void;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default function TrainingDrawer(props: TrainingDrawerProps) {
|
|
|
|
|
|
let lossCanvasRef: HTMLCanvasElement | undefined;
|
|
|
|
|
|
|
|
|
|
|
|
// ─── Button handlers ───
|
|
|
|
|
|
|
|
|
|
|
|
function onAddExample(): void {
|
|
|
|
|
|
props.mlStore.addExample();
|
|
|
|
|
|
flashButton('btn-add-example');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function onTrain(): void {
|
|
|
|
|
|
const iml = props.mlStore.getActiveIml();
|
|
|
|
|
|
if (!iml || (iml as any).isTraining) return;
|
|
|
|
|
|
flashButton('btn-train');
|
|
|
|
|
|
props.mlStore.trainAsync().then(() => {
|
|
|
|
|
|
drawLossPlot();
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function onClearExamples(): void {
|
|
|
|
|
|
props.mlStore.clearExamples();
|
|
|
|
|
|
drawLossPlot();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function onClearAll(): void {
|
|
|
|
|
|
props.mlStore.clearAll();
|
|
|
|
|
|
drawLossPlot();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function onRandomize(): void {
|
|
|
|
|
|
props.mlStore.randomise();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-07 20:28:17 +02:00
|
|
|
|
function onLoadPreset(name: string): void {
|
|
|
|
|
|
props.mlStore.loadVisualPreset(name);
|
|
|
|
|
|
drawLossPlot();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
feat: add training drawer with dock, buttons, status line, and loss plot (f08)
Build training drawer UI for milestone training-rl:
- Dock component with 6 icons (Train, Mode, Synth, NISPS, FX, Help)
- TrainingDrawer with Add Example, Train, Clear Ex, Clear All, Randomize
- StatusLine showing 'N examples · loss/noise' reactively
- Loss plot canvas with training history visualization
- ML store: add noiseLevel, exampleCountSignal, lastLossSignal, clearAll, addExample
- Debug probe: add clearAll() and getLossHistory() methods
- 22 Playwright e2e tests covering VAL-TRAIN-001 through VAL-TRAIN-009
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
2026-04-07 19:37:27 +02:00
|
|
|
|
// ─── Button flash effect ───
|
|
|
|
|
|
|
|
|
|
|
|
function flashButton(id: string): void {
|
|
|
|
|
|
const btn = document.getElementById(id);
|
|
|
|
|
|
if (btn) {
|
|
|
|
|
|
btn.classList.add('flash');
|
|
|
|
|
|
setTimeout(() => btn.classList.remove('flash'), 300);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ─── Loss plot drawing ───
|
|
|
|
|
|
|
|
|
|
|
|
function drawLossPlot(): void {
|
|
|
|
|
|
const canvas = lossCanvasRef;
|
|
|
|
|
|
if (!canvas) return;
|
|
|
|
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
|
|
if (!ctx) return;
|
|
|
|
|
|
|
|
|
|
|
|
const w = canvas.width;
|
|
|
|
|
|
const h = canvas.height;
|
|
|
|
|
|
const history = props.mlStore.getLossHistory();
|
|
|
|
|
|
|
|
|
|
|
|
ctx.fillStyle = 'rgba(0, 0, 0, 0.3)';
|
|
|
|
|
|
ctx.fillRect(0, 0, w, h);
|
|
|
|
|
|
|
|
|
|
|
|
if (history.length < 2) return;
|
|
|
|
|
|
|
|
|
|
|
|
const maxLoss = Math.max(...history.slice(-200)) || 1;
|
|
|
|
|
|
const points = history.slice(-200);
|
|
|
|
|
|
|
|
|
|
|
|
ctx.strokeStyle = 'rgba(255, 106, 0, 0.6)';
|
|
|
|
|
|
ctx.lineWidth = 1.5;
|
|
|
|
|
|
ctx.beginPath();
|
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < points.length; i++) {
|
|
|
|
|
|
const x = (i / (points.length - 1)) * w;
|
|
|
|
|
|
const y = h - (points[i] / maxLoss) * h * 0.9;
|
|
|
|
|
|
if (i === 0) ctx.moveTo(x, y);
|
|
|
|
|
|
else ctx.lineTo(x, y);
|
|
|
|
|
|
}
|
|
|
|
|
|
ctx.stroke();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div
|
|
|
|
|
|
class={`drawer${props.visible ? '' : ' hidden'}`}
|
|
|
|
|
|
id="drawer-training"
|
|
|
|
|
|
data-drawer="training"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div class="drawer-header">
|
|
|
|
|
|
<span>Training</span>
|
|
|
|
|
|
<button class="drawer-close" data-drawer="training" onClick={props.onClose}>
|
|
|
|
|
|
×
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="drawer-body">
|
|
|
|
|
|
<div class="action-row" id="examples-actions">
|
|
|
|
|
|
<button class="action-btn" id="btn-add-example" onClick={onAddExample}>
|
|
|
|
|
|
Add Example
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button class="action-btn accent" id="btn-train" onClick={onTrain}>
|
|
|
|
|
|
Train
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button class="action-btn dim" id="btn-clear-examples" onClick={onClearExamples}>
|
|
|
|
|
|
Clear Ex
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button class="action-btn dim" id="btn-clear-all" onClick={onClearAll}>
|
|
|
|
|
|
Clear All
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button class="action-btn dim" id="btn-randomize" onClick={onRandomize}>
|
|
|
|
|
|
Randomize
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
2026-04-07 20:28:17 +02:00
|
|
|
|
<div class="preset-section">
|
|
|
|
|
|
<label>Presets</label>
|
|
|
|
|
|
<div class="preset-chips">
|
|
|
|
|
|
<For each={VISUAL_PRESET_NAMES}>
|
|
|
|
|
|
{(name) => (
|
|
|
|
|
|
<button
|
|
|
|
|
|
class="preset-chip"
|
|
|
|
|
|
data-preset={name}
|
|
|
|
|
|
onClick={() => onLoadPreset(name)}
|
|
|
|
|
|
>
|
|
|
|
|
|
{VISUAL_PRESET_LABELS[name] || name}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</For>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
feat: add training drawer with dock, buttons, status line, and loss plot (f08)
Build training drawer UI for milestone training-rl:
- Dock component with 6 icons (Train, Mode, Synth, NISPS, FX, Help)
- TrainingDrawer with Add Example, Train, Clear Ex, Clear All, Randomize
- StatusLine showing 'N examples · loss/noise' reactively
- Loss plot canvas with training history visualization
- ML store: add noiseLevel, exampleCountSignal, lastLossSignal, clearAll, addExample
- Debug probe: add clearAll() and getLossHistory() methods
- 22 Playwright e2e tests covering VAL-TRAIN-001 through VAL-TRAIN-009
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
2026-04-07 19:37:27 +02:00
|
|
|
|
<div class="loss-section">
|
|
|
|
|
|
<label>Loss History</label>
|
|
|
|
|
|
<canvas
|
|
|
|
|
|
ref={lossCanvasRef}
|
|
|
|
|
|
id="loss-canvas"
|
|
|
|
|
|
width="280"
|
|
|
|
|
|
height="80"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|