feat: cycle the queue through track shuffle, album shuffle and off
North on the now-playing screen, or s anywhere, shuffles what has not played yet. Off goes back to the order the tracks were queued in and carries on after the playing track. Tracks queued while shuffled go to random positions, an album as one block under album shuffle. The player reorders its own list under its lock and keeps a track it already handed to playbin next, so playback stays gapless. Each reorder bumps a queue generation that track and picture events carry, and the app drops an event sent before the last reorder. The saved queue keeps the original order and the mode; older files load unshuffled.
This commit is contained in:
@@ -12,13 +12,21 @@ use anyhow::Result;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::config;
|
||||
use crate::shuffle::Mode;
|
||||
use crate::subsonic::{Client, Song};
|
||||
|
||||
const VERSION: u32 = 1;
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SavedQueue {
|
||||
/// In the order they play.
|
||||
pub songs: Vec<Song>,
|
||||
/// Each song's position in the order it was queued. Empty in files from
|
||||
/// before shuffle, which were saved in that order.
|
||||
#[serde(default)]
|
||||
pub order: Vec<usize>,
|
||||
#[serde(default)]
|
||||
pub shuffle: Mode,
|
||||
pub current: Option<usize>,
|
||||
/// Seconds into the current song.
|
||||
pub position: f64,
|
||||
@@ -121,6 +129,8 @@ mod tests {
|
||||
let mut queues = SavedQueues::default();
|
||||
let a = SavedQueue {
|
||||
songs: vec![song("1"), song("2")],
|
||||
order: vec![1, 0],
|
||||
shuffle: Mode::Tracks,
|
||||
current: Some(1),
|
||||
position: 93.5,
|
||||
};
|
||||
@@ -128,6 +138,7 @@ mod tests {
|
||||
songs: vec![song("9")],
|
||||
current: None,
|
||||
position: 0.0,
|
||||
..SavedQueue::default()
|
||||
};
|
||||
queues.set(&home, a.clone());
|
||||
queues.set(&other, b.clone());
|
||||
@@ -142,6 +153,20 @@ mod tests {
|
||||
let _ = fs::remove_dir_all(path.parent().unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_queue_saved_before_shuffle_loads_unshuffled() {
|
||||
let path = temp("before-shuffle");
|
||||
fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||
let client = Client::new("https://h", "u", Auth::Password("p".into()));
|
||||
let text = r#"{"version": 1, "servers": {"u@https://h": {
|
||||
"songs": [{"id": "1", "title": "One"}], "current": 0, "position": 12.0}}}"#;
|
||||
fs::write(&path, text).unwrap();
|
||||
let q = load(&path).get(&client).cloned().expect("the queue");
|
||||
assert_eq!((q.songs.len(), q.order, q.shuffle), (1, vec![], Mode::Off));
|
||||
assert_eq!(q.songs[0].album_id, None);
|
||||
let _ = fs::remove_dir_all(path.parent().unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unreadable_file_loads_as_empty() {
|
||||
let path = temp("unreadable");
|
||||
|
||||
Reference in New Issue
Block a user