From 894fd9b9ef89c956223576834d1816de51bbe743 Mon Sep 17 00:00:00 2001 From: Lucas Winther Date: Fri, 30 Oct 2026 14:38:36 +0100 Subject: [PATCH] feat(align): alignment web page Token-protected Bun.serve server (bun run align [--host] [--port] [--url-host] [--root]) with the layout-A page: recording and warped-MIDI lanes on one zoomable timeline, draggable anchors (recording end / MIDI end), stretch tempo labels with warnings, fit-flagged windows, Web Audio playback with mix choice, auto-align, save, reset, undo. API per the task brief; transcode/peaks cache under reference//. Adds bun run align auto , writeSmf (tests), encodeWav, recordingOnsets/fitFromOnsets, fitSummary and stretch tempo helpers. Co-Authored-By: Claude Opus 5.5 --- src/align/auto.ts | 13 +- src/align/cli.ts | 40 +- src/align/fit.ts | 10 + src/align/page/app.ts | 635 ++++++++++++++++++++++++++++++ src/align/page/edit.ts | 65 +++ src/align/page/index.html | 65 +++ src/align/page/style.css | 42 ++ src/align/page/timeline.ts | 121 ++++++ src/align/server.ts | 254 ++++++++++++ src/align/smf.ts | 39 ++ src/align/tempo.ts | 35 ++ src/audio/wav.ts | 7 +- src/ref/manifest.ts | 79 +++- tests/align/auto.test.ts | 11 +- tests/align/fit.test.ts | 10 +- tests/align/page/edit.test.ts | 68 ++++ tests/align/page/timeline.test.ts | 91 +++++ tests/align/server.test.ts | 161 ++++++++ tests/align/smf.test.ts | 23 +- tests/align/tempo.test.ts | 25 ++ 20 files changed, 1783 insertions(+), 11 deletions(-) create mode 100644 src/align/page/app.ts create mode 100644 src/align/page/edit.ts create mode 100644 src/align/page/index.html create mode 100644 src/align/page/style.css create mode 100644 src/align/page/timeline.ts create mode 100644 src/align/server.ts create mode 100644 src/align/tempo.ts create mode 100644 tests/align/page/edit.test.ts create mode 100644 tests/align/page/timeline.test.ts create mode 100644 tests/align/server.test.ts create mode 100644 tests/align/tempo.test.ts diff --git a/src/align/auto.ts b/src/align/auto.ts index 7f717eb..27e4f66 100644 --- a/src/align/auto.ts +++ b/src/align/auto.ts @@ -196,10 +196,19 @@ function fitFor(recOnsets: number[], smf: Smf, roles: Record, anchors: Anchor[], durSec: number): FitReport { + return fitFor(onsets, smf, roles, makeWarp(anchors), durSec); +} + /** Fit quality of any alignment (e.g. a hand-made one): onset-flux peaks of the raw recording vs the warped MIDI. */ export function alignmentFit(audio: Audio, smf: Smf, roles: Record, anchors: Anchor[]): FitReport { - const onsets = pickOnsets(features(audio, FINE_RATE).onset, FINE_RATE); - return fitFor(onsets, smf, roles, makeWarp(anchors), durationOf(audio)); + return fitFromOnsets(recordingOnsets(audio), smf, roles, anchors, durationOf(audio)); } /** diff --git a/src/align/cli.ts b/src/align/cli.ts index 8ecde8b..f2b84cd 100644 --- a/src/align/cli.ts +++ b/src/align/cli.ts @@ -1,8 +1,14 @@ import { parseArgs } from "node:util"; -import { addSong, trackKeys } from "../ref/manifest.ts"; +import { addSong, loadSong, readAlignment, trackKeys, writeAlignment } from "../ref/manifest.ts"; import { parseSmf } from "./smf.ts"; +import { autoAlign } from "./auto.ts"; +import { fitSummary } from "./fit.ts"; +import { SF2_PATH, startServer } from "./server.ts"; -const USAGE = `usage: bun run align add