Skip to content

fix starting queue from nth occurrence of a track in playlist starts queue from 1st occurrence, where n > 1 - #1761

Open
HeroBrine1st wants to merge 3 commits into
finamp-app:redesignfrom
HeroBrine1st:fix/multi-instance-tracks
Open

HeroBrine1st wants to merge 3 commits into
finamp-app:redesignfrom
HeroBrine1st:fix/multi-instance-tracks

Conversation

@HeroBrine1st

@HeroBrine1st HeroBrine1st commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Changes

TracksSliverList searches first instance of track in prepared queue, even if user taps later instances, then starts queue there. This means that for a playlist of:

  1. Track A
  2. Track B
  3. Track C
  4. Track B
  5. Track D

Tapping on item 4 starts queue from item 2, which is not correct.

This PR fixes that by assuming duplicates are only possible in this branch since the other branch is guarded against playlists:

else if (!isLoading)
TracksSliverList(
childrenForList: displayChildren,
childrenForQueue: queueChildren,
parent: widget.parent,
onRemoveFromList: onDelete,
adaptiveAdditionalInfoSortBy: (parentIsPlaylist) ? sortSetting.sortBy : null,
forceAlbumArtists: (parentIsPlaylist && sortSetting.sortBy == SortBy.albumArtist),
)

Then, due to the fact queueChildren is a sparse sublist of displayChildren, it's possible to count duplicates in displayChildren preceding tapped item; then, assuming tracks with the same id are either all playable or not (i.e. for all tracks it is either playable or not, see law of excluded middle :P), skipping the same number of duplicates in queueChildren means taking a track at exactly the same position. When it's zero (no duplicates, e.g. an album), it's the same behavior, and when current track is not playable it falls back to -1 as a workaround to the fact it is calculated eagerly even for unplayable tracks.

There is another approach: pass concatenated list of previous queueForLists (which would still be displayChildren for the branch mentioned above and accumulated list for preceding album with discs branch) to be used to calculate dupesBefore. It's only better if albums can have duplicates, too, which isn't possible in Jellyfin I hope.

The only problem with all of this elegance is the fact flutter let me down and doesn't build Finamp due to stdlib problems, and I can't update it at the moment. This was planned to be 20-minute adventure which went wrong for more than 1 hour so idk. I hope CI creates android artifact which I can test myself later.

Todo before merging

  • Test it
  • .where(...).length can possibly be replaced with some kind of count(...) but I didn't find any
  • (Possible follow-up) reduce O(n^2) to O(n) by delaying index calculation into a lambda since it's only required on tap; quadratic complexity is not introduced by this PR

dart format . let me down too. What a day. It changes nothing on my system.

Flake lock file updates:

• Updated input 'fenix':
    'github:nix-community/fenix/a1b770adbc3f6c27485d03b90462ec414d4e1ce5?narHash=sha256-kIRggXyT8RzijtfvyRIzj%2BzIDWM2fnCp8t0X4BkkTVc%3D' (2026-03-14)
  → 'github:nix-community/fenix/9efa138447c5773995d98d9aafa9eba4982aceab?narHash=sha256-ZkvwEHlSa46BkODMEwHCEh9hlUC2igneJ%2BnoEUn9ww4%3D' (2026-09-08)
• Updated input 'fenix/rust-analyzer-src':
    'github:rust-lang/rust-analyzer/6254616e97f358e67b70dfc0463687f5f7911c1a?narHash=sha256-tj3piRd9RnnP36HwHmQD4O4XZeowsH/rvMeyp9Pmot0%3D' (2026-03-12)
  → 'github:rust-lang/rust-analyzer/48d839420745124e85140234ce783ccd90dab24e?narHash=sha256-FROpcpM2ELawfxhW8cWuz8m3dp/0EFAFCiK%2BAbNw95w%3D' (2026-09-07)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/fe416aaedd397cacb33a610b33d60ff2b431b127?narHash=sha256-b/GV2ysM8mKHhinse2wz%2BuP37epUrSE%2BsAKXy/xvBY4%3D' (2026-03-12)
  → 'github:NixOS/nixpkgs/dc5d91f840324650bac8c379428c7037a416959a?narHash=sha256-VaWGJ6%2BcIYN2erfSecbRV%2B4ljI185Ty2wUrXyvQbgOw%3D' (2026-09-07)
@HeroBrine1st
HeroBrine1st force-pushed the fix/multi-instance-tracks branch from e8302a2 to bc1c3d2 Compare September 8, 2026 18:25
@HeroBrine1st HeroBrine1st changed the title (not tested, flutter problems) fix starting queue from nth occurrence of a track in playlist starts queue from 1st occurrence, where n > 1 fix starting queue from nth occurrence of a track in playlist starts queue from 1st occurrence, where n > 1 Sep 8, 2026
@HeroBrine1st

Copy link
Copy Markdown
Contributor Author

okay my CI got new flutter successfully so I tested it on n=2. It now correctly picks second occurence of track when I pick it, and first one is unchanged. I tested multi-disc album too, no issues.

@HeroBrine1st
HeroBrine1st marked this pull request as ready for review September 8, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants