Feat: clean the codebase as much as possible

This commit is contained in:
2026-02-21 14:46:53 +01:00
parent ab353edc0b
commit 7a95207c58
17 changed files with 233 additions and 368 deletions

View File

@@ -1,14 +1,11 @@
use cpal::traits::{DeviceTrait, StreamTrait};
use cpal::Stream;
use crossbeam_channel::Receiver;
use doux::{Engine, EngineMetrics};
use ringbuf::{traits::*, HeapRb};
use rustfft::{num_complex::Complex, FftPlanner};
use std::sync::atomic::{AtomicBool, AtomicU32, AtomicU64, Ordering};
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
use std::sync::Arc;
use std::thread::{self, JoinHandle};
use super::AudioCommand;
#[cfg(feature = "cli")]
use std::sync::atomic::AtomicU64;
pub struct ScopeBuffer {
pub samples: [AtomicU32; 256],
@@ -230,6 +227,36 @@ fn analysis_loop(
}
}
pub fn preload_sample_heads(
entries: Vec<(String, std::path::PathBuf)>,
target_sr: f32,
registry: &doux::SampleRegistry,
) {
let mut batch = Vec::with_capacity(entries.len());
for (name, path) in &entries {
match doux::sampling::decode_sample_head(path, target_sr) {
Ok(data) => batch.push((name.clone(), Arc::new(data))),
Err(e) => eprintln!("preload {name}: {e}"),
}
}
if !batch.is_empty() {
registry.insert_batch(batch);
}
}
#[cfg(feature = "cli")]
use cpal::traits::{DeviceTrait, StreamTrait};
#[cfg(feature = "cli")]
use cpal::Stream;
#[cfg(feature = "cli")]
use crossbeam_channel::Receiver;
#[cfg(feature = "cli")]
use doux::{Engine, EngineMetrics};
#[cfg(feature = "cli")]
use super::AudioCommand;
#[cfg(feature = "cli")]
pub struct AudioStreamConfig {
pub output_device: Option<String>,
pub channels: u16,
@@ -237,12 +264,14 @@ pub struct AudioStreamConfig {
pub max_voices: usize,
}
#[cfg(feature = "cli")]
pub struct AudioStreamInfo {
pub sample_rate: f32,
pub host_name: String,
pub channels: u16,
}
#[cfg(feature = "cli")]
pub fn build_stream(
config: &AudioStreamConfig,
audio_rx: Receiver<AudioCommand>,

View File

@@ -7,16 +7,20 @@ mod timing;
pub use timing::{substeps_in_window, StepTiming, SyncTime};
// AnalysisHandle and SequencerHandle are used by src/bin/desktop.rs
// Used by plugin and desktop crates via the lib; not by the terminal binary directly.
#[allow(unused_imports)]
pub use audio::{
build_stream, spawn_analysis_thread, AnalysisHandle, AudioStreamConfig, ScopeBuffer,
SpectrumBuffer,
preload_sample_heads, spawn_analysis_thread, AnalysisHandle, ScopeBuffer, SpectrumBuffer,
};
#[cfg(feature = "cli")]
#[allow(unused_imports)]
pub use audio::{build_stream, AudioStreamConfig, AudioStreamInfo};
pub use link::LinkState;
#[allow(unused_imports)]
pub use sequencer::{
parse_midi_command, spawn_sequencer, AudioCommand, MidiCommand, PatternChange,
PatternSnapshot, SeqCommand, SequencerConfig, SequencerHandle, SequencerSnapshot,
SequencerState, SharedSequencerState, StepSnapshot, TickInput, TickOutput, TimestampedCommand,
parse_midi_command, spawn_sequencer, AudioCommand, MidiCommand, PatternChange, PatternSnapshot,
SeqCommand, SequencerConfig, SequencerHandle, SequencerSnapshot, SequencerState,
SharedSequencerState, StepSnapshot, TickInput, TickOutput, TimestampedCommand,
};

View File

@@ -28,27 +28,16 @@ mod memory {
false
}
}
#[allow(dead_code)]
pub fn is_memory_locked() -> bool {
MLOCKALL_SUCCESS.load(Ordering::Relaxed)
}
}
#[cfg(target_os = "linux")]
pub use memory::{is_memory_locked, lock_memory};
pub use memory::lock_memory;
#[cfg(not(target_os = "linux"))]
pub fn lock_memory() -> bool {
true
}
#[cfg(not(target_os = "linux"))]
#[allow(dead_code)]
pub fn is_memory_locked() -> bool {
false
}
/// Attempts to set realtime scheduling priority for the current thread.
/// Returns true if RT priority was successfully set, false otherwise.
#[cfg(target_os = "macos")]
@@ -105,7 +94,7 @@ pub fn set_realtime_priority() -> bool {
/// - Configured rtprio limits in /etc/security/limits.conf:
/// @audio - rtprio 95
/// @audio - memlock unlimited
#[cfg(target_os = "linux")]
#[cfg(all(target_os = "linux", feature = "cli"))]
pub fn set_realtime_priority() -> bool {
use thread_priority::unix::{
set_thread_priority_and_policy, thread_native_id, NormalThreadSchedulePolicy,
@@ -138,17 +127,27 @@ pub fn set_realtime_priority() -> bool {
false
}
#[cfg(all(target_os = "linux", not(feature = "cli")))]
pub fn set_realtime_priority() -> bool {
false
}
#[cfg(not(any(unix, target_os = "windows")))]
pub fn set_realtime_priority() -> bool {
false
}
#[cfg(target_os = "windows")]
#[cfg(all(target_os = "windows", feature = "cli"))]
pub fn set_realtime_priority() -> bool {
use thread_priority::{set_current_thread_priority, ThreadPriority};
set_current_thread_priority(ThreadPriority::Max).is_ok()
}
#[cfg(all(target_os = "windows", not(feature = "cli")))]
pub fn set_realtime_priority() -> bool {
false
}
/// High-precision sleep using clock_nanosleep on Linux.
/// Uses monotonic clock for jitter-free sleeping.
#[cfg(target_os = "linux")]