hinto-janai / festival

Music player
https://festival.pm
MIT License
270 stars 3 forks source link

Playlists #58

Closed hinto-janai closed 1 year ago

hinto-janai commented 1 year ago

What

Branch implementing playlists.

Closes https://github.com/hinto-janai/festival/issues/4.

Definition

//                   playlist-name   playlist   exists-or-not 
//                        |             |           |
//                        v             v           v
struct Playlists(BTreeMap<String, VecDeque<PlaylistEntry>>);

where PlaylistEntry is an enum:

enum PlaylistEntry {
    // This is a known song in the current `Collection`
    Key(SongKey),

    // This song is missing, this was the
    // artist name, album title, song title.
    Missing((Arc<str>, Arc<str>, Arc<str>)),
}

Lifetime

Playlists has no lifetime relation to Collection.

  1. Each SongKey is shukusai::validate'd on startup
  2. After Collection resets, missing keys are marked as such, and saved indefinitely
  3. After Collection resets, if missing objects are found, they are recovered

Missing

A Collection across resets may not be the same, and even given the same inputs/files, the indices are not stable.

| Collection 1                  |          | Collection 2                  |
|-------------------------------|          |-------------------------------|
| 0 | artist_1, album_1, song_1 | -------> | 0 | artist_1, album_1, song_1 |
| 1 | artist_1, album_2, song_2 |          | 1 | artist_1, album_2, song_2 |
| 2 | artist_2, album_3, song_3 |    ----> | 2 | artist_3, album_4, song_4 |
| 3 | artist_3, album_4, song_4 |   /
| 4 | artist 3, album_4, song_5 | -/

Upon a Collection reset, playlists will:

  1. Store Artist, Album and Song names by Arc<str>
  2. After Collection reset, use the new Map to reconnect those names with the new indices
  3. Mark the names that don't exist anymore as "Missing"
| Playlist (pre-Collection reset) |                | Playlist (post Collection reset) |
|---------------------------------|                |----------------------------------|
| 0 | SongKey(0)                  |                | 0 | SongKey(0)                   |
| 1 | SongKey(1)                  | ~ Collection ~ | 1 | SongKey(1)                   |
| 2 | SongKey(2)                  |     Reset      | ~ | artist_2, album_3, song_3    |
| 3 | SongKey(3)                  |                | 2 | SongKey(2)                   |
| 4 | SongKey(4)                  |                | ~ | artist 3, album_4, song_5    |

Songs that have have non-matching metadata in the current Collection will indefinitely be Missing, and will only recover to Key form after a Collection reset brings songs in that match that metadata.