| Crates.io | pitchy |
| lib.rs | pitchy |
| version | 0.2.0 |
| created_at | 2025-05-18 09:36:00.793694+00 |
| updated_at | 2025-05-30 11:46:27.880374+00 |
| description | Minimalistic Rust library for working with frequencies (Hz), MIDI numbers, musical notes, and pitch operations like transposition and octave shifts. |
| homepage | |
| repository | https://github.com/paramako/pitchy |
| max_upload_size | |
| id | 1678489 |
| size | 32,301 |
Minimal, no_std-friendly Rust library for working with musical pitches, frequencies, MIDI numbers, and symbolic note representations.
no_std compatible (via feature flag)Add to your Cargo.toml:
[dependencies]
pitchy = "0.2"
Or, to use in no_std mode:
[dependencies.pitchy]
version = "0.2"
default-features = false
features = ["libm"]
use pitchy::Pitch;
use core::str::FromStr;
let pitch = Pitch::from_str("A4").unwrap();
assert_eq!(pitch.try_midi_number().unwrap(), 69);
assert_eq!(pitch.frequency(), 440.0);
let pitch = Pitch::from_str("C4").unwrap();
let up = pitch.transpose(4.0);
assert_eq!(up.try_midi_number().unwrap(), 64); // E4
let pitch = Pitch::try_from_midi_number(60).unwrap();
let actual = pitch.frequency(); // 261.6255653005986
let expected = 261.625565; // C4
let epsilon = 1e-6; // 0.000001
assert!((actual - expected).abs() < epsilon);
use pitchy::{Pitch, Note};
let pitch = Pitch::new(277.183); // C#4
let note = Note::try_from(pitch).unwrap();
#[cfg(feature = "std")]
assert_eq!(note.name(), "C#4");
assert_eq!(note.letter(), pitchy::NoteLetter::C);
assert_eq!(note.accidental(), pitchy::Accidental::Sharp);
assert_eq!(note.octave(), 4);
std (enabled by default): enables note name formattinglibm: enables the libm math backend used in no_std modeTo build without std, use:
cargo build --no-default-features --features libm
MIT © paramako