Skip to main content

music21/musedata/
base12_26.rs

1//! The base-12 and base-26 orders of Hewlett's system, which music21's
2//! `musedata.base12_26` keeps as tables only: base 12 numbers the
3//! natural notes of the twelve semitones, base 26 every letter with one
4//! flat or sharp.
5
6/// music21's `base12Equivalent`: the natural note each of the twelve
7/// numbers is, and the empty name for the five between.
8pub const BASE12_EQUIVALENTS: [(i32, &str); 12] = [
9    (0, "C"),
10    (1, ""),
11    (2, "D"),
12    (3, ""),
13    (4, "E"),
14    (5, "F"),
15    (6, ""),
16    (7, "G"),
17    (8, ""),
18    (9, "A"),
19    (10, ""),
20    (11, "B"),
21];
22
23/// music21's `Base12IntervalTable`: the interval each distance in base 12
24/// is; the tritone, 6, is not there.
25pub const BASE12_INTERVALS: [(i32, &str); 11] = [
26    (0, "P1"),
27    (1, "m2"),
28    (2, "M2"),
29    (3, "m3"),
30    (4, "M3"),
31    (5, "P4"),
32    (7, "P5"),
33    (8, "m6"),
34    (9, "M6"),
35    (10, "m7"),
36    (11, "M7"),
37];
38
39/// music21's `base26Equivalent`: the pitch name each of the twenty-six
40/// numbers is, and the empty name for the four unused.
41pub const BASE26_EQUIVALENTS: [(i32, &str); 26] = [
42    (0, "C-"),
43    (1, "C"),
44    (2, "C#"),
45    (3, ""),
46    (4, "D-"),
47    (5, "D"),
48    (6, "D#"),
49    (7, ""),
50    (8, "E-"),
51    (9, "E"),
52    (10, "E#"),
53    (11, "F-"),
54    (12, "F"),
55    (13, "F#"),
56    (14, ""),
57    (15, "G-"),
58    (16, "G"),
59    (17, "G#"),
60    (18, ""),
61    (19, "A-"),
62    (20, "A"),
63    (21, "A#"),
64    (22, ""),
65    (23, "B-"),
66    (24, "B"),
67    (25, "B#"),
68];
69
70/// music21's `Base26IntervalTable`: the interval each distance in base 26
71/// is, for the eleven it names.
72pub const BASE26_INTERVALS: [(i32, &str); 11] = [
73    (0, "P1"),
74    (3, "m2"),
75    (4, "M2"),
76    (7, "m3"),
77    (8, "M3"),
78    (11, "P4"),
79    (15, "P5"),
80    (18, "m6"),
81    (19, "M6"),
82    (22, "m7"),
83    (23, "M7"),
84];
85
86/// The named rows of a table, which is what music21's `Representation`
87/// dictionaries hold, turned round: each name against its number.
88pub fn named<'a>(
89    table: &'a [(i32, &'static str)],
90) -> impl Iterator<Item = (&'static str, i32)> + 'a {
91    table
92        .iter()
93        .filter(|(_, name)| !name.is_empty())
94        .map(|(number, name)| (*name, *number))
95}
96
97#[cfg(test)]
98mod tests {
99    use super::*;
100
101    #[test]
102    fn the_representations_leave_the_unused_numbers_out() {
103        assert_eq!(named(&BASE12_EQUIVALENTS).count(), 7);
104        assert_eq!(named(&BASE26_EQUIVALENTS).count(), 21);
105        assert!(named(&BASE26_EQUIVALENTS).any(|row| row == ("F-", 11)));
106    }
107}