Some playlistentry cleanup.
parent
b7beb276f2
commit
7109dec4ad
|
@ -110,7 +110,7 @@ escapeForLastFM(NSString *string)
|
||||||
escapeForLastFM([pe title]),
|
escapeForLastFM([pe title]),
|
||||||
escapeForLastFM([pe album]),
|
escapeForLastFM([pe album]),
|
||||||
@"", // TODO: MusicBrainz support
|
@"", // TODO: MusicBrainz support
|
||||||
(int)([[pe totalFrames] longValue]/[[pe sampleRate] floatValue]),
|
(int)(pe.length),
|
||||||
escapeForLastFM([[pe URL] path])
|
escapeForLastFM([[pe URL] path])
|
||||||
]];
|
]];
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,10 +36,10 @@ typedef enum {
|
||||||
|
|
||||||
BOOL shuffle;
|
BOOL shuffle;
|
||||||
RepeatMode repeat;
|
RepeatMode repeat;
|
||||||
|
|
||||||
int selectedRow;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@property(retain) PlaylistEntry *currentEntry;
|
||||||
|
|
||||||
//Private Methods
|
//Private Methods
|
||||||
- (void)updateIndexesFromRow:(int) row;
|
- (void)updateIndexesFromRow:(int) row;
|
||||||
- (void)updateTotalTime;
|
- (void)updateTotalTime;
|
||||||
|
@ -77,9 +77,6 @@ typedef enum {
|
||||||
- (NSString *)totalTimeDisplay;
|
- (NSString *)totalTimeDisplay;
|
||||||
|
|
||||||
//FUN PLAYLIST MANAGEMENT STUFF!
|
//FUN PLAYLIST MANAGEMENT STUFF!
|
||||||
- (id)currentEntry;
|
|
||||||
- (void)setCurrentEntry:(PlaylistEntry *)pe;
|
|
||||||
|
|
||||||
- (BOOL)next;
|
- (BOOL)next;
|
||||||
- (BOOL)prev;
|
- (BOOL)prev;
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
@implementation PlaylistController
|
@implementation PlaylistController
|
||||||
|
|
||||||
|
@synthesize currentEntry;
|
||||||
|
|
||||||
#define SHUFFLE_HISTORY_SIZE 100
|
#define SHUFFLE_HISTORY_SIZE 100
|
||||||
|
|
||||||
+ (void)initialize {
|
+ (void)initialize {
|
||||||
|
@ -177,7 +179,7 @@
|
||||||
ldiv_t hoursAndMinutes;
|
ldiv_t hoursAndMinutes;
|
||||||
|
|
||||||
for (PlaylistEntry *pe in [self arrangedObjects]) {
|
for (PlaylistEntry *pe in [self arrangedObjects]) {
|
||||||
tt += [[pe length] doubleValue];
|
tt += pe.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sec = (int)(tt);
|
int sec = (int)(tt);
|
||||||
|
@ -206,7 +208,7 @@
|
||||||
PlaylistEntry *p;
|
PlaylistEntry *p;
|
||||||
p = [[self arrangedObjects] objectAtIndex:j];
|
p = [[self arrangedObjects] objectAtIndex:j];
|
||||||
|
|
||||||
[p setIndex:[NSNumber numberWithInt:j]];
|
p.index = j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,17 +231,17 @@
|
||||||
- (void)removeObjectsAtArrangedObjectIndexes:(NSIndexSet *)indexes
|
- (void)removeObjectsAtArrangedObjectIndexes:(NSIndexSet *)indexes
|
||||||
{
|
{
|
||||||
NSLog(@"Removing indexes: %@", indexes);
|
NSLog(@"Removing indexes: %@", indexes);
|
||||||
NSLog(@"Current index: %i", [[currentEntry index] intValue]);
|
NSLog(@"Current index: %i", currentEntry.index);
|
||||||
|
|
||||||
if ([[currentEntry index] intValue] >= 0 && [indexes containsIndex:[[currentEntry index] intValue]])
|
if (currentEntry.index >= 0 && [indexes containsIndex:currentEntry.index])
|
||||||
{
|
{
|
||||||
[currentEntry setIndex:[NSNumber numberWithInt:-[[currentEntry index] intValue] - 1]];
|
currentEntry.index = -currentEntry.index - 1;
|
||||||
NSLog(@"Current removed: %i", [[currentEntry index] intValue]);
|
NSLog(@"Current removed: %i", currentEntry.index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([[currentEntry index] intValue] < 0) //Need to update the negative index
|
if (currentEntry.index < 0) //Need to update the negative index
|
||||||
{
|
{
|
||||||
int i = -[[currentEntry index] intValue] - 1;
|
int i = -currentEntry.index - 1;
|
||||||
NSLog(@"I is %i", i);
|
NSLog(@"I is %i", i);
|
||||||
int j;
|
int j;
|
||||||
for (j = i - 1; j >= 0; j--)
|
for (j = i - 1; j >= 0; j--)
|
||||||
|
@ -249,9 +251,8 @@
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[currentEntry setIndex: [NSNumber numberWithInt:-i - 1]];
|
currentEntry.index = -i - 1;
|
||||||
|
|
||||||
NSLog(@"UPDATING INDEX: %@", [currentEntry index]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[super removeObjectsAtArrangedObjectIndexes:indexes];
|
[super removeObjectsAtArrangedObjectIndexes:indexes];
|
||||||
|
@ -392,7 +393,7 @@
|
||||||
|
|
||||||
pe = [queueList objectAtIndex:0];
|
pe = [queueList objectAtIndex:0];
|
||||||
[queueList removeObjectAtIndex:0];
|
[queueList removeObjectAtIndex:0];
|
||||||
[pe setStatus:[NSNumber numberWithInteger:kCogEntryNormal]];
|
pe.status = kCogEntryNormal;
|
||||||
[pe setStatusMessage:nil];
|
[pe setStatusMessage:nil];
|
||||||
[pe setQueuePosition:-1];
|
[pe setQueuePosition:-1];
|
||||||
|
|
||||||
|
@ -409,18 +410,18 @@
|
||||||
|
|
||||||
if (shuffle == YES)
|
if (shuffle == YES)
|
||||||
{
|
{
|
||||||
return [self shuffledEntryAtIndex:([[pe shuffleIndex] intValue] + 1)];
|
return [self shuffledEntryAtIndex:(pe.shuffleIndex + 1)];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
if ([[pe index] intValue] < 0) //Was a current entry, now removed.
|
if (pe.index < 0) //Was a current entry, now removed.
|
||||||
{
|
{
|
||||||
i = -[[pe index] intValue] - 1;
|
i = -pe.index - 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i = [[pe index] intValue] + 1;
|
i = pe.index + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (repeat == RepeatAlbum)
|
if (repeat == RepeatAlbum)
|
||||||
|
@ -457,18 +458,18 @@
|
||||||
|
|
||||||
if (shuffle == YES)
|
if (shuffle == YES)
|
||||||
{
|
{
|
||||||
return [self shuffledEntryAtIndex:([[pe shuffleIndex] intValue] - 1)];
|
return [self shuffledEntryAtIndex:(pe.shuffleIndex - 1)];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
if ([[pe index] intValue] < 0) //Was a current entry, now removed.
|
if (pe.index < 0) //Was a current entry, now removed.
|
||||||
{
|
{
|
||||||
i = -[[pe index] intValue] - 2;
|
i = -pe.index - 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i = [[pe index] intValue] - 1;
|
i = pe.index - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return [self entryAtIndex:i];
|
return [self entryAtIndex:i];
|
||||||
|
@ -512,7 +513,7 @@
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < [shuffleList count]; i++)
|
for (i = 0; i < [shuffleList count]; i++)
|
||||||
{
|
{
|
||||||
[[shuffleList objectAtIndex:i] setShuffleIndex:[NSNumber numberWithInt:i]];
|
[[shuffleList objectAtIndex:i] setShuffleIndex:i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -526,7 +527,7 @@
|
||||||
int i;
|
int i;
|
||||||
for (i = ([shuffleList count] - [newList count]); i < [shuffleList count]; i++)
|
for (i = ([shuffleList count] - [newList count]); i < [shuffleList count]; i++)
|
||||||
{
|
{
|
||||||
[[shuffleList objectAtIndex:i] setShuffleIndex:[NSNumber numberWithInt:i]];
|
[[shuffleList objectAtIndex:i] setShuffleIndex:i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,7 +537,7 @@
|
||||||
|
|
||||||
[self addShuffledListToFront];
|
[self addShuffledListToFront];
|
||||||
|
|
||||||
if (currentEntry && [[currentEntry index] intValue] >= 0)
|
if (currentEntry && currentEntry.index >= 0)
|
||||||
{
|
{
|
||||||
[shuffleList insertObject:currentEntry atIndex:0];
|
[shuffleList insertObject:currentEntry atIndex:0];
|
||||||
[currentEntry setShuffleIndex:0];
|
[currentEntry setShuffleIndex:0];
|
||||||
|
@ -552,26 +553,21 @@
|
||||||
[shuffleList removeObjectAtIndex:i];
|
[shuffleList removeObjectAtIndex:i];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
[[shuffleList objectAtIndex:i] setShuffleIndex:[NSNumber numberWithInt:i]];
|
[[shuffleList objectAtIndex:i] setShuffleIndex: i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)currentEntry
|
|
||||||
{
|
|
||||||
return currentEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setCurrentEntry:(PlaylistEntry *)pe
|
- (void)setCurrentEntry:(PlaylistEntry *)pe
|
||||||
{
|
{
|
||||||
[currentEntry setStatus:[NSNumber numberWithInteger:kCogEntryNormal]];
|
currentEntry.status = kCogEntryNormal;
|
||||||
[currentEntry setStatusMessage:nil];
|
[currentEntry setStatusMessage:nil];
|
||||||
|
|
||||||
[pe setStatus:[NSNumber numberWithInteger:kCogEntryPlaying]];
|
pe.status = kCogEntryPlaying;
|
||||||
[pe setStatusMessage:@"Playing..."];
|
[pe setStatusMessage:@"Playing..."];
|
||||||
|
|
||||||
[tableView scrollRowToVisible:[[pe index] intValue]];
|
[tableView scrollRowToVisible:pe.index];
|
||||||
|
|
||||||
[pe retain];
|
[pe retain];
|
||||||
[currentEntry release];
|
[currentEntry release];
|
||||||
|
@ -649,7 +645,7 @@
|
||||||
{
|
{
|
||||||
for (PlaylistEntry *queueItem in queueList)
|
for (PlaylistEntry *queueItem in queueList)
|
||||||
{
|
{
|
||||||
[queueItem setStatus:[NSNumber numberWithInteger:kCogEntryNormal]];
|
queueItem.status = kCogEntryNormal;
|
||||||
[queueItem setStatusMessage:nil];
|
[queueItem setStatusMessage:nil];
|
||||||
[queueItem setQueuePosition:-1];
|
[queueItem setQueuePosition:-1];
|
||||||
}
|
}
|
||||||
|
@ -662,7 +658,7 @@
|
||||||
{
|
{
|
||||||
for (PlaylistEntry *queueItem in [self selectedObjects])
|
for (PlaylistEntry *queueItem in [self selectedObjects])
|
||||||
{
|
{
|
||||||
[queueItem setStatus: [NSNumber numberWithInteger:kCogEntryQueued]];
|
queueItem.status = kCogEntryQueued;
|
||||||
[queueItem setQueuePosition: [queueList count]+1];
|
[queueItem setQueuePosition: [queueList count]+1];
|
||||||
[queueItem setStatusMessage: [NSString stringWithFormat:@"Queued: %i", queueItem.queuePosition]];
|
[queueItem setStatusMessage: [NSString stringWithFormat:@"Queued: %i", queueItem.queuePosition]];
|
||||||
|
|
||||||
|
@ -678,7 +674,7 @@
|
||||||
if (queueItem.queuePosition < 0)
|
if (queueItem.queuePosition < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
[queueItem setStatus:[NSNumber numberWithInteger:kCogEntryNormal]];
|
queueItem.status = kCogEntryNormal;
|
||||||
[queueItem setStatusMessage:nil];
|
[queueItem setStatusMessage:nil];
|
||||||
[queueList removeObjectAtIndex:queueItem.queuePosition - 1];
|
[queueList removeObjectAtIndex:queueItem.queuePosition - 1];
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,9 @@ typedef enum {
|
||||||
} PlaylistEntryStatus;
|
} PlaylistEntryStatus;
|
||||||
|
|
||||||
@interface PlaylistEntry : NSObject {
|
@interface PlaylistEntry : NSObject {
|
||||||
NSNumber *index;
|
int index;
|
||||||
NSNumber *shuffleIndex;
|
int shuffleIndex;
|
||||||
NSNumber *status;
|
PlaylistEntryStatus status;
|
||||||
NSString *statusMessage;
|
NSString *statusMessage;
|
||||||
int queuePosition;
|
int queuePosition;
|
||||||
|
|
||||||
|
@ -30,15 +30,15 @@ typedef enum {
|
||||||
NSString *title;
|
NSString *title;
|
||||||
NSString *genre;
|
NSString *genre;
|
||||||
NSString *year;
|
NSString *year;
|
||||||
NSNumber *track;
|
int track;
|
||||||
|
|
||||||
NSNumber *totalFrames;
|
long long totalFrames;
|
||||||
NSNumber *bitrate;
|
int bitrate;
|
||||||
NSNumber *channels;
|
int channels;
|
||||||
NSNumber *bitsPerSample;
|
int bitsPerSample;
|
||||||
NSNumber *sampleRate;
|
float sampleRate;
|
||||||
|
|
||||||
NSNumber *seekable;
|
BOOL seekable;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setMetadata: (NSDictionary *)m;
|
- (void)setMetadata: (NSDictionary *)m;
|
||||||
|
@ -47,13 +47,13 @@ typedef enum {
|
||||||
- (void)readPropertiesThread;
|
- (void)readPropertiesThread;
|
||||||
|
|
||||||
@property(readonly) NSString *display;
|
@property(readonly) NSString *display;
|
||||||
@property(readonly) NSNumber *length;
|
@property(readonly) double length;
|
||||||
@property(readonly) NSString *path;
|
@property(readonly) NSString *path;
|
||||||
@property(readonly) NSString *filename;
|
@property(readonly) NSString *filename;
|
||||||
|
|
||||||
@property(retain) NSNumber *index;
|
@property int index;
|
||||||
@property(retain) NSNumber *shuffleIndex;
|
@property int shuffleIndex;
|
||||||
@property(retain) NSNumber *status;
|
@property PlaylistEntryStatus status;
|
||||||
@property(retain) NSString *statusMessage;
|
@property(retain) NSString *statusMessage;
|
||||||
@property int queuePosition;
|
@property int queuePosition;
|
||||||
@property(retain) NSURL *URL;
|
@property(retain) NSURL *URL;
|
||||||
|
@ -63,14 +63,14 @@ typedef enum {
|
||||||
@property(retain) NSString *title;
|
@property(retain) NSString *title;
|
||||||
@property(retain) NSString *genre;
|
@property(retain) NSString *genre;
|
||||||
@property(retain) NSString *year;
|
@property(retain) NSString *year;
|
||||||
@property(retain) NSNumber *track;
|
@property int track;
|
||||||
|
|
||||||
@property(retain) NSNumber *totalFrames;
|
@property long long totalFrames;
|
||||||
@property(retain) NSNumber *bitrate;
|
@property int bitrate;
|
||||||
@property(retain) NSNumber *channels;
|
@property int channels;
|
||||||
@property(retain) NSNumber *bitsPerSample;
|
@property int bitsPerSample;
|
||||||
@property(retain) NSNumber *sampleRate;
|
@property float sampleRate;
|
||||||
|
|
||||||
@property(retain) NSNumber *seekable;
|
@property BOOL seekable;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -44,20 +44,20 @@
|
||||||
|
|
||||||
- (void)setProperties:(NSDictionary *)dict
|
- (void)setProperties:(NSDictionary *)dict
|
||||||
{
|
{
|
||||||
[self setTotalFrames: [dict objectForKey:@"totalFrames" ]];
|
[self setTotalFrames: [[dict objectForKey:@"totalFrames" ] longLongValue]];
|
||||||
[self setBitrate: [dict objectForKey:@"bitrate" ]];
|
[self setBitrate: [[dict objectForKey:@"bitrate" ] intValue]];
|
||||||
[self setChannels: [dict objectForKey:@"channels" ]];
|
[self setChannels: [[dict objectForKey:@"channels" ] intValue]];
|
||||||
[self setBitsPerSample: [dict objectForKey:@"bitsPerSample" ]];
|
[self setBitsPerSample: [[dict objectForKey:@"bitsPerSample" ] intValue]];
|
||||||
[self setSampleRate: [dict objectForKey:@"sampleRate" ]];
|
[self setSampleRate: [[dict objectForKey:@"sampleRate" ] floatValue]];
|
||||||
[self setSeekable: [dict objectForKey:@"seekable" ]];
|
[self setSeekable: [[dict objectForKey:@"seekable" ] boolValue]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)readPropertiesThread
|
- (void)readPropertiesThread
|
||||||
{
|
{
|
||||||
NSDictionary *properties = [AudioPropertiesReader propertiesForURL:self.URL];
|
NSDictionary *properties = [AudioPropertiesReader propertiesForURL:self.URL];
|
||||||
if (!properties) {
|
if (!properties) {
|
||||||
[self setStatus:[NSNumber numberWithInteger:kCogEntryError]];
|
self.status = kCogEntryError;
|
||||||
[self setStatusMessage:@"Failed to read properties!"];
|
self.statusMessage = @"Failed to read properties!";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@
|
||||||
[self setAlbum: [m objectForKey:@"album" ]];
|
[self setAlbum: [m objectForKey:@"album" ]];
|
||||||
[self setGenre: [m objectForKey:@"genre" ]];
|
[self setGenre: [m objectForKey:@"genre" ]];
|
||||||
[self setYear: [m objectForKey:@"year" ]];
|
[self setYear: [m objectForKey:@"year" ]];
|
||||||
[self setTrack: [m objectForKey:@"track" ]];
|
[self setTrack: [[m objectForKey:@"track" ] intValue]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)readMetadataThread
|
- (void)readMetadataThread
|
||||||
|
@ -105,9 +105,9 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSNumber *)length
|
- (double)length
|
||||||
{
|
{
|
||||||
return [NSNumber numberWithDouble:([self.totalFrames longValue] / [self.sampleRate floatValue])];
|
return ((double)self.totalFrames / self.sampleRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)path
|
- (NSString *)path
|
||||||
|
|
|
@ -250,7 +250,7 @@
|
||||||
NSURL *url = [validURLs objectAtIndex:i];
|
NSURL *url = [validURLs objectAtIndex:i];
|
||||||
|
|
||||||
[pe setURL:url];
|
[pe setURL:url];
|
||||||
[pe setIndex:[NSNumber numberWithInt:(index+i)]];
|
pe.index = index+i;
|
||||||
[pe setTitle:[[url path] lastPathComponent]];
|
[pe setTitle:[[url path] lastPathComponent]];
|
||||||
[pe setQueuePosition:-1];
|
[pe setQueuePosition:-1];
|
||||||
[entries addObject:pe];
|
[entries addObject:pe];
|
||||||
|
|
Loading…
Reference in New Issue