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"
|
2007-02-24 20:36:27 +00:00
|
|
|
#import "CogAudio/AudioPropertiesReader.h"
|
|
|
|
#import "CogAudio/AudioMetadataReader.h"
|
2005-06-02 18:16:43 +00:00
|
|
|
|
|
|
|
@implementation PlaylistEntry
|
|
|
|
|
2007-11-01 01:53:52 +00:00
|
|
|
+ (void)initialize {
|
|
|
|
[self setKeys:[NSArray arrayWithObjects:@"artist",@"title",nil] triggerChangeNotificationsForDependentKey:@"display"];
|
2007-11-24 20:16:27 +00:00
|
|
|
[self setKeys:[NSArray arrayWithObjects:@"totalFrames",nil] triggerChangeNotificationsForDependentKey:@"length"];
|
2007-11-01 01:53:52 +00:00
|
|
|
}
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
- (id)init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self)
|
|
|
|
{
|
2007-03-18 17:44:59 +00:00
|
|
|
url = nil;
|
|
|
|
|
|
|
|
artist = nil;
|
|
|
|
album = nil;
|
|
|
|
title = nil;
|
|
|
|
genre = nil;
|
2008-02-18 16:06:54 +00:00
|
|
|
|
|
|
|
relativePath = nil;
|
|
|
|
base = nil;
|
|
|
|
|
2007-03-18 17:44:59 +00:00
|
|
|
year = nil;
|
|
|
|
track = nil;
|
2007-11-24 20:16:27 +00:00
|
|
|
totalFrames = nil;
|
2007-03-18 17:44:59 +00:00
|
|
|
bitrate = nil;
|
|
|
|
channels = nil;
|
|
|
|
bitsPerSample = nil;
|
|
|
|
sampleRate = nil;
|
|
|
|
|
|
|
|
current = nil;
|
|
|
|
|
|
|
|
idx = nil;
|
|
|
|
shuffleIndex = nil;
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
2007-03-02 01:36:52 +00:00
|
|
|
[url release];
|
2007-03-18 17:44:59 +00:00
|
|
|
[artist release];
|
|
|
|
[album release];
|
|
|
|
[title release];
|
|
|
|
[genre release];
|
|
|
|
[year release];
|
|
|
|
[track release];
|
2007-11-24 20:16:27 +00:00
|
|
|
[totalFrames release];
|
2007-03-18 17:44:59 +00:00
|
|
|
[bitrate release];
|
|
|
|
[channels release];
|
|
|
|
[bitsPerSample release];
|
|
|
|
[sampleRate release];
|
|
|
|
[current release];
|
|
|
|
[idx release];
|
|
|
|
[shuffleIndex release];
|
2008-02-18 16:06:54 +00:00
|
|
|
[relativePath release];
|
|
|
|
[base release];
|
2005-06-02 18:16:43 +00:00
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2007-03-14 02:28:30 +00:00
|
|
|
-(void)setShuffleIndex:(NSNumber *)si
|
2006-04-14 17:28:20 +00:00
|
|
|
{
|
2007-03-14 02:28:30 +00:00
|
|
|
[si retain];
|
|
|
|
[shuffleIndex release];
|
|
|
|
|
|
|
|
shuffleIndex = si;
|
2006-04-14 17:28:20 +00:00
|
|
|
}
|
|
|
|
|
2007-03-14 02:28:30 +00:00
|
|
|
-(NSNumber *)shuffleIndex
|
2006-04-14 17:28:20 +00:00
|
|
|
{
|
2007-03-14 02:28:30 +00:00
|
|
|
return shuffleIndex;
|
2006-04-14 17:28:20 +00:00
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
|
2007-03-14 02:28:30 +00:00
|
|
|
-(void)setIndex:(NSNumber *)i
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
2007-03-14 02:28:30 +00:00
|
|
|
[i retain];
|
|
|
|
[idx release];
|
2007-07-11 01:20:32 +00:00
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
idx = i;
|
|
|
|
}
|
2006-04-15 14:17:46 +00:00
|
|
|
|
2007-03-14 02:28:30 +00:00
|
|
|
-(NSNumber *)index
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
2008-02-18 16:55:31 +00:00
|
|
|
|
|
|
|
// Hack for kvc compliance - fix this
|
|
|
|
-(void)setUrl:(NSURL *)u
|
|
|
|
{
|
|
|
|
[self setURL:u];
|
|
|
|
}
|
|
|
|
|
2007-03-02 01:36:52 +00:00
|
|
|
-(void)setURL:(NSURL *)u
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
2007-03-02 01:36:52 +00:00
|
|
|
[u retain];
|
|
|
|
[url release];
|
|
|
|
url = u;
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2007-03-02 01:36:52 +00:00
|
|
|
-(NSURL *)url
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
2007-03-02 01:36:52 +00:00
|
|
|
return url;
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2007-03-18 17:44:59 +00:00
|
|
|
-(void)setCurrent:(NSNumber *) b
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
2007-03-18 17:44:59 +00:00
|
|
|
[b retain];
|
|
|
|
[current release];
|
2005-06-02 18:16:43 +00:00
|
|
|
current = b;
|
|
|
|
}
|
|
|
|
|
2007-03-18 17:44:59 +00:00
|
|
|
-(NSNumber *)current
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
|
|
|
return current;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)setArtist:(NSString *)s
|
|
|
|
{
|
|
|
|
[s retain];
|
|
|
|
[artist release];
|
|
|
|
|
|
|
|
artist = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)artist
|
|
|
|
{
|
|
|
|
return artist;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setAlbum:(NSString *)s
|
|
|
|
{
|
|
|
|
[s retain];
|
|
|
|
[album release];
|
|
|
|
|
|
|
|
album = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)album
|
|
|
|
{
|
|
|
|
return album;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setTitle:(NSString *)s
|
|
|
|
{
|
|
|
|
[s retain];
|
|
|
|
[title release];
|
|
|
|
|
|
|
|
title = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)title
|
|
|
|
{
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setGenre:(NSString *)s
|
|
|
|
{
|
|
|
|
[s retain];
|
|
|
|
[genre release];
|
|
|
|
|
|
|
|
genre = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)genre
|
|
|
|
{
|
|
|
|
return genre;
|
|
|
|
}
|
|
|
|
|
2006-05-12 21:49:51 +00:00
|
|
|
- (void)setYear:(NSString *)y
|
2006-05-12 14:41:02 +00:00
|
|
|
{
|
2006-05-12 21:49:51 +00:00
|
|
|
[y retain];
|
|
|
|
[year release];
|
|
|
|
|
|
|
|
if ([y intValue] == 0)
|
|
|
|
{
|
|
|
|
y = @"";
|
|
|
|
}
|
|
|
|
|
2006-05-12 14:41:02 +00:00
|
|
|
year = y;
|
|
|
|
}
|
2006-05-12 21:49:51 +00:00
|
|
|
- (NSString *)year
|
2006-05-12 14:41:02 +00:00
|
|
|
{
|
|
|
|
return year;
|
|
|
|
}
|
|
|
|
|
2007-03-14 02:28:30 +00:00
|
|
|
- (void)setTrack:(NSNumber *)t
|
2006-05-12 14:41:02 +00:00
|
|
|
{
|
2007-03-14 02:28:30 +00:00
|
|
|
[t retain];
|
|
|
|
[track release];
|
|
|
|
|
2006-05-12 14:41:02 +00:00
|
|
|
track = t;
|
|
|
|
}
|
2007-03-14 02:28:30 +00:00
|
|
|
- (NSNumber *)track
|
2006-05-12 14:41:02 +00:00
|
|
|
{
|
|
|
|
return track;
|
|
|
|
}
|
|
|
|
|
2007-03-09 01:16:06 +00:00
|
|
|
- (void)setProperties:(NSDictionary *)dict
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
2007-11-24 20:16:27 +00:00
|
|
|
[self setTotalFrames: [dict objectForKey:@"totalFrames" ]];
|
2007-03-14 02:28:30 +00:00
|
|
|
[self setBitrate: [dict objectForKey:@"bitrate" ]];
|
|
|
|
[self setChannels: [dict objectForKey:@"channels" ]];
|
|
|
|
[self setBitsPerSample: [dict objectForKey:@"bitsPerSample" ]];
|
|
|
|
[self setSampleRate: [dict objectForKey:@"sampleRate" ]];
|
2007-05-27 15:11:30 +00:00
|
|
|
[self setSeekable: [dict objectForKey:@"seekable" ]];
|
2006-05-12 19:08:39 +00:00
|
|
|
}
|
|
|
|
|
2007-03-09 01:16:06 +00:00
|
|
|
- (void)readPropertiesThread
|
2006-05-12 19:08:39 +00:00
|
|
|
{
|
2007-03-02 01:36:52 +00:00
|
|
|
NSDictionary *properties = [AudioPropertiesReader propertiesForURL:url];
|
2006-05-12 19:08:39 +00:00
|
|
|
|
2007-03-09 01:16:06 +00:00
|
|
|
[self performSelectorOnMainThread:@selector(setProperties:) withObject:properties waitUntilDone:YES];
|
2006-05-12 19:08:39 +00:00
|
|
|
}
|
|
|
|
|
2007-11-24 20:16:27 +00:00
|
|
|
- (void)setTotalFrames:(NSNumber *)t
|
2006-05-13 15:52:52 +00:00
|
|
|
{
|
2007-11-24 20:16:27 +00:00
|
|
|
[t retain];
|
|
|
|
[totalFrames release];
|
2007-03-14 02:28:30 +00:00
|
|
|
|
2007-11-24 20:16:27 +00:00
|
|
|
totalFrames = t;
|
2006-05-13 15:52:52 +00:00
|
|
|
}
|
2007-11-24 20:16:27 +00:00
|
|
|
- (NSNumber *)totalFrames
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
2007-11-24 20:16:27 +00:00
|
|
|
return totalFrames;
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
2006-05-13 15:52:52 +00:00
|
|
|
|
2007-03-14 02:28:30 +00:00
|
|
|
- (void)setBitrate:(NSNumber *) br
|
2006-05-13 15:52:52 +00:00
|
|
|
{
|
2007-03-14 02:28:30 +00:00
|
|
|
[br retain];
|
|
|
|
[bitrate release];
|
|
|
|
|
2006-06-19 00:39:41 +00:00
|
|
|
bitrate = br;
|
2006-05-13 15:52:52 +00:00
|
|
|
}
|
2007-03-14 02:28:30 +00:00
|
|
|
- (NSNumber *)bitrate
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
2006-06-19 00:39:41 +00:00
|
|
|
return bitrate;
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2007-03-14 02:28:30 +00:00
|
|
|
- (void)setChannels:(NSNumber *)c
|
2006-05-13 15:52:52 +00:00
|
|
|
{
|
2007-03-14 02:28:30 +00:00
|
|
|
[c retain];
|
|
|
|
[channels release];
|
|
|
|
|
2006-05-13 15:52:52 +00:00
|
|
|
channels = c;
|
|
|
|
}
|
2007-03-14 02:28:30 +00:00
|
|
|
- (NSNumber *)channels
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
|
|
|
return channels;
|
|
|
|
}
|
2006-05-13 15:52:52 +00:00
|
|
|
|
2007-03-14 02:28:30 +00:00
|
|
|
- (void)setBitsPerSample:(NSNumber *)bps
|
2006-05-13 15:52:52 +00:00
|
|
|
{
|
2007-03-14 02:28:30 +00:00
|
|
|
[bps retain];
|
|
|
|
[bitsPerSample release];
|
|
|
|
|
2006-05-13 15:52:52 +00:00
|
|
|
bitsPerSample = bps;
|
|
|
|
}
|
2007-03-14 02:28:30 +00:00
|
|
|
- (NSNumber *)bitsPerSample
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
|
|
|
return bitsPerSample;
|
|
|
|
}
|
2006-05-13 15:52:52 +00:00
|
|
|
|
2007-03-14 02:28:30 +00:00
|
|
|
- (void)setSampleRate:(NSNumber *)s
|
2006-05-13 15:52:52 +00:00
|
|
|
{
|
2007-03-14 02:28:30 +00:00
|
|
|
[s retain];
|
2007-03-18 17:44:59 +00:00
|
|
|
[sampleRate release];
|
|
|
|
|
2006-05-13 15:52:52 +00:00
|
|
|
sampleRate = s;
|
|
|
|
}
|
2007-03-14 02:28:30 +00:00
|
|
|
- (NSNumber *)sampleRate
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
|
|
|
return sampleRate;
|
|
|
|
}
|
|
|
|
|
2007-11-01 01:53:52 +00:00
|
|
|
- (NSString *)display
|
|
|
|
{
|
2008-02-18 10:25:04 +00:00
|
|
|
if ((artist == NULL) || ([[self artist] isEqualToString:@""]))
|
|
|
|
return title;
|
2007-11-01 01:53:52 +00:00
|
|
|
else {
|
|
|
|
return [NSString stringWithFormat:@"%@ - %@", artist, title];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-27 15:11:30 +00:00
|
|
|
- (void)setSeekable:(NSNumber *)s
|
|
|
|
{
|
|
|
|
[s retain];
|
|
|
|
[seekable release];
|
|
|
|
|
|
|
|
seekable = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSNumber *)seekable
|
|
|
|
{
|
|
|
|
return seekable;
|
|
|
|
}
|
|
|
|
|
2008-02-18 16:06:54 +00:00
|
|
|
- (NSString *)relativePath
|
|
|
|
{
|
|
|
|
return relativePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setRelativePath:(NSString *)rel
|
|
|
|
{
|
|
|
|
[rel retain];
|
|
|
|
[relativePath release];
|
|
|
|
relativePath = rel;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)base
|
|
|
|
{
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setBase:(NSString *)newUrl
|
|
|
|
{
|
|
|
|
[newUrl retain];
|
|
|
|
[base release];
|
|
|
|
base = newUrl;
|
|
|
|
}
|
|
|
|
|
2007-03-09 01:16:06 +00:00
|
|
|
- (void)setMetadata: (NSDictionary *)m
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
2007-02-24 20:36:27 +00:00
|
|
|
NSString *ti = [m objectForKey:@"title"];
|
|
|
|
|
2007-05-24 03:30:43 +00:00
|
|
|
if (ti == nil || [ti isEqualToString:@""]) {
|
2007-03-02 01:36:52 +00:00
|
|
|
[self setTitle:[[url path] lastPathComponent]];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
2007-02-24 20:36:27 +00:00
|
|
|
else {
|
2007-03-09 01:16:06 +00:00
|
|
|
[self setTitle:ti];
|
2007-02-24 20:36:27 +00:00
|
|
|
}
|
|
|
|
|
2008-02-18 16:06:54 +00:00
|
|
|
[self setBase:[[url path] lastPathComponent]];
|
|
|
|
[self setRelativePath:[[url relativePath] stringByAbbreviatingWithTildeInPath]];
|
|
|
|
|
2007-02-24 20:36:27 +00:00
|
|
|
[self setArtist:[m objectForKey:@"artist"]];
|
|
|
|
[self setAlbum:[m objectForKey:@"album"]];
|
|
|
|
[self setGenre:[m objectForKey:@"genre"]];
|
|
|
|
[self setYear:[m objectForKey:@"year"]];
|
2007-03-14 02:28:30 +00:00
|
|
|
[self setTrack:[m objectForKey:@"track"]];
|
2006-05-12 19:08:39 +00:00
|
|
|
}
|
|
|
|
|
2007-03-09 01:16:06 +00:00
|
|
|
- (void)readMetadataThread
|
2006-05-12 19:08:39 +00:00
|
|
|
{
|
2007-03-02 01:36:52 +00:00
|
|
|
NSDictionary *metadata = [AudioMetadataReader metadataForURL:url];
|
2008-02-18 16:06:54 +00:00
|
|
|
|
2007-03-09 01:16:06 +00:00
|
|
|
[self performSelectorOnMainThread:@selector(setMetadata:) withObject:metadata waitUntilDone:YES];
|
2007-02-24 20:36:27 +00:00
|
|
|
|
2006-05-12 19:08:39 +00:00
|
|
|
}
|
|
|
|
|
2006-09-17 18:11:29 +00:00
|
|
|
- (NSString *)description
|
|
|
|
{
|
2007-03-14 02:28:30 +00:00
|
|
|
return [NSString stringWithFormat:@"PlaylistEntry %i:(%@)", idx, url];
|
2006-09-17 18:11:29 +00:00
|
|
|
}
|
|
|
|
|
2007-11-24 20:16:27 +00:00
|
|
|
- (NSNumber *)length
|
|
|
|
{
|
|
|
|
return [NSNumber numberWithDouble:([totalFrames longValue] / [sampleRate floatValue])];
|
|
|
|
}
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
@end
|