Rejigger shuffle list generator for albums mode, to insert the current album at the start of the list, starting from the current track

CQTexperiment
Christopher Snowhill 2019-10-24 17:18:51 -07:00
parent 55564f2991
commit 2ad9584fb2
1 changed files with 51 additions and 17 deletions

View File

@ -809,23 +809,57 @@
if (currentEntry && currentEntry.index >= 0) if (currentEntry && currentEntry.index >= 0)
{ {
[shuffleList insertObject:currentEntry atIndex:0]; if ([self shuffle] == ShuffleAlbums) {
[currentEntry setShuffleIndex:0]; NSString * currentAlbum = currentEntry.album;
if (!currentAlbum)
//Need to rejigger so the current entry is at the start now... currentAlbum = @"";
int i;
BOOL found = NO; NSArray * wholeAlbum = [self filterPlaylistOnAlbum:currentAlbum];
for (i = 1; i < [shuffleList count] && !found; i++)
{ // First prune the shuffle list of the currently playing album
if ([shuffleList objectAtIndex:i] == currentEntry) int i, j;
{ for (i = 0; i < [shuffleList count];) {
found = YES; if ([wholeAlbum containsObject:[shuffleList objectAtIndex:i]]) {
[shuffleList removeObjectAtIndex:i]; [shuffleList removeObjectAtIndex:i];
} }
else { else {
[[shuffleList objectAtIndex:i] setShuffleIndex: i]; ++i;
} }
} }
// Then insert the playing album at the start, beginning with
// the current track
BOOL found = NO;
for (i = 0, j = 0; i < [wholeAlbum count]; i++) {
if (!found && [wholeAlbum objectAtIndex:i] == currentEntry) {
found = YES;
}
if (found) {
[shuffleList insertObject:[wholeAlbum objectAtIndex:i] atIndex:j];
++j;
}
}
}
else {
[shuffleList insertObject:currentEntry atIndex:0];
[currentEntry setShuffleIndex:0];
//Need to rejigger so the current entry is at the start now...
int i;
BOOL found = NO;
for (i = 1; i < [shuffleList count] && !found; i++)
{
if ([shuffleList objectAtIndex:i] == currentEntry)
{
found = YES;
[shuffleList removeObjectAtIndex:i];
}
else {
[[shuffleList objectAtIndex:i] setShuffleIndex: i];
}
}
}
} }
} }