A modern, real-time multiplayer Mellotron web application built with Next.js 15, Tone.js, and Socket.io.
- Interactive Piano Keyboard: Visual piano interface with 2-3 octaves
- Authentic Mellotron Sounds: Multiple sound banks (Strings, Choir, Flutes, Brass)
- Real-time Multiplayer: See and hear other users playing simultaneously
- Audio Effects: Reverb, Delay, ADSR envelope controls
- Recording & Playback: Record your sessions and play them back
- Responsive Design: Works on desktop, tablet, and mobile devices
- Low Latency: Optimized for real-time performance
- Next.js 15 - React framework with App Router and Server Components
- TypeScript - Type-safe development
- Tailwind CSS - Utility-first styling
- Shadcn/ui - Accessible component library
- Tone.js - Web Audio API wrapper for sound synthesis
- Framer Motion - Smooth animations
- Zustand - Lightweight state management
- Next.js API Routes - Backend API endpoints
- Socket.io - WebSocket server for multiplayer
- Upstash Redis (optional) - Presence/session management
- Node.js 18+ and npm/yarn/pnpm
- Modern web browser with Web Audio API support
-
Clone the repository
git clone https://github.com/yourusername/socket-mellotron.git cd socket-mellotron -
Install dependencies
npm install # or yarn install # or pnpm install
-
Add Mellotron samples (required for audio)
- Place audio samples in
public/samples/[sound-bank]/ - See
public/samples/README.mdfor sample requirements - Example:
public/samples/strings/C4.wav
- Place audio samples in
-
Set up environment variables (optional)
cp .env.example .env.local
Edit
.env.local:NEXT_PUBLIC_APP_URL=http://localhost:3000 NEXT_PUBLIC_SOCKET_URL=http://localhost:3000
-
Run the development server
npm run dev
-
Open in browser Navigate to http://localhost:3000
| Key | Note | Key | Note |
|---|---|---|---|
| A | C | S | D |
| D | E | F | F |
| G | G | H | A |
| J | B | K | C |
- White keys: A, S, D, F, G, H, J, K, L
- Black keys: W, E, T, Y, U (above corresponding white keys)
- Sound Banks: Click on sound bank buttons to switch between different Mellotron tapes
- Volume Control: Adjust master volume or mute audio
- Effects: Fine-tune reverb, delay, and envelope settings
- Multiplayer: Each connected user gets a unique color for their key presses
- Recording: Start/stop recording to capture your performance
socket-mellotron/
βββ src/
β βββ app/ # Next.js 15 App Router
β β βββ layout.tsx # Root layout
β β βββ page.tsx # Main page
β β βββ globals.css # Global styles
β β βββ api/
β β βββ socket/ # Socket.io API route
β βββ components/ # React components
β β βββ keyboard/ # Piano keyboard components
β β βββ sound-banks/ # Sound bank switcher
β β βββ controls/ # Volume and effects controls
β β βββ multiplayer/ # User presence and remote keys
β β βββ ui/ # Shadcn/ui components
β βββ lib/ # Utilities and logic
β β βββ audio/ # Tone.js audio engine
β β βββ socket/ # Socket.io client/server
β β βββ store/ # Zustand state management
β β βββ utils.ts # Helper functions
β βββ types/ # TypeScript type definitions
β βββ audio.ts
β βββ socket.ts
β βββ user.ts
βββ public/
β βββ samples/ # Audio sample files
β βββ strings/
β βββ choir/
β βββ flutes/
β βββ brass/
βββ package.json
βββ tsconfig.json
βββ tailwind.config.ts
βββ next.config.js
- Create a new directory in
public/samples/[bank-name]/ - Add audio samples following the naming convention (C3.wav, D3.wav, etc.)
- Update
src/lib/audio/soundBanks.tsto include the new bank - Add bank icon/name to the UI in
src/components/sound-banks/SoundBankSwitcher.tsx
Edit src/components/keyboard/PianoKeyboard.tsx to:
- Change number of octaves
- Modify key mappings
- Adjust visual styling
- Create effect in
src/lib/audio/toneEngine.tsusing Tone.js - Add controls in
src/components/controls/EffectsPanel.tsx - Wire up state management in
src/lib/store/useStore.ts
- Push your code to GitHub
- Import project in Vercel dashboard
- Configure environment variables
- Deploy
Note: Socket.io may require additional configuration for Vercel. Consider using Vercel's Edge Functions or a separate WebSocket server.
docker build -t socket-mellotron .
docker run -p 3000:3000 socket-mellotron- Next.js 15 project initialization
- TypeScript and linting setup
- Tailwind CSS + Shadcn/ui
- Basic keyboard UI component
- Tone.js audio playback integration
- Keyboard input mapping
- Source/record Mellotron samples
- Sound bank switcher UI
- Multiple samples per note with Tone.js Sampler
- ADSR envelope controls
- Socket.io server in Next.js API route
- Note broadcast on key press
- Visual feedback for remote key presses
- User presence with color assignment
- Recording/playback functionality
- Mobile/touch optimization
- Performance optimization
- Deploy to Vercel
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by the classic Mellotron Mark II
- Built with Tone.js
- UI components from Shadcn/ui
- Real-time communication via Socket.io
Your Name - @yourtwitter
Project Link: https://github.com/yourusername/socket-mellotron
Made with β€οΈ and TypeScript