Implemented normalization and auto gain export options

This commit is contained in:
patben8 committed 2026-10-19 21:20:57 +02:00
1 parent 64b0396d66
commit 4cb630d0d5
13 files changed
+677 -35

No files matched your search

+26 -3
View File
@@ -360,6 +360,8 @@ export interface PlatformOption {
computer_only?: boolean
/** As an export target: its library can store a grid lock. */
locks_grids?: boolean
/** As an export target: its library keeps the DJ app's auto gain. */
writes_auto_gain?: boolean
}
export interface EditState {
@@ -832,6 +834,12 @@ export interface ExportSet {
/** Lock every exported grid, so Traktor does not re-analyse a track when it
* is first loaded. Set from the run dialog and remembered here. */
lock_grids: boolean
/** Normalise the COPIES' audio (the sources are never touched). */
normalise: boolean
/** Write the DJ app's auto gain, where a target keeps one. */
auto_gain: boolean
/** Normalise's measure / target / ceiling; null = the app settings. */
level: NormalizeOptions | null
created: number
modified: number
}
@@ -877,6 +885,20 @@ export interface ExportPreview {
/** Targets whose library is only found at a drive's root, when the destination
* is not one. A warning — the export can still run. */
not_drive_root: string[]
/** Normalise audio: copies whose level changes, and each outcome's count. */
normalised: number
level_counts: Record<string, number>
/** Sources the run measures first (no stored loudness). */
to_measure: number
}
/** The run dialog's options; each is remembered on the set. Omitted = the
* set's own answer. */
export interface ExportRunOptions {
lock_grids?: boolean
normalise?: boolean
auto_gain?: boolean
level?: NormalizeOptions
}
export interface FsPlace {
@@ -1106,10 +1128,11 @@ export const api = {
// reason rather than hiding them — an absent option reads as a missing
// feature, a disabled one reads as a roadmap.
exportTargets: () => getJSON<PlatformOption[]>('/api/export-targets'),
exportPreview: (id: string) =>
send<ExportPreview>('POST', `/api/exports/${encodeURIComponent(id)}/preview`, {}),
// The preview takes the run dialog's options as ticked, so its counts match.
exportPreview: (id: string, body: ExportRunOptions = {}) =>
send<ExportPreview>('POST', `/api/exports/${encodeURIComponent(id)}/preview`, body),
// The run dialog's options travel with the click; the set remembers them.
runExport: (id: string, body: { lock_grids?: boolean } = {}) =>
runExport: (id: string, body: ExportRunOptions = {}) =>
send<JobStatus>('POST', `/api/exports/${encodeURIComponent(id)}/run`, body),
// ---- path remapping (per-collection OS-path prefix translation) ----
+92 -4
View File
@@ -1,8 +1,9 @@
import { createPortal } from 'react-dom'
import { useEffect, useRef, useState } from 'react'
import { useQuery, useQueryClient } from '@tanstack/react-query'
import { api, type ExportPreview, type ExportSet, type JobStatus } from '../api'
import { api, type ExportPreview, type ExportRunOptions, type ExportSet, type JobStatus, type NormalizeOptions } from '../api'
import { FolderPicker } from './FolderPicker'
import { LevelInput, useAppSetting } from './AppSettings'
/**
* Run an export: confirm what is about to happen, then watch it happen.
@@ -46,6 +47,15 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
// Remembered on the set (sent with the click), so a stick's next export
// starts from the same answer. Older sets without it read as on.
const [lockGrids, setLockGrids] = useState(set.lock_grids ?? true)
// Remembered on the set the same way (decided 2026-10-19). The level starts
// from the set's own, else Normalize's app settings.
const [normalise, setNormalise] = useState(set.normalise ?? false)
const [autoGain, setAutoGain] = useState(set.auto_gain ?? true)
const defaultMeasure = useAppSetting('levelMeasure')
const defaultTarget = useAppSetting('levelTarget')
const defaultCeiling = useAppSetting('levelCeiling')
const [level, setLevel] = useState<NormalizeOptions | null>(set.level ?? null)
const levelNow: NormalizeOptions = level ?? { measure: defaultMeasure, target: defaultTarget, ceiling: defaultCeiling }
const pollRef = useRef<number | null>(null)
// The set as last saved from here: `set` is a snapshot, and a destination
// changed in this dialog must reach the preview and the run.
@@ -60,10 +70,20 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
const lockable = set.targets.some(
(id) => platforms.data?.find((p) => p.platform === id)?.locks_grids,
)
// Only where a target keeps an auto gain — no stick format does (kit G2).
const gainTargets = set.targets.filter(
(id) => platforms.data?.find((p) => p.platform === id)?.writes_auto_gain,
)
const options: ExportRunOptions = {
...(lockable ? { lock_grids: lockGrids } : {}),
normalise,
...(gainTargets.length ? { auto_gain: autoGain } : {}),
level: levelNow,
}
const preview = useQuery<ExportPreview>({
queryKey: ['export-preview', set.id, current.destination],
queryFn: () => api.exportPreview(set.id),
queryKey: ['export-preview', set.id, current.destination, options],
queryFn: () => api.exportPreview(set.id, options),
enabled: !job,
staleTime: 0,
gcTime: 0,
@@ -124,7 +144,7 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
const start = async () => {
setStarting(true)
try {
setJob(await api.runExport(set.id, lockable ? { lock_grids: lockGrids } : {}))
setJob(await api.runExport(set.id, options))
qc.invalidateQueries({ queryKey: ['exports'] })
} catch (e) {
onError((e as Error).message)
@@ -260,6 +280,74 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
</span>
</label>
)}
<label className="flex cursor-pointer items-start gap-2.5">
<input
type="checkbox"
className="mt-0.5"
checked={normalise}
onChange={(e) => setNormalise(e.target.checked)}
/>
<span className="min-w-0 flex-1">
<span className="block text-sm text-text">Normalise audio</span>
<span className="block text-xs text-faint">
Brings every copy to one level, so the stick plays level on any player.
Your own files are never changed.
</span>
</span>
</label>
{normalise && (
<div className="ml-6 space-y-1.5 text-xs">
<div className="flex items-center justify-between gap-3">
<span className="text-muted">Level by</span>
<select
className="rounded-lg well px-2 py-1 text-xs text-text outline-none"
value={levelNow.measure}
onChange={(e) => setLevel({ ...levelNow, measure: e.target.value as 'lufs' | 'rms' })}
>
<option value="lufs">LUFS</option>
<option value="rms">RMS (loudest sections)</option>
</select>
</div>
<div className="flex items-center justify-between gap-3">
<span className="text-muted">Target</span>
<LevelInput value={levelNow.target} unit={levelNow.measure === 'lufs' ? 'LUFS' : 'dB'}
min={-30} max={0} onCommit={(v) => setLevel({ ...levelNow, target: v })} />
</div>
<div className="flex items-center justify-between gap-3">
<span className="text-muted" title="A raise stops here, so nothing clips">Peak ceiling</span>
<LevelInput value={levelNow.ceiling} unit="dBTP" min={-12} max={0}
onCommit={(v) => setLevel({ ...levelNow, ceiling: v })} />
</div>
<div className="text-faint">
{p.normalised} cop{p.normalised === 1 ? 'y changes' : 'ies change'} level
{(p.level_counts.unsupported ?? 0) > 0 &&
` · ${p.level_counts.unsupported} in a format that can’t be changed losslessly`}
{(p.level_counts.hot_peak_left ?? 0) > 0 && ` · ${p.level_counts.hot_peak_left} with a hot peak, left alone`}
</div>
</div>
)}
{gainTargets.length > 0 && (
<label className="flex cursor-pointer items-start gap-2.5">
<input
type="checkbox"
className="mt-0.5"
checked={autoGain}
onChange={(e) => setAutoGain(e.target.checked)}
/>
<span className="min-w-0">
<span className="block text-sm text-text">Auto gain</span>
<span className="block text-xs text-faint">
Sets {gainTargets.map(nameOf).join(' and ')}’s auto gain from each track’s
loudness, so tracks load at matching levels.
</span>
</span>
</label>
)}
{p.to_measure > 0 && (
<div className="text-xs text-faint">
{p.to_measure} track{p.to_measure === 1 ? ' is' : 's are'} measured first (about a second each).
</div>
)}
<div className="text-xs text-faint">
Writes a library for {set.targets.map(nameOf).join(' and ')}, sharing one copy
of every track under <span className="font-mono">Contents/</span>, in your own