2005-06-02 14:16:43 -04:00
|
|
|
//
|
|
|
|
// PlaylistEntry.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 3/14/05.
|
2005-07-02 17:02:06 -04:00
|
|
|
// Copyright 2005 Vincent Spader All rights reserved.
|
2005-06-02 14:16:43 -04:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "PlaylistEntry.h"
|
2007-02-24 17:36:27 -03:00
|
|
|
#import "CogAudio/AudioPropertiesReader.h"
|
|
|
|
#import "CogAudio/AudioMetadataReader.h"
|
2005-06-02 14:16:43 -04:00
|
|
|
|
|
|
|
@implementation PlaylistEntry
|
|
|
|
|
2008-02-19 21:44:40 -03:00
|
|
|
@synthesize index;
|
|
|
|
@synthesize shuffleIndex;
|
|
|
|
@synthesize current;
|
2005-06-02 14:16:43 -04:00
|
|
|
|
2008-02-19 21:44:40 -03:00
|
|
|
@synthesize URL;
|
2005-06-02 14:16:43 -04:00
|
|
|
|
2008-02-19 21:44:40 -03:00
|
|
|
@synthesize artist;
|
|
|
|
@synthesize album;
|
|
|
|
@synthesize title;
|
|
|
|
@synthesize genre;
|
|
|
|
@synthesize year;
|
|
|
|
@synthesize track;
|
2005-06-02 14:16:43 -04:00
|
|
|
|
2008-02-19 21:44:40 -03:00
|
|
|
@synthesize totalFrames;
|
|
|
|
@synthesize bitrate;
|
|
|
|
@synthesize channels;
|
|
|
|
@synthesize bitsPerSample;
|
|
|
|
@synthesize sampleRate;
|
2005-06-02 14:16:43 -04:00
|
|
|
|
2008-02-19 21:44:40 -03:00
|
|
|
@synthesize seekable;
|
2006-05-12 10:41:02 -04:00
|
|
|
|
2008-02-19 21:44:40 -03:00
|
|
|
+ (void)initialize {
|
|
|
|
[self setKeys:[NSArray arrayWithObjects:@"artist",@"title",nil] triggerChangeNotificationsForDependentKey:@"display"];
|
|
|
|
[self setKeys:[NSArray arrayWithObjects:@"totalFrames",nil] triggerChangeNotificationsForDependentKey:@"length"];
|
2008-02-19 22:01:15 -03:00
|
|
|
[self setKeys:[NSArray arrayWithObjects:@"URL",nil] triggerChangeNotificationsForDependentKey:@"path"];
|
|
|
|
[self setKeys:[NSArray arrayWithObjects:@"URL",nil] triggerChangeNotificationsForDependentKey:@"filename"];
|
2006-05-12 10:41:02 -04:00
|
|
|
}
|
|
|
|
|
2007-03-08 22:16:06 -03:00
|
|
|
- (void)setProperties:(NSDictionary *)dict
|
2005-06-02 14:16:43 -04:00
|
|
|
{
|
2008-02-19 21:45:23 -03:00
|
|
|
[self setTotalFrames: [dict objectForKey:@"totalFrames" ]];
|
2007-03-13 22:28:30 -04:00
|
|
|
[self setBitrate: [dict objectForKey:@"bitrate" ]];
|
|
|
|
[self setChannels: [dict objectForKey:@"channels" ]];
|
|
|
|
[self setBitsPerSample: [dict objectForKey:@"bitsPerSample" ]];
|
|
|
|
[self setSampleRate: [dict objectForKey:@"sampleRate" ]];
|
2007-05-27 11:11:30 -04:00
|
|
|
[self setSeekable: [dict objectForKey:@"seekable" ]];
|
2006-05-12 15:08:39 -04:00
|
|
|
}
|
|
|
|
|
2007-03-08 22:16:06 -03:00
|
|
|
- (void)readPropertiesThread
|
2006-05-12 15:08:39 -04:00
|
|
|
{
|
2008-02-19 21:44:40 -03:00
|
|
|
NSDictionary *properties = [AudioPropertiesReader propertiesForURL:self.URL];
|
2006-05-12 15:08:39 -04:00
|
|
|
|
2007-03-08 22:16:06 -03:00
|
|
|
[self performSelectorOnMainThread:@selector(setProperties:) withObject:properties waitUntilDone:YES];
|
2006-05-12 15:08:39 -04:00
|
|
|
}
|
|
|
|
|
2007-03-08 22:16:06 -03:00
|
|
|
- (void)setMetadata: (NSDictionary *)m
|
2005-06-02 14:16:43 -04:00
|
|
|
{
|
2007-02-24 17:36:27 -03:00
|
|
|
NSString *ti = [m objectForKey:@"title"];
|
|
|
|
|
2007-05-23 23:30:43 -04:00
|
|
|
if (ti == nil || [ti isEqualToString:@""]) {
|
2008-02-19 21:44:40 -03:00
|
|
|
[self setTitle:[[self.URL path] lastPathComponent]];
|
2005-06-02 14:16:43 -04:00
|
|
|
}
|
2007-02-24 17:36:27 -03:00
|
|
|
else {
|
2007-03-08 22:16:06 -03:00
|
|
|
[self setTitle:ti];
|
2007-02-24 17:36:27 -03:00
|
|
|
}
|
|
|
|
|
2008-02-19 21:45:23 -03:00
|
|
|
[self setArtist:[m objectForKey:@"artist" ]];
|
|
|
|
[self setAlbum: [m objectForKey:@"album" ]];
|
|
|
|
[self setGenre: [m objectForKey:@"genre" ]];
|
|
|
|
[self setYear: [m objectForKey:@"year" ]];
|
|
|
|
[self setTrack: [m objectForKey:@"track" ]];
|
2006-05-12 15:08:39 -04:00
|
|
|
}
|
|
|
|
|
2007-03-08 22:16:06 -03:00
|
|
|
- (void)readMetadataThread
|
2006-05-12 15:08:39 -04:00
|
|
|
{
|
2008-02-19 21:44:40 -03:00
|
|
|
NSDictionary *metadata = [AudioMetadataReader metadataForURL:self.URL];
|
2008-02-18 13:06:54 -03:00
|
|
|
|
2007-03-08 22:16:06 -03:00
|
|
|
[self performSelectorOnMainThread:@selector(setMetadata:) withObject:metadata waitUntilDone:YES];
|
2007-02-24 17:36:27 -03:00
|
|
|
|
2006-05-12 15:08:39 -04:00
|
|
|
}
|
|
|
|
|
2006-09-17 14:11:29 -04:00
|
|
|
- (NSString *)description
|
|
|
|
{
|
2008-02-19 21:44:40 -03:00
|
|
|
return [NSString stringWithFormat:@"PlaylistEntry %i:(%@)", self.index, self.URL];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)display
|
|
|
|
{
|
|
|
|
if ((self.artist == NULL) || ([self.artist isEqualToString:@""]))
|
|
|
|
return self.title;
|
|
|
|
else {
|
|
|
|
return [NSString stringWithFormat:@"%@ - %@", self.artist, self.title];
|
|
|
|
}
|
2006-09-17 14:11:29 -04:00
|
|
|
}
|
|
|
|
|
2007-11-24 17:16:27 -03:00
|
|
|
- (NSNumber *)length
|
|
|
|
{
|
2008-02-19 21:44:40 -03:00
|
|
|
return [NSNumber numberWithDouble:([self.totalFrames longValue] / [self.sampleRate floatValue])];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)path
|
|
|
|
{
|
|
|
|
return [[self.URL path] stringByAbbreviatingWithTildeInPath];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)filename
|
|
|
|
{
|
|
|
|
return [[self.URL path] lastPathComponent];
|
2007-11-24 17:16:27 -03:00
|
|
|
}
|
|
|
|
|
2005-06-02 14:16:43 -04:00
|
|
|
@end
|