1use std::{cmp::Ordering, collections::HashMap};
2
3use crate::{defaults::IntegerType, stepname::StepName};
4
5pub(crate) mod concretescale;
6pub mod diatonicscale;
8
9pub use diatonicscale::DiatonicScale;
10
11pub(crate) const FIFTHS_ORDER_SHARP: [StepName; 7] = [
12 StepName::F,
13 StepName::C,
14 StepName::G,
15 StepName::D,
16 StepName::A,
17 StepName::E,
18 StepName::B,
19];
20pub(crate) const FIFTHS_ORDER_FLAT: [StepName; 7] = [
21 StepName::B,
22 StepName::E,
23 StepName::A,
24 StepName::D,
25 StepName::G,
26 StepName::C,
27 StepName::F,
28];
29
30pub(crate) fn altered_steps_from_sharps(sharps: IntegerType) -> HashMap<StepName, IntegerType> {
31 let mut map = HashMap::new();
32 match sharps.cmp(&0) {
33 Ordering::Greater => {
34 for step in FIFTHS_ORDER_SHARP.iter().take(sharps as usize) {
35 *map.entry(*step).or_insert(0) += 1;
36 }
37 }
38 Ordering::Less => {
39 for step in FIFTHS_ORDER_FLAT.iter().take((-sharps) as usize) {
40 *map.entry(*step).or_insert(0) -= 1;
41 }
42 }
43 Ordering::Equal => {}
44 }
45 map
46}
47
48pub(crate) fn accidental_modifier_from_alter(alter: IntegerType) -> String {
49 match alter.cmp(&0) {
50 Ordering::Greater => "#".repeat(alter as usize),
51 Ordering::Less => "-".repeat((-alter) as usize),
52 Ordering::Equal => String::new(),
53 }
54}