Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add TUI logo charge and burst sound cues
Give the logo pulse a generated charge hum and burst sound so the interaction feels tactile without bundling static assets.
  • Loading branch information
kitlangton committed Apr 13, 2026
commit 7d853f30668b48e9826965c9baf3512e8bc94d0a
18 changes: 11 additions & 7 deletions packages/opencode/src/cli/cmd/tui/component/logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ const TRAIL = 0.28
const SWELL = 0.24
const WIDE = 1.85
const DRIFT = 1.45
const EXPAND = 1.62
const LIFE = 1020
const CHARGE = 2000
const CHARGE = 3000
const HOLD = 90
const SINK = 40
const ARC = 2.2
Expand All @@ -30,6 +31,7 @@ const SHIMMER_IN = 60
const SHIMMER_OUT = 2.8
const TRACE = 0.033
const TAIL = 1.8
const TRACE_IN = 200
const PEAK = RGBA.fromInts(255, 255, 255)

type Ring = {
Expand Down Expand Up @@ -232,7 +234,7 @@ function shimmer(x: number, y: number, frame: Frame) {
const dy = y * 2 + 1 - item.y
const dist = Math.hypot(dx, dy)
const p = age / LIFE
const r = SPAN * (1 - (1 - p) ** 1.42)
const r = SPAN * (1 - (1 - p) ** EXPAND)
const lag = r - dist
if (lag < 0.18 || lag > SHIMMER_OUT) return best
const band = Math.exp(-(((lag - 1.05) / 0.68) ** 2))
Expand All @@ -250,7 +252,7 @@ function remain(x: number, y: number, item: Release, t: number) {
const dx = x + 0.5 - item.x - 0.5
const dy = y * 2 + 1 - item.y * 2 - 1
const dist = Math.hypot(dx, dy)
const r = SPAN * (1 - (1 - p) ** 1.42)
const r = SPAN * (1 - (1 - p) ** EXPAND)
if (dist > r) return 1
return clamp((r - dist) / 1.35 < 1 ? 1 - (r - dist) / 1.35 : 0)
}
Expand All @@ -263,7 +265,7 @@ function wave(x: number, y: number, frame: Frame, live: boolean) {
const dx = x + 0.5 - item.x
const dy = y * 2 + 1 - item.y
const dist = Math.hypot(dx, dy)
const r = SPAN * (1 - (1 - p) ** 1.42)
const r = SPAN * (1 - (1 - p) ** EXPAND)
const fade = (1 - p) ** 1.32
const j = 1.02 + noise(x + item.x * 0.7, y + item.y * 0.7, item.at * 0.002 + age * 0.06) * 0.52
const edge = Math.exp(-(((dist - r) / WIDTH) ** 2)) * GAIN * fade * item.force * j
Expand Down Expand Up @@ -347,15 +349,17 @@ function trace(x: number, y: number, frame: Frame) {
if (!step || step.glyph !== item.glyph || step.l < 2) return 0
const age = frame.t - item.at
const rise = held ? ramp(age, HOLD, CHARGE) : rest!.rise
const head = (age * TRACE) % step.l
const appear = held ? ramp(age, 0, TRACE_IN) : 1
const speed = lerp(TRACE * 0.48, TRACE * 0.88, rise)
const head = (age * speed) % step.l
const dist = Math.min(Math.abs(step.i - head), step.l - Math.abs(step.i - head))
const tail = (head - TAIL + step.l) % step.l
const lag = Math.min(Math.abs(step.i - tail), step.l - Math.abs(step.i - tail))
const fade = frame.release && !frame.hold ? remain(x, y, frame.release, frame.t) : 1
const core = Math.exp(-((dist / 1.05) ** 2)) * lerp(0.8, 2.35, rise)
const glow = Math.exp(-((dist / 1.85) ** 2)) * lerp(0.08, 0.34, rise)
const trail = Math.exp(-((lag / 1.45) ** 2)) * lerp(0.04, 0.42, rise)
return (core + glow + trail) * fade
return (core + glow + trail) * appear * fade
}

export function Logo() {
Expand Down Expand Up @@ -529,7 +533,7 @@ export function Logo() {
onCleanup(() => {
stop()
hum = false
Sound.stop()
Sound.dispose()
})

const mouse = (evt: MouseEvent) => {
Expand Down
181 changes: 103 additions & 78 deletions packages/opencode/src/cli/cmd/tui/util/sound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import { Filesystem } from "@/util/filesystem"
import { Process } from "@/util/process"
import { which } from "@/util/which"

const FILE = join(tmpdir(), "opencode-pulse-v7.wav")
const HUM = join(tmpdir(), "opencode-charge-v3.wav")
const FILE = [
join(tmpdir(), "opencode-pulse-a-v7.wav"),
join(tmpdir(), "opencode-pulse-b-v7.wav"),
join(tmpdir(), "opencode-pulse-c-v7.wav"),
]
const HUM = join(tmpdir(), "opencode-charge-v4.wav")
const RATE = 44_100
const TIME = 0.34
const SPAN = 4
const FULL = 2
const TIME = 1
const SPAN = 3.35

const LIST = [
"ffplay",
Expand All @@ -29,80 +32,85 @@ const LIST = [

type Kind = (typeof LIST)[number]

function clamp(n: number) {
return Math.max(-1, Math.min(1, n))
}

function pcm(time: number, fill: (t: number, i: number) => readonly [number, number]) {
const size = Math.floor(RATE * time)
const channels = 2
const bytes = size * channels * 2
const bytes = size * 4
const out = Buffer.alloc(44 + bytes)
out.write("RIFF", 0)
out.writeUInt32LE(36 + bytes, 4)
out.write("WAVE", 8)
out.write("fmt ", 12)
out.writeUInt32LE(16, 16)
out.writeUInt16LE(1, 20)
out.writeUInt16LE(channels, 22)
out.writeUInt16LE(2, 22)
out.writeUInt32LE(RATE, 24)
out.writeUInt32LE(RATE * channels * 2, 28)
out.writeUInt16LE(channels * 2, 32)
out.writeUInt32LE(RATE * 4, 28)
out.writeUInt16LE(4, 32)
out.writeUInt16LE(16, 34)
out.write("data", 36)
out.writeUInt32LE(bytes, 40)

for (let i = 0; i < size; i++) {
const [left, right] = fill(i / RATE, i)
out.writeInt16LE(Math.round(clamp(left) * 0x7fff), 44 + i * 4)
out.writeInt16LE(Math.round(clamp(right) * 0x7fff), 46 + i * 4)
out.writeInt16LE(Math.round(Math.max(-1, Math.min(1, left)) * 0x7fff), 44 + i * 4)
out.writeInt16LE(Math.round(Math.max(-1, Math.min(1, right)) * 0x7fff), 46 + i * 4)
}

return out
}

function wav() {
function wav(mode: number) {
let p0 = 0
let p1 = 0
let p2 = 0
let p3 = 0
let p4 = 0
let p5 = 0
const lift = [1, 1.06, 0.95][mode]
const spread = [1.48, 1.62, 1.38][mode]
const edge = [2.18, 2.02, 1.9][mode]
const ring = [0.74, 0.82, 0.68][mode]
const ping = [0.5, 0.58, 0.44][mode]
const tail = [1.55, 1.65, 1.45][mode]
const root = [110, 122, 100][mode]
const top = [0.05, 0.04, 0.06][mode]
const wide = [0.06, 0.05, 0.08][mode]
return pcm(TIME, (t, i) => {
const attack = Math.min(1, t / 0.004)
const join = Math.max(0, Math.min(1, (t - 0.035) / 0.05))
const mix = join * join * (3 - 2 * join)
const body = Math.exp(-Math.max(0, t - 0.025) * 10.5)
const tail = Math.exp(-Math.max(0, t - 0.05) * 8.5)
const bloom = 0.76 + 0.24 * Math.sin(Math.min(1, t / 0.045) * Math.PI * 0.5)
const attack = Math.min(1, t / 0.0035)
const body = Math.exp(-t * (8.8 + mode * 0.32))
const fade = Math.exp(-t * tail)
const bloom = 0.76 + 0.24 * Math.sin(Math.min(1, t / 0.04) * Math.PI * 0.5)
const env = attack * body * bloom
const drop = Math.exp(-Math.max(0, t - 0.03) * 10)
const f0 = 1180 * drop + 360
const f1 = f0 * 1.5
const f2 = f0 * 2.01
const f3 = 160 + 60 * Math.exp(-t * 18)
const h0 = 180 - t * 65
const h1 = h0 * 1.96
const trail = Math.max(0, t - [0.08, 0.075, 0.1][mode])
const hang = (1 - Math.exp(-trail * [14, 16, 12][mode])) * Math.exp(-trail * [1.45, 1.32, 1.58][mode])
const end = t < TIME - 0.28 ? 1 : ((TIME - t) / 0.28) ** 2 * (3 - 2 * ((TIME - t) / 0.28))
const drop = Math.exp(-t * (9.4 - mode * 0.35))
const f0 = (320 * drop + root) * lift
const f1 = f0 * spread
const f2 = f0 * edge
const f3 = 32 + 13 * Math.exp(-t * 12)
const mod = Math.sin(p2 * 0.5 + 0.4) * Math.exp(-t * 24) * 1.6
const n = Math.sin((i * 12.9898 + 78.233) * 0.017) * 43758.5453
const dust = (n - Math.floor(n) - 0.5) * Math.exp(-t * 85)
p0 += (Math.PI * 2 * (f0 + mod * 90)) / RATE
p1 += (Math.PI * 2 * f1) / RATE
p2 += (Math.PI * 2 * f2) / RATE
p3 += (Math.PI * 2 * f3) / RATE
p4 += (Math.PI * 2 * h0) / RATE
p5 += (Math.PI * 2 * h1) / RATE
const hum = (Math.sin(p4) * 0.68 + Math.sin(p5 + 0.2) * 0.18 + Math.sin(p3 * 0.6) * 0.05) * Math.exp(-t * 11)
const core = Math.sin(p0) * 0.58 + Math.sin(p1 + 0.16) * 0.18 + Math.sin(p2 + 0.32) * 0.08 + Math.sin(p3) * 0.16
const chime = Math.sin(p1 * 1.01 + Math.sin(p2) * 0.14) * Math.exp(-Math.max(0, t - 0.02) * 17) * 0.17
const snap = Math.sin(p2 * 1.7 + 0.3) * Math.exp(-Math.max(0, t - 0.01) * 34) * 0.07
const ring = Math.sin(p1 * 0.82 + Math.sin(p0) * 0.2 + 0.35) * Math.exp(-Math.max(0, t - 0.03) * 7.2) * 0.14
const haze = Math.sin(p2 * 0.56 + 0.7) * Math.exp(-Math.max(0, t - 0.06) * 5.6) * 0.08
const laser = core * env + chime + snap + ring + haze
const sig = Math.tanh((hum * (1 - mix) * 1.35 + laser * mix + dust * 0.16) * 1.5)
const echo = sig * tail * 0.2
const left = sig + Math.sin(p1 * 0.996 + 0.2) * tail * 0.03 + echo * 0.72 + ring * 0.28
const right = sig + Math.sin(p1 * 1.004 + 0.62) * tail * 0.03 + echo + haze * 0.32
const low = Math.sin(p3 + Math.sin(p0) * 0.12) * 0.34
const core = Math.sin(p0) * 0.72 + Math.sin(p1 + 0.16) * 0.1 + Math.sin(p2 + 0.32) * 0.03 + low
const chime = Math.sin(p1 * 0.96 + Math.sin(p2) * 0.1) * Math.exp(-t * 14) * 0.025
const snap = Math.sin(p2 * 1.24 + 0.3) * Math.exp(-t * 26) * 0.02
const boom = Math.sin(p3 * 0.82 + Math.sin(p0) * 0.08) * Math.exp(-t * 8.5) * 0.24
const ringed = Math.sin(p1 * ring + Math.sin(p0) * 0.16 + 0.35) * Math.exp(-Math.max(0, t - 0.03) * 2.8) * top
const pinged = Math.sin(p2 * ping + 0.8) * hang * (wide + 0.04)
const glass = (Math.sin(p1 * 0.31 + 1.1) * 0.7 + Math.sin(p2 * 0.27 + 0.4) * 0.3) * hang * 0.05
const room =
(Math.sin(p0 * 0.27 + 0.8) * 0.24 + Math.sin(p1 * 0.21 + 0.35) * 0.46 + Math.sin(p2 * 0.18 + 1.2) * 0.3) *
hang *
0.12
const sig = Math.tanh((core * env + chime + snap + boom + ringed + pinged + glass + room + dust * 0.07) * 1.48)
const echo = (sig * 0.46 + boom * 0.42 + pinged * 0.22 + room * 0.9) * fade * 0.22
const left = (sig + Math.sin(p1 * 0.996 + 0.18) * fade * 0.01 + echo * 0.58 + glass * 0.08 + room * 0.14) * end
const right =
(sig + Math.sin(p1 * 1.004 + 0.56) * fade * 0.01 + echo + pinged * 0.05 + glass * 0.1 + room * 0.16) * end
return [left, right] as const
})
}
Expand All @@ -113,35 +121,34 @@ function hum() {
let p2 = 0
let p3 = 0
return pcm(SPAN, (t, i) => {
const rise = Math.max(0, Math.min(1, t / FULL))
const rise = Math.max(0, Math.min(1, t / 3))
const fade = Math.max(0, Math.min(1, (SPAN - t) / 0.22))
const attack = Math.min(1, t / 0.05)
const body = rise * rise * (3 - 2 * rise)
const env = attack * fade * lerp(0.08, 0.44, body)
const climb = body * body
const tip = climb * climb
const env = attack * fade * (0.12 + (0.56 - 0.12) * body)
const wobble = 1 + Math.sin(Math.PI * 2 * 3.2 * t) * 0.012
const f0 = (92 + body * 108 + Math.sin(Math.PI * 2 * (0.85 + body * 1.3) * t) * 1.4) * wobble
const f1 = f0 * 2.01
const f2 = f0 * 3.02
const f3 = 280 + body * 620
const f0 =
(72 + body * 92 + climb * 96 + tip * 86 + Math.sin(Math.PI * 2 * (0.72 + climb * 1.9) * t) * 1.8) * wobble
const f1 = f0 * (1.88 + climb * 0.14)
const f2 = f0 * (2.68 + climb * 0.32 + tip * 0.12)
const f3 = 220 + body * 360 + climb * 440 + tip * 180
p0 += (Math.PI * 2 * f0) / RATE
p1 += (Math.PI * 2 * f1) / RATE
p2 += (Math.PI * 2 * f2) / RATE
p3 += (Math.PI * 2 * f3) / RATE
const core = Math.sin(p0) * 0.58 + Math.sin(p1 + Math.sin(p0) * 0.22) * 0.16 + Math.sin(p2 + 0.2) * 0.08
const air = Math.sin(p3 + Math.sin(p1) * 0.5) * body * 0.06
const grind = Math.sin((i * 7.173 + 19.17) * 0.013) * 43758.5453
const dust = (grind - Math.floor(grind) - 0.5) * body * 0.012
const sig = Math.tanh((core + air + dust) * env * 1.7)
const left = sig + Math.sin(p1 * 0.998 + 0.1) * body * 0.014
const right = sig + Math.sin(p1 * 1.002 + 0.5) * body * 0.014
const core = Math.sin(p0) * 0.66 + Math.sin(p1 + Math.sin(p0) * 0.22) * 0.14 + Math.sin(p2 + 0.2) * 0.06
const air = Math.sin(p3 + Math.sin(p1) * 0.5) * (0.02 + climb * 0.08)
const grit = Math.sin((i * 7.173 + 19.17) * 0.013) * 43758.5453
const dust = (grit - Math.floor(grit) - 0.5) * body * 0.01
const sig = Math.tanh((core + air + dust) * env * (1.72 + climb * 0.22))
const left = sig + Math.sin(p1 * 0.998 + 0.1) * (0.01 + climb * 0.018)
const right = sig + Math.sin(p1 * 1.002 + 0.5) * (0.01 + climb * 0.018)
return [left, right] as const
})
}

function lerp(a: number, b: number, t: number) {
return a + (b - a) * Math.max(0, Math.min(1, t))
}

function args(kind: Kind, file: string, volume: number) {
if (kind === "ffplay") return [kind, "-autoexit", "-nodisp", "-af", `volume=${volume}`, file]
if (kind === "mpv")
Expand All @@ -155,17 +162,23 @@ function args(kind: Kind, file: string, volume: number) {
}

export namespace Sound {
let file: Promise<string> | undefined
let file: Promise<string[]> | undefined
let loop: Promise<string> | undefined
let item: Player | null | undefined
let kind: Kind | null | undefined
let proc: Process.Child | undefined
let tail: ReturnType<typeof setTimeout> | undefined
let seq = 0
let shot = 0

function tone() {
if (file) return file
file = (async () => {
if (!(await Filesystem.exists(FILE))) await Filesystem.write(FILE, wav())
await Promise.all(
FILE.map(async (file, i) => {
if (!(await Filesystem.exists(file))) await Filesystem.write(file, wav(i))
}),
)
return FILE
})()
return file
Expand Down Expand Up @@ -206,18 +219,18 @@ export namespace Sound {
})
}

function shot(file: string, volume: number) {
const item = load()
if (!item) return run(file, volume)?.exited
return item.play(file, { volume }).catch(() => run(file, volume)?.exited)
function clear() {
if (!tail) return
clearTimeout(tail)
tail = undefined
}

export function start() {
stop()
const id = ++seq
void rise().then((file) => {
if (id !== seq) return
const next = run(file, 0.18)
const next = run(file, 0.24)
if (!next) return
proc = next
void next.exited.then(
Expand All @@ -231,24 +244,36 @@ export namespace Sound {
})
}

export function stop(fade = false) {
export function stop(delay = 0) {
seq++
clear()
if (!proc) return
const next = proc
proc = undefined
if (!fade) {
if (next) void Process.stop(next).catch(() => undefined)
if (delay <= 0) {
proc = undefined
void Process.stop(next).catch(() => undefined)
return
}
if (!next) return
setTimeout(() => {
tail = setTimeout(() => {
tail = undefined
if (proc === next) proc = undefined
void Process.stop(next).catch(() => undefined)
}, 72)
}, delay)
}

export function pulse() {
stop(true)
stop(140)
const item = load()
void tone()
.then((file) => shot(file, 0.36))
.then((list) => {
const file = list[shot++ % list.length]
if (!item) return run(file, 0.4)?.exited
return item.play(file, { volume: 0.4 }).catch(() => run(file, 0.4)?.exited)
})
.catch(() => undefined)
}

export function dispose() {
stop()
}
}