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. 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.
_Avoid_: Output profile, audio preset, zone

### Stats
Expand Down
3 changes: 3 additions & 0 deletions crates/reverb-core/examples/play_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
//! (direct ALSA cards, rate switching) can be exercised without the app:
//! `REVERB_DEVICE` is a device id from `--devices`, and `REVERB_AUTO_RATE` /
//! `REVERB_EXCLUSIVE` turn on rate matching and exclusive access.
//! `REVERB_LOCKED` locks the output to `REVERB_DEVICE`: give it an id that is
//! not plugged in and nothing plays, rather than the system default.

use std::time::{Duration, Instant};

Expand Down Expand Up @@ -55,6 +57,7 @@ fn main() {
device,
auto_rate: std::env::var("REVERB_AUTO_RATE").is_ok(),
exclusive: std::env::var("REVERB_EXCLUSIVE").is_ok(),
locked: std::env::var("REVERB_LOCKED").is_ok(),
},
false,
);
Expand Down
196 changes: 179 additions & 17 deletions crates/reverb-core/src/audio/engine.rs

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions crates/reverb-core/src/audio/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ pub enum EngineEvent {
OutputDeviceLost {
device: String,
},
/// The output is locked to a device that is not there (see
/// `OutputSettings::locked`). Nothing is open and playback is paused; the
/// engine keeps the device and opens it again the moment it is back.
/// Sent when the device goes, and again whenever playing is asked for
/// while it is still gone.
LockedDeviceMissing {
device: String,
},
/// The device `LockedDeviceMissing` waited for is open again. Playback
/// stays paused until asked to resume.
LockedDeviceReturned {
device: String,
},
/// The current audio chain, source to output (the signal path).
SignalPath(SignalPathInfo),
/// The output's own volume moved — HQPlayer's, turned there or read on
Expand Down
7 changes: 7 additions & 0 deletions crates/reverb-core/src/audio/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,13 @@ fn find_device(host: &cpal::Host, wanted: &str, exclusive: bool) -> Option<cpal:
Some(devices.swap_remove(index))
}

/// Whether the device a preference names is plugged in. Looks without opening
/// anything, so asking costs no device — not the one named, and not the
/// system default that `open_output` would put in its place.
pub fn device_present(id: &str) -> bool {
find_device(&cpal::default_host(), id, false).is_some()
}

pub fn open_output(
shared: Arc<SharedAudioState>,
consumer: rtrb::Consumer<f32>,
Expand Down
13 changes: 11 additions & 2 deletions src-tauri/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ struct VolumePayload {
#[derive(Clone, Serialize)]
#[serde(rename_all = "camelCase")]
struct DeviceLostPayload {
/// The device id that was given up. Its label is unknowable — the device is
/// gone from the enumeration the label would have come from.
/// The device id that was given up, or is waited for. Its label is
/// unknowable — the device is gone from the enumeration the label would
/// have come from.
device: String,
}

Expand Down Expand Up @@ -372,6 +373,14 @@ fn forward(
}
let _ = app.emit("player:device-lost", DeviceLostPayload { device });
}
// A locked config's device: the engine waits for it, paused, and the
// config stays the active one — nothing to save.
EngineEvent::LockedDeviceMissing { device } => {
let _ = app.emit("player:device-missing", DeviceLostPayload { device });
}
EngineEvent::LockedDeviceReturned { device } => {
let _ = app.emit("player:device-returned", DeviceLostPayload { device });
}
EngineEvent::SignalPath(info) => {
let _ = app.emit("player:signal-path", info);
}
Expand Down
50 changes: 47 additions & 3 deletions src-tauri/src/persistence/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ pub struct DeviceConfig {
pub match_source_rate: bool,
/// Take the output device exclusively (macOS hog mode / WASAPI exclusive).
pub exclusive_output: bool,
/// Play on `device` or nowhere: when it is not plugged in, pause and wait
/// for it, with this config staying the active one, instead of moving to
/// the system default. Means nothing without a device.
pub lock_device: bool,
/// Play through this HQPlayer instead of a device here. When set, the
/// three fields above mean nothing: HQPlayer has its own output setup.
/// fields above mean nothing: HQPlayer has its own output setup.
pub hqplayer: Option<HqPlayerEndpoint>,
}

Expand Down Expand Up @@ -214,6 +218,7 @@ impl Preferences {
device: config.device.clone(),
auto_rate: config.match_source_rate,
exclusive: config.exclusive_output,
locked: config.lock_device,
},
)
}
Expand Down Expand Up @@ -296,6 +301,7 @@ impl Settings {
device: audio_device,
match_source_rate,
exclusive_output,
lock_device: false,
hqplayer: None,
});
self.prefs.active_device_config = Some(id);
Expand Down Expand Up @@ -537,6 +543,7 @@ mod tests {
device: Some("coreaudio:BTR17-uid".into()),
auto_rate: true,
exclusive: true,
locked: false,
},
"playback starts where it left off"
);
Expand Down Expand Up @@ -564,7 +571,7 @@ mod tests {
assert_eq!(s.prefs.device_configs[0].name, "System default");
assert_eq!(
s.prefs.output(),
OutputSettings { device: None, auto_rate: true, exclusive: false }
OutputSettings { device: None, auto_rate: true, exclusive: false, locked: false }
);
}

Expand Down Expand Up @@ -600,6 +607,7 @@ mod tests {
device: Some("coreaudio:dac".into()),
match_source_rate: true,
exclusive_output: false,
lock_device: false,
hqplayer: None,
},
DeviceConfig {
Expand All @@ -608,6 +616,7 @@ mod tests {
device: None,
match_source_rate: false,
exclusive_output: true,
lock_device: false,
hqplayer: None,
},
],
Expand All @@ -616,7 +625,10 @@ mod tests {
assert_eq!(prefs.output(), OutputSettings::default(), "none active: system default");

prefs.active_device_config = Some("speakers".into());
assert_eq!(prefs.output(), OutputSettings { device: None, auto_rate: false, exclusive: true });
assert_eq!(
prefs.output(),
OutputSettings { device: None, auto_rate: false, exclusive: true, locked: false }
);

prefs.active_device_config = Some("desk".into());
assert_eq!(prefs.output().device.as_deref(), Some("coreaudio:dac"));
Expand Down Expand Up @@ -653,6 +665,7 @@ mod tests {
device: Some("coreaudio:dac".into()),
auto_rate: false,
exclusive: true,
locked: false,
})
);

Expand All @@ -662,6 +675,37 @@ mod tests {
assert_eq!(back["deviceConfigs"][0]["hqplayer"], serde_json::Value::Null);
}

#[test]
fn a_locked_config_locks_the_output_to_its_device() {
let raw = r#"{
"deviceConfigs": [
{"id": "desk", "name": "Desk DAC", "device": "coreaudio:dac", "lockDevice": true},
{"id": "old", "name": "Speakers", "device": "coreaudio:spk"}
],
"activeDeviceConfig": "desk"
}"#;
let mut prefs: Preferences = serde_json::from_str(raw).unwrap();
assert_eq!(
prefs.output(),
OutputSettings {
device: Some("coreaudio:dac".into()),
auto_rate: false,
exclusive: false,
locked: true,
}
);

// A config from before locking is not locked.
prefs.active_device_config = Some("old".into());
assert!(!prefs.device_configs[1].lock_device);
assert!(!prefs.output().locked);

// And the field round-trips under its name.
let back = serde_json::to_value(&prefs).unwrap();
assert_eq!(back["deviceConfigs"][0]["lockDevice"], serde_json::json!(true));
assert_eq!(back["deviceConfigs"][1]["lockDevice"], serde_json::json!(false));
}

#[test]
fn old_settings_files_parse_with_pref_defaults() {
// A settings.json written before the preferences existed.
Expand Down
2 changes: 2 additions & 0 deletions src/lib/deviceConfigs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const desk: DeviceConfig = {
device: "coreaudio:dac",
matchSourceRate: true,
exclusiveOutput: true,
lockDevice: false,
hqplayer: null,
};
const speakers: DeviceConfig = {
Expand All @@ -26,6 +27,7 @@ const speakers: DeviceConfig = {
device: null,
matchSourceRate: false,
exclusiveOutput: false,
lockDevice: false,
hqplayer: null,
};
const prefs = { deviceConfigs: [desk, speakers], activeDeviceConfig: "desk" };
Expand Down
8 changes: 8 additions & 0 deletions src/lib/i18n/messages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ export const de: Messages = {
"{n, plural, one {Bibliotheksscan abgeschlossen — # Eintrag} other {Bibliotheksscan abgeschlossen — # Einträge}}",
"toast.scanFailed": "Scan fehlgeschlagen",
"toast.outputDeviceLost": "Ausgabegerät getrennt — zurück auf die Systemvorgabe",
"toast.outputDeviceMissing": "Ausgabegerät nicht verbunden — die Wiedergabe pausiert, bis es wieder da ist",
"toast.outputDeviceReturned": "Ausgabegerät wieder verbunden",
"toast.connected": "{service} verbunden",
"toast.imported":
"{n, plural, one {# neuer Scrobble von {service} importiert} other {# neue Scrobbles von {service} importiert}}",
Expand Down Expand Up @@ -471,6 +473,7 @@ export const de: Messages = {
"settings.configShared": "Geteilt",
"settings.configExclusive": "Exklusiv",
"settings.configMatchRate": "Übernimmt die Abtastrate der Quelle",
"settings.configLocked": "Gebunden",
"settings.deviceNotConnected": "Gerät nicht verbunden",
"settings.savedDeviceMissing": "Gespeichertes Gerät (nicht verbunden)",
"settings.outputDevice": "Ausgabegerät",
Expand All @@ -494,6 +497,11 @@ export const de: Messages = {
"Keine andere App kann über das Gerät abspielen, solange Reverb es hält — Hog Mode unter macOS, WASAPI-Exklusivmodus unter Windows. Unter Linux oben ein (direkt)-Ausgabegerät wählen; es wird dann strikt angesprochen, ohne ALSA-Umwandlung.",
"settings.exclusiveUnavailable":
"Benötigt ein direktes Ausgabegerät — über einen Soundserver gibt es keine Karte zu belegen. Oben eines auswählen.",
"settings.lockDevice": "An dieses Gerät binden",
"settings.lockDeviceHint":
"Wird das Gerät getrennt oder ausgeschaltet, pausiert die Wiedergabe und wartet darauf, statt auf die Systemvorgabe zu wechseln. Diese Konfiguration bleibt ausgewählt und ist wieder bereit, sobald das Gerät zurück ist.",
"settings.lockDeviceUnavailable":
"Oben ein Ausgabegerät wählen, an das gebunden werden soll — die Systemvorgabe ist kein festes Gerät.",
"settings.playsOn": "Spielt auf",
"settings.playsOnThisComputer": "Diesem Computer",
"settings.configHqplayer": "HQPlayer auf {address}",
Expand Down
8 changes: 8 additions & 0 deletions src/lib/i18n/messages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ export const en = {
"{n, plural, one {Library scan finished — # entry} other {Library scan finished — # entries}}",
"toast.scanFailed": "Scan failed",
"toast.outputDeviceLost": "Output device disconnected — switched to the system default",
"toast.outputDeviceMissing": "Output device not connected — playback is paused until it is back",
"toast.outputDeviceReturned": "Output device reconnected",
"toast.connected": "{service} connected",
"toast.imported":
"{n, plural, one {Imported # new scrobble from {service}} other {Imported # new scrobbles from {service}}}",
Expand Down Expand Up @@ -496,6 +498,7 @@ export const en = {
"settings.configShared": "Shared",
"settings.configExclusive": "Exclusive",
"settings.configMatchRate": "Matches source rate",
"settings.configLocked": "Locked",
"settings.deviceNotConnected": "Device not connected",
"settings.savedDeviceMissing": "Saved device (not connected)",
"settings.outputDevice": "Output device",
Expand All @@ -519,6 +522,11 @@ export const en = {
"No other app can play through the device while Reverb holds it — hog mode on macOS, WASAPI exclusive mode on Windows. On Linux, pick a (direct) output device above; this then addresses it strictly, with no ALSA conversion.",
"settings.exclusiveUnavailable":
"Needs a direct output device — a sound-server route has no card to claim. Pick one above.",
"settings.lockDevice": "Lock to this device",
"settings.lockDeviceHint":
"If the device is unplugged or switched off, playback pauses and waits for it instead of moving to the system default. This config stays selected, ready again once the device is back.",
"settings.lockDeviceUnavailable":
"Pick an output device above to lock to — the system default is not one fixed device.",
"settings.playsOn": "Plays on",
"settings.playsOnThisComputer": "This computer",
"settings.configHqplayer": "HQPlayer at {address}",
Expand Down
8 changes: 8 additions & 0 deletions src/lib/i18n/messages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ export const es: Messages = {
"{n, plural, one {Análisis terminado — # entrada} other {Análisis terminado — # entradas}}",
"toast.scanFailed": "Error en el análisis",
"toast.outputDeviceLost": "Dispositivo de salida desconectado: se ha vuelto al predeterminado del sistema",
"toast.outputDeviceMissing": "Dispositivo de salida no conectado: la reproducción queda en pausa hasta que vuelva",
"toast.outputDeviceReturned": "Dispositivo de salida reconectado",
"toast.connected": "{service} conectado",
"toast.imported":
"{n, plural, one {# scrobble nuevo importado de {service}} other {# scrobbles nuevos importados de {service}}}",
Expand Down Expand Up @@ -471,6 +473,7 @@ export const es: Messages = {
"settings.configShared": "Compartido",
"settings.configExclusive": "Exclusivo",
"settings.configMatchRate": "Sigue la frecuencia de la fuente",
"settings.configLocked": "Fijado",
"settings.deviceNotConnected": "Dispositivo no conectado",
"settings.savedDeviceMissing": "Dispositivo guardado (no conectado)",
"settings.outputDevice": "Dispositivo de salida",
Expand All @@ -494,6 +497,11 @@ export const es: Messages = {
"Ninguna otra aplicación puede reproducir a través del dispositivo mientras Reverb lo retiene: hog mode en macOS, modo exclusivo de WASAPI en Windows. En Linux, elige arriba un dispositivo (directo); entonces se direcciona de forma estricta, sin conversión de ALSA.",
"settings.exclusiveUnavailable":
"Requiere un dispositivo de salida directo: una ruta a través del servidor de sonido no tiene tarjeta que reclamar. Elige uno arriba.",
"settings.lockDevice": "Fijar a este dispositivo",
"settings.lockDeviceHint":
"Si el dispositivo se desconecta o se apaga, la reproducción se pausa y lo espera en lugar de pasar al predeterminado del sistema. Esta configuración sigue seleccionada y vuelve a estar lista en cuanto vuelva el dispositivo.",
"settings.lockDeviceUnavailable":
"Elige arriba un dispositivo de salida al que fijarla: el predeterminado del sistema no es un dispositivo concreto.",
"settings.playsOn": "Suena en",
"settings.playsOnThisComputer": "Este ordenador",
"settings.configHqplayer": "HQPlayer en {address}",
Expand Down
8 changes: 8 additions & 0 deletions src/lib/i18n/messages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ export const fr: Messages = {
"{n, plural, one {Analyse terminée — # entrée} other {Analyse terminée — # entrées}}",
"toast.scanFailed": "Échec de l'analyse",
"toast.outputDeviceLost": "Périphérique de sortie déconnecté — retour à la valeur par défaut du système",
"toast.outputDeviceMissing": "Périphérique de sortie non connecté — lecture en pause jusqu’à son retour",
"toast.outputDeviceReturned": "Périphérique de sortie reconnecté",
"toast.connected": "{service} connecté",
"toast.imported":
"{n, plural, one {# nouveau scrobble importé depuis {service}} other {# nouveaux scrobbles importés depuis {service}}}",
Expand Down Expand Up @@ -472,6 +474,7 @@ export const fr: Messages = {
"settings.configShared": "Partagé",
"settings.configExclusive": "Exclusif",
"settings.configMatchRate": "Suit la fréquence de la source",
"settings.configLocked": "Verrouillé",
"settings.deviceNotConnected": "Périphérique non connecté",
"settings.savedDeviceMissing": "Périphérique enregistré (non connecté)",
"settings.outputDevice": "Périphérique de sortie",
Expand All @@ -495,6 +498,11 @@ export const fr: Messages = {
"Aucune autre application ne peut jouer sur le périphérique tant que Reverb le détient — hog mode sur macOS, mode exclusif WASAPI sur Windows. Sous Linux, choisissez un périphérique (direct) ci-dessus ; il est alors adressé strictement, sans conversion ALSA.",
"settings.exclusiveUnavailable":
"Nécessite un périphérique de sortie direct — une route via le serveur audio n’a aucune carte à réserver. Choisissez-en un ci-dessus.",
"settings.lockDevice": "Verrouiller sur ce périphérique",
"settings.lockDeviceHint":
"Si le périphérique est débranché ou éteint, la lecture se met en pause et l’attend au lieu de passer à la valeur par défaut du système. Cette configuration reste sélectionnée, prête dès que le périphérique revient.",
"settings.lockDeviceUnavailable":
"Choisissez ci-dessus un périphérique de sortie sur lequel verrouiller — la valeur par défaut du système n’est pas un périphérique fixe.",
"settings.playsOn": "Joue sur",
"settings.playsOnThisComputer": "Cet ordinateur",
"settings.configHqplayer": "HQPlayer sur {address}",
Expand Down
7 changes: 7 additions & 0 deletions src/lib/ipc/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ export interface EventMap {
"player:format": { sampleRate: number };
/** The configured output device vanished; the backend is on the system default. */
"player:device-lost": { device: string };
/**
* The active config is locked to this device and it is not there: playback
* is paused, waiting for it. Sent again when playing is asked for meanwhile.
*/
"player:device-missing": { device: string };
/** The device `player:device-missing` waited for is back; playback stays paused. */
"player:device-returned": { device: string };
/** HQPlayer's own volume moved (or was read on connecting); 0–1, like the slider. */
"player:volume": { volume: number };
"eq:state": import("../subsonic/types").EqState;
Expand Down
Loading
Loading