cog/Playlist/PlaylistEntry.m

275 lines
3.8 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
- (id)init
{
self = [super init];
if (self)
{
[self setIndex:0];
[self setURL:nil];
2005-06-02 18:16:43 +00:00
}
return self;
}
- (void)dealloc
{
[url release];
2005-06-02 18:16:43 +00:00
[super dealloc];
}
-(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;
}
-(void)setURL:(NSURL *)u
2005-06-02 18:16:43 +00:00
{
[u retain];
[url release];
url = u;
2005-06-02 18:16:43 +00:00
}
-(NSURL *)url
2005-06-02 18:16:43 +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;
}
- (void)readInfoThreadedSetVariables:(NSDictionary *)dict
2005-06-02 18:16:43 +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
[self setLengthString:[[dict objectForKey:@"length"] doubleValue]];
2006-05-12 19:08:39 +00:00
}
2007-02-18 21:48:37 +00:00
- (void)readInfoThreaded
2006-05-12 19:08:39 +00:00
{
NSDictionary *properties = [AudioPropertiesReader propertiesForURL:url];
2006-05-12 19:08:39 +00:00
[self performSelectorOnMainThread:@selector(readInfoThreadedSetVariables:) 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];
}
- (void)setLength:(double)l
{
length = l;
}
2005-06-02 18:16:43 +00:00
- (double)length
{
return length;
}
2006-06-19 00:39:41 +00:00
- (void)setBitrate:(int) br
{
2006-06-19 00:39:41 +00:00
bitrate = br;
}
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
}
- (void)setChannels:(int)c
{
channels = c;
}
2005-06-02 18:16:43 +00:00
- (int)channels
{
return channels;
}
- (void)setBitsPerSample:(int)bps
{
bitsPerSample = bps;
}
2005-06-02 18:16:43 +00:00
- (int)bitsPerSample
{
return bitsPerSample;
}
- (void)setSampleRate:(float)s
{
sampleRate = s;
}
2005-06-02 18:16:43 +00:00
- (float)sampleRate
{
return sampleRate;
}
- (void)readTagsThreadedSetVariables: (NSDictionary *)m
2005-06-02 18:16:43 +00:00
{
NSString *ti = [m objectForKey:@"title"];
if ([ti isEqualToString:@""]) {
[self setTitle:[[url path] lastPathComponent]];
2005-06-02 18:16:43 +00:00
}
else {
[self setTitle:[m objectForKey:@"title"]];
}
[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-02-18 21:48:37 +00:00
- (void)readTagsThreaded
2006-05-12 19:08:39 +00:00
{
NSDictionary *metadata = [AudioMetadataReader metadataForURL:url];
2006-05-12 19:08:39 +00:00
[self performSelectorOnMainThread:@selector(readTagsThreadedSetVariables:) withObject:metadata waitUntilDone:YES];
2006-05-12 19:08:39 +00:00
}
- (NSString *)description
{
return [NSString stringWithFormat:@"PlaylistEntry %i:(%@)",idx, url];
}
2005-06-02 18:16:43 +00:00
@end