Feat: background head-preload for sample libraries

This commit is contained in:
2026-02-05 14:35:26 +01:00
parent 88c2b51720
commit 10ed5a629a
8 changed files with 139 additions and 20 deletions

View File

@@ -1,7 +1,7 @@
mod app;
mod init;
mod commands;
mod engine;
mod init;
mod input;
mod midi;
mod model;
@@ -118,6 +118,11 @@ fn main() -> io::Result<()> {
audio_sample_pos.store(0, Ordering::Relaxed);
let preload_entries: Vec<(String, std::path::PathBuf)> = restart_samples
.iter()
.map(|e| (e.name.clone(), e.path.clone()))
.collect();
match build_stream(
&new_config,
new_audio_rx,
@@ -127,7 +132,7 @@ fn main() -> io::Result<()> {
restart_samples,
Arc::clone(&audio_sample_pos),
) {
Ok((new_stream, info, new_analysis)) => {
Ok((new_stream, info, new_analysis, registry)) => {
_stream = Some(new_stream);
_analysis_handle = Some(new_analysis);
app.audio.config.sample_rate = info.sample_rate;
@@ -135,7 +140,18 @@ fn main() -> io::Result<()> {
app.audio.config.channels = info.channels;
sample_rate_shared.store(info.sample_rate as u32, Ordering::Relaxed);
app.audio.error = None;
app.audio.sample_registry = Some(Arc::clone(&registry));
app.ui.set_status("Audio restarted".to_string());
if !preload_entries.is_empty() {
let sr = info.sample_rate;
std::thread::Builder::new()
.name("sample-preload".into())
.spawn(move || {
init::preload_sample_heads(preload_entries, sr, &registry);
})
.expect("failed to spawn preload thread");
}
}
Err(e) => {
app.audio.error = Some(e.clone());