cog/Playlist/PlaylistEntry.m

127 lines
3.2 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"
#import "CogAudio/AudioPropertiesReader.h"
#import "CogAudio/AudioMetadataReader.h"
2005-06-02 18:16:43 +00:00
@implementation PlaylistEntry
2008-02-20 00:44:40 +00:00
@synthesize index;
@synthesize shuffleIndex;
@synthesize status;
@synthesize statusMessage;
@synthesize queuePosition;
2005-06-02 18:16:43 +00:00
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 title;
@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;
@synthesize sampleRate;
2005-06-02 18:16:43 +00:00
2008-02-20 00:44:40 +00:00
@synthesize seekable;
2006-05-12 14:41:02 +00:00
2008-02-20 00:44:40 +00:00
+ (void)initialize {
[self setKeys:[NSArray arrayWithObjects:@"artist",@"title",nil] triggerChangeNotificationsForDependentKey:@"display"];
[self setKeys:[NSArray arrayWithObjects:@"totalFrames",nil] triggerChangeNotificationsForDependentKey:@"length"];
[self setKeys:[NSArray arrayWithObjects:@"URL",nil] triggerChangeNotificationsForDependentKey:@"path"];
[self setKeys:[NSArray arrayWithObjects:@"URL",nil] triggerChangeNotificationsForDependentKey:@"filename"];
2006-05-12 14:41:02 +00:00
}
- (void)setProperties:(NSDictionary *)dict
2005-06-02 18:16:43 +00:00
{
2008-02-23 19:46:23 +00: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 19:08:39 +00:00
}
- (void)readPropertiesThread
2006-05-12 19:08:39 +00:00
{
2008-02-20 00:44:40 +00:00
NSDictionary *properties = [AudioPropertiesReader propertiesForURL:self.URL];
if (!properties) {
2008-02-23 19:46:23 +00:00
self.status = kCogEntryError;
self.statusMessage = @"Failed to read properties!";
2006-05-12 19:08:39 +00:00
return;
}
[self performSelectorOnMainThread:@selector(setProperties:) withObject:properties waitUntilDone:YES];
2006-05-12 19:08:39 +00:00
}
- (void)setMetadata: (NSDictionary *)m
2005-06-02 18:16:43 +00:00
{
NSString *ti = [m objectForKey:@"title"];
if (ti == nil || [ti isEqualToString:@""]) {
self.title = [[self.URL path] lastPathComponent];
2005-06-02 18:16:43 +00:00
}
else {
self.title = ti;
}
self.artist = [m objectForKey:@"artist"];
self.album = [m objectForKey:@"album"];
self.genre = [m objectForKey:@"genre"];
self.year = [m objectForKey:@"year"];
self.track = [m objectForKey:@"track"];
2006-05-12 19:08:39 +00:00
}
- (void)readMetadataThread
2006-05-12 19:08:39 +00:00
{
2008-02-20 00:44:40 +00:00
NSDictionary *metadata = [AudioMetadataReader metadataForURL:self.URL];
[self performSelectorOnMainThread:@selector(setMetadata:) withObject:metadata waitUntilDone:YES];
2006-05-12 19:08:39 +00:00
}
- (NSString *)description
{
2008-02-20 00:44:40 +00: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];
}
}
@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];
}
2005-06-02 18:16:43 +00:00
@end