metronome_rs/lib.rs
1//! # Metronome RS
2//!
3//! A Rust library for generating audio tones and metronome functionality using CPAL.
4//!
5//! ## Quick Start
6//!
7//! ```no_run
8//! use metronome_rs::{start_simple_metronome, stop_global_metronome};
9//! use std::{thread, time::Duration};
10//!
11//! // Start a simple 120 BPM metronome
12//! start_simple_metronome(120.0)?;
13//!
14//! // Let it play for 5 seconds
15//! thread::sleep(Duration::from_secs(5));
16//!
17//! // Stop the metronome
18//! stop_global_metronome();
19//! # Ok::<(), Box<dyn std::error::Error>>(())
20//! ```
21//!
22//! ## High-Level Helpers
23//!
24//! The library provides convenient high-level functions for common use cases:
25//!
26//! - `start_simple_metronome(bpm)` - Simple metronome without accents
27//! - `start_metronome_with_time_signature(bpm, beats)` - Metronome with time signature accents
28//! - `play_metronome_for_duration(bpm, beats, duration_ms)` - Timed metronome that auto-stops
29//! - `start_practice_metronome(bpm, beats)` - Optimized for practice with subtle accents
30//! - `start_performance_metronome(bpm, beats)` - Optimized for performance with strong accents
31//! - `start_custom_metronome(bpm, beats, config)` - Full customization control
32//!
33//! ## Subdivision Support
34//!
35//! The library supports subdivisions for practicing complex rhythms:
36//!
37//! - `start_metronome_with_eighth_notes(bpm, beats)` - 2 subdivisions per beat
38//! - `start_metronome_with_sixteenth_notes(bpm, beats)` - 4 subdivisions per beat
39//! - `start_metronome_with_triplets(bpm, beats)` - 3 subdivisions per beat (triplets)
40//! - `start_metronome_with_subdivisions(bpm, beats, subdivisions, volume)` - Custom subdivisions
41//!
42//! ## Modules
43//!
44//! - `audio` - Audio device and configuration utilities
45//! - `tone` - Tone generation and playbook functionality
46//! - `metronome` - Metronome implementation with accent support
47//! - `accent` - Accent configuration for metronomes
48
49// Be a perfectionist, no code is good enough!
50#![deny(
51 clippy::all,
52 clippy::suspicious,
53 clippy::complexity,
54 clippy::perf,
55 clippy::style,
56 clippy::pedantic,
57 clippy::cargo,
58 clippy::nursery
59)]
60// Allow multiple crate versions as it's out of our control due to transitive dependencies
61#![allow(clippy::multiple_crate_versions)]
62
63pub mod accent;
64pub mod audio;
65pub mod metronome;
66pub mod tone;
67
68#[cfg(feature = "python")]
69pub mod python;
70
71#[cfg(test)]
72mod tests;
73
74// Re-export commonly used items for convenience
75pub use accent::{AccentConfig, WaveType};
76pub use audio::{get_default_host, get_default_output_config, get_default_output_device};
77pub use metronome::{
78 Metronome,
79 get_global_metronome,
80 play_custom_metronome_for_duration,
81 play_metronome_for_duration,
82 start_custom_metronome,
83 // Subdivision helper functions
84 start_metronome_with_eighth_notes,
85 start_metronome_with_sixteenth_notes,
86 start_metronome_with_subdivisions,
87 start_metronome_with_time_signature,
88 start_metronome_with_triplets,
89 start_performance_metronome,
90 start_practice_metronome,
91 // High-level helper functions
92 start_simple_metronome,
93 stop_global_metronome,
94};
95pub use tone::{
96 beep, beep_frequency, create_sine_wave_generator, play_beep_with_config,
97 play_beep_with_config_and_params, play_beep_with_wave_type,
98 play_beep_with_wave_type_and_volume, play_default_beep, play_tone, play_tone_with_wave_type,
99 play_tone_with_wave_type_and_volume,
100};
101
102// Re-export Python bindings when feature is enabled
103#[cfg(feature = "python")]
104pub use python::{PyAccentConfig, PyWaveType};