pitchy
Minimal, no_std-friendly Rust library for working with musical pitches, frequencies, MIDI numbers, and symbolic note representations.
✨ Features
- Convert between musical frequencies (Hz) and MIDI note numbers
- Transpose notes by semitones or octaves
- Convert ASCII note names like "C#4" or "Db3" into pitch (frequency-based) representations
- Reconstruct symbolic notes (e.g., "C#4") from pitch via default sharp-based spelling
- Extract musical components like note letter, accidental, and octave
- Lightweight and
no_stdcompatible (via feature flag)
🚀 Usage
Add to your Cargo.toml:
[]
= "0.2"
Or, to use in no_std mode:
[]
= "0.2"
= false
= ["libm"]
🔧 Example Usage
Parse and Analyze a Note
use Pitch;
use FromStr;
let pitch = from_str.unwrap;
assert_eq!;
assert_eq!;
Transpose a Note
let pitch = from_str.unwrap;
let up = pitch.transpose;
assert_eq!; // E4
Convert from MIDI Number
let pitch = try_from_midi_number.unwrap;
let actual = pitch.frequency; // 261.6255653005986
let expected = 261.625565; // C4
let epsilon = 1e-6; // 0.000001
assert!;
Convert Pitch to Note
use ;
let pitch = new; // C#4
let note = try_from.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
⚙️ Optional Features
std(enabled by default): enables note name formattinglibm: enables thelibmmath backend used inno_stdmode
To build without std, use:
📄 License
MIT © paramako