Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions cohen_gig/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ korg_nano_kontrol_2 = "0.1.1"
midir = "0.5"
rayon = "1"
uuid = { version = "1", features = ["v4"] }
rfd = "0.15"
24 changes: 22 additions & 2 deletions cohen_gig/src/audio_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pub struct AudioInput {
selected_device_name: Option<String>,
device_error: Option<String>,
last_device_refresh: Instant,
/// Receiver for background device enumeration results.
pending_device_refresh: Option<std::sync::mpsc::Receiver<Vec<AudioDeviceInfo>>>,
pub peak_history: VecDeque<f32>,
pub waveform_history: VecDeque<f32>,
pub envelope_history: VecDeque<f32>,
Expand Down Expand Up @@ -79,6 +81,7 @@ impl AudioInput {
selected_device_name: None,
device_error: None,
last_device_refresh: Instant::now(),
pending_device_refresh: None,
peak_history: VecDeque::from(vec![0.0; history_len]),
waveform_history: VecDeque::from(vec![0.0; waveform_history_len]),
envelope_history: VecDeque::from(vec![0.0; history_len]),
Expand Down Expand Up @@ -197,8 +200,25 @@ impl AudioInput {
}

fn refresh_available_devices_if_needed(&mut self) {
if self.last_device_refresh.elapsed() >= DEVICE_REFRESH_INTERVAL {
self.refresh_available_devices();
// Collect result from background enumeration if ready.
if let Some(ref rx) = self.pending_device_refresh {
if let Ok(devices) = rx.try_recv() {
self.available_devices = devices;
self.pending_device_refresh = None;
self.ensure_selected_device();
}
}

// Kick off a new background enumeration if interval elapsed and none pending.
if self.pending_device_refresh.is_none()
&& self.last_device_refresh.elapsed() >= DEVICE_REFRESH_INTERVAL
{
self.last_device_refresh = Instant::now();
let (tx, rx) = std::sync::mpsc::channel();
self.pending_device_refresh = Some(rx);
std::thread::spawn(move || {
let _ = tx.send(enumerate_input_devices());
});
}
}

Expand Down
6 changes: 6 additions & 0 deletions cohen_gig/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ pub struct Config {
pub led_output_fps: LedOutputFps,
#[serde(default)]
pub led_layout: LedLayout,
/// Optional path to a MadMapper .mad project file.
/// When Some, the layout and DMX addressing are derived from this file
/// instead of the manual `led_layout` and `led_start_universe` fields.
#[serde(default)]
pub madmapper_project_path: Option<String>,
#[serde(default)]
pub presets: Presets,
#[serde(default)]
Expand Down Expand Up @@ -127,6 +132,7 @@ impl Default for Config {
sacn_interface_ip: default::sacn_interface_ip(),
led_output_fps: Default::default(),
led_layout: Default::default(),
madmapper_project_path: None,
presets: Default::default(),
preset_lerp_secs: Default::default(),
}
Expand Down
Loading