Skip to main content

A metronome library with audio beep functionality

Project description

Metronome-RS

Metronome-RS Logo

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.

License: MIT OR Apache-2.0 Rust Python

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:

[dependencies]
metronome-rs = "1.0.0"
use metronome_rs::{start_simple_metronome, stop_global_metronome};
use std::{thread, time::Duration};

// Start a 120 BPM metronome
start_simple_metronome(120.0)?;

// Let it play for 5 seconds
thread::sleep(Duration::from_secs(5));

// Stop the metronome
stop_global_metronome();

Python

pip install metronome-rs
import metronome_rs
import time

# Start a 120 BPM metronome
metronome_rs.py_start_simple_metronome(120.0)

# Let it play for 5 seconds
time.sleep(5)

# Stop the metronome
metronome_rs.py_stop_global_metronome()

Documentation

Rust Documentation

Python Documentation

Advanced Usage

Time Signatures and Accents

Rust:

use metronome_rs::{start_metronome_with_time_signature, AccentConfig};

// 4/4 time with accented first beat
start_metronome_with_time_signature(100.0, 4)?;

// Custom accent configuration
let config = AccentConfig::strong();
start_custom_metronome(120.0, Some(4), config)?;

Python:

# 4/4 time with accented first beat
metronome_rs.py_start_metronome_with_time_signature(100.0, 4)

# Custom accent configuration
config = metronome_rs.PyAccentConfig.strong()
metronome_rs.py_start_custom_metronome(120.0, 4, config)

Subdivisions for Practice

Rust:

// Eighth note subdivisions (2 per beat)
start_metronome_with_eighth_notes(100.0, Some(4))?;

// Sixteenth note subdivisions (4 per beat)
start_metronome_with_sixteenth_notes(80.0, Some(4))?;

// Triplets (3 per beat)
start_metronome_with_triplets(90.0, Some(4))?;

// Custom subdivisions
start_metronome_with_subdivisions(120.0, Some(4), 6, 0.6)?;

Python:

# Eighth note subdivisions
metronome_rs.py_start_metronome_with_eighth_notes(100.0, 4)

# Sixteenth note subdivisions  
metronome_rs.py_start_metronome_with_sixteenth_notes(80.0, 4)

# Triplets
metronome_rs.py_start_metronome_with_triplets(90.0, 4)

# Custom subdivisions (6 per beat at 60% volume)
metronome_rs.py_start_metronome_with_subdivisions(120.0, 4, 6, 0.6)

Different Wave Types

Rust:

use metronome_rs::{AccentConfig, WaveType};

let config = AccentConfig::with_wave_types(
    WaveType::Square,    // Accent beats
    WaveType::Triangle   // Regular beats
);
start_custom_metronome(110.0, Some(4), config)?;

Python:

square_wave = metronome_rs.PyWaveType.square()
triangle_wave = metronome_rs.PyWaveType.triangle()

config = metronome_rs.PyAccentConfig.with_wave_types(square_wave, triangle_wave)
metronome_rs.py_start_custom_metronome(110.0, 4, config)

Timed Practice Sessions

Rust:

// Play for exactly 30 seconds
play_metronome_for_duration(120.0, Some(4), 30000)?;

Python:

# Play for exactly 30 seconds
metronome_rs.py_play_metronome_for_duration(120.0, 4, 30000)

GUI Examples

Simple Tkinter Metronome (Python)

python simple_tkinter_demo.py

Features a minimal GUI with:

  • BPM input
  • Start/Stop button
  • Status display

Full-Featured GUI Demo (Python)

python tkinter_demo.py

Features:

  • BPM and time signature input
  • Multiple metronome types
  • Test beep functionality
  • Advanced controls

Installation & Building

For Rust Projects

[dependencies]
metronome-rs = "1.0.0"

For Python Projects

From PyPI (recommended):

pip install metronome-rs

Build from source:

# Install Rust and maturin
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
pip install maturin

# Clone and build
git clone https://github.com/arymus/metronome-rs
cd metronome-rs
maturin develop --features python

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 enumeration
  • PyAccentConfig - 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
git clone https://github.com/arymus/metronome-rs
cd metronome-rs

# Run Rust tests
cargo test

# Run examples
cargo run --example simple_metronome

# Build Python bindings
maturin develop --features python

# Test Python bindings
python python_example.py

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

metronome_rs-1.1.0-cp313-cp313-win_amd64.whl (229.6 kB view details)

Uploaded CPython 3.13Windows x86-64

metronome_rs-1.1.0-cp313-cp313-macosx_11_0_arm64.whl (318.9 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

metronome_rs-1.1.0-cp312-cp312-win_amd64.whl (229.8 kB view details)

Uploaded CPython 3.12Windows x86-64

metronome_rs-1.1.0-cp312-cp312-manylinux_2_34_x86_64.whl (815.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

metronome_rs-1.1.0-cp312-cp312-macosx_11_0_arm64.whl (319.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

metronome_rs-1.1.0-cp311-cp311-win_amd64.whl (230.0 kB view details)

Uploaded CPython 3.11Windows x86-64

metronome_rs-1.1.0-cp311-cp311-manylinux_2_34_x86_64.whl (815.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

metronome_rs-1.1.0-cp311-cp311-macosx_11_0_arm64.whl (322.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

metronome_rs-1.1.0-cp310-cp310-win_amd64.whl (230.0 kB view details)

Uploaded CPython 3.10Windows x86-64

metronome_rs-1.1.0-cp39-cp39-win_amd64.whl (230.3 kB view details)

Uploaded CPython 3.9Windows x86-64

File details

Details for the file metronome_rs-1.1.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for metronome_rs-1.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 45cdce27aa04b4c3ce9b2b95907e407192660de86ff96ae64648ca02ce28a902
MD5 dd0cbc1608799ddc4e1069a4f403e54e
BLAKE2b-256 77e47d8956b73573e67b44376d032bfca49eb497fd31708d7fa5a571ada4defe

See more details on using hashes here.

Provenance

The following attestation bundles were made for metronome_rs-1.1.0-cp313-cp313-win_amd64.whl:

Publisher: build-wheels.yml on ofluffydev/metronome-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file metronome_rs-1.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for metronome_rs-1.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 da96e1ffb6e4898bbeec34590eee72b1b506cd552f182f550b41442474f94b6e
MD5 9c34d71ff7bb6f37b9641991ef64324c
BLAKE2b-256 d1303c01397a6c3cb28436f12a8bb431a1dc2e74713a6426f24c17d3773786a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for metronome_rs-1.1.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on ofluffydev/metronome-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file metronome_rs-1.1.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for metronome_rs-1.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 faa62bce319f8029bd3ae6dbfa1643722a601ed868df5620a7c61c5867407d4b
MD5 d1a09f8c1cf3a689f3e3cae6bb2360f2
BLAKE2b-256 ac5e35cc6c010827945f129c93090c0e2fff32e6d7055a8c068d3da9be246ee5

See more details on using hashes here.

Provenance

The following attestation bundles were made for metronome_rs-1.1.0-cp312-cp312-win_amd64.whl:

Publisher: build-wheels.yml on ofluffydev/metronome-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file metronome_rs-1.1.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for metronome_rs-1.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 26a27d9e6a0f7bfcbd6b2a44fd64679e2362b1677b0eee340d447261c33e144b
MD5 e2f6a6313fe3f0ec612a757895c53ae2
BLAKE2b-256 69d9024c094d2bfff27cfc34696ab48ff7f1e198f0fdc4aeebfdaeac478ff145

See more details on using hashes here.

Provenance

The following attestation bundles were made for metronome_rs-1.1.0-cp312-cp312-manylinux_2_34_x86_64.whl:

Publisher: build-wheels.yml on ofluffydev/metronome-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file metronome_rs-1.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for metronome_rs-1.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 236375ff0a0cebede94b630481456bfe659598a33216b49d3ad09ffe27c54baf
MD5 77dd40e0f1de4d372f73910a6664359c
BLAKE2b-256 eb26afe1663f85e8e38213a133e89c2ac2dd82ba53b8b9e336525c29a4c485dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for metronome_rs-1.1.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on ofluffydev/metronome-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file metronome_rs-1.1.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for metronome_rs-1.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8d6c44c90b34183be22f96c1f097224e6731e7401530160a220977539d3d4bb6
MD5 df2a5c4c0f2701a2c40b11df52633e41
BLAKE2b-256 1a1938216a8c8442844e0d7a1c7fbddc2920d2bd81ae4361534213bffd16240c

See more details on using hashes here.

Provenance

The following attestation bundles were made for metronome_rs-1.1.0-cp311-cp311-win_amd64.whl:

Publisher: build-wheels.yml on ofluffydev/metronome-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file metronome_rs-1.1.0-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for metronome_rs-1.1.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ca93b88ac00408d38fd5a96a18e4ca52c392e2c932c32fdf83fc578a15a4b15b
MD5 ec5df4cda1d70c74a1c1817882246d8a
BLAKE2b-256 abca857f796f54e56167743fe2c476967cb32adde65b1b0cce19ef3373aea1db

See more details on using hashes here.

Provenance

The following attestation bundles were made for metronome_rs-1.1.0-cp311-cp311-manylinux_2_34_x86_64.whl:

Publisher: build-wheels.yml on ofluffydev/metronome-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file metronome_rs-1.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for metronome_rs-1.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2d32d5db014e5b506ace17b907001b349e67c3679a0b3166fed1be0c8a769aba
MD5 ec11cc70fd85f9aa30034acb5da7e5ab
BLAKE2b-256 ede1c5153644efee52fdb6be16b5232c2ef9dc091a79a76382386e693327be5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for metronome_rs-1.1.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on ofluffydev/metronome-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file metronome_rs-1.1.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for metronome_rs-1.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 5b9d4963ee28cdbf1333023d1b4d28700f0f5fe0ce65130ab16cd73e0fbbdd5d
MD5 ea1e8d15cedff2a84d73b6d64cc2d487
BLAKE2b-256 3721d14680f99c103b12c37e1180303f0282c40ab2a7823cab405597898e2006

See more details on using hashes here.

Provenance

The following attestation bundles were made for metronome_rs-1.1.0-cp310-cp310-win_amd64.whl:

Publisher: build-wheels.yml on ofluffydev/metronome-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file metronome_rs-1.1.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: metronome_rs-1.1.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 230.3 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for metronome_rs-1.1.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 4eca748ec1edc68bf26e4478c99b39e5327a341296bc1094acc0b2cf2caf59f0
MD5 cae8a0d04b441c425b34692c4170ede4
BLAKE2b-256 2f3df8407b86774d97117c264e310ed2216f41e426fe853317e58eaf9ca73afc

See more details on using hashes here.

Provenance

The following attestation bundles were made for metronome_rs-1.1.0-cp39-cp39-win_amd64.whl:

Publisher: build-wheels.yml on ofluffydev/metronome-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page