Crate pitchy

Source
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" into Pitch values
  • Optional formatting of symbolic note names like "A4" when std is enabled
  • Uses the libm math backend in no_std mode (via the libm feature)

§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); // A5

Structs§

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).
NoteLetter
Represents the base letter of a musical note (C, D, E, F, G, A, B).
PitchyError
An error type representing failures when parsing or converting notes or pitches.