A browser-based drum machine featuring multiple drum kits, advanced swing timing, and real-time audio scheduling. Built with vanilla JavaScript and the Web Audio API.
- Classic - Traditional rock/pop drum sounds
- Electronic - Digital and synthetic textures
- 808 - Iconic drum machine sounds with deep sub bass
- Vintage - Warm analog-style sounds with tape flutter
- Trap - Modern hip-hop oriented sounds with punch
- Real-time BPM control (60-200 BPM)
- Sophisticated swing timing with multiple curve algorithms
- Per-track volume control and sound selection
- Variable pattern lengths (8, 16, or 32 steps per track)
- Custom audio file uploads for any track
- 4 independent tracks with up to 32 steps each
- Built-in preset patterns optimized for each kit
- Save/load pattern functionality with named storage
- Auto-save for session persistence
- Visual step sequencer with beat emphasis
- Hardware-inspired design with realistic controls
- Mobile-optimized touch interface with haptic feedback
- Keyboard shortcuts (Spacebar to play, 1-4 to trigger tracks)
- Real-time visual feedback during playback
- Sample-accurate timing using Web Audio API
-
Clone the repository:
git clone https://github.com/yourusername/web-drum-machine.git cd web-drum-machine -
Open in browser:
# Serve locally (recommended) python -m http.server 8000 # Or simply open drums.html in your browser
-
Start creating:
- Click step buttons to create patterns
- Press spacebar to play/pause
- Use number keys 1-4 to trigger individual tracks
- Experiment with different kits and swing settings
- Play/Pause - Spacebar or click play button
- Stop - Stop button (resets to beginning)
- Clear All - Removes all patterns
- Step Buttons - Click to toggle steps on/off
- Track Length - Choose 8, 16, or 32 steps per track
- Clear Track - Remove all steps from a single track
- Volume Sliders - Adjust individual track levels
- Kit Selector - Switch between 5 different drum kits
- Sound Dropdown - Choose different sounds per track
- File Upload - Load your own audio samples
- BPM Slider - Real-time tempo control
- Swing Control - Add groove with advanced timing algorithms
- Save Patterns - Name and store your creations
- Load Patterns - Recall saved patterns from dropdown
- Preset Buttons - Load genre-specific starting patterns
- Sample-accurate scheduling using Web Audio API's currentTime
- Advanced swing algorithms with multiple timing curves
- Buffer pooling for optimized memory usage
- Real-time sound synthesis for all built-in sounds
- Professional audio mixing with proper gain staging
- Lookahead scheduling prevents audio dropouts
- Object pooling reduces garbage collection
- Efficient DOM updates using requestAnimationFrame
- Mobile gesture optimization with proper touch handling
- Modern browsers with Web Audio API support
- Chrome, Firefox, Safari, Edge (latest versions)
- Mobile browsers (iOS Safari, Chrome Mobile)
- Progressive enhancement for older browsers
EnhancedDrumMachine- Main orchestrator and sequencerEnhancedSoundGenerator- Real-time drum sound synthesisAdvancedSwing- Sophisticated timing algorithmsDrumKitManager- Kit switching and sound managementAudioBufferPool- Memory optimization for audio buffers
- Observer pattern for UI updates
- Factory pattern for sound generation
- Object pooling for performance
- Modular architecture for maintainability
// In EnhancedSoundGenerator class
generateCustomKick() {
// Your custom kick drum synthesis
const sampleRate = this.audioContext.sampleRate;
// ... implement your sound generation
return buffer;
}// Pattern format: array of 16 booleans per track
const myPattern = {
name: 'Custom Beat',
patterns: [
{ pattern: [true, false, true, false, ...], length: 16 }, // Kick
{ pattern: [false, false, true, false, ...], length: 16 }, // Snare
{ pattern: [true, true, true, true, ...], length: 16 }, // Hi-hat
{ pattern: [false, false, false, false, ...], length: 16 } // Crash
]
};The hardware-inspired CSS uses CSS Grid and Flexbox with custom properties for easy theming:
:root {
--primary-color: #ff6b35;
--background-gradient: linear-gradient(135deg, #2c3e50, #34495e);
--control-background: linear-gradient(145deg, #3a3a3a, #2c2c2c);
}- Web Audio API specification and community
- Classic drum machines (Roland TR-808, TR-909) for inspiration
- Open source audio community for techniques and algorithms
This project is licensed under the MIT License - see the LICENSE file for details.
