}
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));
}
}
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(())
}
-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,
+}
--- /dev/null
+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,
+ ],
+ }
+ }
+}
--- /dev/null
+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),
+}