custom-shuffle-order
Installation
SKILL.md
Custom shuffle order
A media engine keeps items in timeline order and plays them through a shuffle order: a
permutation array shuffled, where shuffled[playPosition] = timelineIndex. The engine asks it for
next/previous and for the first/last entry, and asks it to clone itself whenever the queue changes.
The default implementation shuffles newly inserted items into random positions across the whole remaining order. That is defensible for "shuffle the album" and wrong for everything else: a user who hits "play next" wants the track next, and a queue that grows by appending a continuation page wants that page to stay in one block. Replacing it is a small class:
class BetterShuffleOrder(private val shuffled: IntArray) : ShuffleOrder {
// reverse map: indexInShuffled[timelineIndex] = playPosition
private val indexInShuffled = IntArray(shuffled.size).also {
for (i in shuffled.indices) it[shuffled[i]] = i
}