Skip to content

Commit ba551c5

Browse files
committed
Make the display more interesting
1 parent 104359c commit ba551c5

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

inputmodule-control/src/inputmodule.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -681,11 +681,8 @@ fn input_eq_cmd(serialdevs: &Vec<String>) {
681681
move |info, samples| {
682682
analyzer.analyze(samples);
683683

684-
let sampled_volume = samples.volume(0.3) * 400.0;
685-
let display_max_width = 34.0;
686-
687684
info.spectrum.fill_from(&analyzer.average());
688-
info.volume = if sampled_volume < 34.0 { sampled_volume } else { display_max_width};
685+
info.volume = samples.volume(0.3) * 400.0;
689686
info.beat = info.spectrum.slice(50.0, 100.0).max() * 0.01;
690687
info
691688
},
@@ -697,14 +694,26 @@ fn input_eq_cmd(serialdevs: &Vec<String>) {
697694
// This is just a primitive example, your vis core belongs here
698695

699696
frame.info(|info| {
697+
698+
let sampled_volume = info.volume;
699+
let limited_volume = if sampled_volume < 34.0 { sampled_volume } else { 34.0 };
700+
701+
let display_max_widths = [10.0, 14.0, 20.0, 28.0, 34.0, 28.0, 20.0, 14.0, 10.0];
702+
703+
let volumes_to_display = display_max_widths.iter().map(|x| {
704+
let computed_width = (limited_volume / 34.0) * x;
705+
let next_lowest_odd = computed_width - (computed_width % 2.0) - 1.0;
706+
next_lowest_odd as u8
707+
}).collect::<Vec<_>>();
708+
700709
for serialdev in serialdevs {
701710
eq_cmd(
702711
serialdev,
703-
&[info.volume as u8; 9]
712+
volumes_to_display.as_slice()
704713
)
705714
}
706715
});
707-
thread::sleep(Duration::from_millis(15));
716+
thread::sleep(Duration::from_millis(30));
708717
}
709718
}
710719

0 commit comments

Comments
 (0)