diff --git a/src/lib/components/DACSetupWizard.svelte b/src/lib/components/DACSetupWizard.svelte index a35b56ab7..b67b2fd83 100644 --- a/src/lib/components/DACSetupWizard.svelte +++ b/src/lib/components/DACSetupWizard.svelte @@ -88,6 +88,27 @@ let dacCapabilities = $state(null); let isQueryingDac = $state(false); + // Sample rate selection for PipeWire config (step 5) + const COMMON_SAMPLE_RATES = [44100, 48000, 88200, 96000, 176400, 192000]; + let selectedSampleRates = $state>(new Set()); + + // Derive DAC short name for config filenames + const dacShortName = $derived(() => { + if (!dacNodeName) return 'dac'; + // Extract meaningful part from node name + // alsa_output.usb-Cambridge_Audio_DacMagic_Plus-00.analog-stereo -> dacmagic-plus + // alsa_output.usb-Generic_Macaron-00.analog-stereo -> macaron + const match = dacNodeName.match(/usb-([^-]+)_([^-]+)/i); + if (match) { + return match[2].toLowerCase().replace(/_/g, '-'); + } + // Fallback: try to get something from description + if (dacCapabilities?.description) { + return dacCapabilities.description.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '').slice(0, 20); + } + return 'dac'; + }); + async function queryDacCapabilities() { if (!dacNodeName.trim() || dacValidation !== 'valid') return; @@ -99,6 +120,11 @@ nodeName: dacNodeName }); dacCapabilities = caps; + + // Pre-fill selected sample rates from detected capabilities + if (caps.sample_rates.length > 0) { + selectedSampleRates = new Set(caps.sample_rates.filter(r => COMMON_SAMPLE_RATES.includes(r))); + } } catch (err) { console.error('Failed to query DAC capabilities:', err); dacCapabilities = { @@ -114,6 +140,31 @@ } } + function toggleSampleRate(rate: number) { + const newSet = new Set(selectedSampleRates); + if (newSet.has(rate)) { + newSet.delete(rate); + } else { + newSet.add(rate); + } + selectedSampleRates = newSet; + } + + function generatePipewireConfig(): string[] { + const rates = Array.from(selectedSampleRates).sort((a, b) => a - b); + const ratesStr = rates.length > 0 ? rates.join(' ') : '44100 48000 88200 96000 176400 192000'; + + return [ + 'mkdir -p ~/.config/pipewire/pipewire.conf.d', + `cat > ~/.config/pipewire/pipewire.conf.d/99-qbz-dac.conf << 'EOF'`, + '# QBZ DAC Setup - Sample Rate Switching', + 'context.properties = {', + ` default.clock.allowed-rates = [ ${ratesStr} ]`, + '}', + 'EOF' + ]; + } + // Reset state when modal opens $effect(() => { if (isOpen) { @@ -128,6 +179,7 @@ showRollback = false; dacCapabilities = null; isQueryingDac = false; + selectedSampleRates = new Set(); } }); @@ -212,18 +264,23 @@ // Generate WirePlumber config with user's DAC node name function generateWireplumberConfig(): string[] { + const rates = Array.from(selectedSampleRates).sort((a, b) => a - b); + const ratesStr = rates.length > 0 ? rates.join(' ') : '44100 48000 88200 96000 176400 192000'; + const fileName = `99-qbz-dac-${dacShortName()}.conf`; + const nodeName = dacNodeName || 'alsa_output.usb-YOUR_DAC-00.analog-stereo'; + return [ 'mkdir -p ~/.config/wireplumber/wireplumber.conf.d', - `cat > ~/.config/wireplumber/wireplumber.conf.d/99-qbz-dac.conf << 'EOF'`, - '# QBZ DAC Setup - Device-Specific Rules', + `cat > ~/.config/wireplumber/wireplumber.conf.d/${fileName} << 'EOF'`, + `# QBZ DAC Setup - ${dacCapabilities?.description || dacShortName()}`, 'monitor.alsa.rules = [', ' {', ' matches = [', - ` { node.name = "${dacNodeName}", media.class = "Audio/Sink" }`, + ` { node.name = "${nodeName}", media.class = "Audio/Sink" }`, ' ]', ' actions = {', ' update-props = {', - ' audio.allowed-rates = [ 44100 48000 88200 96000 176400 192000 ]', + ` audio.allowed-rates = [ ${ratesStr} ]`, ' resample.disable = true', ' channelmix.disable = true', ' }', @@ -475,17 +532,29 @@

{$t('dacWizard.pipewireConfig.explanation')}

- ~/.config/pipewire/pipewire.conf.d/99-qbz-dac.conf << 'EOF'`, - '# QBZ DAC Setup - Sample Rate Switching', - 'context.properties = {', - ' default.clock.allowed-rates = [ 44100 48000 88200 96000 176400 192000 ]', - '}', - 'EOF' - ]} - /> +
+ +
+ {#each COMMON_SAMPLE_RATES as rate} + + {/each} +
+ {#if selectedSampleRates.size === 0} +

{$t('dacWizard.pipewireConfig.noRatesHint')}

+ {/if} +
+ +
{:else if currentStep === 'pulse-config'} @@ -936,6 +1005,81 @@ color: var(--color-success, #22c55e); } + .sample-rate-selector { + display: flex; + flex-direction: column; + gap: 10px; + margin-bottom: 12px; + } + + .selector-label { + font-size: 13px; + font-weight: 500; + color: var(--text-secondary); + } + + .rate-checkboxes { + display: flex; + flex-wrap: wrap; + gap: 8px; + } + + .rate-checkbox { + display: flex; + align-items: center; + gap: 6px; + padding: 8px 12px; + background: var(--bg-tertiary); + border: 1px solid var(--border-subtle); + border-radius: 6px; + cursor: pointer; + transition: all 150ms ease; + font-size: 13px; + color: var(--text-primary); + } + + .rate-checkbox:hover { + background: var(--bg-hover); + } + + .rate-checkbox:has(input:checked) { + border-color: var(--accent-primary); + background: rgba(66, 133, 244, 0.1); + } + + .rate-checkbox.detected { + border-color: var(--color-success, #22c55e); + } + + .rate-checkbox.detected:has(input:checked) { + border-color: var(--color-success, #22c55e); + background: rgba(34, 197, 94, 0.1); + } + + .rate-checkbox input { + accent-color: var(--accent-primary); + } + + .rate-checkbox.detected input { + accent-color: var(--color-success, #22c55e); + } + + .detected-badge { + font-size: 10px; + padding: 2px 6px; + background: var(--color-success, #22c55e); + color: white; + border-radius: 4px; + text-transform: uppercase; + letter-spacing: 0.5px; + } + + .rate-hint { + font-size: 12px; + color: var(--text-muted); + font-style: italic; + } + .targeting-info { display: flex; flex-direction: column; diff --git a/src/lib/i18n/locales/de.json b/src/lib/i18n/locales/de.json index b0f81dd89..70c23e312 100644 --- a/src/lib/i18n/locales/de.json +++ b/src/lib/i18n/locales/de.json @@ -1020,7 +1020,9 @@ "pipewireConfig": { "title": "Mehrere Abtastraten erlauben", "subtitle": "Ermöglicht automatisches Umschalten ohne 48kHz-Zwang.", - "explanation": "Standardmäßig sperrt PipeWire auf 48kHz. Diese Konfiguration ermöglicht es Ihrem DAC, zur nativen Abtastrate des Tracks zu wechseln." + "explanation": "Standardmäßig sperrt PipeWire auf 48kHz. Diese Konfiguration ermöglicht es Ihrem DAC, zur nativen Abtastrate des Tracks zu wechseln.", + "selectRates": "Wählen Sie die von Ihrem DAC unterstützten Abtastraten:", + "noRatesHint": "Keine Raten ausgewählt. Standardwerte werden verwendet." }, "pulseConfig": { "title": "Apps für Bit-Perfect wählen", diff --git a/src/lib/i18n/locales/en.json b/src/lib/i18n/locales/en.json index 64a0b98a2..d04e997fd 100644 --- a/src/lib/i18n/locales/en.json +++ b/src/lib/i18n/locales/en.json @@ -1079,7 +1079,9 @@ "pipewireConfig": { "title": "Allow Multiple Sample Rates", "subtitle": "Enables automatic switching without forcing 48kHz.", - "explanation": "By default, PipeWire locks to 48kHz. This config allows your DAC to switch to the track's native sample rate." + "explanation": "By default, PipeWire locks to 48kHz. This config allows your DAC to switch to the track's native sample rate.", + "selectRates": "Select sample rates your DAC supports:", + "noRatesHint": "No rates selected. Default values will be used." }, "pulseConfig": { "title": "Choose Apps for Bit-Perfect", diff --git a/src/lib/i18n/locales/es.json b/src/lib/i18n/locales/es.json index 17e0f2dde..a96845ffa 100644 --- a/src/lib/i18n/locales/es.json +++ b/src/lib/i18n/locales/es.json @@ -1079,7 +1079,9 @@ "pipewireConfig": { "title": "Permitir Múltiples Sample Rates", "subtitle": "Habilita cambio automático sin forzar 48kHz.", - "explanation": "Por defecto, PipeWire fija 48kHz. Esta config permite que tu DAC cambie al sample rate nativo de cada pista." + "explanation": "Por defecto, PipeWire fija 48kHz. Esta config permite que tu DAC cambie al sample rate nativo de cada pista.", + "selectRates": "Selecciona los sample rates que soporta tu DAC:", + "noRatesHint": "Sin rates seleccionados. Se usarán valores por defecto." }, "pulseConfig": { "title": "Elegir Apps para Bit-Perfect", diff --git a/src/lib/i18n/locales/fr.json b/src/lib/i18n/locales/fr.json index c2dfbbb27..dece2b424 100644 --- a/src/lib/i18n/locales/fr.json +++ b/src/lib/i18n/locales/fr.json @@ -1020,7 +1020,9 @@ "pipewireConfig": { "title": "Autoriser plusieurs taux d'échantillonnage", "subtitle": "Permet le changement automatique sans forcer 48kHz.", - "explanation": "Par défaut, PipeWire verrouille à 48kHz. Cette configuration permet à votre DAC de basculer vers le taux d'échantillonnage natif de la piste." + "explanation": "Par défaut, PipeWire verrouille à 48kHz. Cette configuration permet à votre DAC de basculer vers le taux d'échantillonnage natif de la piste.", + "selectRates": "Sélectionnez les taux d'échantillonnage pris en charge par votre DAC :", + "noRatesHint": "Aucun taux sélectionné. Les valeurs par défaut seront utilisées." }, "pulseConfig": { "title": "Choisir les applications bit-perfect",