Skip to main content

Module key

Module key 

Source
Expand description

Keys: the key parser, relative and parallel keys, Camelot and Open Key.

The parser tries three forms in order: a Camelot code (8A), an Open Key code (1m), then a letter name with an optional sharp or flat and mode word (A, Am, A minor, Bb, E♭ moll, C sharp minor). A bare capital reads as major and a lone lowercase letter as minor; both readings come back flagged, so the caller records or asks.

use sound_to_patch::music::key::{Key, Mode, parse_key};

let reading = parse_key("C sharp minor")?;
assert_eq!(reading.key, Key::new(1, Mode::Minor));
assert_eq!(reading.key.camelot().to_string(), "12A");
assert_eq!(reading.key.open_key().to_string(), "5m");

Structs§

Camelot
A Camelot code: a number from 1 to 12, A for minor and B for major.
Key
A tonic pitch class and a mode.
KeyReading
A parsed key and the assumption it rests on, if any.
OpenKey
An Open Key code: a number from 1 to 12, m for minor and d for major.

Enums§

KeyAssumption
A mode the parser assumed because the text named none.
Mode
Major or minor.

Functions§

parse_key
Parses a key name.