A Rust application that downloads random classical piano MIDI files from piano-midi.de and plays them through USB-connected MIDI devices.
I have a Yamaha P71 keyboard that sounds great, and I wanted to explore the possibilities of playing classical piano pieces on it. Like a rust based player piano.
Most of this codebase were generated with the assistance of ClaudeCode during development. I wanted to try out this idea.
- Downloads and caches MIDI files from piano-midi.de
- Supports all major classical composers (Bach, Mozart, Beethoven, Chopin, etc.)
- Random playback of classical piano pieces
- Cross-platform support (macOS and Raspberry Pi)
- USB MIDI device output
- Command-line interface with device selection
- Rust 1.70+ (2024 edition)
- USB MIDI cable/interface
- MIDI-compatible piano or synthesizer
cargo build --release./target/release/midi-van --list-devices./target/release/midi-van./target/release/midi-van --device "USB MIDI Interface"./target/release/midi-van --cache-dir /path/to/cache- Install the target:
rustup target add aarch64-unknown-linux-gnu- Install cross-compilation tools:
brew install aarch64-elf-gcc- Configure Cargo for cross-compilation by creating
.cargo/config.toml:
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"- Build for Raspberry Pi:
cargo build --release --target aarch64-unknown-linux-gnuInstall cross for easier cross-compilation:
cargo install cross
cross build --release --target aarch64-unknown-linux-gnu- Copy the compiled binary to your Raspberry Pi
- Install required system dependencies:
sudo apt update
sudo apt install libasound2-dev- Connect your USB MIDI cable to the Pi
- Run the application:
./midi-van --list-devices
./midi-van- Ensure your USB MIDI cable is properly connected
- On Linux/Raspberry Pi, check that your user is in the
audiogroup:sudo usermod -a -G audio $USER - Verify the device is recognized:
lsusb # Should show your MIDI interface aconnect -l # List ALSA MIDI connections
- Ensure you have internet connectivity
- The application caches downloaded files in
./midi_cache/by default - If downloads fail, try again as some files may be temporarily unavailable
- Verify your MIDI receiving device (piano/synthesizer) is set to receive on the correct channel
- Some MIDI files may have different channel configurations
- Try different MIDI files if one doesn't play correctly
The application consists of several modules:
midi_scraper.rs- Web scraping and MIDI file downloadingdevice_manager.rs- MIDI device discovery and connectionmidi_player.rs- MIDI file parsing and playback with accurate timingmain.rs- CLI interface and application coordination
midir- Cross-platform MIDI I/Oreqwest- HTTP client for downloading filesscraper- HTML parsingmidly- MIDI file parsingtokio- Async runtimeclap- Command-line argument parsingrand- Random selection