]> git.huck.website - cellseq.git/commitdiff
added: song/transport structs
authorHuck Boles <huck@huck.website>
Mon, 29 May 2023 18:31:38 +0000 (13:31 -0500)
committerHuck Boles <huck@huck.website>
Mon, 29 May 2023 18:31:38 +0000 (13:31 -0500)
src/cells.rs
src/main.rs
src/music.rs
src/music/scale.rs [new file with mode: 0644]
src/music/transport.rs [new file with mode: 0644]

index 9f24fcb6a9248346bb0a97ac91273939ad506808..366dddc5f87792a0cdcc0c2a175de0562ae90a53 100644 (file)
@@ -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));
     }
 }
 
index 069843a464f1ebeb7cb1f5ea75907b6915dae4a9..4a8445a923f2adb9e9206749d4115c1ef2fc9918 100644 (file)
@@ -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(())
 }
index 7fe4d64f967581e9cf743bcb4e7444e25925c8c1..472a4b242ab52a05b00cc86d7b2ed1f2003815a9 100644 (file)
@@ -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 (file)
index 0000000..b74b38d
--- /dev/null
@@ -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 (file)
index 0000000..0c147d1
--- /dev/null
@@ -0,0 +1,30 @@
+use super::*;
+
+pub struct Song {
+    pub bpm: usize,
+    pub time_sig: TimeSignature,
+    pub key: Option<Note>,
+    pub scale: Option<Scale>,
+}
+
+impl Song {
+    pub fn new(
+        bpm: usize,
+        time_sig: TimeSignature,
+        key: Option<Note>,
+        scale: Option<Scale>,
+    ) -> Self {
+        Self {
+            bpm,
+            time_sig,
+            key,
+            scale,
+        }
+    }
+}
+
+pub enum Transport {
+    Pause,
+    Play,
+    FastForward(usize),
+}