From 76594c10624a22b9ebb05df32cca328f0334e33b Mon Sep 17 00:00:00 2001 From: vspader Date: Tue, 19 Feb 2008 23:49:51 +0000 Subject: [PATCH] Cleaned up repeat one/all code. --- Application/PlaybackController.m | 16 +----------- Playlist/PlaylistController.m | 42 +++++++++++--------------------- 2 files changed, 15 insertions(+), 43 deletions(-) diff --git a/Application/PlaybackController.m b/Application/PlaybackController.m index 4c96849d4..9270aa69a 100644 --- a/Application/PlaybackController.m +++ b/Application/PlaybackController.m @@ -485,21 +485,7 @@ - (void)audioPlayer:(AudioPlayer *)player requestNextStream:(id)userInfo { PlaylistEntry *curEntry = (PlaylistEntry *)userInfo; - PlaylistEntry *pe; - - if ([playlistController repeat] == RepeatOne) - pe = curEntry; - - else if ([playlistController repeat] == RepeatAll) - { - if ([[curEntry index] intValue] == [[playlistController arrangedObjects] count] - 1) - if ([playlistController shuffle] == YES) - pe = [playlistController shuffledEntryAtIndex:0]; - else - pe = [playlistController entryAtIndex:0]; - } - else - pe = [playlistController getNextEntry:curEntry]; + PlaylistEntry *pe = [playlistController getNextEntry:curEntry]; [player setNextStream:[pe url] withUserInfo:pe]; } diff --git a/Playlist/PlaylistController.m b/Playlist/PlaylistController.m index 7493f765b..e8fe5a733 100644 --- a/Playlist/PlaylistController.m +++ b/Playlist/PlaylistController.m @@ -328,14 +328,14 @@ { if (i < 0) { - if (repeat == YES) + if (repeat == RepeatAll) i += [[self arrangedObjects] count]; else return nil; } else if (i >= [[self arrangedObjects] count]) { - if (repeat == YES) + if (repeat == RepeatAll) i -= [[self arrangedObjects] count]; else return nil; @@ -348,7 +348,7 @@ { while (i < 0) { - if (repeat == YES) + if (repeat == RepeatAll) { [self addShuffledListToFront]; //change i appropriately @@ -361,7 +361,7 @@ } while (i >= [shuffleList count]) { - if (repeat == YES) + if (repeat == RepeatAll) { [self addShuffledListToBack]; } @@ -376,6 +376,10 @@ - (PlaylistEntry *)getNextEntry:(PlaylistEntry *)pe { + if (repeat == RepeatOne) { + return pe; + } + if (shuffle == YES) { return [self shuffledEntryAtIndex:([[pe shuffleIndex] intValue] + 1)]; @@ -398,6 +402,10 @@ - (PlaylistEntry *)getPrevEntry:(PlaylistEntry *)pe { + if (repeat == RepeatOne) { + return pe; + } + if (shuffle == YES) { return [self shuffledEntryAtIndex:([[pe shuffleIndex] intValue] - 1)]; @@ -422,23 +430,10 @@ { PlaylistEntry *pe; - if (repeat == RepeatOne) - return NO; - pe = [self getNextEntry:[self currentEntry]]; - /* needs to reshuffle playlist for added greatness */ if (pe == nil) - { - // we are at end of shuffle list, and repeat all is requested - if (repeat == RepeatAll) - if (shuffle == YES) - pe = [self shuffledEntryAtIndex:0]; - else - pe = [self entryAtIndex:0]; - else - return NO; - } + return NO; [self setCurrentEntry:pe]; @@ -449,18 +444,9 @@ { PlaylistEntry *pe; - if (repeat == RepeatOne) - return NO; - pe = [self getPrevEntry:[self currentEntry]]; if (pe == nil) - { - // we are at end of shuffle list, and repeat all is requested - if ((shuffle = YES) && (repeat == RepeatAll)) - pe = [self shuffledEntryAtIndex:[shuffleList count]-1]; - else - return NO; - } + return NO; [self setCurrentEntry:pe];