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)
|
|
|
|
{
|
|
|
|
[self setIndex:0];
|
2007-03-02 01:36:52 +00:00
|
|
|
[self setURL:nil];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
2007-03-02 01:36:52 +00:00
|
|
|
[url release];
|
2005-06-02 18:16:43 +00:00
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2006-04-14 17:28:20 +00:00
|
|
|
-(void)setShuffleIndex:(int)si
|
|
|
|
{
|
|
|
|
shuffleIdx = si;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(int)shuffleIndex
|
|
|
|
{
|
|
|
|
return shuffleIdx;
|
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
|
|
|
|
-(void)setIndex:(int)i
|
|
|
|
{
|
|
|
|
idx = i;
|
2006-04-15 14:17:46 +00:00
|
|
|
[self setDisplayIndex:i+1];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
2006-04-15 14:17:46 +00:00
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
-(int)index
|
|
|
|
{
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
2006-04-15 14:17:46 +00:00
|
|
|
-(void)setDisplayIndex:(int)i
|
|
|
|
{
|
|
|
|
displayIdx=i;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(int)displayIndex
|
|
|
|
{
|
|
|
|
return displayIdx;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
-(void)setCurrent:(BOOL) b
|
|
|
|
{
|
|
|
|
current = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(BOOL)current
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setTrack:(int)t
|
|
|
|
{
|
|
|
|
track = t;
|
|
|
|
}
|
|
|
|
- (int)track
|
|
|
|
{
|
|
|
|
return track;
|
|
|
|
}
|
|
|
|
|
2007-03-09 01:16:06 +00:00
|
|
|
- (void)setProperties:(NSDictionary *)dict
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
2007-02-24 20:36:27 +00:00
|
|
|
[self setLength: [[dict objectForKey:@"length" ] doubleValue]];
|
|
|
|
[self setBitrate: [[dict objectForKey:@"bitrate" ] intValue]];
|
|
|
|
[self setChannels: [[dict objectForKey:@"channels" ] intValue]];
|
|
|
|
[self setBitsPerSample: [[dict objectForKey:@"bitsPerSample"] intValue]];
|
|
|
|
[self setSampleRate: [[dict objectForKey:@"sampleRate" ] floatValue]];
|
2005-06-02 18:16:43 +00:00
|
|
|
|
2007-02-24 20:36:27 +00:00
|
|
|
[self setLengthString:[[dict objectForKey:@"length"] doubleValue]];
|
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
|
|
|
}
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
- (NSString *)lengthString
|
|
|
|
{
|
|
|
|
return lengthString;
|
|
|
|
}
|
|
|
|
- (void)setLengthString:(double)l
|
|
|
|
{
|
|
|
|
int sec = (int)(l/1000.0);
|
|
|
|
|
|
|
|
[lengthString release];
|
|
|
|
lengthString = [[NSString alloc] initWithFormat:@"%i:%02i",sec/60,sec%60];
|
|
|
|
}
|
|
|
|
|
2006-05-13 15:52:52 +00:00
|
|
|
|
|
|
|
- (void)setLength:(double)l
|
|
|
|
{
|
|
|
|
length = l;
|
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
- (double)length
|
|
|
|
{
|
|
|
|
return length;
|
|
|
|
}
|
2006-05-13 15:52:52 +00:00
|
|
|
|
2006-06-19 00:39:41 +00:00
|
|
|
- (void)setBitrate:(int) br
|
2006-05-13 15:52:52 +00:00
|
|
|
{
|
2006-06-19 00:39:41 +00:00
|
|
|
bitrate = br;
|
2006-05-13 15:52:52 +00:00
|
|
|
}
|
2006-06-19 00:39:41 +00:00
|
|
|
- (int)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
|
|
|
}
|
|
|
|
|
2006-05-13 15:52:52 +00:00
|
|
|
- (void)setChannels:(int)c
|
|
|
|
{
|
|
|
|
channels = c;
|
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
- (int)channels
|
|
|
|
{
|
|
|
|
return channels;
|
|
|
|
}
|
2006-05-13 15:52:52 +00:00
|
|
|
|
|
|
|
- (void)setBitsPerSample:(int)bps
|
|
|
|
{
|
|
|
|
bitsPerSample = bps;
|
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
- (int)bitsPerSample
|
|
|
|
{
|
|
|
|
return bitsPerSample;
|
|
|
|
}
|
2006-05-13 15:52:52 +00:00
|
|
|
|
|
|
|
- (void)setSampleRate:(float)s
|
|
|
|
{
|
|
|
|
sampleRate = s;
|
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
- (float)sampleRate
|
|
|
|
{
|
|
|
|
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"];
|
|
|
|
|
|
|
|
if ([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"]];
|
|
|
|
[self setTrack:[[m objectForKey:@"track"] intValue]];
|
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-02 01:36:52 +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
|