Expand description
§pitchy
pitchy is a minimal, no_std-friendly Rust library for working with musical pitch,
represented as audio frequencies (Hz). It supports conversion to and from MIDI numbers,
pitch transposition, and symbolic note mapping.
§Features
- Convert frequencies to MIDI note numbers and back
- Transpose pitches by semitones with precise frequency calculations
- Query pitch octave and MIDI number mappings
- Parse standard note strings like
"C#4"intoPitchvalues - Optional formatting of symbolic note names like
"A4"whenstdis enabled - Uses the
libmmath backend inno_stdmode (via thelibmfeature)
§Example
use pitchy::Pitch;
use std::str::FromStr;
let a4 = Pitch::from_str("A4").unwrap();
assert_eq!(a4.try_midi_number().unwrap(), 69);
let up = a4.transpose(12.0);
assert_eq!(up.try_midi_number().unwrap(), 81); // A5Structs§
- Note
- A musical note spelled with a letter, accidental, and octave.
- Pitch
- A musical pitch represented purely by its frequency in Hertz (Hz).
Enums§
- Accidental
- Represents the accidental applied to a note (double flat, flat, natural, sharp, double sharp).
- Note
Letter - Represents the base letter of a musical note (C, D, E, F, G, A, B).
- Pitchy
Error - An error type representing failures when parsing or converting notes or pitches.