Expose latency compensation on UI

This commit is contained in:
Eric Van Albert
2023-06-29 23:25:18 -04:00
parent bcaade071f
commit fed3b61f43
2 changed files with 12 additions and 4 deletions
+8
View File
@@ -518,6 +518,14 @@ pub async fn run() {
);
}
});
ui.label("Latency compensation:");
ui.add(
egui::DragValue::new(&mut mir.latency_compensation)
.speed(0.001)
.fixed_decimals(3)
.suffix("s")
.clamp_range(0. ..=1.),
);
});
let mosaic_response = ui.add(mosaic(
+4 -4
View File
@@ -5,8 +5,6 @@ use std::sync::mpsc;
use std::time;
const MAX_TIME: f32 = 64.;
// Anticipate beats by this many seconds
const LATENCY_COMPENSATION: f32 = 0.10;
const DEFAULT_BPM: f32 = 120.;
@@ -32,6 +30,7 @@ pub struct Mir {
receiver: mpsc::Receiver<Update>,
last_update: Update,
pub global_timescale: f32,
pub latency_compensation: f32, // Anticipate beats by this many seconds
}
/// Updates sent over a queue
@@ -264,6 +263,7 @@ impl Mir {
spectrum: [0.; SPECTRUM_LENGTH],
},
global_timescale: 1.,
latency_compensation: 0.1,
}
}
@@ -282,12 +282,12 @@ impl Mir {
let unscaled_time = self
.last_update
.t(time::Instant::now() + time::Duration::from_secs_f32(LATENCY_COMPENSATION))
.t(time::Instant::now() + time::Duration::from_secs_f32(self.latency_compensation))
.rem_euclid(MAX_TIME);
let time = (self
.last_update
.t(time::Instant::now() + time::Duration::from_secs_f32(LATENCY_COMPENSATION))
.t(time::Instant::now() + time::Duration::from_secs_f32(self.latency_compensation))
* self.global_timescale)
.rem_euclid(MAX_TIME);