A modern, interactive drum machine and beat sequencer web application inspired by the classic Roland TR-808. Create, program, and play complex drum patterns across 10 instrument tracks with a responsive 16-step grid interface.
-
16-Step Beat Grid: Intuitive step sequencer with 16th note resolution
-
10 Instrument Tracks:
- 2 Kick drums
- 2 Bass synth samples
- 2 Snare/clap samples
- 2 Synth stabs
- 2 Hi-hat samples
-
Real-Time Playback: Play, pause, and stop functionality with Transport-precise timing via Tone.js
-
BPM Control: Adjust tempo in real-time (40β300 BPM range)
- Volume Knob Control (Current Branch): Interactive knob for real-time volume adjustment with rotational angle-to-dB conversion
- Commit #22: Visual refinementβ16th notes now display with slightly dimmed brightness for clarity
- Commit #21: Audio bundling improvementβsamples imported as ES modules for production reliability
- Commit #20: Asset path fixes for relative image imports
- Commit #19: CI/CD setup with superlinter
- Commit #18: Beat naming featureβclick title to customize sequence name
tr-08/
βββ src/
β βββ App.tsx # Main app, state & track config
β βββ sequencer.ts # Tone.js Transport engine
β βββ App.css # App-specific styles
β βββ index.css # Global styles (Tailwind imports)
β βββ main.tsx # React entry point
β βββ components/
β β βββ Pad.tsx # Individual grid button
β β βββ PlayStopBtn.tsx # Play/stop toggle with split design
β β βββ Button.tsx # Reusable button component
β β βββ TempoDisplay.tsx # BPM display with +/- controls
β β βββ Knob.tsx # Interactive volume control knob
β βββ assets/
β βββ images/
β β βββ MPC_mark.png # TR-08 logo
β βββ samples/ # 10 drum audio samples (WAV)
βββ dist/ # Production build output
βββ vite.config.ts # Vite configuration
βββ tsconfig.app.json # TypeScript app config
βββ tsconfig.node.json # TypeScript node config
βββ eslint.config.js # ESLint rules
βββ tailwind.config.ts # Tailwind customization
βββ package.json # Dependencies & scripts
βββ README.md # This file
The application uses React hooks with a functional component architecture. Key state in App.tsx:
- Grid State (
grid): 10Γ16 2D array of booleans (track Γ step) - BPM State (
bpm): Tempo in beats per minute (40β300 range) - Current Step (
currentStep): Active step position (0β15) - Beat Name (
beatName): User-defined sequence name (max 25 chars) - Knob Angle (
knobAngle): Volume knob rotation in degrees (10β256 range) - Loading State (
loadedCount,allPlayersReady,isLoading): Audio sample status
The volume knob uses a rotational angle-to-dB conversion system:
- Props:
rotationAngle: Current rotation in degrees (10β256)onDrag: Callback fired when user drags knob
- Interaction: Vertical mouse movement adjusts angle; clamped to min/max bounds
- Visual: Amber button with black indicator line; offset by
-130degrees for rendering - Behavior: Drag position updates continuously via
handleWindowMouseMoveevent listener
getKnobRotation(newAngle: number): number (App.tsx:~200)
- Converts dB values to rotation degrees
- Formula:
(newAngle + 20) * (350 / 25) + KNOB_STARTING_ANGLE - Used during initialization to set starting knob position based on initial volume (-5 dB)
getDbFromRotation(rotationAngle: number): number (App.tsx:~204)
- Core conversion function: Maps knob angle to dB value
- Input range: 10β256 degrees
- Output range: -25 dB to +5 dB (decibels)
- Linear interpolation formula:
((rotationAngle - inputMin) / (inputMax - inputMin)) * (outputMax - outputMin) + outputMin - Currently logs dB value to console for debugging
handleKnobValueChange(newAngleFromKnob: number): void (App.tsx:~195)
- Handler triggered by
onDragcallback from Knob component - Updates
knobAnglestate for visual rendering - Calls
getDbFromRotation()to calculate audio volume - Note: Currently calculates but doesn't apply dB value to audio players yet
- User drags knob β Knob component fires
onDrag(newAngle) handleKnobValueChange()updatesknobAnglestate- Knob re-renders with new visual angle
getDbFromRotation()converts angle to dB (logged but not applied to audio)- Future: dB value should be applied to all track players' volume property
Users customize the beat name via title interaction (Commit #18):
Component Integration (App.tsx)
[beatName, setBeatName]: Stores current sequence name[isEditTitleActive, setIsEditTitleActive]: Toggles edit mode
handleTitleClick(): void (App.tsx:~173)
- Triggered when user clicks the h1 heading
- Sets
isEditTitleActiveto true to show input field
getDisplayTitle(): JSX.Element (App.tsx:~177)
- Conditional render: Returns either input field or heading
- Input mode:
<input>with maxLength 25 chars, placeholder, keyboard handlers - Display mode:
<h1>with click handler and Stack Sans Notch font
handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void (App.tsx:~164)
- Enter key: Saves input value and exits edit mode
- Escape key: Cancels edit without saving
- Validates empty string (trims whitespace) before saving
All UI components are functional with TypeScript prop types:
-
Pad.tsx: Individual grid button
- Props:
color,isActive,isCurrentStep,is16thNote,onClick - Styling: Opacity for active/inactive; brightness for playhead and 16th notes
- Props:
-
PlayStopBtn.tsx: Play/stop toggle with split visual design
- Shows START/STOP as separate visual sections
- Indicates current playback state
- Disabled during loading
-
Button.tsx: Reusable control button
- Props:
text,customStyles,onClick
- Props:
-
TempoDisplay.tsx: BPM display with +/β controls
- Props:
bpmValue,onIncrementClick,onDecrementClick - Real-time BPM adjustment during playback
- Props:
-
Knob.tsx: Interactive volume control
- Props:
rotationAngle,onDrag - Drag-based interaction with min/max clamping
- Props:
The createSequencer() function provides core timing:
- Uses Tone.js Transport for precise scheduling
- Schedules playback at 16th note intervals (
"16n") - Methods:
start(),stop(),updateBpm(),dispose() - Callback:
onStep(step)fires each 16th note with current step number (0β15)
Audio samples imported as ES modules (Commit #21):
- Vite bundles them into production build
- No runtime network requests
- 10 drum samples across 5 track pairs (kicks, bass, snares, synths, hi-hats)
- Tailwind CSS v4 via
@tailwindcss/vite - Color system: Track colors defined in
tracksarray - Grid layout: CSS Grid with 16 columns (
grid-cols-16) - Pad states:
- Playhead:
brightness-175(very bright) - 16th notes:
brightness-135(slightly dimmed) - Active:
opacity-100| Inactive:opacity-50
- Playhead:
- Custom font: Stack Sans Notch (Google Fonts)
- Grid interaction: User clicks pad β
handlePadClick()βtogglePad()β state update β Pad re-renders - Playback: Sequencer fires
onStepcallback β updatescurrentStepβ Pad brightness changes - Volume: User drags knob β
handleKnobValueChange()βgetDbFromRotation()β (future: apply to players) - Title: User clicks title β
handleTitleClick()β shows input βhandleKeyDown()handles save/cancel
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
Currently, two official plugins are available:
- @vitejs/plugin-react uses Babel (or oxc when used in rolldown-vite) for Fast Refresh
- @vitejs/plugin-react-swc uses SWC for Fast Refresh
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see this documentation.
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
export default defineConfig([
globalIgnores(["dist"]),
{
files: ["**/*.{ts,tsx}"],
extends: [
// Other configs...
// Remove tseslint.configs.recommended and replace with this
tseslint.configs.recommendedTypeChecked,
// Alternatively, use this for stricter rules
tseslint.configs.strictTypeChecked,
// Optionally, add this for stylistic rules
tseslint.configs.stylisticTypeChecked,
// Other configs...
],
languageOptions: {
parserOptions: {
project: ["./tsconfig.node.json", "./tsconfig.app.json"],
tsconfigRootDir: import.meta.dirname,
},
// other options...
},
},
]);You can also install eslint-plugin-react-x and eslint-plugin-react-dom for React-specific lint rules:
// eslint.config.js
import reactX from "eslint-plugin-react-x";
import reactDom from "eslint-plugin-react-dom";
export default defineConfig([
globalIgnores(["dist"]),
{
files: ["**/*.{ts,tsx}"],
extends: [
// Other configs...
// Enable lint rules for React
reactX.configs["recommended-typescript"],
// Enable lint rules for React DOM
reactDom.configs.recommended,
],
languageOptions: {
parserOptions: {
project: ["./tsconfig.node.json", "./tsconfig.app.json"],
tsconfigRootDir: import.meta.dirname,
},
// other options...
},
},
]);