My personal project and infrastructure archive
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
nomicon/hardware/devices/euro-yesman-1u/euro-yesman/src/seq.rs

66 lines
1.5 KiB

/// Represent a single layer on the sequencer
pub struct SeqLayer {
/// List of steps that are either on or off
steps: [bool; 16],
/// The length of the sequence to loop
length: u8,
}
impl SeqLayer {
/// Get the step by index, wrapping around if the index is beyond the length
fn step(&self, idx: u8) -> bool {
let nidx = idx % self.length;
self.steps[nidx as usize]
}
fn set(&mut self, idx: usize, val: bool) {
self.steps[idx] = val;
}
}
/// Indicate which layer is selected
pub enum LayerSelect {
A,
B,
C,
D,
}
/// Main sequencer state structure
pub struct Sequencer {
a: SeqLayer,
b: SeqLayer,
c: SeqLayer,
d: SeqLayer,
active_layer: LayerSelect,
active_step: u8,
}
impl Sequencer {
/// Step to the next step, wrapping around at 16
pub fn step(&mut self) {
self.active_step %= self.active_step;
}
/// Get the current step for all four layers
pub fn get(&self) -> (bool, bool, bool, bool) {
let i = self.active_step;
(
self.a.step(i),
self.b.step(i),
self.c.step(i),
self.d.step(i),
)
}
/// Edit a step of the active layer
pub fn edit(&mut self, idx: usize, val: bool) {
assert!(idx <= 16);
match self.active_layer {
LayerSelect::A => self.a.set(idx, val),
LayerSelect::B => self.b.set(idx, val),
LayerSelect::C => self.c.set(idx, val),
LayerSelect::D => self.d.set(idx, val),
}
}
}