cog/Playlist/PlaylistEntry.m

462 lines
8.4 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 "TagLib/tag_c.h"
@implementation PlaylistEntry
- (id)init
{
self = [super init];
if (self)
{
[self setIndex:0];
[self setFilename:@""];
[self setDisplay:@"Untitled"];
}
return self;
}
- (void)dealloc
{
NSLog(@"DEALLOCATING A PLAYLIST ENTRY: %@", display);
2005-06-02 18:16:43 +00:00
[filename release];
[display release];
[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;
}
2005-06-02 18:16:43 +00:00
-(void)setFilename:(NSString *)f
{
f = [f copy];
[filename release];
filename = f;
/*
//GO THROUGH HELLA SHIT TO DETERMINE FILE...NEED TO MAKE SOME KIND OF REGISTERING MECHANISM
if ([[filename pathExtension] isEqualToString:@"wav"] || [[filename pathExtension] isEqualToString:@"aiff"])
{
soundFile = [[WaveFile alloc] init];
}
else if ([[filename pathExtension] isEqualToString:@"ogg"])
{
soundFile = [[VorbisFile alloc] init];
}
else if ([[filename pathExtension] isEqualToString:@"mpc"])
{
soundFile = [[MusepackFile alloc] init];
}
else if ([[filename pathExtension] isEqualToString:@"flac"])
{
soundFile = [[FlacFile alloc] init];
}
else if ([[filename pathExtension] isEqualToString:@"ape"])
{
soundFile = [[MonkeysFile alloc] init];
}
else if ([[filename pathExtension] isEqualToString:@"mp3"])
{
soundFile = [[MPEGFile alloc] init];
}
else
{
soundFile = nil;
}
[soundFile open:[filename UTF8String]];
*/
}
-(NSString *)filename
{
return filename;
}
-(void)setDisplay:(NSString *)d
{
d = [d copy];
[display release];
display = d;
}
-(NSString *)display
{
return display;
}
-(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;
}
2005-06-02 18:16:43 +00:00
- (void)readInfo
{
SoundFile *sf = [SoundFile readInfo:filename];
2006-04-22 01:26:57 +00:00
if (sf == nil)
return;
2005-06-02 18:16:43 +00:00
length = [sf length];
bitRate = [sf bitRate];
channels = [sf channels];
bitsPerSample = [sf bitsPerSample];
sampleRate = [sf frequency];
[self setLengthString:length];
2006-05-12 19:08:39 +00:00
2006-05-07 13:19:23 +00:00
[sf release];
2005-06-02 18:16:43 +00:00
// DBLog(@"Length: %f bitRate: %i channels: %i bps: %i samplerate: %f", length, bitRate, channels, bitsPerSample, sampleRate);
2005-06-29 15:28:20 +00:00
//[(SoundFile *)sf close];
// [sp close];
2005-06-02 18:16:43 +00:00
}
2006-05-12 19:08:39 +00:00
- (void)readInfoThreadSetVariables:(SoundFile *)sf
{
length = [sf length];
bitRate = [sf bitRate];
channels = [sf channels];
bitsPerSample = [sf bitsPerSample];
sampleRate = [sf frequency];
[self setLengthString:length];
[sf release];
}
- (void)readInfoThread
{
SoundFile *sf = [SoundFile readInfo:filename];
if (sf == nil)
return;
[self performSelectorOnMainThread:@selector(readInfoThreadSetVariables:) withObject:sf waitUntilDone:YES];
}
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];
}
- (double)length
{
return length;
}
- (int)bitRate
{
return bitRate;
}
- (int)channels
{
return channels;
}
- (int)bitsPerSample
{
return bitsPerSample;
}
- (float)sampleRate
{
return sampleRate;
}
-(void)readTags
{
TagLib_File *tagFile = taglib_file_new((const char *)[filename UTF8String]);
2006-04-04 01:08:21 +00:00
DBLog(@"Does it have a file? %i %s", tagFile, (const char *)[filename UTF8String]);
2005-06-02 18:16:43 +00:00
if (tagFile)
{
TagLib_Tag *tag = taglib_file_tag(tagFile);
2006-04-04 01:08:21 +00:00
DBLog(@"Does it have a tag? %i", tag);
2005-09-07 22:33:16 +00:00
2005-06-02 18:16:43 +00:00
if (tag)
{
char *pArtist, *pTitle, *pAlbum, *pGenre, *pComment;
pArtist = taglib_tag_artist(tag);
pTitle = taglib_tag_title(tag);
pAlbum = taglib_tag_album(tag);
pGenre = taglib_tag_genre(tag);
pComment = taglib_tag_comment(tag);
2006-05-12 21:49:51 +00:00
[self setYear:[[NSNumber numberWithInt:taglib_tag_year(tag)] stringValue]];
2006-05-12 14:41:02 +00:00
[self setTrack:taglib_tag_track(tag)];
2005-06-02 18:16:43 +00:00
if (pArtist != NULL)
[self setArtist:[NSString stringWithUTF8String:(char *)pArtist]];
else
[self setArtist:nil];
if (pAlbum != NULL)
[self setAlbum:[NSString stringWithUTF8String:(char *)pAlbum]];
else
[self setAlbum:nil];
if (pTitle != NULL)
[self setTitle:[NSString stringWithUTF8String:(char *)pTitle]];
else
[self setTitle:nil];
if (pGenre != NULL)
[self setGenre:[NSString stringWithUTF8String:(char *)pGenre]];
else
[self setGenre:nil];
if ([artist isEqualToString:@""] || [title isEqualToString:@""])
2006-04-30 13:01:33 +00:00
{
2005-06-02 18:16:43 +00:00
[self setDisplay:[filename lastPathComponent]];
2006-04-30 13:01:33 +00:00
[self setTitle:[filename lastPathComponent]];
}
2005-06-02 18:16:43 +00:00
else
2006-04-30 13:01:33 +00:00
{
2005-06-02 18:16:43 +00:00
[self setDisplay:[NSString stringWithFormat:@"%@ - %@", artist, title]];
2006-04-30 13:01:33 +00:00
}
2005-06-02 18:16:43 +00:00
taglib_tag_free_strings();
}
taglib_file_free(tagFile);
}
else
{
[self setDisplay:[filename lastPathComponent]];
2006-04-30 13:01:33 +00:00
[self setTitle:[filename lastPathComponent]];
2005-06-02 18:16:43 +00:00
}
}
2006-05-12 19:08:39 +00:00
- (void)readTagsThreadSetVariables: (NSArray *)a
{
2006-05-13 04:51:11 +00:00
NSLog(@"SETTING TITLE TO: %@", [a objectAtIndex:0]);
2006-05-12 19:08:39 +00:00
[self setDisplay:[a objectAtIndex:0]];
NSLog(@"SETTING TITLE TO: %@", [a objectAtIndex:1]);
[self setTitle:[a objectAtIndex:1]];
2006-05-13 04:51:11 +00:00
NSLog(@"SETTING TITLE TO: %@", [a objectAtIndex:2]);
2006-05-12 19:08:39 +00:00
[self setArtist:[a objectAtIndex:2]];
2006-05-13 04:51:11 +00:00
NSLog(@"SETTING TITLE TO: %@", [a objectAtIndex:3]);
2006-05-12 19:08:39 +00:00
[self setAlbum:[a objectAtIndex:3]];
2006-05-13 04:51:11 +00:00
NSLog(@"SETTING TITLE TO: %@", [a objectAtIndex:4]);
2006-05-12 19:08:39 +00:00
[self setGenre:[a objectAtIndex:4]];
2006-05-13 04:51:11 +00:00
NSLog(@"SETTING TITLE TO: %@", [a objectAtIndex:5]);
2006-05-12 21:49:51 +00:00
[self setYear:[[a objectAtIndex:5] stringValue]];
2006-05-13 04:51:11 +00:00
NSLog(@"SETTING TITLE TO: %@", [a objectAtIndex:6]);
2006-05-12 19:08:39 +00:00
[self setTrack:[[a objectAtIndex:6] intValue]];
}
- (void)readTagsThread
{
2006-05-13 04:51:11 +00:00
NSString *lDisplay = @"", *lArtist = @"", *lTitle = @"", *lAlbum = @"", *lGenre = @"";
2006-05-12 19:08:39 +00:00
int lYear = 0, lTrack = 0;
TagLib_File *tagFile = taglib_file_new((const char *)[filename UTF8String]);
DBLog(@"Does it have a file? %i %s", tagFile, (const char *)[filename UTF8String]);
if (tagFile)
{
TagLib_Tag *tag = taglib_file_tag(tagFile);
DBLog(@"Does it have a tag? %i", tag);
if (tag)
{
char *pArtist, *pTitle, *pAlbum, *pGenre, *pComment;
pArtist = taglib_tag_artist(tag);
pTitle = taglib_tag_title(tag);
pAlbum = taglib_tag_album(tag);
pGenre = taglib_tag_genre(tag);
pComment = taglib_tag_comment(tag);
lYear = taglib_tag_year(tag);
lTrack = taglib_tag_track(tag);
if (pArtist != NULL)
lArtist = [NSString stringWithUTF8String:(char *)pArtist];
else
2006-05-13 04:51:11 +00:00
lArtist = @"";
2006-05-12 19:08:39 +00:00
if (pAlbum != NULL)
lAlbum = [NSString stringWithUTF8String:(char *)pAlbum];
else
2006-05-13 04:51:11 +00:00
lAlbum = @"";
2006-05-12 19:08:39 +00:00
if (pTitle != NULL)
{
NSLog(@"SET TITLE PROPERLY");
lTitle = [NSString stringWithUTF8String:(char *)pTitle];
}
else
2006-05-13 04:51:11 +00:00
lTitle = @"";
2006-05-12 19:08:39 +00:00
if (pGenre != NULL)
lGenre = [NSString stringWithUTF8String:(char *)pGenre];
else
2006-05-13 04:51:11 +00:00
lGenre = @"";
2006-05-12 19:08:39 +00:00
if ([lArtist isEqualToString:@""] || [lTitle isEqualToString:@""])
{
NSLog(@"SET TITLE IMPROPERLY");
lDisplay = [filename lastPathComponent];
lTitle = [filename lastPathComponent];
}
else
{
lDisplay = [NSString stringWithFormat:@"%@ - %@", lArtist, lTitle];
}
taglib_tag_free_strings();
}
taglib_file_free(tagFile);
}
else
{
NSLog(@"SET TITLE IMPROPERLY2");
lDisplay = [filename lastPathComponent];
lTitle = [filename lastPathComponent];
}
NSLog(@"TITLE IS: %@", lTitle);
[self performSelectorOnMainThread:@selector(readTagsThreadSetVariables:) withObject:
[NSArray arrayWithObjects:
lDisplay,
lTitle,
lArtist,
lAlbum,
lGenre,
[NSNumber numberWithInt:lYear],
2006-05-13 04:51:11 +00:00
[NSNumber numberWithInt:lTrack],
nil]
2006-05-12 19:08:39 +00:00
waitUntilDone:YES];
}
2005-06-02 18:16:43 +00:00
@end