Beat jumping can now be done outside of the song range

This commit is contained in:
patben8 committed 2026-11-03 11:59:50 +01:00
1 parent 2a40106ea5
commit 5d1bfcf7f1
9 files changed
+126 -10

No files matched your search

+8 -1
View File
@@ -1395,7 +1395,14 @@ Two independent apps that talk over HTTP:
badge, with the `autoFocusDeck` setting off); a load, Enter, a row's play button and a drop on the strip badge, with the `autoFocusDeck` setting off); a load, Enter, a row's play button and a drop on the strip
go to the FOCUSED deck (A outside the mode), "Load to Deck A/B" to either, go to the FOCUSED deck (A outside the mode), "Load to Deck A/B" to either,
and the table lights the focused deck's row. Entering with B empty focuses and the table lights the focused deck's row. Entering with B empty focuses
B. B's `useDeck` stays MOUNTED while hidden — leaving pauses it, coming B. **Past the edges** (decided 2026-11-03): in performance mode a beat
jump or loop move may land BEFORE the track — the engine's lead-in
(`setLeadIn`, up to 32 s): silence until the track starts, on the beat,
ELAPSED counting up from −; SYNC may align into it — and a loop may reach
past the END (it loops silence). A jump past the end still stops the
deck there, as the end of a track does. Prep mode keeps both edges hard;
leaving performance mode in the lead-in snaps to 0.
B's `useDeck` stays MOUNTED while hidden — leaving pauses it, coming
back finds it as it was; a library switch empties both decks. Not back finds it as it was; a library switch empties both decks. Not
persisted. **Header**: cover, title/artist · album · genre, a Read-only persisted. **Header**: cover, title/artist · album · genre, a Read-only
badge, the readout well (ELAPSED / REMAIN to tenths, KEY, and `BpmReadout` — badge, the readout well (ELAPSED / REMAIN to tenths, KEY, and `BpmReadout` —
+5 -3
View File
@@ -9,9 +9,11 @@ import type { Deck } from './useDeck'
/** mm:ss.f — tenths by default, as a CDJ does; `places` is the /** mm:ss.f — tenths by default, as a CDJ does; `places` is the
* `timeReadoutDecimals` setting (0 drops the fraction). Truncates, never * `timeReadoutDecimals` setting (0 drops the fraction). Truncates, never
* rounds, so the readout never shows a second before it has been reached. */ * rounds, so the readout never shows a second before it has been reached.
* Before the track (performance mode's lead-in) it counts up to it: −00:01.5. */
function fmtTime(secs: number, places: number): string { function fmtTime(secs: number, places: number): string {
if (!isFinite(secs) || secs < 0) secs = 0 if (!isFinite(secs)) secs = 0
if (secs < 0) return `−${fmtTime(-secs, places)}`
const scale = 10 ** places const scale = 10 ** places
// The epsilon keeps e.g. 0.3 s from reading 0.299 at 3 places. // The epsilon keeps e.g. 0.3 s from reading 0.299 at 3 places.
const units = Math.floor(secs * scale + 1e-6) const units = Math.floor(secs * scale + 1e-6)
@@ -109,7 +111,7 @@ export function DeckHeader({
<span aria-hidden className="my-2 w-px bg-line" /> <span aria-hidden className="my-2 w-px bg-line" />
<div className={cell}> <div className={cell}>
<span className="text-[10px] tracking-[0.08em] text-faint">REMAIN</span> <span className="text-[10px] tracking-[0.08em] text-faint">REMAIN</span>
<span className={`font-mono font-medium ${compact ? 'text-[15px]' : 'text-[17px]'}`}>−{fmtTime(Math.max(0, duration - current), timeDecimals)}</span> <span className={`font-mono font-medium ${compact ? 'text-[15px]' : 'text-[17px]'}`}>−{fmtTime(Math.max(0, duration - Math.max(0, current)), timeDecimals)}</span>
</div> </div>
<span aria-hidden className="my-2 w-px bg-line" /> <span aria-hidden className="my-2 w-px bg-line" />
<div className={cell}> <div className={cell}>
+9 -1
View File
@@ -559,7 +559,9 @@ export function useDeck({
nStart = start + dir * len nStart = start + dir * len
nEnd = nStart + len nEnd = nStart + len
} }
if (nStart < 0 || nEnd > duration) return // would leave the track // Inside the track — but in performance mode a loop may sit past
// either edge (it loops silence there; decided 2026-11-03).
if (!tempoActive && (nStart < 0 || nEnd > duration)) return
// The playhead travels with the loop, keeping its place inside it. The // The playhead travels with the loop, keeping its place inside it. The
// NEW loop is set first: the engine's seek honours the loop in force, so // NEW loop is set first: the engine's seek honours the loop in force, so
// seeking first would wrap the playhead straight back into the old one. // seeking first would wrap the playhead straight back into the old one.
@@ -1221,6 +1223,12 @@ export function useDeck({
useEffect(() => { useEffect(() => {
playbackRef.current?.setKeylock(keylock) playbackRef.current?.setKeylock(keylock)
}, [keylock, ready]) }, [keylock, ready])
// Performance mode: a beat jump or loop move may land before the track
// (silence until it starts, still on the beat). Past the end a jump still
// stops the deck there, as the end of a track does (decided 2026-11-03).
useEffect(() => {
playbackRef.current?.setLeadIn(tempoActive)
}, [tempoActive, ready])
const setPitch = (p: number) => setPitchState(Math.max(-1, Math.min(1, p))) const setPitch = (p: number) => setPitchState(Math.max(-1, Math.min(1, p)))
/** An exact rate (SYNC), widening the range when the fader cannot reach it. /** An exact rate (SYNC), widening the range when the fader cannot reach it.
* Never called mid-bend: a bend releases the deck's SYNC. */ * Never called mid-bend: a bend releases the deck's SYNC. */
+57
View File
@@ -128,6 +128,57 @@ describe('DeckCore transport', () => {
}) })
}) })
describe('DeckCore lead-in (performance mode)', () => {
it('a seek before the track plays silence, then the track exactly on time', () => {
const core = new DeckCore(SR, null)
const src = ramp(SR)
core.load(src)
core.setLeadIn(true)
const lead = 2 * QUANTUM + 37
core.seek(-lead / SR)
expect(core.positionSec).toBeCloseTo(-lead / SR, 9)
core.play()
const out = run(core, 6)
for (let i = 0; i < lead - 2; i++) expect(out[i]).toBeCloseTo(0, 6)
for (let i = lead + 2; i < out.length; i++) expect(out[i]).toBeCloseTo(src.stems[0][0][i - lead], 6)
})
it('without lead-in a seek stops at the start; turning it off brings the playhead back', () => {
const core = new DeckCore(SR, null)
core.load(ramp(SR))
core.seek(-0.5)
expect(core.positionSec).toBe(0)
core.setLeadIn(true)
core.seek(-0.5)
expect(core.positionSec).toBeCloseTo(-0.5, 9)
core.setLeadIn(false)
expect(core.positionSec).toBe(0)
})
it('a loop past the end loops silence and keeps playing; released, the deck stops', () => {
const core = new DeckCore(SR, null)
const len = QUANTUM * 4
core.load(ramp(len))
core.setLeadIn(true)
core.setLoop((len - 100) / SR, (len + 200) / SR, true)
core.seek((len - 100) / SR)
core.play()
const events: string[] = []
for (let b = 0; b < 20; b++) {
run(core, 1)
events.push(...core.events)
}
expect(events).toEqual([])
expect(core.playing).toBe(true)
core.setLoop((len - 100) / SR, (len + 200) / SR, false)
for (let b = 0; b < 5; b++) {
run(core, 1)
events.push(...core.events)
}
expect(events).toEqual(['ended'])
})
})
describe('DeckCore scratch', () => { describe('DeckCore scratch', () => {
it('follows the drag, then coasts back to playing speed and plays on by itself', () => { it('follows the drag, then coasts back to playing speed and plays on by itself', () => {
const core = new DeckCore(SR, null) const core = new DeckCore(SR, null)
@@ -290,4 +341,10 @@ describe('extrapolate', () => {
const m = { pos: 9, time: 0, speed: 1, playing: true, scratching: false } const m = { pos: 9, time: 0, speed: 1, playing: true, scratching: false }
expect(extrapolate(m, 2.5, { start: 8, end: 10, on: true }, 100)).toBeCloseTo(9.5, 9) expect(extrapolate(m, 2.5, { start: 8, end: 10, on: true }, 100)).toBeCloseTo(9.5, 9)
}) })
it('runs on before the track and past its end inside a loop that reaches there', () => {
const lead = { pos: -1, time: 0, speed: 1, playing: true, scratching: false }
expect(extrapolate(lead, 0.4, { start: 0, end: 0, on: false }, 100)).toBeCloseTo(-0.6, 9)
const out = { pos: 99.5, time: 0, speed: 1, playing: true, scratching: false }
expect(extrapolate(out, 1, { start: 99, end: 101, on: true }, 100)).toBeCloseTo(100.5, 9)
})
}) })
+25 -1
View File
@@ -53,6 +53,8 @@ export const WARM_QUANTA = 10
const WARM_BUDGET = 384 const WARM_BUDGET = 384
/** Stem mute/solo ramp (s). */ /** Stem mute/solo ramp (s). */
const GAIN_TAU = 0.004 const GAIN_TAU = 0.004
/** The furthest a lead-in reaches before the track (s). */
const LEAD_IN_SEC = 32
export class DeckCore { export class DeckCore {
private stems: Float32Array[][] = [] private stems: Float32Array[][] = []
@@ -64,6 +66,9 @@ export class DeckCore {
private pos = 0 private pos = 0
private rate = 1 private rate = 1
private keylock = false private keylock = false
/** Performance mode: the playhead may sit BEFORE the track (silence until
* it starts, on the beat) — a beat jump or loop move past the start. */
private leadIn = false
private loopOn = false private loopOn = false
private loopStart = 0 private loopStart = 0
@@ -174,10 +179,29 @@ export class DeckCore {
} }
seek(sec: number): void { seek(sec: number): void {
this.pos = Math.max(0, Math.min(sec * this.srcRate, this.len)) this.pos = Math.max(this.minPos, Math.min(sec * this.srcRate, this.maxPos))
this.needRewarm = true this.needRewarm = true
} }
setLeadIn(on: boolean): void {
this.leadIn = on
if (!on && this.pos < 0) {
this.pos = 0
this.needRewarm = true
}
}
/** How far before the track the playhead may go (with lead-in), in source
* samples: far beyond any beat jump (32 beats at 60 BPM). */
private get minPos(): number {
return this.leadIn ? -LEAD_IN_SEC * this.srcRate : 0
}
/** The end, or an engaged loop's end where it reaches past the track. */
private get maxPos(): number {
return this.loopOn ? Math.max(this.len, this.loopEnd) : this.len
}
setLoop(startSec: number, endSec: number, enabled: boolean): void { setLoop(startSec: number, endSec: number, enabled: boolean): void {
const wasOn = this.loopOn const wasOn = this.loopOn
this.loopStart = startSec * this.srcRate this.loopStart = startSec * this.srcRate
+14 -1
View File
@@ -14,6 +14,9 @@ import { audioContext, loadDeckWorklet, resumeAudio } from './context'
import type { DeckCommand, DeckInbound, DeckOutbound } from './deckProcessor.worklet' import type { DeckCommand, DeckInbound, DeckOutbound } from './deckProcessor.worklet'
import { extrapolate, type Loop, type Model } from './position' import { extrapolate, type Loop, type Model } from './position'
/** As `deckCore`'s: the furthest a lead-in reaches before the track (s). */
const LEAD_IN_SEC = 32
export class DeckEngine { export class DeckEngine {
readonly output: GainNode readonly output: GainNode
private readonly ctx: AudioContext private readonly ctx: AudioContext
@@ -22,6 +25,7 @@ export class DeckEngine {
private m: Model = { pos: 0, time: 0, speed: 0, playing: false, scratching: false } private m: Model = { pos: 0, time: 0, speed: 0, playing: false, scratching: false }
private loop: Loop = { start: 0, end: 0, on: false } private loop: Loop = { start: 0, end: 0, on: false }
private rate = 1 private rate = 1
private leadIn = false
private _duration = 0 private _duration = 0
private _keylockAvailable = false private _keylockAvailable = false
private onEnded: (() => void) | null = null private onEnded: (() => void) | null = null
@@ -146,7 +150,8 @@ export class DeckEngine {
} }
seek(t: number): void { seek(t: number): void {
const sec = Math.max(0, Math.min(t, this._duration)) const end = this.loop.on ? Math.max(this._duration, this.loop.end) : this._duration
const sec = Math.max(this.leadIn ? -LEAD_IN_SEC : 0, Math.min(t, end))
this.m = { ...this.m, pos: sec, time: this.ctx.currentTime } this.m = { ...this.m, pos: sec, time: this.ctx.currentTime }
this.send({ op: 'seek', sec }) this.send({ op: 'seek', sec })
} }
@@ -176,6 +181,14 @@ export class DeckEngine {
this.send({ op: 'rate', rate }) this.send({ op: 'rate', rate })
} }
/** Performance mode: a seek may land before the track (silence until it
* starts) — and a loop may reach past its end. */
setLeadIn(on: boolean): void {
this.leadIn = on
if (!on && this.m.pos < 0) this.m = { ...this.m, pos: 0, time: this.ctx.currentTime }
this.send({ op: 'leadIn', on })
}
/** Keylock: keep the pitch while the rate changes. */ /** Keylock: keep the pitch while the rate changes. */
setKeylock(on: boolean): void { setKeylock(on: boolean): void {
this.send({ op: 'keylock', on }, false) this.send({ op: 'keylock', on }, false)
@@ -28,6 +28,7 @@ export type DeckCommand =
| { op: 'gains'; levels: number[] } | { op: 'gains'; levels: number[] }
| { op: 'rate'; rate: number } | { op: 'rate'; rate: number }
| { op: 'keylock'; on: boolean } | { op: 'keylock'; on: boolean }
| { op: 'leadIn'; on: boolean }
| { op: 'scratchBegin'; sec: number } | { op: 'scratchBegin'; sec: number }
| { op: 'scratchRegrab' } | { op: 'scratchRegrab' }
| { op: 'scratchTarget'; sec: number } | { op: 'scratchTarget'; sec: number }
@@ -109,6 +110,8 @@ class DeckProcessor extends AudioWorkletProcessor {
return core.setRate(c.rate) return core.setRate(c.rate)
case 'keylock': case 'keylock':
return core.setKeylock(c.on) return core.setKeylock(c.on)
case 'leadIn':
return core.setLeadIn(c.on)
case 'scratchBegin': case 'scratchBegin':
return core.scratchBegin(c.sec) return core.scratchBegin(c.sec)
case 'scratchRegrab': case 'scratchRegrab':
+2 -1
View File
@@ -23,5 +23,6 @@ export function extrapolate(m: Model, now: number, loop: Loop, duration: number)
if (loop.on && loop.end > loop.start && p >= loop.end && m.pos < loop.end) { if (loop.on && loop.end > loop.start && p >= loop.end && m.pos < loop.end) {
p = loop.start + ((p - loop.start) % (loop.end - loop.start)) p = loop.start + ((p - loop.start) % (loop.end - loop.start))
} }
return Math.min(p, duration) // The end — or an engaged loop's, where it reaches past the track.
return Math.min(p, loop.on ? Math.max(duration, loop.end) : duration)
} }
+3 -2
View File
@@ -65,10 +65,11 @@ export function phaseOffset(master: DeckTempo, follower: DeckTempo, octave: numb
return d return d
} }
/** The follower's playhead with its beats on the master's (the smallest move). */ /** The follower's playhead with its beats on the master's (the smallest move;
* it may fall before the track — performance mode's lead-in). */
export function alignedPosition(follower: DeckTempo, offset: number, octave: number): number { export function alignedPosition(follower: DeckTempo, offset: number, octave: number): number {
const g = follower.grid! const g = follower.grid!
return Math.max(0, g.timeOfBeat(g.beatIndexAt(follower.pos) - offset / octave)) return g.timeOfBeat(g.beatIndexAt(follower.pos) - offset / octave)
} }
/** The pitch ranges a deck offers (fraction of the tempo either way). */ /** The pitch ranges a deck offers (fraction of the tempo either way). */