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
|
|
|
|
|
|
|
|
- (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;
|
|
|
|
|
|
|
|
year = nil;
|
|
|
|
track = nil;
|
|
|
|
length = nil;
|
|
|
|
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];
|
|
|
|
[length release];
|
|
|
|
[bitrate release];
|
|
|
|
[channels release];
|
|
|
|
[bitsPerSample release];
|
|
|
|
[sampleRate release];
|
|
|
|
[current release];
|
|
|
|
[idx release];
|
|
|
|
[shuffleIndex 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];
|
|
|
|
NSLog(@"INDEX: %@", i);
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
// DBLog(@"HERE FUCK: %@", 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-03-14 02:28:30 +00:00
|
|
|
[self setLength: [dict objectForKey:@"length" ]];
|
|
|
|
[self setBitrate: [dict objectForKey:@"bitrate" ]];
|
|
|
|
[self setChannels: [dict objectForKey:@"channels" ]];
|
|
|
|
[self setBitsPerSample: [dict objectForKey:@"bitsPerSample" ]];
|
|
|
|
[self setSampleRate: [dict objectForKey:@"sampleRate" ]];
|
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-03-14 02:28:30 +00:00
|
|
|
- (void)setLength:(NSNumber *)l
|
2006-05-13 15:52:52 +00:00
|
|
|
{
|
2007-03-14 02:28:30 +00:00
|
|
|
[l retain];
|
|
|
|
[length release];
|
|
|
|
|
2006-05-13 15:52:52 +00:00
|
|
|
length = l;
|
|
|
|
}
|
2007-03-14 02:28:30 +00:00
|
|
|
- (NSNumber *)length
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
|
|
|
return length;
|
|
|
|
}
|
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-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
|
|
|
}
|
|
|
|
|
|
|
|
[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];
|
2006-05-12 19:08:39 +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
|
|
|
}
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
@end
|