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
2 changes: 1 addition & 1 deletion GLOSSARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Sending Plays straight to the Scrobbling account instead of to Navidrome, which
_Avoid_: Last.fm only

**Device config**:
A named output setup: one output device (or the system default), and whether Reverb matches each Song's sample rate and takes the device exclusively. Or instead an HQPlayer, on this computer or another, that Reverb hands playback to: HQPlayer then fetches and plays the Songs itself, while the Queue, transport and Plays stay in Reverb. One is active at a time; with none active, Reverb plays on the system default, shared, at the device's own rate — which is also where playback goes when the active one's device is unplugged. The config keeps its device, so picking it again once the device is back is all it takes. A config locked to its device never moves playback elsewhere: while the device is away, playback pauses and the config stays active, ready again the moment the device is back. Switching configs carries the playing Song across, from where it was.
A named output setup: one output device (or the system default), and whether Reverb matches each Song's sample rate and takes the device exclusively. Or instead an HQPlayer, on this computer or another, that Reverb hands playback to: HQPlayer then fetches and plays the Songs itself, while the Queue, transport and Plays stay in Reverb. One is active at a time; with none active, Reverb plays on the system default, shared, at the device's own rate — which is also where playback goes when the active one's device is unplugged. The config keeps its device, so picking it again once the device is back is all it takes. A config locked to its device never moves playback elsewhere: while the device is away, playback pauses and the config stays active, ready again the moment the device is back. Switching configs carries the playing Song across, from where it was. Launches can be set to begin on one config, or on the system default, whichever was active when Reverb closed; otherwise a launch picks up the config last active.
_Avoid_: Output profile, audio preset, zone

### Stats
Expand Down
14 changes: 14 additions & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ pub fn run() {
}
}

// A launch can be set to begin on one device config (or the
// system default), whatever was active at the last quit. Switch
// before the engine is built from the preferences, so it opens
// that output first.
{
let prefs = settings.get().prefs;
let launch = prefs.launch_device_config();
if launch != prefs.active_device_config {
if let Err(e) = settings.update(|s| s.prefs.active_device_config = launch) {
log::warn!("could not switch to the startup device config: {e}");
}
}
}

let keychain = Keychain::new(config_dir);
let subsonic = Arc::new(SubsonicClient::new());

Expand Down
59 changes: 59 additions & 0 deletions src-tauri/src/persistence/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ use serde::{Deserialize, Serialize};

use crate::error::ReverbError;

/// [`Preferences::startup_device_config`] value that starts every launch on
/// the system default. Config ids are nanoids or UUIDs, so none can be this.
pub const STARTUP_SYSTEM_DEFAULT: &str = "system-default";

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EqPreset {
Expand Down Expand Up @@ -95,6 +99,10 @@ pub struct Preferences {
/// The device config playing now, by id. `None` — or an id no config has —
/// plays on the system default, shared, at the device's own rate.
pub active_device_config: Option<String>,
/// The device config every launch starts on, by id, whatever was active
/// when Reverb closed — or [`STARTUP_SYSTEM_DEFAULT`] for none. `None` —
/// or an id no config has — starts on the one last active.
pub startup_device_config: Option<String>,
/// "raw" for the original file, or "mp3-320" / "mp3-192" / "mp3-128"
/// for server-side transcoding.
pub streaming_format: String,
Expand Down Expand Up @@ -176,6 +184,7 @@ impl Default for Preferences {
playlist_layout: "grid".into(),
device_configs: Vec::new(),
active_device_config: None,
startup_device_config: None,
streaming_format: "raw".into(),
replay_gain: ReplayGainSettings::default(),
crossfade_secs: 0,
Expand Down Expand Up @@ -208,6 +217,19 @@ impl Preferences {
self.device_configs.iter().find(|config| config.id == id)
}

/// The config a launch starts on, as `active_device_config` should then
/// read (`None` = system default): the startup choice, or the one last
/// active when there is none or it names a config that no longer exists.
pub fn launch_device_config(&self) -> Option<String> {
match self.startup_device_config.as_deref() {
Some(STARTUP_SYSTEM_DEFAULT) => None,
Some(id) if self.device_configs.iter().any(|config| config.id == id) => {
Some(id.to_owned())
}
_ => self.active_device_config.clone(),
}
}

/// What the local engine should be playing through. An HQPlayer config
/// has no device here, so with one active this is the system default —
/// which the engine, in standby, does not open.
Expand Down Expand Up @@ -706,6 +728,42 @@ mod tests {
assert_eq!(back["deviceConfigs"][1]["lockDevice"], serde_json::json!(false));
}

#[test]
fn a_launch_switches_to_the_startup_config() {
let raw = r#"{
"deviceConfigs": [
{"id": "a", "name": "Config A", "device": "coreaudio:dac"},
{"id": "b", "name": "Config B", "device": null}
],
"activeDeviceConfig": "b",
"startupDeviceConfig": "a"
}"#;
let mut prefs: Preferences = serde_json::from_str(raw).unwrap();
assert_eq!(prefs.launch_device_config().as_deref(), Some("a"));

// From the system default too.
prefs.active_device_config = None;
assert_eq!(prefs.launch_device_config().as_deref(), Some("a"));

// The system default can be the startup choice as well.
prefs.active_device_config = Some("b".into());
prefs.startup_device_config = Some(STARTUP_SYSTEM_DEFAULT.into());
assert_eq!(prefs.launch_device_config(), None);

// No startup config, or a deleted one: the last one active stays.
prefs.startup_device_config = None;
assert_eq!(prefs.launch_device_config().as_deref(), Some("b"));
prefs.startup_device_config = Some("gone".into());
assert_eq!(prefs.launch_device_config().as_deref(), Some("b"));
prefs.active_device_config = None;
assert_eq!(prefs.launch_device_config(), None);

// And the field round-trips under its name.
prefs.startup_device_config = Some("a".into());
let back = serde_json::to_value(&prefs).unwrap();
assert_eq!(back["startupDeviceConfig"], serde_json::json!("a"));
}

#[test]
fn old_settings_files_parse_with_pref_defaults() {
// A settings.json written before the preferences existed.
Expand All @@ -728,6 +786,7 @@ mod tests {
assert!(!s.prefs.direct_scrobble_reset_on_start);
assert!(!s.prefs.direct_scrobble_pinned);
assert!(s.prefs.device_configs.is_empty());
assert_eq!(s.prefs.startup_device_config, None, "no startup config: start on the last one");
assert_eq!(s.prefs.output(), OutputSettings::default());
assert!(s.prefs.check_for_updates, "update checks default to on");
assert!(!s.prefs.discord_presence, "Discord presence defaults to off");
Expand Down
38 changes: 37 additions & 1 deletion src/lib/deviceConfigs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
isConnected,
parsePort,
saveDeviceConfig,
STARTUP_SYSTEM_DEFAULT,
startupDeviceConfig,
} from "./deviceConfigs";
import type { DeviceConfig, OutputDevice } from "./subsonic/types";

Expand All @@ -30,7 +32,11 @@ const speakers: DeviceConfig = {
lockDevice: false,
hqplayer: null,
};
const prefs = { deviceConfigs: [desk, speakers], activeDeviceConfig: "desk" };
const prefs = {
deviceConfigs: [desk, speakers],
activeDeviceConfig: "desk",
startupDeviceConfig: null,
};

describe("activeDeviceConfig", () => {
it("finds the config by id", () => {
Expand All @@ -49,6 +55,7 @@ describe("saveDeviceConfig", () => {
expect(saveDeviceConfig(prefs, fresh)).toEqual({
deviceConfigs: [desk, speakers, fresh],
activeDeviceConfig: "new",
startupDeviceConfig: null,
});
});

Expand All @@ -57,24 +64,53 @@ describe("saveDeviceConfig", () => {
expect(saveDeviceConfig(prefs, renamed)).toEqual({
deviceConfigs: [desk, renamed],
activeDeviceConfig: "desk",
startupDeviceConfig: null,
});
});

it("keeps the startup config", () => {
const withStartup = { ...prefs, startupDeviceConfig: "speakers" };
const fresh = { ...speakers, id: "new", name: "Headphones" };
expect(saveDeviceConfig(withStartup, fresh).startupDeviceConfig).toBe("speakers");
expect(saveDeviceConfig(withStartup, desk).startupDeviceConfig).toBe("speakers");
});
});

describe("deleteDeviceConfig", () => {
it("keeps the active config when another one goes", () => {
expect(deleteDeviceConfig(prefs, "speakers")).toEqual({
deviceConfigs: [desk],
activeDeviceConfig: "desk",
startupDeviceConfig: null,
});
});

it("falls back to the system default when the active one goes", () => {
expect(deleteDeviceConfig(prefs, "desk")).toEqual({
deviceConfigs: [speakers],
activeDeviceConfig: null,
startupDeviceConfig: null,
});
});

it("drops the startup config when it goes, and only then", () => {
const withStartup = { ...prefs, startupDeviceConfig: "speakers" };
expect(deleteDeviceConfig(withStartup, "speakers").startupDeviceConfig).toBeNull();
expect(deleteDeviceConfig(withStartup, "desk").startupDeviceConfig).toBe("speakers");
});
});

describe("startupDeviceConfig", () => {
it("is a config's id, or the system default", () => {
expect(startupDeviceConfig({ ...prefs, startupDeviceConfig: "speakers" })).toBe("speakers");
const systemDefault = { ...prefs, startupDeviceConfig: STARTUP_SYSTEM_DEFAULT };
expect(startupDeviceConfig(systemDefault)).toBe(STARTUP_SYSTEM_DEFAULT);
});

it("is none without one, or with one that was deleted", () => {
expect(startupDeviceConfig(prefs)).toBeNull();
expect(startupDeviceConfig({ ...prefs, startupDeviceConfig: "gone" })).toBeNull();
});
});

describe("afterDeviceLost", () => {
Expand Down
34 changes: 31 additions & 3 deletions src/lib/deviceConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@

import type { DeviceConfig, HqPlayerEndpoint, OutputDevice, Preferences } from "./subsonic/types";

/**
* `startupDeviceConfig` value that starts every launch on the system default.
* Config ids are nanoids or UUIDs, so none can be this.
*/
export const STARTUP_SYSTEM_DEFAULT = "system-default";

/** The port HQPlayer listens for control on unless told otherwise. */
export const HQPLAYER_DEFAULT_PORT = 4321;

type ConfigPrefs = Pick<Preferences, "deviceConfigs" | "activeDeviceConfig">;
type ConfigPrefs = Pick<
Preferences,
"deviceConfigs" | "activeDeviceConfig" | "startupDeviceConfig"
>;

/** The device config playing now; `null` means the system default. */
export function activeDeviceConfig(prefs: ConfigPrefs): DeviceConfig | null {
Expand All @@ -24,19 +33,38 @@ export function saveDeviceConfig(prefs: ConfigPrefs, config: DeviceConfig): Conf
return {
deviceConfigs: prefs.deviceConfigs.map((c) => (c.id === config.id ? config : c)),
activeDeviceConfig: prefs.activeDeviceConfig,
startupDeviceConfig: prefs.startupDeviceConfig,
};
}
return { deviceConfigs: [...prefs.deviceConfigs, config], activeDeviceConfig: config.id };
return {
deviceConfigs: [...prefs.deviceConfigs, config],
activeDeviceConfig: config.id,
startupDeviceConfig: prefs.startupDeviceConfig,
};
}

/** Delete a config. Deleting the active one moves playback to the system default. */
/**
* Delete a config. Deleting the active one moves playback to the system
* default; deleting the startup one leaves launches on the one last active.
*/
export function deleteDeviceConfig(prefs: ConfigPrefs, id: string): ConfigPrefs {
return {
deviceConfigs: prefs.deviceConfigs.filter((c) => c.id !== id),
activeDeviceConfig: prefs.activeDeviceConfig === id ? null : prefs.activeDeviceConfig,
startupDeviceConfig: prefs.startupDeviceConfig === id ? null : prefs.startupDeviceConfig,
};
}

/**
* What launches start on: a config's id, `STARTUP_SYSTEM_DEFAULT`, or `null`
* for the one last active — which is also what an id no config has means.
*/
export function startupDeviceConfig(prefs: ConfigPrefs): string | null {
const id = prefs.startupDeviceConfig;
if (id === STARTUP_SYSTEM_DEFAULT) return id;
return prefs.deviceConfigs.some((c) => c.id === id) ? id : null;
}

/**
* Mirror the backend after `device` was unplugged: playback fell back to the
* system default, so that is what is active now. A config switched to since
Expand Down
4 changes: 4 additions & 0 deletions src/lib/i18n/messages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,10 @@ export const de: Messages = {
"settings.deleteDeviceConfigTitle": "„{name}“ löschen?",
"settings.deleteActiveDeviceConfigBody":
"Sie ist gerade aktiv, daher wechselt die Wiedergabe auf den Systemstandard.",
"settings.startupDeviceConfig": "Konfiguration beim Start",
"settings.startupDeviceConfigHint":
"Die Gerätekonfiguration, mit der Reverb startet, egal welche beim Beenden aktiv war. „Zuletzt verwendet“ macht dort weiter, wo du aufgehört hast.",
"settings.startupDeviceConfigLastUsed": "Zuletzt verwendet",
"settings.deviceConfigName": "Name",
"settings.deviceConfigNameHint": "Leer lassen, um den Namen des Geräts zu verwenden.",
"settings.systemDefaultConfigHint":
Expand Down
4 changes: 4 additions & 0 deletions src/lib/i18n/messages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@ export const en = {
"settings.deleteDeviceConfig": "Delete {name}",
"settings.deleteDeviceConfigTitle": "Delete “{name}”?",
"settings.deleteActiveDeviceConfigBody": "It is in use, so playback moves to the system default.",
"settings.startupDeviceConfig": "Config at startup",
"settings.startupDeviceConfigHint":
"Reverb starts on this config every time, whichever one was in use when it closed. “Last used” picks up where you left off.",
"settings.startupDeviceConfigLastUsed": "Last used",
"settings.deviceConfigName": "Name",
"settings.deviceConfigNameHint": "Leave empty to use the device's name.",
"settings.systemDefaultConfigHint":
Expand Down
4 changes: 4 additions & 0 deletions src/lib/i18n/messages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,10 @@ export const es: Messages = {
"settings.deleteDeviceConfigTitle": "¿Eliminar “{name}”?",
"settings.deleteActiveDeviceConfigBody":
"Está en uso, así que la reproducción pasa al predeterminado del sistema.",
"settings.startupDeviceConfig": "Configuración al iniciar",
"settings.startupDeviceConfigHint":
"La configuración de dispositivo con la que arranca Reverb, sea cual sea la que estaba en uso al cerrarlo. “Última usada” continúa donde lo dejaste.",
"settings.startupDeviceConfigLastUsed": "Última usada",
"settings.deviceConfigName": "Nombre",
"settings.deviceConfigNameHint": "Déjalo vacío para usar el nombre del dispositivo.",
"settings.systemDefaultConfigHint":
Expand Down
4 changes: 4 additions & 0 deletions src/lib/i18n/messages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,10 @@ export const fr: Messages = {
"settings.deleteDeviceConfigTitle": "Supprimer « {name} » ?",
"settings.deleteActiveDeviceConfigBody":
"Elle est en cours d'utilisation : la lecture passe sur le périphérique par défaut.",
"settings.startupDeviceConfig": "Configuration au démarrage",
"settings.startupDeviceConfigHint":
"La configuration de périphérique avec laquelle Reverb démarre, quelle que soit celle utilisée à sa fermeture. « Dernière utilisée » reprend là où vous vous étiez arrêté.",
"settings.startupDeviceConfigLastUsed": "Dernière utilisée",
"settings.deviceConfigName": "Nom",
"settings.deviceConfigNameHint": "Laissez vide pour utiliser le nom du périphérique.",
"settings.systemDefaultConfigHint":
Expand Down
7 changes: 7 additions & 0 deletions src/lib/subsonic/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,13 @@ export interface Preferences {
* plays on the system default, shared, at the device's own rate.
*/
activeDeviceConfig: string | null;
/**
* The device config every launch starts on, by id, whatever was active when
* Reverb closed — or `STARTUP_SYSTEM_DEFAULT` for none. `null` — or an id no
* config has — starts on the one last active. The backend switches at
* launch, before the engine opens.
*/
startupDeviceConfig: string | null;
streamingFormat: StreamingFormat;
replayGain: ReplayGainSettings;
/** Crossfade between tracks in seconds (0 = gapless). */
Expand Down
1 change: 1 addition & 0 deletions src/stores/prefsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ const DEFAULT_PREFS: Preferences = {
playlistLayout: "grid",
deviceConfigs: [],
activeDeviceConfig: null,
startupDeviceConfig: null,
streamingFormat: "raw",
replayGain: { mode: "off", preampDb: 0, clipProtection: true, fallbackDb: 0 },
crossfadeSecs: 0,
Expand Down
26 changes: 26 additions & 0 deletions src/views/settings/SettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import {
isConnected,
parsePort,
saveDeviceConfig,
STARTUP_SYSTEM_DEFAULT,
startupDeviceConfig,
} from "../../lib/deviceConfigs";
import { formatSampleRate } from "../../lib/format";
import { LANGUAGE_NAMES, LOCALES, useT, type MessageKey, type T } from "../../lib/i18n";
Expand Down Expand Up @@ -479,6 +481,30 @@ function AudioSection() {
})}
</div>

{/* Only worth asking once there is a config: until then every launch
is on the system default anyway. Reads the resolved choice, so a
config deleted elsewhere shows as "Last used". */}
{prefs.deviceConfigs.length > 0 && (
<SettingRow
label={t("settings.startupDeviceConfig")}
hint={t("settings.startupDeviceConfigHint")}
>
<select
className={selectClass}
value={startupDeviceConfig(prefs) ?? ""}
onChange={(e) => set({ startupDeviceConfig: e.target.value || null })}
>
<option value="">{t("settings.startupDeviceConfigLastUsed")}</option>
<option value={STARTUP_SYSTEM_DEFAULT}>{t("settings.systemDefault")}</option>
{prefs.deviceConfigs.map((config) => (
<option key={config.id} value={config.id}>
{config.name}
</option>
))}
</select>
</SettingRow>
)}

{/* Reverb's own stream; with HQPlayer playing there is none, and the
signal path shows HQPlayer's rate instead. */}
{!active?.hqplayer && (
Expand Down
Loading