Skip to content

Commit

Permalink
Remove rewind configuration access
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 12, 2023
1 parent 67a6491 commit e1ef0f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 140 deletions.
12 changes: 0 additions & 12 deletions control/src/cache/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub enum CalibrationScreen {
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum ConfigurationScreen {
Idle(u32),
Rewind((usize, usize)),
DefaultScreen(usize),
ControlMapping(Option<usize>),
TapIntervalDenominator(usize),
Expand Down Expand Up @@ -262,7 +261,6 @@ fn ticked_dialog(menu: DialogScreen) -> DialogScreen {
match menu {
DialogScreen::Configuration(configuration) => match configuration {
ConfigurationScreen::Idle(cycles) => ticked_configuration_idle(cycles),
ConfigurationScreen::Rewind(_) => menu,
ConfigurationScreen::DefaultScreen(_) => menu,
ConfigurationScreen::ControlMapping(_) => menu,
ConfigurationScreen::TapIntervalDenominator(_) => menu,
Expand Down Expand Up @@ -401,16 +399,6 @@ fn leds_for_configuration(configuration: &ConfigurationScreen) -> [bool; 8] {
[false, true, false, true, true, false, true, false]
}
}
ConfigurationScreen::Rewind((rewind, fast_forward)) => {
let mut leds = [false; 8];
for i in 0..=*fast_forward {
leds[i] = true;
}
for i in 0..=*rewind {
leds[leds.len() - 1 - i] = true;
}
leds
}
ConfigurationScreen::DefaultScreen(selection) => index_to_leds(*selection),
ConfigurationScreen::ControlMapping(mapping) => {
let mut leds = [false; 8];
Expand Down
149 changes: 21 additions & 128 deletions control/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::cache::mapping::AttributeIdentifier;
use crate::cache::{Cache, Configuration};
use crate::input::pot::Pot;
use crate::input::snapshot::Snapshot as InputSnapshot;
use crate::input::store::{Head as InputHead, Store as Input};
use crate::input::store::Store as Input;
use crate::log;
use crate::output::DesiredOutput;
use crate::save::Save;
Expand Down Expand Up @@ -428,13 +428,6 @@ impl Store {
&mut self,
mut draft: Configuration,
) -> (Configuration, Option<ConfigurationScreen>) {
for (i, head) in self.input.head.iter().enumerate() {
let maybe_screen = update_rewind_configuration(&mut draft, i, head);
if let Some(screen) = maybe_screen {
return (draft, Some(screen));
}
}

if let Some(screen) =
update_default_display_configuration(&mut draft, &mut self.input.speed)
{
Expand Down Expand Up @@ -535,37 +528,6 @@ impl Store {
}
}

fn update_rewind_configuration(
draft: &mut Configuration,
i: usize,
head: &InputHead,
) -> Option<ConfigurationScreen> {
let screen = None;

let volume_active = head.volume.activation_movement();
let feedback_active = head.feedback.activation_movement();

if !volume_active && !feedback_active {
return screen;
}

let rewind_speed = if volume_active {
f32_to_index_of_4(head.volume.value())
} else {
draft.rewind_speed[i].0
};

let fast_forward_speed = if feedback_active {
f32_to_index_of_4(head.feedback.value())
} else {
draft.rewind_speed[i].1
};

let tuple = (rewind_speed, fast_forward_speed);
draft.rewind_speed[i] = tuple;
Some(ConfigurationScreen::Rewind(tuple))
}

fn update_default_display_configuration(
draft: &mut Configuration,
pot: &mut Pot,
Expand Down Expand Up @@ -648,18 +610,6 @@ fn update_tap_interval_denominator(
Some(ConfigurationScreen::TapIntervalDenominator(denominator))
}

fn f32_to_index_of_4(x: f32) -> usize {
if x < 0.25 {
0
} else if x < 0.5 {
1
} else if x < 0.75 {
2
} else {
3
}
}

impl From<Save> for Store {
fn from(save: Save) -> Self {
let mut store = Self::new();
Expand Down Expand Up @@ -1072,26 +1022,7 @@ mod tests {

hold_button(&mut store, input);

input.head[0].volume = 1.0;
input.head[0].feedback = 1.0;
for _ in 0..32 {
store.apply_input_snapshot(input);
store.tick();
}
input.head[1].volume = 1.0;
input.head[1].feedback = 1.0;
for _ in 0..32 {
store.apply_input_snapshot(input);
store.tick();
}
input.head[2].volume = 1.0;
input.head[2].feedback = 1.0;
for _ in 0..32 {
store.apply_input_snapshot(input);
store.tick();
}
input.head[3].volume = 1.0;
input.head[3].feedback = 1.0;
input.speed = 1.0;
for _ in 0..32 {
store.apply_input_snapshot(input);
store.tick();
Expand All @@ -1102,10 +1033,10 @@ mod tests {
let mut store = Store::from(save.unwrap());
store.apply_input_snapshot(input);

assert_eq!(store.cache.configuration.rewind_speed[0], (3, 3));
assert_eq!(store.cache.configuration.rewind_speed[1], (3, 3));
assert_eq!(store.cache.configuration.rewind_speed[2], (3, 3));
assert_eq!(store.cache.configuration.rewind_speed[3], (3, 3));
assert_eq!(
store.cache.configuration.default_display_page,
DisplayPage::Heads
);
}

#[cfg(test)]
Expand Down Expand Up @@ -1395,80 +1326,42 @@ mod tests {
fn when_clicks_button_it_saves_configuration_and_enters_normal_mode() {
let (mut store, mut input) = init_store();

input.head[0].volume = 0.05;
apply_input_snapshot(&mut store, input);
input.head[0].feedback = 0.05;
apply_input_snapshot(&mut store, input);
input.head[1].volume = 0.35;
apply_input_snapshot(&mut store, input);
input.head[1].feedback = 0.35;
apply_input_snapshot(&mut store, input);
input.head[2].volume = 0.7;
apply_input_snapshot(&mut store, input);
input.head[2].feedback = 0.7;
apply_input_snapshot(&mut store, input);
input.head[3].volume = 1.0;
apply_input_snapshot(&mut store, input);
input.head[3].feedback = 1.0;
input.speed = 1.0;
apply_input_snapshot(&mut store, input);

click_button(&mut store, input);

assert_eq!(store.cache.configuration.rewind_speed[0], (0, 0));
assert_eq!(store.cache.configuration.rewind_speed[1], (1, 1));
assert_eq!(store.cache.configuration.rewind_speed[2], (2, 2));
assert_eq!(store.cache.configuration.rewind_speed[3], (3, 3));
}

#[test]
fn when_turns_volume_and_feedback_the_rewind_speed_is_visualized_on_display() {
let (mut store, mut input) = init_store();

input.head[0].volume = 0.05;
input.head[0].feedback = 0.05;
apply_input_snapshot(&mut store, input);
assert_animation(&mut store, &[9006]);

input.head[1].volume = 0.35;
input.head[1].feedback = 0.35;
apply_input_snapshot(&mut store, input);
assert_animation(&mut store, &[9966]);

input.head[2].volume = 0.7;
input.head[2].feedback = 0.7;
apply_input_snapshot(&mut store, input);
assert_animation(&mut store, &[9886]);

input.head[3].volume = 1.0;
input.head[3].feedback = 1.0;
apply_input_snapshot(&mut store, input);
assert_animation(&mut store, &[8888]);
assert_eq!(
store.cache.configuration.default_display_page,
DisplayPage::Heads
);
}

#[test]
fn when_does_not_change_attribute_it_keeps_the_previously_set_value() {
let (mut store, mut input) = init_store();

input.head[2].volume = 0.7;
input.head[2].feedback = 0.7;
input.speed = 1.0;
apply_input_snapshot(&mut store, input);
click_button(&mut store, input);

assert_eq!(store.cache.configuration.rewind_speed[2], (2, 2));
assert_eq!(
store.cache.configuration.default_display_page,
DisplayPage::Heads
);

input.head[2].volume = 0.0;
input.head[2].feedback = 0.0;
input.speed = 0.0;
apply_input_snapshot(&mut store, input);

hold_button(&mut store, input);

input.head[1].volume = 0.35;
input.head[1].feedback = 0.35;
apply_input_snapshot(&mut store, input);
click_button(&mut store, input);

assert_eq!(store.cache.configuration.rewind_speed[2], (2, 2));
assert_eq!(store.cache.configuration.rewind_speed[1], (1, 1));
assert_eq!(
store.cache.configuration.default_display_page,
DisplayPage::Heads
);
}

#[test]
Expand Down

0 comments on commit e1ef0f8

Please sign in to comment.