From 6449f9c67887593a7005e53e6a69c6ad3dfc2dc4 Mon Sep 17 00:00:00 2001 From: Huck Boles Date: Sat, 27 May 2023 16:29:43 -0500 Subject: [PATCH] added: music structs --- src/music.rs | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/music.rs diff --git a/src/music.rs b/src/music.rs new file mode 100644 index 0000000..7fe4d64 --- /dev/null +++ b/src/music.rs @@ -0,0 +1,56 @@ +pub type NoteMask = [bool; 12]; + +pub enum Scale { + Ionian, + Dorian, + Phrygian, + Lydian, + Mixolydian, + Aeolian, + Locrian, + MajPent, + SusEgypt, + BlueMajPent, + BlueMinPen, + MinPent, + WholeTone, + Chromatic, +} + +impl Scale { + pub fn to_notes(&self) -> NoteMask { + let mut diatonic: NoteMask = [ + true, false, true, false, true, true, false, true, false, true, false, true, + ]; + + let mut pentatonic: NoteMask = [ + true, false, true, false, true, false, false, true, false, true, false, false, + ]; + + macro_rules! rotate { + ($i:ident,$e:expr) => {{ + $i.rotate_left($e); + $i + }}; + } + + match self { + Scale::Ionian => diatonic, + Scale::Dorian => rotate!(diatonic, 2), + Scale::Phrygian => rotate!(diatonic, 4), + Scale::Lydian => rotate!(diatonic, 5), + Scale::Mixolydian => rotate!(diatonic, 7), + Scale::Aeolian => rotate!(diatonic, 9), + Scale::Locrian => rotate!(diatonic, 11), + Scale::MajPent => pentatonic, + Scale::SusEgypt => rotate!(pentatonic, 2), + Scale::BlueMinPen => rotate!(pentatonic, 4), + Scale::BlueMajPent => rotate!(pentatonic, 7), + Scale::MinPent => rotate!(pentatonic, 9), + Scale::Chromatic => [true; 12], + Scale::WholeTone => [ + true, false, true, false, true, false, true, false, true, false, true, false, + ], + } + } +} -- 2.44.2