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

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-0.1.0-cp313-cp313-win_amd64.whl (229.3 kB view details)

Uploaded CPython 3.13Windows x86-64

metronome_rs-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (318.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

metronome_rs-0.1.0-cp312-cp312-win_amd64.whl (229.4 kB view details)

Uploaded CPython 3.12Windows x86-64

metronome_rs-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl (813.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

metronome_rs-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (318.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

metronome_rs-0.1.0-cp311-cp311-win_amd64.whl (229.6 kB view details)

Uploaded CPython 3.11Windows x86-64

metronome_rs-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl (813.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

metronome_rs-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (321.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

metronome_rs-0.1.0-cp310-cp310-win_amd64.whl (229.7 kB view details)

Uploaded CPython 3.10Windows x86-64

metronome_rs-0.1.0-cp39-cp39-win_amd64.whl (229.8 kB view details)

Uploaded CPython 3.9Windows x86-64

File details

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

File metadata

File hashes

Hashes for metronome_rs-0.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 050c478150880b9fe9ba2a9237507b11bd032e3505093d89732f0c2b04b50951
MD5 755fbd845490793012a2c99614f083ff
BLAKE2b-256 3b8eda17593200d5b98fd68f8da12349dbb354f1205f5f44c3a12a502a72038b

See more details on using hashes here.

Provenance

The following attestation bundles were made for metronome_rs-0.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-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for metronome_rs-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f48b882503b798a28acc4dccc9860daf7ebe09c81036fc438898491a5f01ebea
MD5 e43a1f5eb271ecffd376727cf9efe29e
BLAKE2b-256 0ea8771b8a0e7fa2d560af5f0cee122fe79295647152412bdd646a6fb174f43b

See more details on using hashes here.

Provenance

The following attestation bundles were made for metronome_rs-0.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-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for metronome_rs-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4f9ee0b089625d87f6a3d60a4cef2d196201fda00109ddc522b93cd59a94cba5
MD5 295ed12d73266d7a9936225f4664d7b8
BLAKE2b-256 93c867e6a25200469a3269b44a889c2b90d49cf8dd0189e0d40ecef2c304f9b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for metronome_rs-0.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-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for metronome_rs-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b5f5b13078b00345884e5ceea03c060e8688a17621d10dbc98bec146f0abd1ea
MD5 f7e49991d1367e32d1d468421940c26c
BLAKE2b-256 73c936a03d78da7c7aabe8e4a22bc91aa88ecb6c191925632dfbca1e69726185

See more details on using hashes here.

Provenance

The following attestation bundles were made for metronome_rs-0.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-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for metronome_rs-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 25718f75648a28b97d88d49cb538668267680127ac7f585965e63460d6eb35f7
MD5 4887399731a6e830b878e1aed37669ae
BLAKE2b-256 f03bf19fcd70cab9a94259180c318777c26f199aec5f1cc533ae2601bcc21e76

See more details on using hashes here.

Provenance

The following attestation bundles were made for metronome_rs-0.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-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for metronome_rs-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3959bde40fd83989b9b36f93600252284110cbedd1d2b848f533ce15957b3347
MD5 7e32e143f56ab34c7f7182a033da0959
BLAKE2b-256 35e5702a79ece414035556c508a5da5a32fc41c0dbcd3adcfe18b3105de17ecd

See more details on using hashes here.

Provenance

The following attestation bundles were made for metronome_rs-0.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-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for metronome_rs-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0f6906d5523fe08766eaffb59e24f8ff171b40168c1f46538f99b4a78889a838
MD5 355411f30bcae73903554544fc4daa21
BLAKE2b-256 fadfeb73eaef80df4c6a792e59775523ee15fd6d44bb3db633dbd12d675252b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for metronome_rs-0.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-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for metronome_rs-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2cf57f6b29293d8860f7c32b3f4d355c47754c7c9a12c83aaed5d0f75c9fa9e1
MD5 2dc48ae6fc2db5aebf7e41dbae1a5e0d
BLAKE2b-256 e90a7136ccbb295fb151b28ced7f18ba1f1585f3baaf2f3f84fe1985419a0fe9

See more details on using hashes here.

Provenance

The following attestation bundles were made for metronome_rs-0.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-0.1.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for metronome_rs-0.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 9418f1a2cb540ec6c3991302306f7555125e13eba71aa7c753bba56d272f6f16
MD5 2949f5fe0c41de14684ea0279142680e
BLAKE2b-256 9775cdf79034991a9f3d65c992472b2d21f2d918623513531edfb711342b9119

See more details on using hashes here.

Provenance

The following attestation bundles were made for metronome_rs-0.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-0.1.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: metronome_rs-0.1.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 229.8 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-0.1.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 3b3445d6e5481ded0e2774131fe4cdb85587471cf17bd3cede7abf15c66eda3f
MD5 ee65c3c8389ee8c25d10b71166e5c339
BLAKE2b-256 c00d727c0d49fc2d98f4ff9530489a65b691bb0a4074597a79918682d61e6b03

See more details on using hashes here.

Provenance

The following attestation bundles were made for metronome_rs-0.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