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;
|
2008-02-21 23:19:46 -03:00
|
|
|
@synthesize status;
|
|
|
|
@synthesize statusMessage;
|
2008-02-22 12:26:46 -03:00
|
|
|
@synthesize queuePosition;
|
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-23 16:46:23 -03:00
|
|
|
[self setTotalFrames: [[dict objectForKey:@"totalFrames" ] longLongValue]];
|
|
|
|
[self setBitrate: [[dict objectForKey:@"bitrate" ] intValue]];
|
|
|
|
[self setChannels: [[dict objectForKey:@"channels" ] intValue]];
|
|
|
|
[self setBitsPerSample: [[dict objectForKey:@"bitsPerSample" ] intValue]];
|
|
|
|
[self setSampleRate: [[dict objectForKey:@"sampleRate" ] floatValue]];
|
|
|
|
[self setSeekable: [[dict objectForKey:@"seekable" ] boolValue]];
|
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];
|
2008-02-22 00:44:06 -03:00
|
|
|
if (!properties) {
|
2008-02-23 16:46:23 -03:00
|
|
|
self.status = kCogEntryError;
|
|
|
|
self.statusMessage = @"Failed to read properties!";
|
2006-05-12 15:08:39 -04:00
|
|
|
|
2008-02-22 00:44:06 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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" ]];
|
2008-02-23 16:46:23 -03:00
|
|
|
[self setTrack: [[m objectForKey:@"track" ] intValue]];
|
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
|
|
|
}
|
|
|
|
|
2008-02-23 16:46:23 -03:00
|
|
|
- (double)length
|
2007-11-24 17:16:27 -03:00
|
|
|
{
|
2008-02-23 16:46:23 -03:00
|
|
|
return ((double)self.totalFrames / self.sampleRate);
|
2008-02-19 21:44:40 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (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
|