klib/lib.rs
1//! A library to easily explore music theory principles.
2//!
3//! # Examples
4//!
5//! ```
6//! use klib::core::chord::*;
7//! use klib::core::known_chord::KnownChord;
8//! use klib::core::modifier::Degree;
9//! use klib::core::note::*;
10//!
11//! // Check to see what _kind_ of chord this is.
12//! assert_eq!(
13//! Chord::new(C).augmented().seven().known_chord(),
14//! KnownChord::AugmentedDominant(Degree::Seven)
15//! );
16//! ```
17//!
18//! ```
19//! use klib::core::base::Parsable;
20//! use klib::core::chord::*;
21//! use klib::core::note::*;
22//!
23//! // Parse a chord from a string, and inspect the scale.
24//! assert_eq!(
25//! Chord::parse("Cm7b5").unwrap().scale(),
26//! vec![C, DFlat, EFlat, F, GFlat, AFlat, BFlat]
27//! );
28//! ```
29//!
30//! ```
31//! use klib::core::chord::*;
32//! use klib::core::note::*;
33//!
34//! // From a note, create a chord, and look at the chord tones.
35//! assert_eq!(
36//! C.into_chord().augmented().major7().chord(),
37//! vec![C, E, GSharp, B]
38//! );
39//! ```
40//!
41//! # Scales and Modes
42//!
43//! ```
44//! use klib::core::base::HasName;
45//! use klib::core::mode::*;
46//! use klib::core::mode_kind::*;
47//! use klib::core::note::*;
48//! use klib::core::scale::*;
49//! use klib::core::scale_kind::*;
50//!
51//! // Create a D Dorian mode
52//! let mode = Mode::new(D, ModeKind::Dorian);
53//! assert_eq!(mode.name(), "D dorian");
54//!
55//! // Create an A harmonic minor scale
56//! let scale = Scale::new(A, ScaleKind::HarmonicMinor);
57//! assert_eq!(scale.name(), "A harmonic minor");
58//! ```
59//!
60//! # Notation (Unified Parsing)
61//!
62//! ```
63//! use klib::core::base::Parsable;
64//! use klib::core::notation::Notation;
65//!
66//! // Automatically detects and parses scales, modes, or chords
67//! let scale = Notation::parse("C major pentatonic").unwrap();
68//! assert!(scale.is_scale());
69//!
70//! let mode = Notation::parse("D dorian").unwrap();
71//! assert!(mode.is_mode());
72//!
73//! let chord = Notation::parse("Cmaj7").unwrap();
74//! assert!(chord.is_chord());
75//! ```
76
77#![warn(rustdoc::broken_intra_doc_links, rust_2018_idioms, clippy::all, missing_docs)]
78#![allow(incomplete_features)]
79#![allow(clippy::needless_range_loop)]
80#![feature(generic_const_exprs)]
81#![feature(specialization)]
82#![feature(coverage_attribute)]
83
84pub mod core;
85pub mod helpers;
86
87#[cfg(feature = "analyze_base")]
88pub mod analyze;
89
90#[cfg(feature = "ml_base")]
91pub mod ml;
92
93#[cfg(feature = "wasm")]
94pub mod wasm;
95
96#[cfg(feature = "audio")]
97pub use rodio;