Crate staff

source ·
Expand description

Music theory library with midi, notes, chords, scales, and more

Examples

Create a C Major (1st inversion) chord and iterate over its notes.

use staff::{midi, Chord, Pitch};

// C/E
let notes = [midi!(E, 3), midi!(G, 3), midi!(C, 4)];
let chord = Chord::from_midi(midi!(C, 4), notes).unwrap();

assert_eq!(chord.to_string(), "C/E");

assert!(chord.into_iter().eq(notes));

Create a C Major scale and iterate over its notes.

use staff::{midi, Note, Scale};

// C major
let scale = Scale::major(midi!(C, 4));

assert!(scale.eq([
    midi!(C, 4),
    midi!(D, 4),
    midi!(E, 4),
    midi!(F, 4),
    midi!(G, 4),
    midi!(A, 4),
    midi!(B, 4),
]));

Re-exports

pub use chord::Chord;
pub use fmt::Format;
pub use note::Note;
pub use scale::Scale;

Modules

Chord struct and iterators
Format trait to adjust fmt::Display output
Fretboard iterator for guitar and other instruments
Midi notes, octaves, and sets
Formatted notes
Scales with iterators
Collections of intervals and pitches

Macros

Structs

Music interval in semitones.
A key signature represented as the total number of sharps or flats.

Enums

A natural pitch
Pitch class that can be found on the chromatic scale.