Cleaned up PlaylistEntry.

CQTexperiment
vspader 2008-02-20 00:44:40 +00:00
parent 38e23ef442
commit eeba50f6e1
10 changed files with 2201 additions and 2502 deletions

View File

@ -157,7 +157,7 @@
[self updateTimeField:0.0f];
[audioPlayer play:[pe url] withUserInfo:pe];
[audioPlayer play:[pe URL] withUserInfo:pe];
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
[scrobbler start:pe];
@ -487,7 +487,7 @@
PlaylistEntry *curEntry = (PlaylistEntry *)userInfo;
PlaylistEntry *pe = [playlistController getNextEntry:curEntry];
[player setNextStream:[pe url] withUserInfo:pe];
[player setNextStream:[pe URL] withUserInfo:pe];
}
- (void)audioPlayer:(AudioPlayer *)player streamChanged:(id)userInfo

View File

@ -111,7 +111,7 @@ escapeForLastFM(NSString *string)
escapeForLastFM([pe album]),
@"", // TODO: MusicBrainz support
(int)([[pe totalFrames] longValue]/[[pe sampleRate] floatValue]),
escapeForLastFM([[pe url] path])
escapeForLastFM([[pe URL] path])
]];
}

File diff suppressed because it is too large Load Diff

View File

@ -572,7 +572,7 @@
if ([self selectionIndex] < 0)
return;
NSURL *url = [[[self selectedObjects] objectAtIndex:0] url];
NSURL *url = [[[self selectedObjects] objectAtIndex:0] URL];
if ([url isFileURL])
[ws selectFile:[url path] inFileViewerRootedAtPath:[url path]];
}

View File

@ -9,17 +9,18 @@
#import <Cocoa/Cocoa.h>
@interface PlaylistEntry : NSObject {
NSURL *url;
NSString *relativePath;
NSString *base;
NSNumber *index;
NSNumber *shuffleIndex;
NSNumber *current;
NSURL *URL;
NSString *artist;
NSString *album;
NSString *title;
NSString *genre;
NSString *year;
NSNumber *track;
NSNumber *track;
NSNumber *totalFrames;
NSNumber *bitrate;
@ -27,68 +28,38 @@
NSNumber *bitsPerSample;
NSNumber *sampleRate;
NSNumber *current;
NSNumber *idx;
NSNumber *shuffleIndex;
NSNumber *seekable;
}
- (void)setIndex:(NSNumber *)i;
- (NSNumber *)index;
- (void)setShuffleIndex:(NSNumber *)si;
- (NSNumber *)shuffleIndex;
// Hack for KVC compliance
- (void)setUrl:(NSURL *)u;
- (void)setURL:(NSURL *)u;
- (NSURL *)url;
- (void)setCurrent:(NSNumber *) b;
- (NSNumber *)current;
- (NSString *)relativePath;
- (void)setRelativePath:(NSString *)rel;
- (NSString *)base;
- (void)setBase:(NSString *)newUrl;
- (void)setArtist:(NSString *)s;
- (NSString *)artist;
- (void)setAlbum:(NSString *)s;
- (NSString *)album;
- (void)setTitle:(NSString *)s;
- (NSString *)title;
- (void)setGenre:(NSString *)s;
- (NSString *)genre;
- (void)setYear:(NSString *)y;
- (NSString *)year;
- (void)setTrack:(NSNumber *)y;
- (NSNumber *)track;
- (void)setTotalFrames:(NSNumber *)l;
- (NSNumber *)totalFrames;
- (void)setBitrate:(NSNumber *) br;
- (NSNumber *)bitrate;
- (void)setChannels:(NSNumber *)c;
- (NSNumber *)channels;
- (void)setBitsPerSample:(NSNumber *)bps;
- (NSNumber *)bitsPerSample;
- (void)setSampleRate:(NSNumber *)s;
- (NSNumber *)sampleRate;
- (NSString *)display;
- (NSNumber *)length;
- (void)setSeekable:(NSNumber *)s;
- (NSNumber *)seekable;
- (void)setMetadata: (NSDictionary *)m;
- (void)readMetadataThread;
- (void)setProperties: (NSDictionary *)p;
- (void)readPropertiesThread;
@property(readonly) NSString *display;
@property(readonly) NSNumber *length;
@property(readonly) NSString *path;
@property(readonly) NSString *filename;
@property(retain) NSNumber *index;
@property(retain) NSNumber *shuffleIndex;
@property(retain) NSNumber *current;
@property(retain) NSURL *URL;
@property(retain) NSString *artist;
@property(retain) NSString *album;
@property(retain) NSString *title;
@property(retain) NSString *genre;
@property(retain) NSString *year;
@property(retain) NSNumber *track;
@property(retain) NSNumber *totalFrames;
@property(retain) NSNumber *bitrate;
@property(retain) NSNumber *channels;
@property(retain) NSNumber *bitsPerSample;
@property(retain) NSNumber *sampleRate;
@property(retain) NSNumber *seekable;
@end

View File

@ -12,203 +12,32 @@
@implementation PlaylistEntry
@synthesize index;
@synthesize shuffleIndex;
@synthesize current;
@synthesize URL;
@synthesize artist;
@synthesize album;
@synthesize title;
@synthesize genre;
@synthesize year;
@synthesize track;
@synthesize totalFrames;
@synthesize bitrate;
@synthesize channels;
@synthesize bitsPerSample;
@synthesize sampleRate;
@synthesize seekable;
+ (void)initialize {
[self setKeys:[NSArray arrayWithObjects:@"artist",@"title",nil] triggerChangeNotificationsForDependentKey:@"display"];
[self setKeys:[NSArray arrayWithObjects:@"totalFrames",nil] triggerChangeNotificationsForDependentKey:@"length"];
}
- (id)init
{
self = [super init];
if (self)
{
url = nil;
artist = nil;
album = nil;
title = nil;
genre = nil;
relativePath = nil;
base = nil;
year = nil;
track = nil;
totalFrames = nil;
bitrate = nil;
channels = nil;
bitsPerSample = nil;
sampleRate = nil;
current = nil;
idx = nil;
shuffleIndex = nil;
}
return self;
}
- (void)dealloc
{
[url release];
[artist release];
[album release];
[title release];
[genre release];
[year release];
[track release];
[totalFrames release];
[bitrate release];
[channels release];
[bitsPerSample release];
[sampleRate release];
[current release];
[idx release];
[shuffleIndex release];
[relativePath release];
[base release];
[super dealloc];
}
-(void)setShuffleIndex:(NSNumber *)si
{
[si retain];
[shuffleIndex release];
shuffleIndex = si;
}
-(NSNumber *)shuffleIndex
{
return shuffleIndex;
}
-(void)setIndex:(NSNumber *)i
{
[i retain];
[idx release];
idx = i;
}
-(NSNumber *)index
{
return idx;
}
// Hack for kvc compliance - fix this
-(void)setUrl:(NSURL *)u
{
[self setURL:u];
}
-(void)setURL:(NSURL *)u
{
[u retain];
[url release];
url = u;
}
-(NSURL *)url
{
return url;
}
-(void)setCurrent:(NSNumber *) b
{
[b retain];
[current release];
current = b;
}
-(NSNumber *)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
{
return title;
}
- (void)setGenre:(NSString *)s
{
[s retain];
[genre release];
genre = s;
}
- (NSString *)genre
{
return genre;
}
- (void)setYear:(NSString *)y
{
[y retain];
[year release];
if ([y intValue] == 0)
{
y = @"";
}
year = y;
}
- (NSString *)year
{
return year;
}
- (void)setTrack:(NSNumber *)t
{
[t retain];
[track release];
track = t;
}
- (NSNumber *)track
{
return track;
[self setKeys:[NSArray arrayWithObjects:@"url",nil] triggerChangeNotificationsForDependentKey:@"path"];
[self setKeys:[NSArray arrayWithObjects:@"url",nil] triggerChangeNotificationsForDependentKey:@"filename"];
}
- (void)setProperties:(NSDictionary *)dict
@ -223,131 +52,22 @@
- (void)readPropertiesThread
{
NSDictionary *properties = [AudioPropertiesReader propertiesForURL:url];
NSDictionary *properties = [AudioPropertiesReader propertiesForURL:self.URL];
[self performSelectorOnMainThread:@selector(setProperties:) withObject:properties waitUntilDone:YES];
}
- (void)setTotalFrames:(NSNumber *)t
{
[t retain];
[totalFrames release];
totalFrames = t;
}
- (NSNumber *)totalFrames
{
return totalFrames;
}
- (void)setBitrate:(NSNumber *) br
{
[br retain];
[bitrate release];
bitrate = br;
}
- (NSNumber *)bitrate
{
return bitrate;
}
- (void)setChannels:(NSNumber *)c
{
[c retain];
[channels release];
channels = c;
}
- (NSNumber *)channels
{
return channels;
}
- (void)setBitsPerSample:(NSNumber *)bps
{
[bps retain];
[bitsPerSample release];
bitsPerSample = bps;
}
- (NSNumber *)bitsPerSample
{
return bitsPerSample;
}
- (void)setSampleRate:(NSNumber *)s
{
[s retain];
[sampleRate release];
sampleRate = s;
}
- (NSNumber *)sampleRate
{
return sampleRate;
}
- (NSString *)display
{
if ((artist == NULL) || ([[self artist] isEqualToString:@""]))
return title;
else {
return [NSString stringWithFormat:@"%@ - %@", artist, title];
}
}
- (void)setSeekable:(NSNumber *)s
{
[s retain];
[seekable release];
seekable = s;
}
- (NSNumber *)seekable
{
return seekable;
}
- (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;
}
- (void)setMetadata: (NSDictionary *)m
{
NSString *ti = [m objectForKey:@"title"];
if (ti == nil || [ti isEqualToString:@""]) {
[self setTitle:[[url path] lastPathComponent]];
[self setTitle:[[self.URL path] lastPathComponent]];
}
else {
[self setTitle:ti];
}
[self setBase:[[url path] lastPathComponent]];
[self setRelativePath:[[url relativePath] stringByAbbreviatingWithTildeInPath]];
[self setArtist:[m objectForKey:@"artist"]];
[self setAlbum:[m objectForKey:@"album"]];
[self setGenre:[m objectForKey:@"genre"]];
@ -357,7 +77,7 @@
- (void)readMetadataThread
{
NSDictionary *metadata = [AudioMetadataReader metadataForURL:url];
NSDictionary *metadata = [AudioMetadataReader metadataForURL:self.URL];
[self performSelectorOnMainThread:@selector(setMetadata:) withObject:metadata waitUntilDone:YES];
@ -365,12 +85,31 @@
- (NSString *)description
{
return [NSString stringWithFormat:@"PlaylistEntry %i:(%@)", idx, url];
return [NSString stringWithFormat:@"PlaylistEntry %i:(%@)", self.index, self.URL];
}
- (NSString *)display
{
if ((self.artist == NULL) || ([self.artist isEqualToString:@""]))
return self.title;
else {
return [NSString stringWithFormat:@"%@ - %@", self.artist, self.title];
}
}
- (NSNumber *)length
{
return [NSNumber numberWithDouble:([totalFrames longValue] / [sampleRate floatValue])];
return [NSNumber numberWithDouble:([self.totalFrames longValue] / [self.sampleRate floatValue])];
}
- (NSString *)path
{
return [[self.URL path] stringByAbbreviatingWithTildeInPath];
}
- (NSString *)filename
{
return [[self.URL path] lastPathComponent];
}
@end

View File

@ -81,7 +81,7 @@
while (pe = [e nextObject])
{
NSString *path = [self relativePathFrom:filename toURL:[pe url]];
NSString *path = [self relativePathFrom:filename toURL:[pe URL]];
[fileHandle writeData:[[path stringByAppendingString:@"\n"] dataUsingEncoding:NSUTF8StringEncoding]];
}
@ -105,7 +105,7 @@
int i = 1;
while (pe = [e nextObject])
{
NSString *path = [self relativePathFrom:filename toURL:[pe url]];
NSString *path = [self relativePathFrom:filename toURL:[pe URL]];
NSString *entry = [NSString stringWithFormat:@"File%i=%@\n",i,path];
[fileHandle writeData:[entry dataUsingEncoding:NSUTF8StringEncoding]];

View File

@ -18,7 +18,7 @@
{
[spotlightWindowController.query disableUpdates];
NSArray *urls = [[self selectedObjects]valueForKey:@"url"];
NSArray *urls = [[self selectedObjects]valueForKey:@"URL"];
[pboard declareTypes:[NSArray arrayWithObjects:CogUrlsPboardType,nil] owner:nil]; //add it to pboard
[pboard setData:[NSArchiver archivedDataWithRootObject:urls] forType:CogUrlsPboardType];

View File

@ -19,7 +19,7 @@ static NSDictionary *importKeys;
{
// We need to translate the path string to a full URL
NSArray *URLTransform =
[NSArray arrayWithObjects:@"url", @"PathToURLTransformer", nil];
[NSArray arrayWithObjects:@"URL", @"PathToURLTransformer", nil];
// Extract the artist name from the authors array
NSArray *artistTransform =

View File

@ -266,7 +266,7 @@ static NSPredicate * musicOnlyPredicate = nil;
tracks = playlistController.selectedObjects;
if ([tracks count] == 0)
tracks = playlistController.arrangedObjects;
[playlistLoader addURLs:[tracks valueForKey:@"url"] sort:NO];
[playlistLoader addURLs:[tracks valueForKey:@"URL"] sort:NO];
[self.query enableUpdates];
}