Tape recorder Pro
One payment, every Pro piece. $9 tomorrow.
Install
npx shadcn@latest add @mu-pro/tape-recorderPro. Installs with your licence key through the @mu-pro registry; the key comes with Pro. Lands in components/mu/tape-recorder/ with the shared foundation.
Usage
import { TapeRecorder } from "@/components/mu/tape-recorder/TapeRecorder";
<TapeRecorder
tracks={[{ title: "Night drive", duration: 152 }]}
onModeChange={(mode, seconds) => {
if (mode === "recording") recorder.state === "paused" ? recorder.resume() : recorder.start();
else if (mode === "paused-recording") recorder.pause();
else if (recorder.state !== "inactive") recorder.stop();
}}
onMarker={(seconds) => saveMarker(seconds)}
/>Use with an agent Beta
npx shadcn@latest add @mu-pro/uisdk/tape-recorderOptional. An AI agent in your app can read and set this piece by name, and you can ask before anything it can’t undo. The piece itself doesn’t change; installs with your Pro key, like the piece. Built on UI SDK 0.1.0-beta.23, which is in beta too, so this add-on follows its releases.
Source
How it works
Building with an agent? Hand it a ready prompt for this piece.
Input and reduced motion
- Pointer / touch: record starts recording, play plays or pauses (and pauses or resumes a take), stop rewinds to the start, the flag drops a marker. Drag along the waveform to scrub: the reels turn under your hand, and a press more than two seconds away winds there.
- Keyboard: every key is a button with a name (Add marker, Play, Record, Stop); the waveform is a slider (arrow keys move 5s, Shift moves 15s, Page Up and Page Down 30s, Home and End go to the ends). A held arrow key keeps building on where it was going.
- Reduced motion: the reels don't spin, rewinds jump, and markers appear at once; the tape packs, playhead and timecode still follow the song, and a recording fills in a bar at a time. The REC lamp stays lit instead of blinking, and a wind makes no whirr.
- Off-screen, the frame loop and the REC lamp's blink pause until the recorder is back in view. At rest nothing repaints.
The transport
One state owns the machine: stopped, playing, recording, paused-recording or winding (a wind carries where it is going and the state it returns to). Keys, the record lamp and LED, the counter, the reels, the play key's glyph and the waveform all follow it, so two states can never show at once. tapeTransport (the reducer) and its types are exported.
- Record from stopped or playing starts recording (record and play together, like a deck). Record while recording does nothing; the key stays latched. At the end of the tape there is nothing left to record on: record rewinds to the start, and the next press records.
- While recording the tape runs, the REC lamp blinks, the record key and the play key's LED glow red, the counter climbs, the reels turn, and the level writes itself into the waveform in red behind the head, replacing the track's bars over the recorded span.
- Play while recording pauses the take: the tape coasts to a hold and the lamp stays lit. Play or record resumes it. Play never starts a separate playback during a recording.
- Stop ends recording and playback from any state, and rewinds to the start.
- The marker key (the flag at the strip's right end, beside the time left) drops a marker where the head is, in any state: a small stepped cue notch in ink hanging just under the waveform at that moment, kept per track for the session, and the readout counts them where a track number would be. A press within a quarter second of a marker finds that one instead of stacking, and says it again.
- Scrubbing is disabled while recording or paused (no press,
aria-disabled). - Any key interrupts a wind, which then acts on the state the wind came from. The end of the tape stops recording and playback (silently, the take and its markers still on the strip); play there rewinds to the start and plays.
- A polite live region announces "Recording", "Recording paused", "Recording resumed", "Recording stopped" and each marker ("Marker 2, 00:14"; set them in
labels).
The transport is play, record in the middle (the big key, its red bead lighting while it records) and stop, one group with equal gaps, so record sits on the recorder's centre by symmetry. There are no track keys: it is a recorder, not a playlist.
The waveform
The scrubber is the current track's waveform: fine mirrored bars, 1.5px wide on a 4px pitch and up to 28px tall, so the count follows the width and every bar lands on whole device pixels. Behind the head the bars are in ink, ahead of it in the faint line colour. A take is kept per track for the session (in memory): while recording it is bright red, and on playback it is a dimmer red, a solid mix of the red into the panel. Scrubbing is off while recording, so the strip stays at full strength to show the take. Markers hang 1px under the strip as stepped 3×4 notches in ink (a 1px stem on a 3px foot), on whole device pixels, clear of the head's line.
The reels
The reels are one canvas, drawn at one backing pixel per device pixel. Each pack keeps its area, so the emptier reel turns faster; both turn clockwise as the tape plays and back as it rewinds. A reel turns at most 20° a frame, and within a frame its windows and hub teeth are drawn as a motion blur, so a fast wind reads as a smear and never runs backwards. Everything that doesn't turn (head, guides, shadows, rims, hubs, the acrylic's gloss, a full reel's wound layers) is baked once per size and theme, so a frame draws only what moves; the canvas paints only while the machine moves, and is drawn sharp once it parks. Glows use canvas shadows rather than filters, so Safari draws them too.
The drawing lives in reels.ts and runs on a worker (the canvas is handed over; in Safari the worker sends bitmaps back), so while the tape runs the page's thread only passes a message a frame. Bundlers that support new Worker(new URL("./reels.ts", import.meta.url)) (Vite, Next.js with Turbopack or webpack 5, Parcel) get the worker, shipped beside the component as reels.ts; the canvas is handed over only after the worker's first frame. If a bundler can't make the worker, a Content Security Policy refuses it (worker-src), it fails, or it sends no first frame within a second, the same code draws on the page on a fresh canvas instead, so the reels never stay blank and the fallback never throws. Under a worker-src 'none' policy the browser still logs its own refusal.
On the page's thread, at a 4× slower CPU on a 3× phone: about 46 ms a second playing, 69 recording and 110 for the 1.2s of a wind (82, 143 and 201 in headless Chromium with a GPU, whose compositor path costs more); about 0 at rest and off-screen.
Props
| Prop | Default | What it does |
|---|---|---|
tracks | one demo track | the tape: { title, duration, peaks? }, of which the first is loaded (the face has no track keys); duration in seconds; peaks is its waveform, numbers 0–1 of any length, resampled to the bars (without it, a seeded song-like waveform). A list with other titles or lengths is a new tape: the takes and markers go. An empty list is a blank tape, ready to record: a flat strip five minutes long, titled "Blank tape" (blank), never the demo |
device | "RTT—02" | the name in the status bar |
onModeChange | — | (mode, seconds): called whenever the transport state changes (stopped, playing, recording, paused-recording, winding), with the tape's time then; drive a MediaRecorder from it |
onMarker | — | (seconds, track): called when a new marker is dropped (not when a press finds one already there) |
mode | — | controlled: stopped, playing, recording or paused-recording. A change drives the deck there as its keys would, quietly: no onModeChange or onSeek comes back for it, and a wind it starts makes no whirr unless it was set inside a person's press. winding is the deck's own, and ignored. A key's change reaches you through onModeChange; the deck never undoes it, so a host that answers late (a transition, a server) loses neither the place nor the take |
time | its own clock | () => number, your own audio's clock (() => audio.currentTime), read every frame while the tape plays, so the reels, packs and timecode follow your player (a take always runs on the tape's own clock); or seconds, to wind the tape there when the number changes by more than half a second |
defaultTime | 0 | seconds: where the tape starts (a saved place), when time is left out |
onTimeChange | — | (seconds): the tape's time, about four times a second while it moves and once more where it stops; never per frame. A time within half a second of the tape is taken as an echo, so you can pass it straight back |
markers | — | controlled: the markers on the tape, in seconds, so saved ones come back |
defaultMarkers | — | the markers at first, when markers is left out |
onMarkersChange | — | (markers): every marker in seconds, in order, when one is dropped, and [] when a new tape clears them |
onSeek | — | (seconds): called when a person moves the tape: a drag let go, or a wind (stop's rewind, a press along the strip, a key) arriving; never for a wind your mode or time started. Set your audio's currentTime from it |
onTrackChange | — | kept for compatibility: the face never changes track, so it is not called |
level | simulated voice | () => number, the live input level 0–1, read every frame while recording (for example from a microphone analyser); without it, a simulated voice in syllables, phrases and pauses |
labels | English | accessible names { play, pause, resume, stop, record, marker, seek }, what a screen reader hears as recording changes { recording, recordingPaused, recordingResumed, recordingStopped }, marked, said for each marker, a template with {n} and {time} ("Marker {n}, {time}"), and blank, the title of a blank tape. prev and next are still accepted and no longer shown |
sound | off | key clunks and the wind's whirr: true, or a volume 0–1 (see Sound) |
className | — | added to the root |
Sound
Off by default. With sound (or a volume, sound={0.5}) every key that can press clunks, record arms with a heavier double latch when it starts a take, the marker key clicks a little higher, and a wind (stop, play at the end of the tape, a far press on the waveform, the slider keys) whirrs for exactly as long as the tape winds. The whirr runs down when the wind ends or is cut short, and stops if the recorder leaves the view. The end of a track is silent. setMuted(true) from components/mu/sounds.ts silences every cottoncandy item at once.
Licence
Included with Pro: use it in unlimited end products for you and your clients; no reselling as a kit. See the licence.
A tape deck that plays, scrubs and records. Press play and the tape winds between smoked acrylic reels; scrub the waveform and the reels turn under your hand. The only colour is light: amber while it plays, red while you record.
For podcasts, voice memos and recordingsMore in Audio & media