Moved PlaylistEntry number variables over to NSNumber. Removed displayIndex and lengthString, using formatters instead. Fix bug with autosaving playlist.

CQTexperiment
vspader 2007-03-14 02:28:30 +00:00
parent 71577bac3d
commit 4ed575f475
15 changed files with 152 additions and 127 deletions

View File

@ -161,15 +161,7 @@ increase/decrease as long as the user holds the left/right, plus/minus button */
{
NSURL *url = [NSURL URLWithString:[urlComboBox stringValue]];
PlaylistEntry *pe = [[PlaylistEntry alloc] init];
[pe setURL:url];
[pe setIndex:[[playlistController arrangedObjects] count]];
[pe setTitle:[urlComboBox stringValue]];
[playlistController addObject:pe];
[pe release];
[playlistLoader addURLs:[NSArray arrayWithObject:url] sort:NO];
[NSApp endSheet:addURLPanel];
[addURLPanel orderOut:self];

View File

@ -5,10 +5,10 @@
#import <Growl/GrowlApplicationBridge.h>
#import "CogAudio/AudioPlayer.h"
#import "PlaylistController.h"
#import "TrackingSlider.h"
#import "AudioScrobbler.h"
@class PlaylistController;
@class PlaylistView;
@interface PlaybackController : NSObject <GrowlApplicationBridgeDelegate>

View File

@ -4,6 +4,9 @@
#import "DBLog.h"
#import "CogAudio/Status.h"
#import "PlaylistController.h"
#import "PlaylistEntry.h"
@implementation PlaybackController
- (id)init
@ -289,11 +292,11 @@
if ([playlistController shuffle] == YES)
{
pe = [playlistController entryAtIndex:[curEntry shuffleIndex]+1];
pe = [playlistController entryAtIndex:[[curEntry shuffleIndex] intValue] + 1];
}
else
{
pe = [playlistController entryAtIndex:[curEntry index]+1];
pe = [playlistController entryAtIndex:[[curEntry index] intValue] + 1];
}
if (pe == nil)

View File

@ -104,7 +104,7 @@ escapeForLastFM(NSString *string)
escapeForLastFM([pe title]),
escapeForLastFM([pe album]),
@"", // TODO: MusicBrainz support
(int)([pe length]/1000.0),
(int)([[pe length] doubleValue]/1000.0),
escapeForLastFM([[pe url] path])
]];
}

View File

@ -100,6 +100,12 @@
8E7575D009F31DCA0080F1EE /* Credits.html in Resources */ = {isa = PBXBuildFile; fileRef = 8E7575C809F31DCA0080F1EE /* Credits.html */; };
8E7575D109F31DCA0080F1EE /* README in Resources */ = {isa = PBXBuildFile; fileRef = 8E7575C909F31DCA0080F1EE /* README */; };
8E7575DB09F31E930080F1EE /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8E7575D909F31E930080F1EE /* Localizable.strings */; };
8E9A2E850BA78B500091081B /* SecondsFormatter.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8E9A2E830BA78B500091081B /* SecondsFormatter.h */; };
8E9A2E860BA78B500091081B /* SecondsFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E9A2E840BA78B500091081B /* SecondsFormatter.m */; };
8E9A2ED90BA78D9D0091081B /* IndexFormatter.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8E9A2ED70BA78D9D0091081B /* IndexFormatter.h */; };
8E9A2EDA0BA78D9D0091081B /* IndexFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E9A2ED80BA78D9D0091081B /* IndexFormatter.m */; };
8E9A30150BA792DC0091081B /* NSFileHandle+CreateFile.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8E9A30130BA792DC0091081B /* NSFileHandle+CreateFile.h */; };
8E9A30160BA792DC0091081B /* NSFileHandle+CreateFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E9A30140BA792DC0091081B /* NSFileHandle+CreateFile.m */; };
8EFFCD5F0AA093AF00C458A5 /* DirectoryNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EFFCD430AA093AF00C458A5 /* DirectoryNode.m */; };
8EFFCD610AA093AF00C458A5 /* FileIconCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EFFCD450AA093AF00C458A5 /* FileIconCell.m */; };
8EFFCD630AA093AF00C458A5 /* FileNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EFFCD470AA093AF00C458A5 /* FileNode.m */; };
@ -141,6 +147,9 @@
170680840B950164006BA573 /* Growl.framework in CopyFiles */,
17F94CCD0B8D090800A34E87 /* Sparkle.framework in CopyFiles */,
1755E1F80BA0D2B600CA3560 /* PlaylistLoader.h in CopyFiles */,
8E9A2E850BA78B500091081B /* SecondsFormatter.h in CopyFiles */,
8E9A2ED90BA78D9D0091081B /* IndexFormatter.h in CopyFiles */,
8E9A30150BA792DC0091081B /* NSFileHandle+CreateFile.h in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -277,6 +286,12 @@
8E7575C909F31DCA0080F1EE /* README */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
8E7575DA09F31E930080F1EE /* English */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/Localizable.strings; sourceTree = "<group>"; };
8E7575DC09F31EAF0080F1EE /* French */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = French; path = French.lproj/Localizable.strings; sourceTree = "<group>"; };
8E9A2E830BA78B500091081B /* SecondsFormatter.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SecondsFormatter.h; sourceTree = "<group>"; };
8E9A2E840BA78B500091081B /* SecondsFormatter.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = SecondsFormatter.m; sourceTree = "<group>"; };
8E9A2ED70BA78D9D0091081B /* IndexFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IndexFormatter.h; sourceTree = "<group>"; };
8E9A2ED80BA78D9D0091081B /* IndexFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IndexFormatter.m; sourceTree = "<group>"; };
8E9A30130BA792DC0091081B /* NSFileHandle+CreateFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSFileHandle+CreateFile.h"; sourceTree = "<group>"; };
8E9A30140BA792DC0091081B /* NSFileHandle+CreateFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSFileHandle+CreateFile.m"; sourceTree = "<group>"; };
8EFFCD420AA093AF00C458A5 /* DirectoryNode.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DirectoryNode.h; sourceTree = "<group>"; };
8EFFCD430AA093AF00C458A5 /* DirectoryNode.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = DirectoryNode.m; sourceTree = "<group>"; };
8EFFCD440AA093AF00C458A5 /* FileIconCell.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FileIconCell.h; sourceTree = "<group>"; };
@ -470,6 +485,8 @@
177EC01B0B8BC2CF0000BC8C /* TrackingCell.m */,
177EC01C0B8BC2CF0000BC8C /* TrackingSlider.h */,
177EC01D0B8BC2CF0000BC8C /* TrackingSlider.m */,
8E9A30130BA792DC0091081B /* NSFileHandle+CreateFile.h */,
8E9A30140BA792DC0091081B /* NSFileHandle+CreateFile.m */,
);
path = Utils;
sourceTree = "<group>";
@ -630,6 +647,10 @@
8E75753209F31D5A0080F1EE /* PlaylistView.m */,
8E75753309F31D5A0080F1EE /* Shuffle.h */,
8E75753409F31D5A0080F1EE /* Shuffle.m */,
8E9A2E830BA78B500091081B /* SecondsFormatter.h */,
8E9A2E840BA78B500091081B /* SecondsFormatter.m */,
8E9A2ED70BA78D9D0091081B /* IndexFormatter.h */,
8E9A2ED80BA78D9D0091081B /* IndexFormatter.m */,
);
path = Playlist;
sourceTree = "<group>";
@ -796,6 +817,9 @@
1766C6930B911DF1004A7AE4 /* AudioScrobbler.m in Sources */,
1766C6950B911DF1004A7AE4 /* AudioScrobblerClient.m in Sources */,
1755E1F90BA0D2B600CA3560 /* PlaylistLoader.m in Sources */,
8E9A2E860BA78B500091081B /* SecondsFormatter.m in Sources */,
8E9A2EDA0BA78D9D0091081B /* IndexFormatter.m in Sources */,
8E9A30160BA792DC0091081B /* NSFileHandle+CreateFile.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -166,6 +166,7 @@
LANGUAGE = ObjC;
SUPERCLASS = NSObject;
},
{CLASS = SecondsFormatter; LANGUAGE = ObjC; SUPERCLASS = NSFormatter; },
{
ACTIONS = {
changeVolume = id;

View File

@ -7,17 +7,17 @@
<key>IBEditorPositions</key>
<dict>
<key>1063</key>
<string>0 320 136 49 0 0 1680 1028 </string>
<string>0 228 136 49 0 0 1024 746 </string>
<key>1156</key>
<string>719 527 241 366 0 0 1680 1028 </string>
<string>391 336 241 366 0 0 1024 746 </string>
<key>1324</key>
<string>788 657 137 182 0 0 1680 1028 </string>
<string>453 438 137 182 0 0 1024 746 </string>
<key>29</key>
<string>-3 975 383 44 0 0 1680 1028 </string>
<string>-3 696 383 44 0 0 1024 746 </string>
<key>463</key>
<string>669 637 341 145 0 0 1680 1028 </string>
<string>341 447 341 145 0 0 1024 746 </string>
<key>513</key>
<string>352 836 125 137 0 0 1680 1028 </string>
<string>204 571 125 137 0 0 1024 746 </string>
</dict>
<key>IBFramework Version</key>
<string>446.1</string>
@ -34,16 +34,16 @@
<integer>4</integer>
<key>IBOpenObjects</key>
<array>
<integer>1307</integer>
<integer>513</integer>
<integer>1324</integer>
<integer>21</integer>
<integer>463</integer>
<integer>29</integer>
<integer>21</integer>
<integer>1307</integer>
<integer>1063</integer>
<integer>1156</integer>
<integer>1324</integer>
</array>
<key>IBSystem Version</key>
<string>8L2127</string>
<string>8L127</string>
</dict>
</plist>

Binary file not shown.

View File

@ -60,6 +60,6 @@
- (void)addShuffledListToFront;
- (void)resetShuffleList;
- (void)handlePlaylistViewHeaderNotification:(NSNotification*)notif;
- (PlaylistEntry *)entryAtIndex:(int)i;
@end

View File

@ -121,7 +121,7 @@
PlaylistEntry* pe;
while (pe = [enumerator nextObject]) {
tt += [pe length];
tt += [[pe length] doubleValue];
}
int sec = (int)(tt/1000.0);
@ -148,7 +148,7 @@
PlaylistEntry *p;
p = [[self arrangedObjects] objectAtIndex:j];
[p setIndex:j];
[p setIndex:[NSNumber numberWithInt:j]];
}
}
@ -159,7 +159,7 @@
if ([a containsObject:currentEntry])
{
[currentEntry setIndex:-1];
[currentEntry setIndex:[NSNumber numberWithInt:-1]];
}
[super removeObjectsAtArrangedObjectIndexes:indexes];
@ -281,11 +281,11 @@
{
if (shuffle == YES)
{
return [self shuffledEntryAtIndex:[pe shuffleIndex] + 1];
return [self shuffledEntryAtIndex:([[pe shuffleIndex] intValue] + 1)];
}
else
{
return [self entryAtIndex:[pe index] + 1];
return [self entryAtIndex:([[pe index] intValue] + 1)];
}
}
@ -293,18 +293,18 @@
{
if (shuffle == YES)
{
return [self shuffledEntryAtIndex:[pe shuffleIndex] - 1];
return [self shuffledEntryAtIndex:([[pe shuffleIndex] intValue] - 1)];
}
else
{
//Fix for removing a track, then pressing prev with repeat turned on
if ([pe index] == -1)
if ([[pe index] intValue] == -1)
{
return [self entryAtIndex:[pe index]];
return [self entryAtIndex:[[pe index] intValue]];
}
else
{
return [self entryAtIndex:[pe index] - 1];
return [self entryAtIndex:[[pe index] intValue] - 1];
}
}
}
@ -347,7 +347,7 @@
int i;
for (i = 0; i < [shuffleList count]; i++)
{
[[shuffleList objectAtIndex:i] setShuffleIndex:i];
[[shuffleList objectAtIndex:i] setShuffleIndex:[NSNumber numberWithInt:i]];
}
}
@ -361,7 +361,7 @@
int i;
for (i = ([shuffleList count] - [newList count]); i < [shuffleList count]; i++)
{
[[shuffleList objectAtIndex:i] setShuffleIndex:i];
[[shuffleList objectAtIndex:i] setShuffleIndex:[NSNumber numberWithInt:i]];
}
}
@ -372,7 +372,7 @@
[self addShuffledListToFront];
if (currentEntry && [currentEntry index] != -1)
if (currentEntry && [[currentEntry index] intValue] != -1)
{
[shuffleList insertObject:currentEntry atIndex:0];
[currentEntry setShuffleIndex:0];
@ -388,7 +388,7 @@
[shuffleList removeObjectAtIndex:i];
}
[[shuffleList objectAtIndex:i] setShuffleIndex:i];
[[shuffleList objectAtIndex:i] setShuffleIndex:[NSNumber numberWithInt:i]];
}
}
}
@ -403,7 +403,7 @@
[currentEntry setCurrent:NO];
[pe setCurrent:YES];
[tableView scrollRowToVisible:[pe index]];
[tableView scrollRowToVisible:[[pe index] intValue]];
[pe retain];
[currentEntry release];

View File

@ -17,28 +17,26 @@
NSString *genre;
NSString *year;
unsigned int track;
NSNumber *track;
NSString *lengthString;
double length;
int bitrate;
int channels;
int bitsPerSample;
float sampleRate;
NSNumber *length;
NSNumber *bitrate;
NSNumber *channels;
NSNumber *bitsPerSample;
NSNumber *sampleRate;
BOOL current;
int idx; //Can't use index due to some weird bug...might be fixed...should test in the future...think it was a conflict with flac, which is now an external lib
int shuffleIdx;
int displayIdx;
NSNumber *idx;
NSNumber *shuffleIndex;
NSNumber *displayIndex;
}
- (void)setIndex:(int)i;
- (int)index;
- (void)setIndex:(NSNumber *)i;
- (NSNumber *)index;
- (void)setShuffleIndex:(int)si;
- (int)shuffleIndex;
- (void)setShuffleIndex:(NSNumber *)si;
- (NSNumber *)shuffleIndex;
- (void)setURL:(NSURL *)u;
- (NSURL *)url;
@ -54,25 +52,23 @@
- (void)setGenre:(NSString *)s;
- (NSString *)genre;
- (NSString *)lengthString;
- (void)setLengthString:(double)l;
- (void)setYear:(NSString *)y;
- (NSString *)year;
- (void)setTrack:(int)y;
- (int)track;
- (void)setTrack:(NSNumber *)y;
- (NSNumber *)track;
- (void)setLength:(double)l;
- (void)setBitrate:(int) br;
- (void)setChannels:(int)c;
- (void)setBitsPerSample:(int)bps;
- (void)setSampleRate:(float)s;
- (void)setLength:(NSNumber *)l;
- (NSNumber *)length;
- (double)length;
- (int)bitrate;
- (int)channels;
- (int)bitsPerSample;
- (float)sampleRate;
- (void)setBitrate:(NSNumber *) br;
- (NSNumber *)bitrate;
- (void)setChannels:(NSNumber *)c;
- (NSNumber *)channels;
- (void)setBitsPerSample:(NSNumber *)bps;
- (NSNumber *)bitsPerSample;
- (void)setSampleRate:(NSNumber *)s;
- (NSNumber *)sampleRate;
- (void)setMetadata: (NSDictionary *)m;
- (void)readMetadataThread;

View File

@ -17,7 +17,7 @@
self = [super init];
if (self)
{
[self setIndex:0];
[self setIndex:nil];
[self setURL:nil];
}
@ -31,37 +31,32 @@
[super dealloc];
}
-(void)setShuffleIndex:(int)si
-(void)setShuffleIndex:(NSNumber *)si
{
shuffleIdx = si;
[si retain];
[shuffleIndex release];
shuffleIndex = si;
}
-(int)shuffleIndex
-(NSNumber *)shuffleIndex
{
return shuffleIdx;
return shuffleIndex;
}
-(void)setIndex:(int)i
-(void)setIndex:(NSNumber *)i
{
[i retain];
[idx release];
NSLog(@"INDEX: %@", i);
idx = i;
[self setDisplayIndex:i+1];
}
-(int)index
-(NSNumber *)index
{
return idx;
}
-(void)setDisplayIndex:(int)i
{
displayIdx=i;
}
-(int)displayIndex
{
return displayIdx;
}
-(void)setURL:(NSURL *)u
{
[u retain];
@ -155,24 +150,25 @@
return year;
}
- (void)setTrack:(int)t
- (void)setTrack:(NSNumber *)t
{
[t retain];
[track release];
track = t;
}
- (int)track
- (NSNumber *)track
{
return track;
}
- (void)setProperties:(NSDictionary *)dict
{
[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]];
[self setLengthString:[[dict objectForKey:@"length"] doubleValue]];
[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" ]];
}
- (void)readPropertiesThread
@ -182,60 +178,62 @@
[self performSelectorOnMainThread:@selector(setProperties:) withObject:properties waitUntilDone:YES];
}
- (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
- (void)setLength:(NSNumber *)l
{
[l retain];
[length release];
length = l;
}
- (double)length
- (NSNumber *)length
{
return length;
}
- (void)setBitrate:(int) br
- (void)setBitrate:(NSNumber *) br
{
[br retain];
[bitrate release];
bitrate = br;
}
- (int)bitrate
- (NSNumber *)bitrate
{
return bitrate;
}
- (void)setChannels:(int)c
- (void)setChannels:(NSNumber *)c
{
[c retain];
[channels release];
channels = c;
}
- (int)channels
- (NSNumber *)channels
{
return channels;
}
- (void)setBitsPerSample:(int)bps
- (void)setBitsPerSample:(NSNumber *)bps
{
[bps retain];
[bitsPerSample release];
bitsPerSample = bps;
}
- (int)bitsPerSample
- (NSNumber *)bitsPerSample
{
return bitsPerSample;
}
- (void)setSampleRate:(float)s
- (void)setSampleRate:(NSNumber *)s
{
[s retain];
[s release];
sampleRate = s;
}
- (float)sampleRate
- (NSNumber *)sampleRate
{
return sampleRate;
}
@ -255,7 +253,7 @@
[self setAlbum:[m objectForKey:@"album"]];
[self setGenre:[m objectForKey:@"genre"]];
[self setYear:[m objectForKey:@"year"]];
[self setTrack:[[m objectForKey:@"track"] intValue]];
[self setTrack:[m objectForKey:@"track"]];
}
- (void)readMetadataThread
@ -268,7 +266,7 @@
- (NSString *)description
{
return [NSString stringWithFormat:@"PlaylistEntry %i:(%@)",idx, url];
return [NSString stringWithFormat:@"PlaylistEntry %i:(%@)", idx, url];
}
@end

View File

@ -10,6 +10,8 @@
#import "PlaylistController.h"
#import "PlaylistEntry.h"
#import "NSFileHandle+CreateFile.h"
#import "CogAudio/AudioPlayer.h"
@implementation PlaylistLoader
@ -136,8 +138,9 @@
- (BOOL)saveM3u:(NSString *)filename
{
NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:filename];
NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:filename createFile:YES];
if (!fileHandle) {
NSLog(@"Error!");
return NO;
}
[fileHandle truncateFileAtOffset:0];
@ -201,7 +204,7 @@
- (BOOL)savePls:(NSString *)filename
{
NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:filename];
NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:filename createFile:YES];
if (!fileHandle) {
return NO;
}
@ -327,7 +330,7 @@
NSURL *url = [finalURLs objectAtIndex:i];
[pe setURL:url];
[pe setIndex:index+i];
[pe setIndex:[NSNumber numberWithInt:(index+i)]];
[pe setTitle:[[url path] lastPathComponent]];
[entries addObject:pe];

View File

@ -12,6 +12,9 @@
#import "PlaylistHeaderView.h"
#import "IndexFormatter.h"
#import "SecondsFormatter.h"
@implementation PlaylistView
- (void)awakeFromNib
@ -31,7 +34,7 @@
[[c dataCell] setControlSize:s];
[[c dataCell] setFont:f];
}
NSTableHeaderView *currentTableHeaderView = [self headerView];
PlaylistHeaderView *customTableHeaderView = [[PlaylistHeaderView alloc] init];
@ -40,6 +43,14 @@
// [self setColumnAutoresizingStyle:NSTableViewNoColumnAutoresizing];
[self setHeaderView:customTableHeaderView];
NSFormatter *secondsFormatter = [[SecondsFormatter alloc] init];
[[[self tableColumnWithIdentifier:@"length"] dataCell] setFormatter:secondsFormatter];
[secondsFormatter release];
NSFormatter *indexFormatter = [[IndexFormatter alloc] init];
[[[self tableColumnWithIdentifier:@"index"] dataCell] setFormatter:indexFormatter];
[indexFormatter release];
[self setVerticalMotionCanBeginDrag:YES];
}

3
TODO
View File

@ -1,5 +1,2 @@
Make playlist table header menu, (See Play _streamTableHeaderContextMenu).
Make PlaylistEntry numbers use NSNumber.
Instead of LengthString, use a formatter.
Add automatic header seperator without testing explicit types. Pull out binding? Perhaps the table column can do a objectAtIndex and then get a stringValue to get the width.