Files
qbz/crates/qbz-models/src/playback.rs
T
vicrodh 3fe06195c6 feat(queue): expose stop-after marker through QueueState
The marker becomes part of the queue state snapshot the frontend
already consumes via syncQueueState(). Single source of truth — no
parallel event channel, no separate store on the frontend.

Refs #356.

cc
2026-04-28 13:23:38 -06:00

137 lines
3.8 KiB
Rust

//! Playback-related types for QBZ
//!
//! This module contains types related to audio playback:
//! - Queue track representation
//! - Repeat mode
//! - Queue state snapshots
//! - Playback state
use serde::{Deserialize, Serialize};
// ============ Queue Types ============
/// Track info stored in the queue
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QueueTrack {
pub id: u64,
pub title: String,
/// Subtitle/edition info from Qobuz (e.g. "Player's Ball Mix") that
/// the frontend renders parenthesized after the title (issue #360).
#[serde(default)]
pub version: Option<String>,
pub artist: String,
pub album: String,
pub duration_secs: u64,
pub artwork_url: Option<String>,
#[serde(default)]
pub hires: bool,
pub bit_depth: Option<u32>,
pub sample_rate: Option<f64>,
/// Whether this is a local library track (not from streaming service)
#[serde(default)]
pub is_local: bool,
/// Album ID for navigation
pub album_id: Option<String>,
/// Artist ID for navigation
pub artist_id: Option<u64>,
/// Whether the track is streamable (false = removed/unavailable)
#[serde(default = "default_streamable")]
pub streamable: bool,
/// Source identifier (e.g., "qobuz", "local", "plex")
#[serde(default)]
pub source: Option<String>,
/// Parental advisory / explicit content
#[serde(default)]
pub parental_warning: bool,
/// Opaque identifier of the Mixtape/Collection item that produced this track,
/// used by v2_skip_to_next_item / v2_skip_to_previous_item to detect boundaries.
/// For non-Mixtape enqueue paths, set to the track's album_id so boundary
/// detection still works for "play album" flows. None is a safe fallback
/// (the skip commands fall back to album_id when this is absent).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub source_item_id_hint: Option<String>,
}
fn default_streamable() -> bool {
true
}
/// Repeat mode options
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum RepeatMode {
Off,
All,
One,
}
impl Default for RepeatMode {
fn default() -> Self {
Self::Off
}
}
/// Queue state snapshot for frontend
#[derive(Debug, Clone, Serialize)]
pub struct QueueState {
pub current_track: Option<QueueTrack>,
pub current_index: Option<usize>,
pub upcoming: Vec<QueueTrack>,
pub history: Vec<QueueTrack>,
pub shuffle: bool,
pub repeat: RepeatMode,
pub total_tracks: usize,
pub stop_after_track_id: Option<u64>,
}
// ============ Playback State ============
/// Current playback state
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum PlaybackState {
/// No track loaded
Stopped,
/// Track loaded and playing
Playing,
/// Track loaded but paused
Paused,
/// Loading/buffering track
Loading,
}
impl Default for PlaybackState {
fn default() -> Self {
Self::Stopped
}
}
/// Detailed playback status with position and duration
#[derive(Debug, Clone, Serialize)]
pub struct PlaybackStatus {
pub state: PlaybackState,
pub track_id: Option<u64>,
pub position_secs: u64,
pub duration_secs: u64,
pub volume: f32,
/// Sample rate of currently playing track (Hz)
pub sample_rate: Option<u32>,
/// Bit depth of currently playing track
pub bit_depth: Option<u32>,
}
impl Default for PlaybackStatus {
fn default() -> Self {
Self {
state: PlaybackState::Stopped,
track_id: None,
position_secs: 0,
duration_secs: 0,
volume: 1.0,
sample_rate: None,
bit_depth: None,
}
}
}
// Note: Audio backend types (AudioBackendType, AudioDevice, etc.) are defined
// in qbz-audio crate to keep the audio module self-contained and immutable.