1 unstable release
Uses new Rust 2024
new 0.1.1 | May 18, 2025 |
---|---|
0.1.0 |
|
#113 in No standard library
15KB
236 lines
pitchy
Minimalistic Rust library for working with musical notes, frequencies (Hz), MIDI numbers, and pitch operations like transposition and octave shifts.
✨ Features
- Parse note names like
"A4"
,"C#3"
,"Db5"
- Convert to MIDI note number and frequency in Hz
- Transpose notes by semitones or octaves
- Lightweight and
no_std
compatible (via feature flag)
🚀 Usage
Add to your Cargo.toml
:
[dependencies]
pitchy = "0.1"
Or, to use in no_std
mode:
[dependencies.pitchy]
version = "0.1"
default-features = false
🔧 Example Usage
Parse and Analyze a Note
use pitchy::Note;
use core::str::FromStr;
let note = Note::from_str("A4").unwrap();
assert_eq!(note.midi_number(), Some(69));
assert_eq!(note.frequency(), 440.0);
Transpose a Note
let note = Note::from_str("C4").unwrap();
let up = note.transpose(4.0);
assert_eq!(up.midi_number(), Some(64)); // E4
Convert from MIDI Number
let note = Note::try_from_midi_number(60).unwrap();
assert_eq!(note.frequency(), 261.625565); // ≈ C4
Get Note Parts (no_std friendly)
let note = Note::from_str("F#3").unwrap();
let (semitone, octave) = note.note_parts().unwrap();
assert_eq!(semitone, 6); // F#
assert_eq!(octave, 3);
⚙️ Optional Features
std
(enabled by default): enables note name formatting andDisplay
implslibm
: enables thelibm
math backend used inno_std
mode
To build without std
, use:
cargo build --no-default-features --features libm
📄 License
MIT © paramako
Dependencies
~145KB