Skip to content

Edge-Drop is a clipboard shelf on the edge of your screen. Hover to open it. Drag files and images into any app, click to copy text and links. Free and open-source for Windows.

feat(sound): one coherent UI sound set; smoother sliders

Deepender25803a2cd9d206
diff --git a/src/components/Settings.tsx b/src/components/Settings.tsx
index a4ca3c4..2b87da8 100644
--- a/src/components/Settings.tsx
+++ b/src/components/Settings.tsx
@@ -69,7 +69,6 @@ export function Settings({
l.code === 'system' || l.nativeName.includes('(') ? l.nativeName : `${l.nativeName} (${l.name})`
const selectedLang = languages.find((l) => l.code === (language || 'system')) || languages[0]
- const lastTickVal = useRef<number>(settings.verticalOffset ?? 0.5)
const horizontalTab = useStore((s) => s.settingsTab)
const shelfTrackRef = useRef<HTMLDivElement>(null)
const horizontalTabScrollPositions = useRef<Record<SettingsTab, number>>({
@@ -110,29 +109,22 @@ export function Settings({
return () => cancelAnimationFrame(id)
}, [isHorizontal, horizontalTab])
+ // The slider plays its own detent ticks while dragging; presets tick on click.
const handleSliderInput = (rawVal: number) => {
const clamped = Math.min(1.0, Math.max(0.0, rawVal))
- if (Math.abs(clamped - lastTickVal.current) >= 0.05) {
- lastTickVal.current = clamped
- playDialTickSound()
- }
useStore.setState((s) => ({
settings: { ...s.settings, verticalOffset: clamped }
}))
}
const handleSliderRelease = (rawVal: number) => {
- const snapped = Math.round(rawVal / 0.05) * 0.05
- const clamped = Math.min(1.0, Math.max(0.0, snapped))
- lastTickVal.current = clamped
- playDialTickSound()
+ const clamped = Math.min(1.0, Math.max(0.0, Math.round(rawVal * 100) / 100))
patch({ verticalOffset: clamped })
}
const handleThicknessInput = (rawVal: number) => {
const clamped = Math.min(7, Math.max(1, Math.round(rawVal)))
if (clamped !== (settings.hotZoneWidth ?? 3)) {
- playDialTickSound()
useStore.setState((s) => ({
settings: { ...s.settings, hotZoneWidth: clamped }
}))
@@ -142,7 +134,6 @@ export function Settings({
const handleThicknessRelease = (rawVal: number) => {
const clamped = Math.min(7, Math.max(1, Math.round(rawVal)))
setSliderActive(false)
- playDialTickSound()
patch({ hotZoneWidth: clamped })
}
@@ -155,7 +146,6 @@ export function Settings({
const handleHoverDelayInput = (rawVal: number) => {
const next = normalizeHoverOpenDelay(rawVal)
if (next !== normalizeHoverOpenDelay(useStore.getState().settings.hoverOpenDelay)) {
- playDialTickSound()
useStore.setState((s) => ({
settings: { ...s.settings, hoverOpenDelay: next }
}))
@@ -164,7 +154,6 @@ export function Settings({
const handleHoverDelayRelease = (rawVal: number) => {
setSliderActive(false)
- playDialTickSound()
patch({ hoverOpenDelay: normalizeHoverOpenDelay(rawVal) })
}
@@ -1084,7 +1073,7 @@ export function Settings({
ariaLabel={offsetIsHorizontal ? (t('position.horizontalPositionTitle') || 'Horizontal Position') : t('position.verticalPositionTitle')}
min={0}
max={1}
- step={0.002}
+ step={0.01}
bars={28}
height={28}
restHeight={8}
@@ -1123,6 +1112,7 @@ export function Settings({
type="button"
className={`slider-label-btn${active ? ' active' : ''}`}
onClick={() => {
+ playDialTickSound()
if (offsetIsHorizontal) {
patch({ horizontalOffset: pos.val })
} else {
@@ -1269,6 +1259,7 @@ export function Settings({
className={`slider-label-btn${thicknessPx === preset.val ? ' active' : ''}`}
onClick={() => {
if (thicknessPx !== preset.val) {
+ playDialTickSound()
handleThicknessRelease(preset.val)
}
}}
diff --git a/src/components/WakeSlider.tsx b/src/components/WakeSlider.tsx
index 430c63d..ec8aa7c 100644
--- a/src/components/WakeSlider.tsx
+++ b/src/components/WakeSlider.tsx
@@ -88,6 +88,7 @@ export function WakeSlider({
const barEls = useRef<(HTMLSpanElement | null)[]>([])
const crestEls = useRef<(HTMLSpanElement | null)[]>([])
const pointerId = useRef<number | null>(null)
+ const pendingX = useRef<number | null>(null)
const lastAmp = useRef(0)
const latest = useRef(value)
latest.current = value
@@ -99,12 +100,16 @@ export function WakeSlider({
const wv = 2000 / smoothing
const speed = useSpring(rawSpeed, { stiffness: wv * wv, damping: 2.5 * wv, mass: 1 })
+ // While dragging, the pointer drives `target` directly (see flushDrag); the
+ // snapped value only takes over again on release.
useEffect(() => {
- target.set(pct)
+ if (pointerId.current === null) target.set(pct)
}, [pct, target])
const paint = (force = false) => {
- const h = ((reduce ? target.get() : head.get()) / 100) * (bars - 1)
+ // Under the finger the fill tracks the pointer 1:1; the spring only drives
+ // the wake (and glides between values for clicks, keys and the release).
+ const h = ((reduce || pointerId.current !== null ? target.get() : head.get()) / 100) * (bars - 1)
const v = reduce ? 0 : speed.get()
const amp = smoothstep(clamp((Math.abs(v) * sensitivity) / FULL_SPEED, 0, 1))
const dir = Math.sign(v) || 1
@@ -141,12 +146,17 @@ export function WakeSlider({
paintRef.current(true)
})
+ // One tick per detent: every value step, but never more than one per bar,
+ // so fine-grained sliders don't buzz.
+ const detents = Math.max(1, Math.min(bars - 1, Math.round((max - min) / (step > 0 ? step : 1))))
+ const detentOf = (v: number) => Math.round((toPct(v, min, max) / 100) * detents)
+
const commit = (next: number) => {
const clean = snap(next, min, max, step)
if (clean === latest.current) return
+ if (detentOf(clean) !== detentOf(latest.current)) playDialTickSound()
latest.current = clean
if (valueProp === undefined) setInner(clean)
- playDialTickSound()
onChange?.(clean)
}
const commitFromX = (x: number) => {
@@ -156,8 +166,19 @@ export function WakeSlider({
if (!rect.width) return
let ratio = clamp((x - rect.left) / rect.width, 0, 1)
if (getComputedStyle(track).direction === 'rtl') ratio = 1 - ratio
+ target.set(ratio * 100)
+ schedule()
commit(min + ratio * (max - min))
}
+ // Pointer moves can arrive far faster than the screen refreshes (1000 Hz
+ // mice); handle only the latest one, once per frame.
+ const flushDrag = useCallback(() => {
+ const x = pendingX.current
+ pendingX.current = null
+ if (x !== null && pointerId.current !== null) commitRef.current(x)
+ }, [])
+ const commitRef = useRef(commitFromX)
+ commitRef.current = commitFromX
const onPointerDown = (e: React.PointerEvent<HTMLDivElement>) => {
if (disabled || pointerId.current !== null) return
pointerId.current = e.pointerId
@@ -170,14 +191,24 @@ export function WakeSlider({
commitFromX(e.clientX)
}
const onPointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
- if (e.pointerId === pointerId.current) commitFromX(e.clientX)
+ if (e.pointerId !== pointerId.current) return
+ pendingX.current = e.clientX
+ frameSteps.update.schedule(flushDrag)
}
const endDrag = (e: React.PointerEvent<HTMLDivElement>) => {
if (e.pointerId !== pointerId.current) return
try {
e.currentTarget.releasePointerCapture(e.pointerId)
} catch {}
+ if (pendingX.current !== null) {
+ commitFromX(pendingX.current)
+ pendingX.current = null
+ }
pointerId.current = null
+ // Hand the fill back to the spring from where the finger left it, then
+ // let it settle into the snapped value.
+ head.jump(target.get())
+ target.set(toPct(latest.current, min, max))
onRelease?.(latest.current)
}
const onKeyDown = (e: React.KeyboardEvent<HTMLButtonElement>) => {
diff --git a/src/lib/soundEffects.ts b/src/lib/soundEffects.ts
index ef90455..bdb1164 100644
--- a/src/lib/soundEffects.ts
+++ b/src/lib/soundEffects.ts
@@ -1,6 +1,18 @@
/**
- * Web Audio API Haptic Sound Synthesizer for Edge-Drop.
- * Provides zero-latency, tactile mechanical audio effects for sliders, toggles, and buttons.
+ * UI sound design for Edge-Drop, synthesized live with the Web Audio API.
+ *
+ * Every sound is built from the same three ingredients, so the app speaks with
+ * one voice:
+ * - touch: a very short band-passed noise tick (a fingertip on glass)
+ * - body: a damped sine, like a small struck piece of wood or glass
+ * - air: a soft filtered-noise swell for things that move (the shelf)
+ * All pitches come from one scale (D major pentatonic), every attack eases in
+ * over a millisecond or two (no clicks from instant gain steps), and everything
+ * goes through one bus with a gentle high cut, so nothing turns harsh. Each
+ * sound's loudness is set once, in its `play` call, and the set is levelled by
+ * ear-weighted loudness: the slider tick lightest, everyday taps next, then
+ * toggles, deletes, cards and shelf moves; closing sounds sit a touch softer
+ * than opening ones.
*/
import { useStore } from '../store/appStore'
@@ -42,7 +54,8 @@ function getAudioContext(): any | null {
*/
export function warmAudioContext(): void {
try {
- getAudioContext()
+ const ctx = getAudioContext()
+ if (ctx) busFor(ctx)
} catch {
/* ignore Web Audio API restrictions */
}
@@ -68,468 +81,238 @@ if (win && win.addEventListener) {
win.addEventListener('keydown', unlockAudio, true)
}
-/**
- * Plays a satisfying mechanical rotary dial tick sound.
- * Emulates a camera dial / Apple Watch Digital Crown detent click.
- */
-export function playDialTickSound(): void {
- try {
- const ctx = getAudioContext()
- if (!ctx) return
-
- const play = () => {
- const now = ctx.currentTime
-
- // 1. High-frequency metallic ratchet sweep (2600Hz -> 700Hz in 10ms)
- const osc = ctx.createOscillator()
- const gain = ctx.createGain()
-
- osc.type = 'sine'
- osc.frequency.setValueAtTime(2600, now)
- osc.frequency.exponentialRampToValueAtTime(700, now + 0.01)
-
- gain.gain.setValueAtTime(0.18, now)
- gain.gain.exponentialRampToValueAtTime(0.001, now + 0.01)
-
- osc.connect(gain)
- gain.connect(ctx.destination)
-
- osc.start(now)
- osc.stop(now + 0.01)
-
- // 2. Subtle low-end mechanical detent thud (180Hz -> 60Hz in 12ms)
- const bodyOsc = ctx.createOscillator()
- const bodyGain = ctx.createGain()
+// ── Scale ──────────────────────────────────────────────────────────────────
+// D major pentatonic: any two of these sound good together.
+const D4 = 293.66
+const A4 = 440
+const D5 = 587.33
+const E5 = 659.26
+const FS5 = 739.99
+const A5 = 880
+const B5 = 987.77
+const D6 = 1174.66
+const A6 = 1760
+
+// ── Bus ────────────────────────────────────────────────────────────────────
+
+interface Bus {
+ ctx: any
+ out: any
+ noise: any
+}
- bodyOsc.type = 'triangle'
- bodyOsc.frequency.setValueAtTime(180, now)
- bodyOsc.frequency.exponentialRampToValueAtTime(60, now + 0.012)
+let bus: Bus | null = null
+
+/** One shared output chain and noise buffer per context, built once. */
+function busFor(ctx: any): Bus {
+ if (bus && bus.ctx === ctx) return bus
+ // Takes the glassy edge off without dulling the ticks. (No compressor: the
+ // levels below peak around -15 dBFS, and Chromium's adds ~6ms of latency.)
+ const out = ctx.createBiquadFilter()
+ out.type = 'lowpass'
+ out.frequency.value = 7000
+ out.Q.value = 0.5
+ out.connect(ctx.destination)
+
+ const length = Math.floor(ctx.sampleRate * 0.5)
+ const noise = ctx.createBuffer(1, length, ctx.sampleRate)
+ const data = noise.getChannelData(0)
+ for (let i = 0; i < length; i++) data[i] = Math.random() * 2 - 1
+
+ bus = { ctx, out, noise }
+ return bus
+}
- bodyGain.gain.setValueAtTime(0.12, now)
- bodyGain.gain.exponentialRampToValueAtTime(0.001, now + 0.012)
+/** Eases in over `attack`, then decays naturally to silence over `decay`. */
+function envelope(param: any, at: number, peak: number, attack: number, decay: number): void {
+ param.setValueAtTime(0.0001, at)
+ param.linearRampToValueAtTime(peak, at + attack)
+ param.exponentialRampToValueAtTime(0.0001, at + attack + decay)
+}
- bodyOsc.connect(bodyGain)
- bodyGain.connect(ctx.destination)
+/** Slight per-play variation so repeated sounds feel physical, not machine-gunned. */
+const vary = (value: number, amount: number) => value * (1 + (Math.random() * 2 - 1) * amount)
+
+// ── Ingredients ────────────────────────────────────────────────────────────
+
+function touch(b: Bus, at: number, freq: number, level: number, decay: number, q = 1): void {
+ const { ctx } = b
+ const src = ctx.createBufferSource()
+ src.buffer = b.noise
+ const band = ctx.createBiquadFilter()
+ band.type = 'bandpass'
+ band.frequency.value = vary(freq, 0.04)
+ band.Q.value = q
+ const gain = ctx.createGain()
+ envelope(gain.gain, at, level, 0.0008, decay)
+ src.connect(band)
+ band.connect(gain)
+ gain.connect(b.out)
+ src.start(at, Math.random() * 0.4)
+ src.stop(at + decay + 0.02)
+}
- bodyOsc.start(now)
- bodyOsc.stop(now + 0.012)
- }
+interface BodyOptions {
+ attack?: number
+ /** End pitch as a ratio of the start, reached over the first half of the decay. */
+ glide?: number
+ /** A quieter overtone at `ratio` x the pitch; 2 sounds glassy, 2.76 woody. */
+ partial?: { ratio: number; level: number }
+}
- if (ctx.state === 'suspended') {
- ctx.resume().then(() => play()).catch(() => {})
- } else {
- play()
- }
- } catch {
- /* ignore Web Audio API restrictions */
+function body(b: Bus, at: number, freq: number, level: number, decay: number, opts: BodyOptions = {}): void {
+ const { ctx } = b
+ const attack = opts.attack ?? 0.0015
+ const voice = (pitch: number, peak: number, length: number) => {
+ const osc = ctx.createOscillator()
+ osc.type = 'sine'
+ osc.frequency.setValueAtTime(pitch, at)
+ if (opts.glide) osc.frequency.exponentialRampToValueAtTime(pitch * opts.glide, at + attack + length * 0.5)
+ const gain = ctx.createGain()
+ envelope(gain.gain, at, peak, attack, length)
+ osc.connect(gain)
+ gain.connect(b.out)
+ osc.start(at)
+ osc.stop(at + attack + length + 0.02)
}
+ voice(freq, level, decay)
+ if (opts.partial) voice(freq * opts.partial.ratio, level * opts.partial.level, decay * 0.45)
}
-/**
- * Plays a mechanical toggle switch sound (ON / OFF).
- * Emulates a tactile hardware toggle switch snap.
- */
-export function playToggleSound(enabled: boolean): void {
- try {
- const ctx = getAudioContext()
- if (!ctx) return
-
- const play = () => {
- const now = ctx.currentTime
-
- const osc = ctx.createOscillator()
- const gain = ctx.createGain()
-
- const startFreq = enabled ? 2200 : 1300
- const endFreq = enabled ? 950 : 450
- const vol = enabled ? 0.15 : 0.11
-
- osc.type = 'sine'
- osc.frequency.setValueAtTime(startFreq, now)
- osc.frequency.exponentialRampToValueAtTime(endFreq, now + 0.014)
-
- gain.gain.setValueAtTime(vol, now)
- gain.gain.exponentialRampToValueAtTime(0.001, now + 0.014)
-
- osc.connect(gain)
- gain.connect(ctx.destination)
-
- osc.start(now)
- osc.stop(now + 0.014)
-
- // Mechanical click thud
- const bodyOsc = ctx.createOscillator()
- const bodyGain = ctx.createGain()
-
- bodyOsc.type = 'triangle'
- bodyOsc.frequency.setValueAtTime(enabled ? 220 : 150, now)
- bodyOsc.frequency.exponentialRampToValueAtTime(enabled ? 70 : 40, now + 0.016)
-
- bodyGain.gain.setValueAtTime(0.10, now)
- bodyGain.gain.exponentialRampToValueAtTime(0.001, now + 0.016)
+function air(b: Bus, at: number, from: number, to: number, level: number, dur: number): void {
+ const { ctx } = b
+ const src = ctx.createBufferSource()
+ src.buffer = b.noise
+ src.loop = true
+ const sweep = ctx.createBiquadFilter()
+ sweep.type = 'lowpass'
+ sweep.Q.value = 0.7
+ sweep.frequency.setValueAtTime(from, at)
+ sweep.frequency.exponentialRampToValueAtTime(to, at + dur)
+ const gain = ctx.createGain()
+ gain.gain.setValueAtTime(0.0001, at)
+ gain.gain.linearRampToValueAtTime(level, at + dur * 0.4)
+ gain.gain.exponentialRampToValueAtTime(0.0001, at + dur)
+ src.connect(sweep)
+ sweep.connect(gain)
+ gain.connect(b.out)
+ src.start(at, Math.random() * 0.4)
+ src.stop(at + dur + 0.02)
+}
- bodyOsc.connect(bodyGain)
- bodyGain.connect(ctx.destination)
+// ── Player ─────────────────────────────────────────────────────────────────
- bodyOsc.start(now)
- bodyOsc.stop(now + 0.016)
- }
-
- if (ctx.state === 'suspended') {
- ctx.resume().then(() => play()).catch(() => {})
- } else {
- play()
- }
- } catch {
- /* ignore Web Audio API restrictions */
- }
-}
+const lastPlayed: Record<string, number> = {}
/**
- * Plays a subtle, tactile keycap button click sound.
- * Ideal for filter chips, action buttons, pills, and icons.
+ * Schedules a sound a few ms ahead (so its attack is never cut off) at `level`,
+ * skipping repeats of the same sound closer than `minGap` seconds apart.
*/
-export function playButtonClickSound(): void {
+function play(key: string, minGap: number, level: number, voice: (b: Bus, at: number) => void): void {
try {
const ctx = getAudioContext()
if (!ctx) return
-
- const play = () => {
+ const go = () => {
const now = ctx.currentTime
-
- const osc = ctx.createOscillator()
+ if (now - (lastPlayed[key] ?? -1) < minGap) return
+ lastPlayed[key] = now
+ const main = busFor(ctx)
const gain = ctx.createGain()
-
- osc.type = 'sine'
- osc.frequency.setValueAtTime(2100, now)
- osc.frequency.exponentialRampToValueAtTime(900, now + 0.009)
-
- gain.gain.setValueAtTime(0.10, now)
- gain.gain.exponentialRampToValueAtTime(0.001, now + 0.009)
-
- osc.connect(gain)
- gain.connect(ctx.destination)
-
- osc.start(now)
- osc.stop(now + 0.009)
+ gain.gain.value = level
+ gain.connect(main.out)
+ voice({ ...main, out: gain }, now + 0.004)
}
-
if (ctx.state === 'suspended') {
- ctx.resume().then(() => play()).catch(() => {})
+ ctx.resume().then(go).catch(() => {})
} else {
- play()
+ go()
}
} catch {
/* ignore Web Audio API restrictions */
}
}
-/**
- * Plays a satisfying downward popping delete sound.
- * Pitch sweeps rapidly downward (1400Hz -> 250Hz) with a soft low-end thud (150Hz -> 40Hz)
- * to instantly signify item removal/deletion.
- */
-export function playDeleteSound(): void {
- try {
- const ctx = getAudioContext()
- if (!ctx) return
-
- const play = () => {
- const now = ctx.currentTime
-
- // 1. Downward popping pitch sweep (1400Hz -> 250Hz in 14ms)
- const osc = ctx.createOscillator()
- const gain = ctx.createGain()
-
- osc.type = 'sine'
- osc.frequency.setValueAtTime(1400, now)
- osc.frequency.exponentialRampToValueAtTime(250, now + 0.014)
-
- gain.gain.setValueAtTime(0.14, now)
- gain.gain.exponentialRampToValueAtTime(0.001, now + 0.014)
-
- osc.connect(gain)
- gain.connect(ctx.destination)
-
- osc.start(now)
- osc.stop(now + 0.014)
-
- // 2. Soft mechanical release thud (150Hz -> 40Hz in 16ms)
- const bodyOsc = ctx.createOscillator()
- const bodyGain = ctx.createGain()
-
- bodyOsc.type = 'triangle'
- bodyOsc.frequency.setValueAtTime(150, now)
- bodyOsc.frequency.exponentialRampToValueAtTime(40, now + 0.016)
+// ── Sounds ─────────────────────────────────────────────────────────────────
- bodyGain.gain.setValueAtTime(0.12, now)
- bodyGain.gain.exponentialRampToValueAtTime(0.001, now + 0.016)
+/** Slider detent: the lightest tick in the set, fine to repeat quickly. */
+export function playDialTickSound(): void {
+ play('dial', 0.025, 0.42, (b, at) => {
+ touch(b, at, 3600, 0.62, 0.009, 1.4)
+ body(b, at, A6, 0.14, 0.018)
+ })
+}
- bodyOsc.connect(bodyGain)
- bodyGain.connect(ctx.destination)
+/** Toggle switch: one soft click, a step brighter when switching on. */
+export function playToggleSound(enabled: boolean): void {
+ play('toggle', 0.03, 0.42, (b, at) => {
+ touch(b, at, enabled ? 2800 : 2200, 0.36, 0.014)
+ body(b, at, enabled ? B5 : FS5, enabled ? 0.19 : 0.18, 0.05, { partial: { ratio: 2.76, level: 0.25 } })
+ })
+}
- bodyOsc.start(now)
- bodyOsc.stop(now + 0.016)
- }
+/** Buttons, chips and pills: the everyday tap. */
+export function playButtonClickSound(): void {
+ play('tap', 0.03, 0.4, (b, at) => {
+ touch(b, at, 2600, 0.56, 0.012)
+ body(b, at, A5, 0.23, 0.03)
+ })
+}
- if (ctx.state === 'suspended') {
- ctx.resume().then(() => play()).catch(() => {})
- } else {
- play()
- }
- } catch {
- /* ignore Web Audio API restrictions */
- }
+/** Removing an item: a soft, low tap that settles downward as it swipes away. */
+export function playDeleteSound(): void {
+ play('delete', 0.04, 0.55, (b, at) => {
+ touch(b, at, 1500, 0.27, 0.022, 0.8)
+ body(b, at, D5, 0.16, 0.09, { glide: 0.8 })
+ air(b, at, 2400, 500, 0.047, 0.12)
+ })
}
-/**
- * Plays a warm mechanical expansion/contraction sound for collapsible sections (e.g. Pinned section).
- */
+/** Collapsible sections: two quick notes, up to open and down to close. */
export function playExpandSound(expanding: boolean): void {
- try {
- const ctx = getAudioContext()
- if (!ctx) return
-
- const play = () => {
- const now = ctx.currentTime
-
- const startFreq = expanding ? 450 : 1100
- const endFreq = expanding ? 1250 : 380
- const dur = expanding ? 0.022 : 0.018
-
- const osc = ctx.createOscillator()
- const gain = ctx.createGain()
-
- osc.type = 'sine'
- osc.frequency.setValueAtTime(startFreq, now)
- osc.frequency.exponentialRampToValueAtTime(endFreq, now + dur)
-
- gain.gain.setValueAtTime(0.12, now)
- gain.gain.exponentialRampToValueAtTime(0.001, now + dur)
-
- osc.connect(gain)
- gain.connect(ctx.destination)
-
- osc.start(now)
- osc.stop(now + dur)
-
- const bodyOsc = ctx.createOscillator()
- const bodyGain = ctx.createGain()
-
- bodyOsc.type = 'triangle'
- bodyOsc.frequency.setValueAtTime(expanding ? 90 : 140, now)
- bodyOsc.frequency.exponentialRampToValueAtTime(expanding ? 180 : 60, now + dur + 0.004)
-
- bodyGain.gain.setValueAtTime(0.09, now)
- bodyGain.gain.exponentialRampToValueAtTime(0.001, now + dur + 0.004)
-
- bodyOsc.connect(bodyGain)
- bodyGain.connect(ctx.destination)
-
- bodyOsc.start(now)
- bodyOsc.stop(now + dur + 0.004)
- }
-
- if (ctx.state === 'suspended') {
- ctx.resume().then(() => play()).catch(() => {})
- } else {
- play()
- }
- } catch {
- /* ignore */
- }
+ play('section', 0.05, 1.42, (b, at) => {
+ const [first, second] = expanding ? [D5, A5] : [A5, D5]
+ touch(b, at, 2400, 0.07, 0.012)
+ body(b, at, first, 0.042, 0.06, { partial: { ratio: 2, level: 0.2 } })
+ body(b, at + 0.045, second, 0.042, 0.08, { attack: 0.004, partial: { ratio: 2, level: 0.2 } })
+ })
}
-/**
- * Plays a rich 3D glassmorphic pop sound when cards expand, file bundles open/close, or preview flyout toggles.
- */
+/** Cards, stacks and the preview: the section notes, a little fuller, with a breath of air. */
export function playCardExpandSound(expanding: boolean): void {
- try {
- const ctx = getAudioContext()
- if (!ctx) return
-
- const play = () => {
- const now = ctx.currentTime
-
- const startFreq = expanding ? 650 : 1500
- const endFreq = expanding ? 1650 : 480
- const dur = expanding ? 0.028 : 0.022
-
- // Primary tone
- const osc = ctx.createOscillator()
- const gain = ctx.createGain()
-
- osc.type = 'sine'
- osc.frequency.setValueAtTime(startFreq, now)
- osc.frequency.exponentialRampToValueAtTime(endFreq, now + dur)
-
- gain.gain.setValueAtTime(0.15, now)
- gain.gain.exponentialRampToValueAtTime(0.001, now + dur)
-
- osc.connect(gain)
- gain.connect(ctx.destination)
-
- osc.start(now)
- osc.stop(now + dur)
-
- // Harmonics for rich glassmorphic texture
- const harmonicOsc = ctx.createOscillator()
- const harmonicGain = ctx.createGain()
-
- harmonicOsc.type = 'triangle'
- harmonicOsc.frequency.setValueAtTime(startFreq * 1.5, now)
- harmonicOsc.frequency.exponentialRampToValueAtTime(endFreq * 1.5, now + dur * 0.8)
-
- harmonicGain.gain.setValueAtTime(0.06, now)
- harmonicGain.gain.exponentialRampToValueAtTime(0.001, now + dur * 0.8)
-
- harmonicOsc.connect(harmonicGain)
- harmonicGain.connect(ctx.destination)
-
- harmonicOsc.start(now)
- harmonicOsc.stop(now + dur * 0.8)
- }
-
- if (ctx.state === 'suspended') {
- ctx.resume().then(() => play()).catch(() => {})
- } else {
- play()
- }
- } catch {
- /* ignore */
- }
+ play('card', 0.05, 1.39, (b, at) => {
+ const [first, second] = expanding ? [E5, B5] : [B5, E5]
+ touch(b, at, 2400, 0.066, 0.014)
+ body(b, at, first, 0.038, 0.07, { partial: { ratio: 2, level: 0.25 } })
+ body(b, at + 0.05, second, 0.038, expanding ? 0.12 : 0.09, { attack: 0.004, partial: { ratio: 2, level: 0.25 } })
+ if (expanding) air(b, at, 700, 2600, 0.012, 0.12)
+ else air(b, at, 2600, 700, 0.01, 0.1)
+ })
}
-/**
- * 1. Plays a tactile mechanical dock/retract sound when the panel slides into the edge bar.
- */
+/** The shelf slides into its edge bar: air falls away and lands with a low, soft tock. */
export function playEdgeRetractSound(): void {
- try {
- const ctx = getAudioContext()
- if (!ctx) return
-
- const play = () => {
- const now = ctx.currentTime
-
- // Smooth downward glide into the dock
- const osc = ctx.createOscillator()
- const gain = ctx.createGain()
- osc.type = 'sine'
- osc.frequency.setValueAtTime(540, now)
- osc.frequency.exponentialRampToValueAtTime(190, now + 0.08)
- gain.gain.setValueAtTime(0.09, now)
- gain.gain.exponentialRampToValueAtTime(0.001, now + 0.08)
- osc.connect(gain)
- gain.connect(ctx.destination)
- osc.start(now)
- osc.stop(now + 0.08)
-
- // Mechanical latch click thud
- const bodyOsc = ctx.createOscillator()
- const bodyGain = ctx.createGain()
- bodyOsc.type = 'triangle'
- bodyOsc.frequency.setValueAtTime(140, now + 0.06)
- bodyOsc.frequency.exponentialRampToValueAtTime(45, now + 0.11)
- bodyGain.gain.setValueAtTime(0.08, now + 0.06)
- bodyGain.gain.exponentialRampToValueAtTime(0.001, now + 0.11)
- bodyOsc.connect(bodyGain)
- bodyGain.connect(ctx.destination)
- bodyOsc.start(now + 0.06)
- bodyOsc.stop(now + 0.11)
- }
-
- if (ctx.state === 'suspended') {
- ctx.resume().then(() => play()).catch(() => {})
- } else {
- play()
- }
- } catch {
- /* ignore */
- }
+ play('retract', 0.1, 1.8, (b, at) => {
+ air(b, at, 2200, 380, 0.037, 0.2)
+ touch(b, at + 0.15, 1200, 0.05, 0.016, 0.8)
+ body(b, at + 0.15, D4, 0.08, 0.09, { partial: { ratio: 2, level: 0.15 } })
+ })
}
-/**
- * 2. Plays a subtle magnetic detent ping when the edge bar fades in on the new screen edge.
- */
+/** The edge bar appears on its new edge: one quiet glass note. */
export function playEdgeBeaconAppearSound(): void {
- try {
- const ctx = getAudioContext()
- if (!ctx) return
-
- const play = () => {
- const now = ctx.currentTime
-
- const osc = ctx.createOscillator()
- const gain = ctx.createGain()
- osc.type = 'sine'
- osc.frequency.setValueAtTime(780, now)
- osc.frequency.exponentialRampToValueAtTime(520, now + 0.045)
- gain.gain.setValueAtTime(0.07, now)
- gain.gain.exponentialRampToValueAtTime(0.001, now + 0.045)
- osc.connect(gain)
- gain.connect(ctx.destination)
- osc.start(now)
- osc.stop(now + 0.045)
- }
-
- if (ctx.state === 'suspended') {
- ctx.resume().then(() => play()).catch(() => {})
- } else {
- play()
- }
- } catch {
- /* ignore */
- }
+ play('beacon', 0.1, 0.77, (b, at) => {
+ body(b, at, D6, 0.037, 0.2, { attack: 0.004, partial: { ratio: 2, level: 0.3 } })
+ })
}
-/**
- * 3. Plays a tactile mechanical spring unlatch sound when the clipboard expands out from the bar.
- */
+/** The shelf grows out of the bar: the retract sound in reverse, rising into the open. */
export function playEdgeExpandSound(): void {
- try {
- const ctx = getAudioContext()
- if (!ctx) return
-
- const play = () => {
- const now = ctx.currentTime
-
- // Upward expanding slide
- const osc = ctx.createOscillator()
- const gain = ctx.createGain()
- osc.type = 'sine'
- osc.frequency.setValueAtTime(260, now)
- osc.frequency.exponentialRampToValueAtTime(740, now + 0.06)
- gain.gain.setValueAtTime(0.08, now)
- gain.gain.exponentialRampToValueAtTime(0.001, now + 0.06)
- osc.connect(gain)
- gain.connect(ctx.destination)
- osc.start(now)
- osc.stop(now + 0.06)
-
- // Tactile detent release snap
- const snapOsc = ctx.createOscillator()
- const snapGain = ctx.createGain()
- snapOsc.type = 'triangle'
- snapOsc.frequency.setValueAtTime(180, now + 0.02)
- snapOsc.frequency.exponentialRampToValueAtTime(70, now + 0.07)
- snapGain.gain.setValueAtTime(0.10, now + 0.02)
- snapGain.gain.exponentialRampToValueAtTime(0.001, now + 0.07)
- snapOsc.connect(snapGain)
- snapGain.connect(ctx.destination)
- snapOsc.start(now + 0.02)
- snapOsc.stop(now + 0.07)
- }
-
- if (ctx.state === 'suspended') {
- ctx.resume().then(() => play()).catch(() => {})
- } else {
- play()
- }
- } catch {
- /* ignore */
- }
+ play('expand', 0.1, 0.55, (b, at) => {
+ touch(b, at, 1400, 0.16, 0.016, 0.8)
+ body(b, at, A4, 0.2, 0.08, { partial: { ratio: 2, level: 0.15 } })
+ air(b, at, 380, 2200, 0.12, 0.2)
+ })
}
/** Legacy alias for backwards compatibility */
export const playEdgeTransitionSound = playEdgeRetractSound
-
diff --git a/tests/soundEffects.test.ts b/tests/soundEffects.test.ts
new file mode 100644
index 0000000..4c40d62
--- /dev/null
+++ b/tests/soundEffects.test.ts
@@ -0,0 +1,39 @@
+import { describe, expect, it } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { join } from 'node:path'
+import * as sfx from '../src/lib/soundEffects'
+
+const src = readFileSync(join(__dirname, '..', 'src/lib/soundEffects.ts'), 'utf8')
+
+describe('UI sound design', () => {
+ it('every sound goes through the shared player with its own level and repeat guard', () => {
+ const exported = [...src.matchAll(/export function (play\w+Sound)\(/g)].map((m) => m[1])
+ expect(exported).toHaveLength(9)
+ const plays = [...src.matchAll(/play\('([a-z]+)', ([\d.]+), ([\d.]+), \(b, at\)/g)]
+ expect(plays).toHaveLength(9)
+ expect(new Set(plays.map((m) => m[1])).size).toBe(9)
+ })
+
+ it('no instant gain steps or pitch swoops: envelopes ease in from silence', () => {
+ expect(src).toContain('param.setValueAtTime(0.0001, at)')
+ expect(src).toContain('param.linearRampToValueAtTime(peak, at + attack)')
+ expect(src).not.toMatch(/gain\.setValueAtTime\(0\.[1-9]/)
+ expect(src).not.toMatch(/type = '(triangle|square|sawtooth)'/)
+ })
+
+ it('no compressor on the bus (it adds latency and auto makeup gain)', () => {
+ expect(src).not.toContain('createDynamicsCompressor')
+ })
+
+ it('every sound is safe to call without Web Audio', () => {
+ for (const fn of [
+ sfx.playDialTickSound, sfx.playButtonClickSound, sfx.playDeleteSound,
+ sfx.playEdgeRetractSound, sfx.playEdgeBeaconAppearSound, sfx.playEdgeExpandSound, sfx.warmAudioContext
+ ]) expect(() => fn()).not.toThrow()
+ for (const on of [true, false]) {
+ expect(() => sfx.playToggleSound(on)).not.toThrow()
+ expect(() => sfx.playExpandSound(on)).not.toThrow()
+ expect(() => sfx.playCardExpandSound(on)).not.toThrow()
+ }
+ })
+})
diff --git a/tests/wakeSlider.test.ts b/tests/wakeSlider.test.ts
new file mode 100644
index 0000000..6300410
--- /dev/null
+++ b/tests/wakeSlider.test.ts
@@ -0,0 +1,39 @@
+import { describe, expect, it } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { join } from 'node:path'
+
+const read = (p: string) => readFileSync(join(__dirname, '..', p), 'utf8')
+const slider = read('src/components/WakeSlider.tsx')
+const settings = read('src/components/Settings.tsx')
+
+describe('slider drag feel', () => {
+ it('the fill tracks the pointer 1:1 while dragging, not a spring behind it', () => {
+ expect(slider).toContain('(reduce || pointerId.current !== null ? target.get() : head.get())')
+ expect(slider).toContain('target.set(ratio * 100)')
+ // value-driven updates do not fight the pointer mid-drag
+ expect(slider).toContain('if (pointerId.current === null) target.set(pct)')
+ })
+
+ it('handles pointer moves at most once per frame', () => {
+ expect(slider).toMatch(/onPointerMove[\s\S]*?pendingX\.current = e\.clientX\s+frameSteps\.update\.schedule\(flushDrag\)/)
+ expect(slider).not.toMatch(/onPointerMove = [^}]*commitFromX\(e\.clientX\)/)
+ })
+
+ it('release hands back to the spring from the finger, then settles on the value', () => {
+ expect(slider).toMatch(/head\.jump\(target\.get\(\)\)\s+target\.set\(toPct\(latest\.current, min, max\)\)/)
+ })
+
+ it('ticks once per detent, never more than once per bar', () => {
+ expect(slider).toContain('Math.min(bars - 1, Math.round((max - min) / (step > 0 ? step : 1)))')
+ expect(slider).toContain('if (detentOf(clean) !== detentOf(latest.current)) playDialTickSound()')
+ })
+
+ it('settings does not double the ticks while dragging, and keeps the 1% position on release', () => {
+ for (const fn of ['handleSliderInput', 'handleThicknessInput', 'handleHoverDelayInput', 'handleSliderRelease', 'handleThicknessRelease', 'handleHoverDelayRelease']) {
+ const body = settings.slice(settings.indexOf(`const ${fn} = `), settings.indexOf('\n }\n', settings.indexOf(`const ${fn} = `)))
+ expect(body, fn).not.toContain('playDialTickSound')
+ }
+ expect(settings).toContain('step={0.01}')
+ expect(settings).toContain('Math.round(rawVal * 100) / 100')
+ })
+})