music_note/
lib.rs

1//! Music theory library with midi, notes, chords, scales, and more
2//!
3//! # Examples
4//!
5//! Create a C Major (1st inversion) chord and iterate over its notes.
6//! ```
7//! use music_note::{midi, Chord, Pitch};
8//!
9//! // C/E
10//! let chord = Chord::from_midi(
11//!     midi!(C, 4),
12//!     [midi!(E, 3), midi!(G, 3), midi!(C, 4)]
13//! );
14//!
15//! assert_eq!(chord.to_string(), "C/E");
16//!
17//! let pitches = [Pitch::E, Pitch::G, Pitch::C];
18//! assert!(chord.into_iter().eq(pitches));
19//! ```
20//!
21//! Create a C Major scale and iterate over its notes.
22//! ```
23//! use music_note::{midi, Note, Scale};
24//!
25//! // C major
26//! let scale = Scale::major(midi!(C, 4));
27//!
28//! assert!(scale.eq([
29//!     midi!(C, 4),
30//!     midi!(D, 4),
31//!     midi!(E, 4),
32//!     midi!(F, 4),
33//!     midi!(G, 4),
34//!     midi!(A, 4),
35//!     midi!(B, 4),
36//! ]));
37//! ```
38
39#![cfg_attr(not(test), no_std)]
40
41pub mod chord;
42pub use chord::Chord;
43
44mod interval;
45pub use interval::Interval;
46
47pub mod staff;
48pub use staff::{Key, Staff};
49
50mod natural;
51pub use natural::Natural;
52
53pub mod midi;
54
55pub mod note;
56pub use note::Note;
57
58mod pitch;
59pub use pitch::Pitch;
60
61pub mod scale;
62pub use scale::Scale;
63
64pub mod set;
65
66/// ```
67/// use music_note::{midi, Pitch};
68/// use music_note::midi::Octave;
69///
70/// let midi = midi!(C, 4);
71///
72/// assert_eq!(midi.pitch(), Pitch::C);
73/// assert_eq!(midi.octave(), Octave::FOUR);
74/// ```
75#[macro_export]
76macro_rules! midi {
77    ($pitch:ident, $octave:literal) => {
78        music_note::midi::MidiNote::new(
79            music_note::Pitch::$pitch,
80            music_note::midi::Octave::new_unchecked($octave),
81        )
82    };
83}