Implement ALSA Direct backend and smart toggles for incompatible features

ALSA Direct Backend Implementation:
- Fully functional ALSA backend using CPAL's ALSA host
- Enumerates ALSA devices with hardware names
- Supports custom sample rates for bit-perfect playback
- Supports exclusive mode (device blocking)
- Smaller buffer size (512 samples) for lower latency in exclusive mode
- Clear error messages when device is in use

Smart Toggles in UI:
- Exclusive Mode auto-disabled with PipeWire/Auto backends
  (PipeWire is multiplexed and cannot provide true exclusive access)
- Gapless Playback auto-disabled with DAC Passthrough
  (bit-perfect requires recreating streams for sample rate changes)
- Toggle component now supports 'disabled' prop with visual feedback
- Tooltips updated to explain why features are disabled
- Auto-disable exclusive mode when switching to PipeWire backend

User Benefits:
- ALSA Direct now appears in backend dropdown
- True exclusive mode available with ALSA Direct
- Prevents confusing feature combinations
- Clear explanations via tooltips
- No more wondering why exclusive mode doesn't work with PipeWire

Technical Notes:
- ALSA backend uses CPAL host selection (not alsa-rs directly)
- Disabled toggles shown as grayed out with cursor: not-allowed
- Backend switching auto-adjusts incompatible settings
This commit is contained in:
vicrodh committed 2026-01-17 17:21:23 -06:00
1 parent 30e8fef7a4
commit 89126446bb
3 files changed
+240 -25

No files matched your search

+32 -4
View File
@@ -226,6 +226,20 @@
// Show ALSA plugin selector only when ALSA backend is selected (derived)
let showAlsaPluginSelector = $derived(selectedBackend === 'ALSA Direct');
// Smart toggle states - auto-disable incompatible features
let exclusiveModeDisabled = $derived(selectedBackend === 'PipeWire' || selectedBackend === 'Auto');
let exclusiveModeTooltipOverride = $derived(
exclusiveModeDisabled
? 'Exclusive mode is only available with ALSA Direct backend. PipeWire is a multiplexed audio server and cannot provide true exclusive access.'
: null
);
let gaplessDisabled = $derived(dacPassthrough);
let gaplessTooltipOverride = $derived(
gaplessDisabled
? 'Gapless playback is disabled when DAC Passthrough is enabled. Bit-perfect audio requires recreating streams for each sample rate change.'
: null
);
// Playback settings
let gaplessPlayback = $state(true);
let crossfade = $state(0);
@@ -989,6 +1003,15 @@
const backend = availableBackends.find(b => b.name === backendName);
const backendType = backendName === 'Auto' ? null : backend?.backend_type ?? null;
// Auto-disable incompatible features
if (backendName === 'PipeWire' || backendName === 'Auto') {
if (exclusiveMode) {
exclusiveMode = false;
await invoke('set_audio_exclusive_mode', { enabled: false });
console.log('[Audio] Disabled exclusive mode (incompatible with PipeWire)');
}
}
try {
// Save backend preference
await invoke('set_audio_backend_type', { backendType });
@@ -1385,9 +1408,9 @@
<div class="setting-row">
<div class="label-with-tooltip">
<span class="setting-label">{$t('settings.audio.exclusiveMode')}</span>
<Tooltip text={$t('settings.audio.exclusiveModeDesc')} />
<Tooltip text={exclusiveModeTooltipOverride || $t('settings.audio.exclusiveModeDesc')} />
</div>
<Toggle enabled={exclusiveMode} onchange={handleExclusiveModeChange} />
<Toggle enabled={exclusiveMode} onchange={handleExclusiveModeChange} disabled={exclusiveModeDisabled} />
</div>
<div class="setting-row">
<div class="label-with-tooltip">
@@ -1415,8 +1438,13 @@
<section class="section" bind:this={playbackSection}>
<h3 class="section-title">{$t('settings.playback.title')}</h3>
<div class="setting-row">
<span class="setting-label">{$t('settings.playback.gapless')}</span>
<Toggle enabled={gaplessPlayback} onchange={handleGaplessPlaybackChange} />
<div class="label-with-tooltip">
<span class="setting-label">{$t('settings.playback.gapless')}</span>
{#if gaplessTooltipOverride}
<Tooltip text={gaplessTooltipOverride} />
{/if}
</div>
<Toggle enabled={gaplessPlayback} onchange={handleGaplessPlaybackChange} disabled={gaplessDisabled} />
</div>
<div class="setting-row">
<span class="setting-label">{$t('settings.playback.crossfade')}</span>