From: Huck Boles Date: Mon, 29 May 2023 18:31:38 +0000 (-0500) Subject: added: song/transport structs X-Git-Url: https://git.huck.website/?a=commitdiff_plain;h=3c9162ced41e5ac9a6aa80b5fabf251839317026;p=cellseq.git added: song/transport structs --- diff --git a/src/cells.rs b/src/cells.rs index 9f24fcb..366dddc 100644 --- a/src/cells.rs +++ b/src/cells.rs @@ -33,19 +33,18 @@ impl World { } fn wrap_walls(&mut self) { - for (bottom, top) in self.row(self.y_size() - 1).iter().zip(self.row(0).iter()) { - bottom.set(State::Dead); - top.set(State::Dead); + macro_rules! wrap { + ($portal:expr,$wall:expr) => { + for (portal, wall) in $portal.iter().zip($wall) { + portal.set(wall.get()) + } + }; } - for (right, left) in self - .column(self.x_size() - 1) - .iter() - .zip(self.column(0).iter()) - { - right.set(State::Dead); - left.set(State::Dead); - } + wrap!(self.column(0), self.column(self.x_size() - 2)); + wrap!(self.column(self.x_size() - 1), self.column(1)); + wrap!(self.row(0), self.row(self.y_size() - 2)); + wrap!(self.row(self.y_size() - 1), self.row(1)); } } diff --git a/src/main.rs b/src/main.rs index 069843a..4a8445a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,10 +8,10 @@ fn main() -> Result<()> { let mut map = World::new(74, 32); map.randomize(0.75); - let time = bpm_to_ms(120); + let time = bpm_to_ms(100); - // loop_map(&mut map, Point::new(10, 2), time, 32)?; + run_map(&mut map, Point::new(10, 2), time)?; // edit_mask(&mask, (10, 5))?; - move_cursor()?; + // move_cursor()?; Ok(()) } diff --git a/src/music.rs b/src/music.rs index 7fe4d64..472a4b2 100644 --- a/src/music.rs +++ b/src/music.rs @@ -1,56 +1,37 @@ -pub type NoteMask = [bool; 12]; - -pub enum Scale { - Ionian, - Dorian, - Phrygian, - Lydian, - Mixolydian, - Aeolian, - Locrian, - MajPent, - SusEgypt, - BlueMajPent, - BlueMinPen, - MinPent, - WholeTone, - Chromatic, -} +mod scale; +mod transport; -impl Scale { - pub fn to_notes(&self) -> NoteMask { - let mut diatonic: NoteMask = [ - true, false, true, false, true, true, false, true, false, true, false, true, - ]; +pub use scale::*; +pub use transport::*; - let mut pentatonic: NoteMask = [ - true, false, true, false, true, false, false, true, false, true, false, false, - ]; +pub type NoteMask = [bool; 12]; - macro_rules! rotate { - ($i:ident,$e:expr) => {{ - $i.rotate_left($e); - $i - }}; - } +pub struct TimeSignature { + pub top: usize, + pub bottom: usize, +} - 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, - ], +impl From<(usize, usize)> for TimeSignature { + fn from(value: (usize, usize)) -> Self { + Self { + top: value.0, + bottom: value.1, } } } + +pub enum Note { + A(Acc), + B(Acc), + C(Acc), + D(Acc), + E(Acc), + F(Acc), + G(Acc), +} + +pub enum Acc { + Shp, + Nat, + Flt, +} diff --git a/src/music/scale.rs b/src/music/scale.rs new file mode 100644 index 0000000..b74b38d --- /dev/null +++ b/src/music/scale.rs @@ -0,0 +1,56 @@ +use super::*; + +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, + ], + } + } +} diff --git a/src/music/transport.rs b/src/music/transport.rs new file mode 100644 index 0000000..0c147d1 --- /dev/null +++ b/src/music/transport.rs @@ -0,0 +1,30 @@ +use super::*; + +pub struct Song { + pub bpm: usize, + pub time_sig: TimeSignature, + pub key: Option, + pub scale: Option, +} + +impl Song { + pub fn new( + bpm: usize, + time_sig: TimeSignature, + key: Option, + scale: Option, + ) -> Self { + Self { + bpm, + time_sig, + key, + scale, + } + } +} + +pub enum Transport { + Pause, + Play, + FastForward(usize), +}