cog/Playlist/PlaylistEntry.m

205 lines
3.4 KiB
Matlab
Raw Normal View History

2005-06-02 18:16:43 +00:00
//
// PlaylistEntry.m
// Cog
//
// Created by Vincent Spader on 3/14/05.
2005-07-02 21:02:06 +00:00
// Copyright 2005 Vincent Spader All rights reserved.
2005-06-02 18:16:43 +00:00
//
#import "PlaylistEntry.h"
@implementation PlaylistEntry
2008-02-20 00:44:40 +00:00
@synthesize index;
@synthesize shuffleIndex;
@synthesize current;
@synthesize removed;
@synthesize stopAfter;
@synthesize queued;
@synthesize queuePosition;
2005-06-02 18:16:43 +00:00
@synthesize error;
@synthesize errorMessage;
2008-02-20 00:44:40 +00:00
@synthesize URL;
2005-06-02 18:16:43 +00:00
2008-02-20 00:44:40 +00:00
@synthesize artist;
@synthesize album;
@synthesize genre;
@synthesize year;
@synthesize track;
2009-03-08 20:04:09 +00:00
@synthesize albumArt;
2005-06-02 18:16:43 +00:00
2008-02-20 00:44:40 +00:00
@synthesize totalFrames;
@synthesize bitrate;
@synthesize channels;
@synthesize bitsPerSample;
@synthesize sampleRate;
2005-06-02 18:16:43 +00:00
@synthesize endian;
2008-02-20 00:44:40 +00:00
@synthesize seekable;
2006-05-12 14:41:02 +00:00
@synthesize metadataLoaded;
2008-02-29 21:54:09 +00:00
// The following read-only keys depend on the values of other properties
+ (NSSet *)keyPathsForValuesAffectingDisplay
{
return [NSSet setWithObjects:@"artist",@"title",nil];
}
+ (NSSet *)keyPathsForValuesAffectingLength
{
return [NSSet setWithObject:@"totalFrames"];
2006-05-12 14:41:02 +00:00
}
2008-02-29 21:54:09 +00:00
+ (NSSet *)keyPathsForValuesAffectingPath
2005-06-02 18:16:43 +00:00
{
2008-02-29 21:54:09 +00:00
return [NSSet setWithObject:@"URL"];
}
+ (NSSet *)keyPathsForValuesAffectingFilename
{
return [NSSet setWithObject:@"URL"];
2006-05-12 19:08:39 +00:00
}
+ (NSSet *)keyPathsForValuesAffectingStatus
2006-05-12 19:08:39 +00:00
{
return [NSSet setWithObjects:@"current",@"queued", @"error", @"stopAfter", nil];
}
+ (NSSet *)keyPathsForValuesAffectingStatusMessage
{
return [NSSet setWithObjects:@"current", @"queued", @"queuePosition", @"error", @"errorMessage", @"stopAfter", nil];
}
- (NSString *)description
{
2008-02-20 00:44:40 +00:00
return [NSString stringWithFormat:@"PlaylistEntry %i:(%@)", self.index, self.URL];
}
- (void)dealloc
{
self.errorMessage = nil;
self.URL = nil;
self.artist = nil;
self.album = nil;
self.title = nil;
self.genre = nil;
self.year = nil;
self.track = nil;
2009-03-08 20:04:09 +00:00
self.albumArt = nil;
self.endian = nil;
[super dealloc];
}
2008-02-29 21:54:09 +00:00
// Get the URL if the title is blank
@synthesize title;
- (NSString *)title
{
if((title == nil || [title isEqualToString:@""]) && self.URL)
2008-02-29 21:54:09 +00:00
{
return [[self.URL path] lastPathComponent];
}
return title;
2008-02-29 21:54:09 +00:00
}
2008-02-29 21:56:01 +00:00
@dynamic display;
- (NSString *)display
{
if ((self.artist == NULL) || ([self.artist isEqualToString:@""]))
return self.title;
else {
return [NSString stringWithFormat:@"%@ - %@", self.artist, self.title];
}
}
@dynamic length;
- (NSNumber *)length
{
return [NSNumber numberWithDouble:((double)self.totalFrames / self.sampleRate)];
2008-02-20 00:44:40 +00:00
}
@dynamic path;
2008-02-20 00:44:40 +00:00
- (NSString *)path
{
return [[self.URL path] stringByAbbreviatingWithTildeInPath];
}
@dynamic filename;
2008-02-20 00:44:40 +00:00
- (NSString *)filename
{
return [[self.URL path] lastPathComponent];
}
@dynamic status;
- (NSString *)status
{
if (self.stopAfter)
{
return @"stopAfter";
}
else if (self.current)
{
return @"playing";
}
else if (self.queued)
{
return @"queued";
}
else if (self.error)
{
return @"error";
}
return nil;
}
@dynamic statusMessage;
- (NSString *)statusMessage
{
if (self.stopAfter)
{
return @"Stopping once finished...";
}
else if (self.current)
{
return @"Playing...";
}
else if (self.queued)
{
return [NSString stringWithFormat:@"Queued: %i", self.queuePosition + 1];
}
else if (self.error)
{
return errorMessage;
}
return nil;
}
- (void)setMetadata:(NSDictionary *)metadata
{
if (metadata == nil)
{
self.error = YES;
self.errorMessage = @"Unable to retrieve metadata.";
}
else
{
[self setValuesForKeysWithDictionary:metadata];
}
metadataLoaded = YES;
}
2005-06-02 18:16:43 +00:00
@end