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"
|
2013-10-04 11:16:09 +00:00
|
|
|
#import "SecondsFormatter.h"
|
2005-06-02 18:16:43 +00:00
|
|
|
|
|
|
|
@implementation PlaylistEntry
|
|
|
|
|
2008-02-20 00:44:40 +00:00
|
|
|
@synthesize index;
|
|
|
|
@synthesize shuffleIndex;
|
2008-03-01 03:29:21 +00:00
|
|
|
|
|
|
|
@synthesize current;
|
|
|
|
@synthesize removed;
|
|
|
|
|
|
|
|
@synthesize stopAfter;
|
|
|
|
|
|
|
|
@synthesize queued;
|
2008-02-22 15:26:46 +00:00
|
|
|
@synthesize queuePosition;
|
2005-06-02 18:16:43 +00:00
|
|
|
|
2008-03-01 03:29:21 +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;
|
2005-06-02 18:16:43 +00:00
|
|
|
|
2008-02-20 00:44:40 +00:00
|
|
|
@synthesize totalFrames;
|
|
|
|
@synthesize bitrate;
|
|
|
|
@synthesize channels;
|
|
|
|
@synthesize bitsPerSample;
|
2013-10-05 21:15:09 +00:00
|
|
|
@synthesize floatingPoint;
|
2013-10-07 18:26:23 +00:00
|
|
|
@synthesize Unsigned;
|
2008-02-20 00:44:40 +00:00
|
|
|
@synthesize sampleRate;
|
2005-06-02 18:16:43 +00:00
|
|
|
|
2013-10-02 09:30:04 +00:00
|
|
|
@synthesize replayGainAlbumGain;
|
|
|
|
@synthesize replayGainAlbumPeak;
|
|
|
|
@synthesize replayGainTrackGain;
|
|
|
|
@synthesize replayGainTrackPeak;
|
|
|
|
@synthesize volume;
|
|
|
|
|
2013-10-04 11:16:09 +00:00
|
|
|
@synthesize currentPosition;
|
|
|
|
|
2008-03-01 03:29:21 +00:00
|
|
|
@synthesize endian;
|
|
|
|
|
2008-02-20 00:44:40 +00:00
|
|
|
@synthesize seekable;
|
2006-05-12 14:41:02 +00:00
|
|
|
|
2009-03-06 04:46:42 +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
|
|
|
}
|
|
|
|
|
2008-03-01 03:29:21 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingStatus
|
2006-05-12 19:08:39 +00:00
|
|
|
{
|
2008-03-01 03:35:27 +00:00
|
|
|
return [NSSet setWithObjects:@"current",@"queued", @"error", @"stopAfter", nil];
|
2008-03-01 03:29:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSSet *)keyPathsForValuesAffectingStatusMessage
|
|
|
|
{
|
2008-03-01 03:35:27 +00:00
|
|
|
return [NSSet setWithObjects:@"current", @"queued", @"queuePosition", @"error", @"errorMessage", @"stopAfter", nil];
|
2008-03-01 03:29:21 +00:00
|
|
|
}
|
|
|
|
|
2013-10-04 11:16:09 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingSpam
|
|
|
|
{
|
|
|
|
return [NSSet setWithObjects:@"artist", @"title", @"album", @"track", @"totalFrames", @"currentPosition", @"bitrate", nil];
|
|
|
|
}
|
|
|
|
|
2013-10-09 20:53:13 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingAlbumArt
|
|
|
|
{
|
|
|
|
return [NSSet setWithObject:@"albumArtInternal"];
|
|
|
|
}
|
|
|
|
|
2006-09-17 18:11:29 +00:00
|
|
|
- (NSString *)description
|
|
|
|
{
|
2008-02-20 00:44:40 +00:00
|
|
|
return [NSString stringWithFormat:@"PlaylistEntry %i:(%@)", self.index, self.URL];
|
|
|
|
}
|
|
|
|
|
2013-10-02 09:30:04 +00:00
|
|
|
- (id)init
|
|
|
|
{
|
|
|
|
if (self = [super init]) {
|
|
|
|
self.replayGainAlbumGain = 0;
|
|
|
|
self.replayGainAlbumPeak = 0;
|
|
|
|
self.replayGainTrackGain = 0;
|
|
|
|
self.replayGainTrackPeak = 0;
|
|
|
|
self.volume = 1;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2008-03-09 00:22:48 +00:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
2008-03-09 02:05:00 +00:00
|
|
|
self.errorMessage = nil;
|
|
|
|
|
|
|
|
self.URL = nil;
|
|
|
|
|
|
|
|
self.artist = nil;
|
|
|
|
self.album = nil;
|
|
|
|
self.title = nil;
|
|
|
|
self.genre = nil;
|
|
|
|
self.year = nil;
|
|
|
|
self.track = nil;
|
2013-10-09 20:53:13 +00:00
|
|
|
self.albumArtInternal = nil;
|
2008-03-09 02:05:00 +00:00
|
|
|
|
|
|
|
self.endian = nil;
|
|
|
|
|
|
|
|
[super dealloc];
|
2008-03-09 00:22:48 +00:00
|
|
|
}
|
|
|
|
|
2008-02-29 21:54:09 +00:00
|
|
|
// Get the URL if the title is blank
|
|
|
|
@synthesize title;
|
|
|
|
- (NSString *)title
|
|
|
|
{
|
2009-01-18 08:00:39 +00:00
|
|
|
if((title == nil || [title isEqualToString:@""]) && self.URL)
|
2008-02-29 21:54:09 +00:00
|
|
|
{
|
|
|
|
return [[self.URL path] lastPathComponent];
|
|
|
|
}
|
2008-03-09 02:05:00 +00:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-04 11:16:09 +00:00
|
|
|
@dynamic spam;
|
|
|
|
- (NSString *)spam
|
|
|
|
{
|
|
|
|
BOOL hasBitrate = (self.bitrate != 0);
|
|
|
|
BOOL hasArtist = (self.artist != nil) && (![self.artist isEqualToString:@""]);
|
|
|
|
BOOL hasAlbum = (self.album != nil) && (![self.album isEqualToString:@""]);
|
|
|
|
BOOL hasTrack = (self.track != 0);
|
|
|
|
BOOL hasLength = (self.totalFrames != 0);
|
|
|
|
BOOL hasCurrentPosition = (self.currentPosition != 0) && (self.current);
|
|
|
|
BOOL hasExtension = NO;
|
|
|
|
BOOL hasTitle = (title != nil) && (![title isEqualToString:@""]);
|
|
|
|
|
|
|
|
NSMutableString * filename = [NSMutableString stringWithString:[self filename]];
|
|
|
|
NSRange dotPosition = [filename rangeOfString:@"." options:NSBackwardsSearch];
|
|
|
|
NSString * extension = nil;
|
|
|
|
|
|
|
|
if (dotPosition.length > 0) {
|
|
|
|
dotPosition.location++;
|
|
|
|
dotPosition.length = [filename length] - dotPosition.location;
|
|
|
|
extension = [filename substringWithRange:dotPosition];
|
|
|
|
dotPosition.location--;
|
|
|
|
dotPosition.length++;
|
|
|
|
[filename deleteCharactersInRange:dotPosition];
|
|
|
|
hasExtension = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableArray * elements = [NSMutableArray array];
|
|
|
|
|
|
|
|
if (hasExtension) {
|
|
|
|
[elements addObject:@"["];
|
|
|
|
[elements addObject:[extension uppercaseString]];
|
|
|
|
if (hasBitrate) {
|
|
|
|
[elements addObject:@"@"];
|
2013-10-05 09:47:25 +00:00
|
|
|
[elements addObject:[NSString stringWithFormat:@"%u", self.bitrate]];
|
2013-10-04 11:16:09 +00:00
|
|
|
[elements addObject:@"kbps"];
|
|
|
|
}
|
|
|
|
[elements addObject:@"] "];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasArtist) {
|
|
|
|
[elements addObject:self.artist];
|
|
|
|
[elements addObject:@" - "];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasAlbum) {
|
|
|
|
[elements addObject:@"["];
|
|
|
|
[elements addObject:self.album];
|
|
|
|
if (hasTrack) {
|
|
|
|
[elements addObject:@" #"];
|
|
|
|
[elements addObject:[NSString stringWithFormat:@"%@", self.track]];
|
|
|
|
}
|
|
|
|
[elements addObject:@"] "];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasTitle) {
|
|
|
|
[elements addObject:title];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
[elements addObject:filename];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasCurrentPosition || hasLength) {
|
|
|
|
SecondsFormatter *secondsFormatter = [[SecondsFormatter alloc] init];
|
|
|
|
[elements addObject:@" ("];
|
|
|
|
if (hasCurrentPosition) {
|
|
|
|
[elements addObject:[secondsFormatter stringForObjectValue:[NSNumber numberWithFloat:currentPosition]]];
|
|
|
|
}
|
|
|
|
if (hasLength) {
|
|
|
|
if (hasCurrentPosition) {
|
|
|
|
[elements addObject:@" / "];
|
|
|
|
}
|
|
|
|
[elements addObject:[secondsFormatter stringForObjectValue:[self length]]];
|
|
|
|
}
|
|
|
|
[elements addObject:@")"];
|
|
|
|
[secondsFormatter release];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [elements componentsJoinedByString:@""];
|
|
|
|
}
|
|
|
|
|
2013-10-09 20:53:13 +00:00
|
|
|
@synthesize albumArtInternal;
|
|
|
|
|
|
|
|
@dynamic albumArt;
|
|
|
|
- (NSImage *)albumArt
|
|
|
|
{
|
|
|
|
if (!albumArtInternal) return nil;
|
|
|
|
|
|
|
|
NSString *imageCacheTag = [NSString stringWithFormat:@"%@-%@-%@-%@", album, artist, genre, year];
|
|
|
|
NSImage *image = [NSImage imageNamed:imageCacheTag];
|
|
|
|
|
|
|
|
if (image == nil)
|
|
|
|
{
|
|
|
|
image = [[[NSImage alloc] initWithData:albumArtInternal] autorelease];
|
|
|
|
[image setName:imageCacheTag];
|
|
|
|
}
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setAlbumArt:(id)data
|
|
|
|
{
|
2013-10-09 23:14:23 +00:00
|
|
|
if ([data isKindOfClass:[NSData class]])
|
2013-10-09 20:53:13 +00:00
|
|
|
{
|
|
|
|
[self setAlbumArtInternal:data];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-29 20:09:59 +00:00
|
|
|
@dynamic length;
|
|
|
|
- (NSNumber *)length
|
2007-11-24 20:16:27 +00:00
|
|
|
{
|
2008-02-29 20:09:59 +00:00
|
|
|
return [NSNumber numberWithDouble:((double)self.totalFrames / self.sampleRate)];
|
2008-02-20 00:44:40 +00:00
|
|
|
}
|
|
|
|
|
2008-02-29 20:09:59 +00:00
|
|
|
@dynamic path;
|
2008-02-20 00:44:40 +00:00
|
|
|
- (NSString *)path
|
|
|
|
{
|
|
|
|
return [[self.URL path] stringByAbbreviatingWithTildeInPath];
|
|
|
|
}
|
|
|
|
|
2008-02-29 20:09:59 +00:00
|
|
|
@dynamic filename;
|
2008-02-20 00:44:40 +00:00
|
|
|
- (NSString *)filename
|
|
|
|
{
|
|
|
|
return [[self.URL path] lastPathComponent];
|
2007-11-24 20:16:27 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 03:29:21 +00:00
|
|
|
@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;
|
|
|
|
}
|
|
|
|
|
2009-03-06 04:46:42 +00:00
|
|
|
- (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
|