Skip to content

Commit

Permalink
Visualize buffer reset
Browse files Browse the repository at this point in the history
Signed-off-by: Petr Horacek <petr@zlosynth.com>
  • Loading branch information
phoracek committed Nov 10, 2023
1 parent df43e31 commit 1242d0e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ backwards compatibility.
* Allow reset of the loop position through a control input.
* Pause/resume the delay line using a control input.
* Allow configuration of the ratio between the tap interval and delay length.
* Visualize progress of the buffer reset.

## 1.2.0

Expand Down
24 changes: 24 additions & 0 deletions control/src/cache/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub enum Screen {
Attribute(u32, AttributeScreen),
Clipping(u32),
Paused(u32),
BufferReset(u32),
}

#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -198,6 +199,17 @@ impl Display {
}
}

pub fn set_buffer_reset(&mut self, progress: u8) {
match self.prioritized[5] {
Some(Screen::BufferReset(_)) => (),
_ => self.set_screen(5, Screen::BufferReset(progress as u32)),
}
}

pub fn reset_buffer_reset(&mut self) {
self.reset_screen(5);
}

pub fn set_paused(&mut self) {
match self.prioritized[5] {
Some(Screen::Paused(_)) => (),
Expand Down Expand Up @@ -231,23 +243,27 @@ impl Screen {
Self::Attribute(_, attribute) => leds_for_attribute(*attribute),
Self::Clipping(cycles) => leds_for_clipping(*cycles),
Self::Paused(cycles) => leds_for_paused(*cycles),
Self::BufferReset(progress) => leds_for_buffer_reset(*progress),
}
}

fn ticked(self) -> Option<Self> {
// TODO: For those that just return themselves unchanged, use => self
match self {
Screen::Failure(cycles) => ticked_failure(cycles),
Screen::Dialog(menu) => Some(Screen::Dialog(ticked_dialog(menu))),
Screen::AltAttribute(age, alt_attribute) => ticked_alt_attribute(age, alt_attribute),
Screen::Attribute(age, attribute) => ticked_attribute(age, attribute),
Screen::Clipping(age) => ticked_clipping(age),
Screen::Paused(cycles) => ticked_paused(cycles),
Screen::BufferReset(_) => Some(self),
}
}
}

fn ticked_dialog(menu: DialogScreen) -> DialogScreen {
match menu {
// TODO: For those that just return themselves unchanged, use => self
DialogScreen::Configuration(configuration) => match configuration {
ConfigurationScreen::Idle(cycles) => ticked_configuration_idle(cycles),
ConfigurationScreen::Rewind(rewind) => ticked_configuration_rewind(rewind),
Expand Down Expand Up @@ -515,6 +531,14 @@ fn leds_for_paused(cycles: u32) -> [bool; 8] {
leds
}

fn leds_for_buffer_reset(progress: u32) -> [bool; 8] {
let mut leds = [true; 8];
for i in 0..progress as usize {
leds[7 - i] = false;
}
leds
}

fn phase_to_leds(phase: f32) -> [bool; 8] {
let mut leds = [false; 8];
for led in leds.iter_mut().take((phase * 7.9) as usize + 1) {
Expand Down
6 changes: 6 additions & 0 deletions control/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ impl Store {
.display
.set_fallback_attribute(AttributeScreen::Position(dsp_reaction.new_position));
}

if let Some(buffer_reset_progress) = dsp_reaction.buffer_reset_progress {
self.cache.display.set_buffer_reset(buffer_reset_progress);
} else {
self.cache.display.reset_buffer_reset();
}
}

pub fn tick(&mut self) -> DesiredOutput {
Expand Down
8 changes: 8 additions & 0 deletions dsp/src/delay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ struct ResetSelector {
pub struct Reaction {
pub impulse: bool,
pub new_position: usize,
pub buffer_reset_progress: Option<u8>,
}

#[derive(Clone, Copy, Debug)]
Expand Down Expand Up @@ -264,9 +265,16 @@ impl Delay {
};
let new_position = self.calculate_position_index();

let buffer_reset_progress = if let BufferReset::Resetting(i, n) = self.buffer_reset {
Some(((i as f32 / n as f32) * 7.99) as u8)
} else {
None
};

Reaction {
impulse,
new_position,
buffer_reset_progress,
}
}

Expand Down
1 change: 1 addition & 0 deletions dsp/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub struct Reaction {
pub delay_impulse: bool,
pub output_clipping: bool,
pub new_position: usize,
pub buffer_reset_progress: Option<u8>,
}

impl Processor {
Expand Down

0 comments on commit 1242d0e

Please sign in to comment.