avoid panics

This commit is contained in:
Michael Sippel 2024-06-11 23:21:23 +02:00
parent 2441c5a133
commit 7dd728b7b9
Signed by: senvas
GPG key ID: 060F22F65102F95C
2 changed files with 17 additions and 55 deletions

View file

@ -179,6 +179,7 @@ async fn main() {
eprintln!("pressed {}", c);
let mut inputs = inputs.write().unwrap();
if c.is_ascii() {
match &c[0..1] {
"x" => {
// tap tempo
@ -189,68 +190,23 @@ async fn main() {
inputs.cycle_len = last_tap - old_tap;
}
}
"q" => {
// sync
inputs.t = Duration::from_millis(0);
tbegin = std::time::Instant::now();
},
"0" => {
inputs.scene_select = 0;
transition_begin = std::time::Instant::now();
}
"1" => {
inputs.scene_select = 1;
transition_begin = std::time::Instant::now();
}
"2" => {
inputs.scene_select = 2;
transition_begin = std::time::Instant::now();
}
"3" => {
inputs.scene_select = 3;
transition_begin = std::time::Instant::now();
}
"4" => {
inputs.scene_select = 4;
transition_begin = std::time::Instant::now();
}
"5" => {
inputs.scene_select = 5;
transition_begin = std::time::Instant::now();
},
"6" => {
inputs.scene_select = 6;
transition_begin = std::time::Instant::now();
}
"7" => {
inputs.scene_select = 7;
transition_begin = std::time::Instant::now();
}
"8" => {
inputs.scene_select = 8;
transition_begin = std::time::Instant::now();
}
"9" => {
inputs.scene_select = 9;
transition_begin = std::time::Instant::now();
}
"a" => {
inputs.scene_select = 10;
transition_begin = std::time::Instant::now();
}
"p" => {
inputs.scene_select = 11;
"0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9" => {
let idx = c.chars().nth(0).unwrap().to_digit(10).unwrap() as u32;
inputs.scene_select = idx as usize;
transition_begin = std::time::Instant::now();
}
"r" => { inputs.master_wave = match inputs.master_wave {
None => Some(Waveform::Sine),
Some(Waveform::Sine) => Some(Waveform::Triangle),
Some(Waveform::Triangle) => Some(Waveform::Square),
Some(Waveform::Square) => Some(Waveform::Sawtooth),
Some(Waveform::Sawtooth) => None
}
None => Some(Waveform::Sine),
Some(Waveform::Sine) => Some(Waveform::Triangle),
Some(Waveform::Triangle) => Some(Waveform::Square),
Some(Waveform::Square) => Some(Waveform::Sawtooth),
Some(Waveform::Sawtooth) => None
}
}
"," => { inputs.master_wave = None; }
"n" => { inputs.master_intensity += 0.1; }
@ -262,7 +218,7 @@ async fn main() {
"e" => { inputs.wheel2 += 1; }
"p"=> { inputs.wheel2 -= 1; }
"-" => {inputs.master_intensity *= -1.0; }
"-" => { inputs.master_intensity *= -1.0; }
"." => {
if active {
eprintln!("DEACTIVATED");
@ -279,6 +235,7 @@ async fn main() {
eprintln!("--------------");
eprintln!("updated inputs:\n {:?}", inputs);
eprintln!("--------------");
}
}
_ => {}
}

View file

@ -75,6 +75,8 @@ impl ColorGrid for SceneLibrary {
);
}
if inputs.scene_select < self.library.len() {
if inputs.scene_select == sc {
// display only one animation
@ -109,6 +111,9 @@ impl ColorGrid for SceneLibrary {
)
}
} else {
Rgb::new(0.0, 0.0, 0.0)
}
}
}