Metronome-RS
A high-performance, cross-platform metronome library written in Rust with Python bindings. Perfect for musicians, music software developers, and anyone needing precise timing and audio generation.
Demo video
View a short video here.
Published
The library is available to both rust and python projects at: crates.io PyPi
Features
- High-Performance Audio: Built on CPAL for low-latency, cross-platform audio
- Multiple Languages: Native Rust API + Python bindings
- Advanced Rhythms: Support for subdivisions, accents, and complex time signatures
- Customizable Sounds: Multiple wave types (sine, square, triangle, sawtooth)
- Cross-Platform: Works on Linux, Windows, and macOS
- Precision Timing: Accurate BPM control for professional use
- Flexible API: From simple beeps to complex rhythmic patterns
Quick Start
Rust
Add to your Cargo.toml:
[]
= "1.0.0"
use ;
use ;
// Start a 120 BPM metronome
start_simple_metronome?;
// Let it play for 5 seconds
sleep;
// Stop the metronome
stop_global_metronome;
Python
# Start a 120 BPM metronome
# Let it play for 5 seconds
# Stop the metronome
Documentation
Rust Documentation
Python Documentation
Advanced Usage
Time Signatures and Accents
Rust:
use ;
// 4/4 time with accented first beat
start_metronome_with_time_signature?;
// Custom accent configuration
let config = strong;
start_custom_metronome?;
Python:
# 4/4 time with accented first beat
# Custom accent configuration
=
Subdivisions for Practice
Rust:
// Eighth note subdivisions (2 per beat)
start_metronome_with_eighth_notes?;
// Sixteenth note subdivisions (4 per beat)
start_metronome_with_sixteenth_notes?;
// Triplets (3 per beat)
start_metronome_with_triplets?;
// Custom subdivisions
start_metronome_with_subdivisions?;
Python:
# Eighth note subdivisions
# Sixteenth note subdivisions
# Triplets
# Custom subdivisions (6 per beat at 60% volume)
Different Wave Types
Rust:
use ;
let config = with_wave_types;
start_custom_metronome?;
Python:
=
=
=
Timed Practice Sessions
Rust:
// Play for exactly 30 seconds
play_metronome_for_duration?;
Python:
# Play for exactly 30 seconds
GUI Examples
Simple Tkinter Metronome (Python)
Features a minimal GUI with:
- BPM input
- Start/Stop button
- Status display
Full-Featured GUI Demo (Python)
Features:
- BPM and time signature input
- Multiple metronome types
- Test beep functionality
- Advanced controls
Installation & Building
For Rust Projects
[]
= "1.0.0"
For Python Projects
From PyPI (recommended):
Build from source:
# Install Rust and maturin
|
# Clone and build
System Dependencies
- Linux:
sudo apt-get install libasound2-dev(ALSA development libraries) - Windows: No additional dependencies
- macOS: No additional dependencies
Cross-Platform Support
The library uses CPAL's platform-specific audio backends:
- Linux: ALSA (Advanced Linux Sound Architecture)
- Windows: WASAPI (Windows Audio Session API)
- macOS: CoreAudio
This means Python wheels are platform-specific, but provides optimal performance and native audio integration on each platform.
API Overview
Core Functions (Rust)
| Function | Description |
|---|---|
start_simple_metronome(bpm) |
Basic metronome without accents |
start_metronome_with_time_signature(bpm, beats) |
Metronome with time signature accents |
start_practice_metronome(bpm, beats) |
Optimized for practice (subtle accents) |
start_performance_metronome(bpm, beats) |
Optimized for performance (strong accents) |
start_custom_metronome(bpm, beats, config) |
Full customization control |
play_metronome_for_duration(bpm, beats, ms) |
Timed metronome (blocking) |
stop_global_metronome() |
Stop any playing metronome |
Python Bindings
All Rust functions are available with py_ prefix:
py_start_simple_metronome()py_start_metronome_with_time_signature()py_play_metronome_for_duration()- etc.
Plus Python-friendly classes:
PyWaveType- Wave type enumerationPyAccentConfig- Accent configuration with builder pattern
Use Cases
Musicians
- Practice Tool: Subdivisions help with complex rhythms
- Performance Aid: Strong accents for live performance
- Tempo Training: Precise BPM control for technique development
Developers
- Music Software: Integrate metronome into DAWs or music apps
- Game Development: Rhythm game mechanics
- Audio Applications: Timing reference for audio processing
Education
- Music Teaching: Visual and audio timing reference
- Rhythm Training: Subdivision practice for students
- Ensemble Practice: Synchronized timing for groups
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Development Setup
# Clone the repository
# Run Rust tests
# Run examples
# Build Python bindings
# Test Python bindings
License
This project is licensed under either of:
at your option.
Acknowledgments
- Built with CPAL for cross-platform audio
- Python bindings powered by PyO3
- Created by @arymus for the music community
Support
Made with care for musicians and developers