feat(ui): add gapless playback toggle button to player bar
Add a toggleable gapless button next to the repeat button in the NowPlayingBar. The setting persists in audio_settings.db and controls whether the audio thread pre-queues the next track for gapless transitions. Includes i18n keys for all 4 locales.
This commit is contained in:
1 parent
a21f7c7a93
commit
71bfb8dc17
9 files changed
+77
-7
No files matched your search
@@ -36,6 +36,9 @@ pub struct AudioSettings {
|
||||
/// Target loudness in LUFS for normalization.
|
||||
/// Common values: -14.0 (Spotify/YouTube), -18.0 (audiophile), -23.0 (EBU broadcast)
|
||||
pub normalization_target_lufs: f32,
|
||||
/// When true, tracks with the same format are cross-faded seamlessly via Rodio Sink queueing.
|
||||
/// Only works with cached tracks on Rodio backend (not ALSA Direct or streaming).
|
||||
pub gapless_enabled: bool,
|
||||
}
|
||||
|
||||
impl Default for AudioSettings {
|
||||
@@ -55,6 +58,7 @@ impl Default for AudioSettings {
|
||||
device_max_sample_rate: None, // Set when device is selected
|
||||
normalization_enabled: false, // Off by default — preserves bit-perfect pipeline
|
||||
normalization_target_lufs: -14.0, // Spotify/YouTube standard
|
||||
gapless_enabled: true, // On by default — seamless track transitions
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,6 +104,7 @@ impl AudioSettingsStore {
|
||||
let _ = conn.execute("ALTER TABLE audio_settings ADD COLUMN device_max_sample_rate INTEGER", []);
|
||||
let _ = conn.execute("ALTER TABLE audio_settings ADD COLUMN normalization_enabled INTEGER DEFAULT 0", []);
|
||||
let _ = conn.execute("ALTER TABLE audio_settings ADD COLUMN normalization_target_lufs REAL DEFAULT -14.0", []);
|
||||
let _ = conn.execute("ALTER TABLE audio_settings ADD COLUMN gapless_enabled INTEGER DEFAULT 1", []);
|
||||
|
||||
Ok(Self { conn })
|
||||
}
|
||||
@@ -118,7 +123,7 @@ impl AudioSettingsStore {
|
||||
pub fn get_settings(&self) -> Result<AudioSettings, String> {
|
||||
self.conn
|
||||
.query_row(
|
||||
"SELECT output_device, exclusive_mode, dac_passthrough, preferred_sample_rate, backend_type, alsa_plugin, alsa_hardware_volume, stream_first_track, stream_buffer_seconds, streaming_only, limit_quality_to_device, device_max_sample_rate, normalization_enabled, normalization_target_lufs FROM audio_settings WHERE id = 1",
|
||||
"SELECT output_device, exclusive_mode, dac_passthrough, preferred_sample_rate, backend_type, alsa_plugin, alsa_hardware_volume, stream_first_track, stream_buffer_seconds, streaming_only, limit_quality_to_device, device_max_sample_rate, normalization_enabled, normalization_target_lufs, gapless_enabled FROM audio_settings WHERE id = 1",
|
||||
[],
|
||||
|row| {
|
||||
// Parse backend_type from JSON string
|
||||
@@ -146,6 +151,7 @@ impl AudioSettingsStore {
|
||||
device_max_sample_rate: row.get::<_, Option<i64>>(11)?.map(|r| r as u32),
|
||||
normalization_enabled: row.get::<_, Option<i64>>(12)?.unwrap_or(0) != 0,
|
||||
normalization_target_lufs: row.get::<_, Option<f64>>(13)?.unwrap_or(-14.0) as f32,
|
||||
gapless_enabled: row.get::<_, Option<i64>>(14)?.unwrap_or(1) != 0,
|
||||
})
|
||||
},
|
||||
)
|
||||
@@ -294,6 +300,16 @@ impl AudioSettingsStore {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_gapless_enabled(&self, enabled: bool) -> Result<(), String> {
|
||||
self.conn
|
||||
.execute(
|
||||
"UPDATE audio_settings SET gapless_enabled = ?1 WHERE id = 1",
|
||||
params![enabled as i64],
|
||||
)
|
||||
.map_err(|e| format!("Failed to set gapless enabled: {}", e))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_normalization_target_lufs(&self, target: f32) -> Result<(), String> {
|
||||
self.conn
|
||||
.execute(
|
||||
@@ -502,3 +518,14 @@ pub fn set_audio_normalization_target(
|
||||
let store = guard.as_ref().ok_or("No active session - please log in")?;
|
||||
store.set_normalization_target_lufs(target_lufs)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn set_audio_gapless_enabled(
|
||||
state: tauri::State<'_, AudioSettingsState>,
|
||||
enabled: bool,
|
||||
) -> Result<(), String> {
|
||||
log::info!("Command: set_audio_gapless_enabled {}", enabled);
|
||||
let guard = state.store.lock().map_err(|e| format!("Lock error: {}", e))?;
|
||||
let store = guard.as_ref().ok_or("No active session - please log in")?;
|
||||
store.set_gapless_enabled(enabled)
|
||||
}
|
||||
@@ -740,6 +740,7 @@ pub fn run() {
|
||||
config::audio_settings::set_audio_device_max_sample_rate,
|
||||
config::audio_settings::set_audio_normalization_enabled,
|
||||
config::audio_settings::set_audio_normalization_target,
|
||||
config::audio_settings::set_audio_gapless_enabled,
|
||||
// Audio backend commands
|
||||
commands::get_available_backends,
|
||||
commands::get_devices_for_backend,
|
||||
|
||||
@@ -1997,8 +1997,14 @@ impl Player {
|
||||
}
|
||||
|
||||
// Gapless readiness: signal frontend when ~5s remain
|
||||
// Only when: playing, not streaming, no gapless already pending
|
||||
if dur > 0
|
||||
// Only when: playing, not streaming, no gapless already pending, gapless enabled
|
||||
let gapless_enabled = thread_settings
|
||||
.lock()
|
||||
.ok()
|
||||
.map(|s| s.gapless_enabled)
|
||||
.unwrap_or(false);
|
||||
if gapless_enabled
|
||||
&& dur > 0
|
||||
&& pos + 5 >= dur
|
||||
&& gapless_pending.is_none()
|
||||
&& !thread_state.is_gapless_ready()
|
||||
|
||||
Reference in new issue
Block a user