Changed theme to liquid glass

This commit is contained in:
patben8 committed 2026-09-25 14:57:27 +02:00
1 parent 950352f7ec
commit 2810f24563
52 files changed
+1353 -529

No files matched your search

+128
View File
@@ -0,0 +1,128 @@
// The app's ambient colour: the backdrop's four washes and the accent hue,
// sampled from the loaded track's cover art.
//
// Everything is written as CSS custom properties on <html> (registered with
// @property in index.css, so a change GLIDES rather than snaps). Nothing in
// React state depends on it, which is what lets a new track recolour the whole
// app without a single re-render.
/** Used when there is no track, no art, or art with no real colour in it. */
const FALLBACK = {
washes: ['#6d4aff', '#e0409a', '#12b5c9', '#2f3fe0'],
hue: 275,
}
// Below this share of saturated pixels an image is treated as greyscale: an
// accent pulled from a black-and-white sleeve would be an accident of JPEG noise.
const MIN_COLOURFUL = 0.06
function apply(washes: string[], hue: number): void {
const root = document.documentElement.style
washes.forEach((c, i) => root.setProperty(`--amb-${i + 1}`, c))
root.setProperty('--accent-hue', hue.toFixed(1))
}
export function resetAmbient(): void {
apply(FALLBACK.washes, FALLBACK.hue)
}
function rgbToHsl(r: number, g: number, b: number): [number, number, number] {
const mx = Math.max(r, g, b)
const mn = Math.min(r, g, b)
const l = (mx + mn) / 2
if (mx === mn) return [0, 0, l]
const d = mx - mn
const s = l > 0.5 ? d / (2 - mx - mn) : d / (mx + mn)
let h: number
if (mx === r) h = (g - b) / d + (g < b ? 6 : 0)
else if (mx === g) h = (b - r) / d + 2
else h = (r - g) / d + 4
return [h * 60, s, l]
}
/**
* The image's dominant colours, as backdrop washes plus an accent hue.
*
* Pixels are binned by hue (12 bins) and weighted by how colourful they are, so
* a large dull background loses to a smaller vivid subject — which is what the
* eye picks out of a sleeve. Each wash is then pushed to a fixed saturation and
* a mid lightness: the backdrop should carry the art's HUES, never its
* brightness, or a white sleeve would wash the whole app out.
*/
function palette(data: Uint8ClampedArray): { washes: string[]; hue: number } | null {
const BINS = 12
const weight = new Float64Array(BINS)
const sumX = new Float64Array(BINS) // hue averaged as a vector, so 350° + 10° = 0°
const sumY = new Float64Array(BINS)
let colourful = 0
let total = 0
for (let i = 0; i < data.length; i += 4) {
if (data[i + 3] < 128) continue
total++
const [h, s, l] = rgbToHsl(data[i] / 255, data[i + 1] / 255, data[i + 2] / 255)
const vivid = s * (1 - Math.abs(2 * l - 1))
if (vivid < 0.12) continue
colourful++
const bin = Math.floor(h / (360 / BINS)) % BINS
const w = vivid * vivid
weight[bin] += w
sumX[bin] += Math.cos((h * Math.PI) / 180) * w
sumY[bin] += Math.sin((h * Math.PI) / 180) * w
}
if (!total || colourful / total < MIN_COLOURFUL) return null
const ranked = Array.from({ length: BINS }, (_, i) => i)
.filter((i) => weight[i] > 0)
.sort((a, b) => weight[b] - weight[a])
const hues = ranked.map((i) => {
const deg = (Math.atan2(sumY[i], sumX[i]) * 180) / Math.PI
return (deg + 360) % 360
})
// Fewer than four distinct hues (a duotone sleeve): rotate the strongest ones
// slightly so the washes still move against each other instead of merging.
while (hues.length < 4) hues.push((hues[0] + 28 * hues.length) % 360)
const lightness = [52, 50, 46, 40]
const washes = hues.slice(0, 4).map((h, i) => `hsl(${h.toFixed(0)} 78% ${lightness[i]}%)`)
return { washes, hue: hues[0] }
}
let generation = 0
/**
* Recolour the app from a cover-art URL (or reset it with null). Failures are
* silent — a track without art, or art that cannot be decoded, keeps the
* default look rather than surfacing an error for decoration.
*
* The image is fetched as a blob and decoded with createImageBitmap rather than
* drawn from an <img>: the API is cross-origin under Tauri, and a cross-origin
* <img> would taint the canvas and make its pixels unreadable.
*/
export async function setAmbientFromArt(url: string | null): Promise<void> {
const mine = ++generation
if (!url) {
resetAmbient()
return
}
try {
const resp = await fetch(url)
if (!resp.ok) throw new Error(String(resp.status))
const bitmap = await createImageBitmap(await resp.blob(), {
resizeWidth: 40,
resizeHeight: 40,
resizeQuality: 'low',
})
const canvas = document.createElement('canvas')
canvas.width = 40
canvas.height = 40
const ctx = canvas.getContext('2d', { willReadFrequently: true })!
ctx.drawImage(bitmap, 0, 0)
bitmap.close()
const found = palette(ctx.getImageData(0, 0, 40, 40).data)
if (mine !== generation) return // a newer track was loaded meanwhile
if (found) apply(found.washes, found.hue)
else resetAmbient()
} catch {
if (mine === generation) resetAmbient()
}
}
+112 -51
View File
@@ -3,13 +3,13 @@ import { BEATS_PER_BAR, type BeatGrid } from './beatgrid'
// Fallback colour by cue type, used when the platform stored none.
const TYPE_COLORS: Record<CueType, string> = {
cue: '#3b82f6', // blue
fade_in: '#ff8c2f', // orange
fade_out: '#ff8c2f', // orange
load: '#ffd60a', // yellow
loop: '#22c55e', // green
cue: '#4d94ff', // blue
fade_in: '#ff9a3d', // orange
fade_out: '#ff9a3d', // orange
load: '#ffd23d', // yellow
loop: '#3ddc84', // green
}
const MEMORY_COLOR = '#8b93a3' // gray
const MEMORY_COLOR = '#9aa1b2' // gray
export const CUE_TYPE_LABELS: Record<CueType, string> = {
cue: 'Cue',
@@ -53,7 +53,7 @@ export function cueGlyph(cue: CuePoint): string {
return TYPE_GLYPHS[cue.type] ?? ''
}
function withAlpha(hex: string, a: number): string {
export function withAlpha(hex: string, a: number): string {
const r = parseInt(hex.slice(1, 3), 16)
const g = parseInt(hex.slice(3, 5), 16)
const b = parseInt(hex.slice(5, 7), 16)
@@ -70,8 +70,13 @@ export function contrastText(hex: string): string {
/**
* Draw cue/loop markers onto a canvas. `timeToX` maps a time (seconds) to a
* device-pixel x. With `labels`, a small numbered flag is drawn at the top for
* hotcues (used on the main waveform); the overview passes labels=false.
* device-pixel x. With `labels`, a rounded flag is drawn at the top for each
* cue carrying its slot label — and its name, where the cue has one (used on
* the main waveform); the overview passes labels=false.
*
* Lines glow in their own colour rather than sitting on a black outline: on the
* glass deck a dark outline reads as a gap in the waveform, where a glow reads
* as the line being lit.
*/
export function drawCues(
ctx: CanvasRenderingContext2D,
@@ -85,10 +90,13 @@ export function drawCues(
slotLabel: (slot: number) => string = (slot) => String(slot + 1),
): void {
const lineW = Math.max(2, Math.round(2 * dpr))
const outline = Math.max(1, Math.round(dpr))
const flagW = Math.round(12 * dpr)
const flagH = Math.round(14 * dpr)
const half = Math.floor(lineW / 2)
const tabH = Math.round(17 * dpr)
const pad = Math.round(6 * dpr)
const radius = Math.round(8 * dpr)
const inset = Math.round(5 * dpr)
ctx.font = `600 ${Math.round(11 * dpr)}px 'Geist Variable', system-ui, sans-serif`
ctx.textBaseline = 'middle'
for (const cue of cues) {
const color = cueColor(cue)
const x = Math.round(timeToX(cue.start))
@@ -97,43 +105,50 @@ export function drawCues(
if (cue.length > 0) {
const x2 = Math.round(timeToX(cue.start + cue.length))
if (x2 > 0 && x < w) {
ctx.fillStyle = withAlpha(color, 0.2)
ctx.fillStyle = withAlpha(color, 0.16)
ctx.fillRect(x, 0, Math.max(1, x2 - x), h)
}
}
if (x < -flagW || x > w + flagW) continue
// A flag can extend well to the right of its line; keep drawing while any
// of it could be on screen.
if (x < -w || x > w + lineW) continue
// Dark outline behind the line so it reads on any waveform colour.
ctx.fillStyle = 'rgba(0,0,0,0.7)'
ctx.fillRect(x - half - outline, 0, lineW + outline * 2, h)
ctx.save()
ctx.shadowColor = color
ctx.shadowBlur = 10 * dpr
ctx.fillStyle = color
ctx.fillRect(x - half, 0, lineW, h)
ctx.restore()
if (labels) {
// A flag tab at the top for every cue (outlined). A banked cue carries its
// slot label; one without a slot (a memory cue) gets a half-height tab, so
// it still reads as a real object rather than an anonymous line.
// A banked cue's flag carries its slot label (plus its name when it has
// a meaningful one); a cue without a slot (a memory cue) gets a short,
// unlabelled flag, so it still reads as a real object rather than an
// anonymous line.
const banked = cue.slot != null
const tabH = banked ? flagH : Math.round(flagH / 2)
ctx.fillStyle = 'rgba(0,0,0,0.7)'
ctx.fillRect(x - half - outline, 0, flagW + outline * 2, tabH + outline * 2)
ctx.fillStyle = color
ctx.fillRect(x - half, 0, flagW, tabH)
if (banked) {
const slotText = banked ? slotLabel(cue.slot!) : ''
const name = cue.name && cue.name !== 'n.n.' ? cue.name : ''
const text = slotText && name ? `${slotText} ${name}` : slotText
const tw = text ? Math.ceil(ctx.measureText(text).width) : 0
const fw = text ? tw + pad * 2 : Math.round(8 * dpr)
const fh = banked ? tabH : Math.round(tabH / 2)
ctx.fillStyle = withAlpha(color, 0.9)
ctx.beginPath()
ctx.roundRect(x - half, inset, fw, fh, [0, radius, radius, 0])
ctx.fill()
if (text) {
ctx.fillStyle = contrastText(color)
ctx.font = `bold ${Math.round(10 * dpr)}px system-ui, sans-serif`
ctx.textBaseline = 'top'
ctx.fillText(slotLabel(cue.slot!), x - half + Math.round(2 * dpr), Math.round(2 * dpr))
ctx.fillText(text, x - half + pad, inset + fh / 2 + dpr * 0.5)
}
}
}
}
/**
* Draw the floating "CUE" point: a gold vertical line with a dark outline and a
* solid downward triangle tab at the top, distinct from numbered hotcue flags,
* the white beatgrid, and the red playhead.
* Draw the floating "CUE" point: a gold vertical line with a solid downward
* triangle tab at the top, distinct from hotcue flags, the white beatgrid, and
* the red playhead.
*/
export function drawCuePoint(
ctx: CanvasRenderingContext2D,
@@ -143,11 +158,11 @@ export function drawCuePoint(
): void {
const lw = Math.max(2, Math.round(2 * dpr))
const half = Math.floor(lw / 2)
const outline = Math.max(1, Math.round(dpr))
const tab = Math.round(8 * dpr)
ctx.fillStyle = 'rgba(0,0,0,0.6)'
ctx.fillRect(x - half - outline, 0, lw + outline * 2, h)
ctx.fillStyle = '#ffb020'
const tab = Math.round(7 * dpr)
ctx.save()
ctx.shadowColor = '#ffc861'
ctx.shadowBlur = 10 * dpr
ctx.fillStyle = '#ffc861'
ctx.fillRect(x - half, 0, lw, h)
ctx.beginPath()
ctx.moveTo(x - tab, 0)
@@ -155,9 +170,10 @@ export function drawCuePoint(
ctx.lineTo(x, tab)
ctx.closePath()
ctx.fill()
ctx.restore()
}
/** Draw the active loop region: a translucent green band with bright edges. */
/** Draw the active loop region: a green band, brightest at the top, with lit edges. */
export function drawLoop(
ctx: CanvasRenderingContext2D,
startX: number,
@@ -165,18 +181,62 @@ export function drawLoop(
h: number,
dpr: number,
): void {
const edge = Math.max(1, Math.round(2 * dpr))
ctx.fillStyle = 'rgba(34,197,94,0.18)'
const edge = Math.max(1, Math.round(1.5 * dpr))
const band = ctx.createLinearGradient(0, 0, 0, h)
band.addColorStop(0, 'rgba(61,220,132,0.22)')
band.addColorStop(1, 'rgba(61,220,132,0.08)')
ctx.fillStyle = band
ctx.fillRect(startX, 0, Math.max(1, endX - startX), h)
ctx.fillStyle = 'rgba(34,197,94,0.95)'
ctx.save()
ctx.shadowColor = '#3ddc84'
ctx.shadowBlur = 8 * dpr
ctx.fillStyle = 'rgba(61,220,132,0.9)'
ctx.fillRect(startX, 0, edge, h)
ctx.fillRect(endX - edge, 0, edge, h)
ctx.restore()
}
/**
* The main waveform's fixed centre playhead: a red line with a soft red glow
* and inward-pointing caps top and bottom that anchor the eye in the quiet
* margins. Shared with the overview so the two can never drift apart in look.
*/
export function drawPlayhead(
ctx: CanvasRenderingContext2D,
x: number,
h: number,
dpr: number,
caps: boolean,
): void {
const core = Math.max(2, Math.round(2 * dpr))
const px = x - Math.floor(core / 2)
ctx.save()
ctx.shadowColor = '#ff4d5e'
ctx.shadowBlur = 12 * dpr
ctx.fillStyle = '#ff4d5e'
ctx.fillRect(px, 0, core, h)
if (caps) {
const cap = Math.round(6 * dpr)
ctx.beginPath()
ctx.moveTo(x - cap, 0)
ctx.lineTo(x + cap, 0)
ctx.lineTo(x, cap)
ctx.closePath()
ctx.fill()
ctx.beginPath()
ctx.moveTo(x - cap, h)
ctx.lineTo(x + cap, h)
ctx.lineTo(x, h - cap)
ctx.closePath()
ctx.fill()
}
ctx.restore()
}
/** Grid marker line colours. Markers are structural, so they are never culled
* by the density check the way ordinary beat lines are. */
export const GRID_MARKER_COLOR = '#4f8cff' // accent — an inactive marker
export const GRID_MARKER_ACTIVE_COLOR = '#ffb020' // gold — governs the playhead
export const GRID_MARKER_COLOR = '#9fb0ff' // periwinkle — an inactive marker
export const GRID_MARKER_ACTIVE_COLOR = '#ffc861' // gold — governs the playhead
/**
* Draw the beatgrid across the visible window [startSec, endSec].
@@ -199,7 +259,6 @@ export function drawBeatgrid(
if (endSec <= startSec) return
const span = endSec - startSec
const toX = (t: number) => Math.round(((t - startSec) / span) * w)
const outline = Math.max(1, Math.round(dpr))
const beatW = Math.max(1, Math.round(dpr))
const barW = Math.max(2, Math.round(2 * dpr))
@@ -210,7 +269,7 @@ export function drawBeatgrid(
if (seg && seg.start < endSec && seg.end > startSec) {
const x1 = toX(Math.max(seg.start, startSec))
const x2 = toX(Math.min(seg.end, endSec))
ctx.fillStyle = 'rgba(255,176,32,0.07)'
ctx.fillStyle = 'rgba(255,200,97,0.07)'
ctx.fillRect(x1, 0, Math.max(1, x2 - x1), h)
}
}
@@ -233,10 +292,10 @@ export function drawBeatgrid(
if (bt < startSec || bt > endSec) continue
const x = toX(bt)
const lw = downbeat ? barW : beatW
// Dark outline so the line reads on any waveform colour, then a bright line.
ctx.fillStyle = 'rgba(0,0,0,0.6)'
ctx.fillRect(x - Math.floor(lw / 2) - outline, 0, lw + outline * 2, h)
ctx.fillStyle = downbeat ? 'rgba(255,255,255,0.95)' : 'rgba(255,255,255,0.65)'
// Translucent white with no outline: the grid should read as a ruler laid
// over the waveform, not bars cut through it. Downbeats are clearly
// brighter, which is what grid editing needs to see.
ctx.fillStyle = downbeat ? 'rgba(255,255,255,0.62)' : 'rgba(255,255,255,0.26)'
ctx.fillRect(x - Math.floor(lw / 2), 0, lw, h)
}
}
@@ -248,8 +307,9 @@ export function drawBeatgrid(
const color = active ? GRID_MARKER_ACTIVE_COLOR : GRID_MARKER_COLOR
const lw = Math.max(2, Math.round((active ? 3 : 2) * dpr))
const x = toX(grid.markers[i].start)
ctx.fillStyle = 'rgba(0,0,0,0.6)'
ctx.fillRect(x - Math.floor(lw / 2) - outline, 0, lw + outline * 2, h)
ctx.save()
ctx.shadowColor = color
ctx.shadowBlur = 10 * dpr
ctx.fillStyle = color
ctx.fillRect(x - Math.floor(lw / 2), 0, lw, h)
const tab = Math.round(7 * dpr)
@@ -259,5 +319,6 @@ export function drawBeatgrid(
ctx.lineTo(x - tab, h)
ctx.closePath()
ctx.fill()
ctx.restore()
}
}
+2 -1
View File
@@ -21,5 +21,6 @@ export function formatBpm(bpm: number | null): string {
*/
export function keyColor(wheel: number | null): string | undefined {
if (wheel == null) return undefined
return `hsl(${((wheel % 12) / 12) * 360} 65% 62%)`
// Light and saturated: it is drawn as text on a tint of itself, on glass.
return `hsl(${((wheel % 12) / 12) * 360} 90% 76%)`
}
+118
View File
@@ -0,0 +1,118 @@
// Line icons for the glass UI: one stroke weight, one grid (24), coloured by
// `currentColor`, so an icon takes its button's text colour and hover state.
// Emoji render in the OS's own colour and style, which clashes with glass.
const PATHS = {
play: <path d="M8 5.5v13a1 1 0 0 0 1.5.86l10.5-6.5a1 1 0 0 0 0-1.72L9.5 4.64A1 1 0 0 0 8 5.5z" fill="currentColor" stroke="none" />,
pause: (
<>
<rect x="6" y="5" width="4" height="14" rx="1.2" fill="currentColor" stroke="none" />
<rect x="14" y="5" width="4" height="14" rx="1.2" fill="currentColor" stroke="none" />
</>
),
trash: <path d="M4 7h16M10 11v6M14 11v6M6 7l1 12a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-12M9 7V4h6v3" />,
lock: (
<>
<rect x="5" y="11" width="14" height="9" rx="2" />
<path d="M8 11V8a4 4 0 0 1 8 0v3" />
</>
),
unlock: (
<>
<rect x="5" y="11" width="14" height="9" rx="2" />
<path d="M8 11V8a4 4 0 0 1 7.7-1.5" />
</>
),
sparkle: <path d="M12 3l1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8zM19 16l.7 1.8 1.8.7-1.8.7L19 21l-.7-1.8-1.8-.7 1.8-.7z" strokeLinejoin="round" />,
wave: <path d="M3 12h2M7 8v8M11 5v14M15 9v6M19 11v2" />,
folder: <path d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z" strokeLinejoin="round" />,
folderOpen: <path d="M3 7a2 2 0 0 1 2-2h4l2 2h6a2 2 0 0 1 2 2v1M3 7v10a2 2 0 0 0 2 2h12.5a2 2 0 0 0 1.9-1.4L21 12a1 1 0 0 0-1-1.3H8.5a2 2 0 0 0-1.9 1.4L4 19" strokeLinejoin="round" />,
playlist: <path d="M8 6h13M8 12h13M8 18h13M3.5 6h.01M3.5 12h.01M3.5 18h.01" />,
smart: <path d="M4 5h16l-6 7.5V19l-4-2v-4.5z" strokeLinejoin="round" />,
music: (
<>
<path d="M9 18V6l11-2v12" />
<circle cx="6.5" cy="18" r="2.5" />
<circle cx="17.5" cy="16" r="2.5" />
</>
),
drive: (
<>
<rect x="3" y="7" width="18" height="10" rx="2" />
<path d="M7 12h.01M11 12h.01" />
</>
),
export: <path d="M12 3v12M7 8l5-5 5 5M5 15v4a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-4" />,
download: <path d="M12 3v12M7 10l5 5 5-5M5 19h14" />,
settings: (
<>
<path d="M4 6h10M18 6h2M4 12h4M12 12h8M4 18h12" />
<circle cx="16" cy="6" r="2" />
<circle cx="10" cy="12" r="2" />
<circle cx="18" cy="18" r="2" />
</>
),
search: (
<>
<circle cx="11" cy="11" r="7" />
<path d="M20 20l-3.5-3.5" />
</>
),
close: <path d="M6 6l12 12M18 6L6 18" />,
check: <path d="M5 12.5l4.5 4.5L19 7.5" strokeLinejoin="round" />,
chevronRight: <path d="M9 6l6 6-6 6" />,
chevronDown: <path d="M6 9l6 6 6-6" />,
chevronLeft: <path d="M15 6l-6 6 6 6" />,
chevronUp: <path d="M6 15l6-6 6 6" />,
switch: <path d="M8 9l4-4 4 4M8 15l4 4 4-4" />,
history: (
<>
<path d="M3 12a9 9 0 1 0 3-6.7L3 8" />
<path d="M3 3v5h5M12 7v5l3 2" />
</>
),
import: <path d="M12 3v12M7 10l5 5 5-5M4 15v4a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-4" />,
link: <path d="M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1" />,
warning: <path d="M12 4l9 16H3zM12 10v4M12 17h.01" strokeLinejoin="round" />,
loop: <path d="M17 2l3 3-3 3M4 11V9a4 4 0 0 1 4-4h12M7 22l-3-3 3-3M20 13v2a4 4 0 0 1-4 4H4" />,
home: <path d="M4 11l8-7 8 7v8a1 1 0 0 1-1 1h-4v-6h-6v6H5a1 1 0 0 1-1-1z" strokeLinejoin="round" />,
file: <path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8zM14 3v5h5" strokeLinejoin="round" />,
desktop: (
<>
<rect x="3" y="4" width="18" height="12" rx="2" />
<path d="M8 20h8M12 16v4" />
</>
),
pencil: <path d="M4 20h4L19 9l-4-4L4 16zM13.5 6.5l4 4" strokeLinejoin="round" />,
plus: <path d="M12 5v14M5 12h14" />,
} as const
export type IconName = keyof typeof PATHS
export function Icon({
name,
size = 16,
className,
strokeWidth = 1.8,
}: {
name: IconName
size?: number
className?: string
strokeWidth?: number
}) {
return (
<svg
width={size}
height={size}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth={strokeWidth}
strokeLinecap="round"
aria-hidden
className={className}
>
{PATHS[name]}
</svg>
)
}
+39 -20
View File
@@ -16,6 +16,7 @@ import {
} from '@tanstack/react-table'
import type { Track } from '../api'
import { formatBpm, formatDuration, keyColor } from './format'
import { cueTypeColor } from './cues'
import { RatingStars } from '../components/RatingStars'
declare module '@tanstack/react-table' {
@@ -75,7 +76,7 @@ function InlineEdit({
}}
onClick={(e) => e.stopPropagation()}
onDoubleClick={(e) => e.stopPropagation()}
className="w-full min-w-0 rounded bg-ink-800 px-1 py-0.5 text-sm text-text outline-none ring-1 ring-accent"
className="w-full min-w-0 rounded-md bg-well px-1 py-0.5 text-sm text-text outline-none ring-1 ring-accent"
/>
)
}
@@ -134,7 +135,7 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
<InlineEdit
value={title}
display={title || <span className="text-faint">Untitled</span>}
className="w-full min-w-0 truncate font-medium text-text"
className="w-full min-w-0 truncate font-medium text-text group-data-[active]:text-accent"
readOnly={!canEdit(c, 'title')}
onCommit={(v) => edit?.(r, 'title', v)}
/>
@@ -182,7 +183,7 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
id: 'bpm',
header: 'BPM',
size: 74,
cell: (c) => <span className="tabular-nums text-text">{formatBpm(c.getValue())}</span>,
cell: (c) => <span className="font-mono text-xs text-text">{formatBpm(c.getValue())}</span>,
}),
col.accessor('key', {
id: 'key',
@@ -193,10 +194,11 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
if (!k) return <span className="text-faint">—</span>
return (
<span
className="rounded px-1.5 py-0.5 text-xs font-semibold"
className="inline-block min-w-[2.1rem] rounded-md px-1.5 py-0.5 text-center font-mono text-[11px] font-semibold"
style={{
color: keyColor(c.row.original.key_wheel),
background: 'color-mix(in srgb, currentColor 14%, transparent)',
background: 'color-mix(in srgb, currentColor 16%, transparent)',
boxShadow: 'inset 0 0 0 1px color-mix(in srgb, currentColor 32%, transparent)',
}}
>
{k}
@@ -225,7 +227,7 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
id: 'length',
header: 'Time',
size: 64,
cell: (c) => <span className="tabular-nums text-muted">{formatDuration(c.getValue())}</span>,
cell: (c) => <span className="font-mono text-xs text-muted">{formatDuration(c.getValue())}</span>,
}),
col.accessor('bitrate', {
id: 'bitrate',
@@ -243,21 +245,38 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
col.accessor('cue_count', {
id: 'cue_count',
header: 'Cues',
size: 72,
size: 104,
cell: (c) => {
const n = c.getValue()
const markers = c.row.original.grid_marker_count
// Gold marks a flexible (multi-tempo) grid, mint an ordinary constant one.
const r = c.row.original
const n = c.getValue() as number
const markers = r.grid_marker_count
// One lit dot per occupied hotcue slot, in the cue's colour, so a row
// previews the track's prep without loading it. Cues that exist but are
// not in the bank (memory cues), or not yet read (a lazily-parsed
// device), fall back to the count so a prepped track never looks bare.
return (
<span className="flex items-center gap-1 tabular-nums">
<span className={n > 0 ? 'text-text' : 'text-faint'}>{n}</span>
{markers > 0 && (
<span
className={markers > 1 ? 'text-[10px] text-gold' : 'text-[10px] text-mint'}
title={markers > 1 ? `Flexible beatgrid (${markers} markers)` : 'Beatgrid analyzed'}
>
⊞
</span>
<span
className="flex items-center gap-1"
title={`${n} cue${n === 1 ? '' : 's'}${
markers > 1 ? ` · flexible beatgrid (${markers} markers)` : markers ? ' · beatgrid analyzed' : ''
}`}
>
{r.hotcues.map((h) => {
const color = h.color ?? cueTypeColor(h.type)
return (
<span
key={h.slot}
className="h-2 w-2 shrink-0 rounded-full"
style={{ background: color, boxShadow: `0 0 6px ${color}` }}
/>
)
})}
{r.hotcues.length === 0 && (
<span className={`font-mono text-xs ${n > 0 ? 'text-text' : 'text-faint'}`}>{n || '—'}</span>
)}
{markers > 1 && (
// Gold marks a flexible (multi-tempo) grid — rare, and worth seeing.
<span className="ml-0.5 text-[10px] text-gold">⊞</span>
)}
</span>
)
@@ -267,7 +286,7 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
id: 'playcount',
header: 'Plays',
size: 68,
cell: (c) => <span className="tabular-nums text-muted">{c.getValue() || 0}</span>,
cell: (c) => <span className="font-mono text-xs text-muted">{c.getValue() || 0}</span>,
}),
col.accessor('import_date', {
id: 'import_date',
+92 -67
View File
@@ -1,39 +1,56 @@
// Frequency-colored waveform analysis (Traktor "Spectrum" theme).
// Frequency waveform analysis + painting.
//
// The audio is downmixed to mono and split into three frequency bands with
// native BiquadFilters (via OfflineAudioContext — fast, off the main thread).
// Per output column we keep each band's RMS energy plus the amplitude peak.
// Each band is mapped to a target colour on Traktor's warm→cool ramp
// (bass→orange, mids→violet, highs→cyan) and the three are blended by energy;
// height = amplitude. Traktor's palette has NO green — mapping bands straight
// to R/G/B (the naive approach) produces yellows/greens it never shows, so we
// blend named palette colours instead. Tune the three constants below.
// Per output column we keep each band's RMS energy, normalised to that band's
// loudest moment in the track.
//
// Painting draws the three bands as LAYERS rather than blending them into one
// colour per column: bass (orange) is drawn first and tallest, then mids
// (violet) and highs (cyan) on top with a screen blend, so where bands overlap
// they mix into light. A kick reads as an orange flare, a hat as a cyan tick,
// and the structure of a track — where the bass drops out, where the highs
// build — is visible at a glance. Still no green, matching Traktor's palette.
export interface WaveColumn {
peak: number // 0..1 amplitude (column height)
r: number // 0..1 final blended colour (already contrast-boosted)
g: number
b: number
peak: number // 0..1 amplitude of the full mix
low: number // 0..1 band energies, each normalised to its own maximum
mid: number
high: number
}
// Band crossover choices. Independent filters, so band energies don't strictly
// partition — that's fine, colour is normalised per column.
// partition — that's fine, each band is normalised on its own.
const LOW_HZ = 250
const MID_HZ = 1200
const MID_Q = 0.6
const HIGH_HZ = 5000
// Target colour per band on Traktor's ramp (0..1 RGB). Blended by band energy.
const LOW_COL = [1.0, 0.30, 0.15] // bass → orange-red
const MID_COL = [0.65, 0.18, 0.95] // mids → violet / magenta
const HIGH_COL = [0.15, 0.65, 1.0] // highs → cyan-blue
// Each layer's colour and its height relative to the waveform's half-height.
// Bass is the envelope; mids and highs sit inside it so all three stay visible.
const LAYERS: { band: 'low' | 'mid' | 'high'; color: string; scale: number; blend: GlobalCompositeOperation }[] = [
{ band: 'low', color: 'rgba(255,138,61,0.95)', scale: 0.96, blend: 'source-over' },
{ band: 'mid', color: 'rgba(143,107,255,0.8)', scale: 0.66, blend: 'screen' },
{ band: 'high', color: 'rgba(94,231,255,0.85)', scale: 0.46, blend: 'screen' },
]
export interface PaintOptions {
/** Bar width and the gap after it, in DEVICE pixels. A gap of 0 paints a
* solid waveform (the overview); a gap gives the main view its bar texture. */
bar: number
gap: number
}
/**
* Paint a slice of the analysed columns across a canvas: source columns in the
* fractional range [startFrac, endFrac) (of the whole track) are mapped across
* the full canvas width, aggregating multiple columns per pixel (max peak,
* averaged colour). Fractions outside [0,1] paint blank — used by the scrolling
* main view so the lead-in/lead-out past the track edges stays empty.
* the full canvas width. Fractions outside [0,1] paint blank — used by the
* scrolling main view so the lead-in/lead-out past the track edges stays empty.
*
* Bars are binned in TRACK space, not screen space: bar k always covers the
* same columns of audio, and only its x moves as the view scrolls. Binning by
* screen pixel instead makes every bar's height flicker as the playhead
* advances, because each frame regroups different columns under each bar.
*/
export function paintWave(
ctx: CanvasRenderingContext2D,
@@ -42,38 +59,38 @@ export function paintWave(
h: number,
startFrac: number,
endFrac: number,
opts: PaintOptions = { bar: 1, gap: 0 },
): void {
const n = cols.length
if (n === 0 || w === 0 || h === 0) return
if (n === 0 || w === 0 || h === 0 || endFrac <= startFrac) return
const mid = h / 2
const span = (endFrac - startFrac) * n
for (let x = 0; x < w; x++) {
const c0 = startFrac * n + (x / w) * span
const c1 = startFrac * n + ((x + 1) / w) * span
const i0 = Math.floor(c0)
const i1 = Math.max(i0 + 1, Math.ceil(c1))
let peak = 0
let r = 0
let g = 0
let b = 0
let count = 0
for (let i = i0; i < i1; i++) {
if (i < 0 || i >= n) continue
const col = cols[i]
if (col.peak > peak) peak = col.peak
r += col.r
g += col.g
b += col.b
count++
const colsPerPx = ((endFrac - startFrac) * n) / w
const step = opts.bar + opts.gap
const colsPerBar = step * colsPerPx
const startCol = startFrac * n
const k0 = Math.floor(Math.max(0, startCol) / colsPerBar)
const k1 = Math.ceil(Math.min(n, endFrac * n) / colsPerBar)
const prevOp = ctx.globalCompositeOperation
for (const layer of LAYERS) {
ctx.globalCompositeOperation = layer.blend
ctx.fillStyle = layer.color
const reach = (mid - 1) * layer.scale
for (let k = k0; k < k1; k++) {
const c0 = k * colsPerBar
const i0 = Math.max(0, Math.floor(c0))
const i1 = Math.min(n, Math.max(i0 + 1, Math.ceil(c0 + colsPerBar)))
let v = 0
for (let i = i0; i < i1; i++) {
const e = cols[i][layer.band]
if (e > v) v = e
}
if (v <= 0) continue
const x = (c0 - startCol) / colsPerPx
const half = Math.max(0.5, v * reach)
ctx.fillRect(x, mid - half, opts.bar, half * 2)
}
if (count === 0) continue // outside the track → blank pixel
r /= count
g /= count
b /= count
const half = Math.max(0.5, peak * (mid - 1))
ctx.fillStyle = `rgb(${(r * 255) | 0},${(g * 255) | 0},${(b * 255) | 0})`
ctx.fillRect(x, mid - half, 1, half * 2)
}
ctx.globalCompositeOperation = prevOp
}
export interface WaveformAnalysis {
@@ -162,32 +179,40 @@ export async function analyzeWaveform(url: string, buckets?: number): Promise<Wa
await accumBand(midE, 'bandpass', MID_HZ, MID_Q)
await accumBand(highE, 'highpass', HIGH_HZ)
// Per-band normalisation, to the band's 99.5th-percentile column rather than
// its single loudest (one clipped transient would otherwise shrink the whole
// band). Each band then gets an EXPANDING curve: dance music keeps its bass
// near full scale for whole sections, so a linear (or compressing) map draws
// a solid wall where the eye wants to see the kick pulse. The bass curve is
// steepest, since it carries the rhythm; highs stay near linear so hats and
// risers keep their detail.
const rms = (e: Float64Array) => {
const out = new Float64Array(e.length)
for (let b = 0; b < e.length; b++) out[b] = Math.sqrt(e[b] / (cnt[b] || 1))
return out
}
const ceiling = (v: Float64Array) => {
const sorted = Float64Array.from(v).sort()
return Math.max(1e-9, sorted[Math.floor((sorted.length - 1) * 0.995)])
}
const lowR = rms(lowE)
const midR = rms(midE)
const highR = rms(highE)
const maxL = ceiling(lowR)
const maxM = ceiling(midR)
const maxH = ceiling(highR)
let maxPeak = 1e-6
for (let b = 0; b < buckets; b++) if (peak[b] > maxPeak) maxPeak = peak[b]
const curve = (v: number, k: number) => Math.pow(Math.min(1, v), k)
const cols: WaveColumn[] = new Array(buckets)
for (let b = 0; b < buckets; b++) {
const n = cnt[b] || 1
const l = Math.sqrt(lowE[b] / n)
const m = Math.sqrt(midE[b] / n)
const h = Math.sqrt(highE[b] / n)
// Normalise to the dominant band so colours stay vivid (brightness is not
// tied to loudness — amplitude is shown by height, like Traktor). Gamma
// sharpens the separation between bands.
const mx = Math.max(l, m, h, 1e-9)
const wl = Math.pow(l / mx, 1.3)
const wm = Math.pow(m / mx, 1.3)
const wh = Math.pow(h / mx, 1.3)
// Blend the three band palette colours by weight, then normalise to the
// brightest channel so the colour stays vivid (height carries loudness).
let cr = wl * LOW_COL[0] + wm * MID_COL[0] + wh * HIGH_COL[0]
let cg = wl * LOW_COL[1] + wm * MID_COL[1] + wh * HIGH_COL[1]
let cb = wl * LOW_COL[2] + wm * MID_COL[2] + wh * HIGH_COL[2]
const cmax = Math.max(cr, cg, cb, 1e-9)
cr /= cmax
cg /= cmax
cb /= cmax
cols[b] = { peak: peak[b] / maxPeak, r: cr, g: cg, b: cb }
cols[b] = {
peak: peak[b] / maxPeak,
low: curve(lowR[b] / maxL, 1.8),
mid: curve(midR[b] / maxM, 1.3),
high: curve(highR[b] / maxH, 1.05),
}
}
return { cols, buffer: audio }
}