Skip to main content

rustriff_lib/commands/
loopback.rs

1use crate::commands::helpers::persist_amp_config;
2use crate::services::amp_config_service::AmpConfigPersistenceService;
3use crate::services::audio_service::AudioService;
4use std::sync::Mutex;
5
6/// Starts the audio loopback on a dedicated background thread.
7///
8/// Delegates to [`AudioService::start_loopback`] to begin capturing and processing audio.
9/// If the loopback is already running, this command is a no-op.
10///
11/// # Arguments
12///
13/// * `audio_service` - The shared [`AudioService`] state, accessed via Tauri's state management.
14#[tauri::command]
15pub(crate) fn start_loopback(
16    audio_service: tauri::State<'_, Mutex<AudioService>>,
17    persistence_service: tauri::State<'_, Mutex<AmpConfigPersistenceService>>,
18) {
19    let mut service = audio_service.lock().unwrap();
20    service.start_loopback();
21    persist_amp_config(&service, &persistence_service);
22}