The object are still not being added to the array correctly, they
are inline
or just all the same object and everything seems to be going wrong.
I know
the first half of the code works for listing the files tags and it
works
exactly as it is supposed to (though it could probably be done
better). The
only thing that the bottom portion of the code needs to do it
create a new
array for each album and update as it goes along through the list
of files
and add each small array to a big array. What is structured so
badly that
makes the whole bottom portion go horribly wrong?
- (void) ListDirectory:(NSString *) dirPath{
BOOL isDir;
NSArrayController * tapesArray = [[[NSArrayController alloc] init]
retain];
NSMutableString *path = [NSMutableString
stringWithString:[directoryPathField stringValue]];
NSString *directory = [[NSString alloc] init];
directory = path;
NSFileManager *filemanager = [NSFileManager defaultManager];
if([filemanager fileExistsAtPath:directory isDirectory:&isDir] &&
isDir){
currentDir = directory;
[currentDir retain];
}
else{
currentDir = [directory stringByDeletingLastPathComponent];
[currentDir retain];
}
NSArray *content = [filemanager directoryContentsAtPath:directory];
// NSLog(@"All Files: %@", content);
int i;
int fileCount = [content count];
for(i = 0; i < fileCount; i++){
TagLib_File *tagFile;
TagLib_Tag *tag;
const TagLib_AudioProperties *tagAudio;
NSString *fullPath;
pathComponents = [NSArray arrayWithObjects: directory, [content
objectAtIndex:i], nil];
fullPath = [NSString pathWithComponents:pathComponents];
if([filemanager fileExistsAtPath:fullPath
isDirectory:&isDir] &&
isDir) continue;
NSString *fileExtension = [fullPath pathExtension];
if(fileExtension == @"flac"){
tagFile = taglib_file_new_type([fullPath UTF8String],
TagLib_File_FLAC);
if(!tagFile) continue;
}
else{
tagFile = taglib_file_new([fullPath UTF8String]);
if(!tagFile) continue;
}
tag = taglib_file_tag(tagFile);
if(!tag) continue;
NSMutableDictionary * tapeObject = [[NSMutableDictionary alloc]
init];
tagAudio = taglib_file_audioproperties(tagFile);
tapeObject = [[tapeObject retain] autorelease];
NSString *venue;
NSString *location;
NSRange aRange = [[NSString stringWithUTF8String:
taglib_tag_album(tag)] rangeOfString:@" - "];
// If we find the split spting " - ", then break it up!
if(aRange.location != NSNotFound){
NSArray *venLoc = [[NSString stringWithUTF8String:
taglib_tag_album(tag)] componentsSeparatedByString:@" - "];
venue = [venLoc objectAtIndex:0];
location = [venLoc objectAtIndex:1];
}
// Else, just use one variable and set location as "None"
else{
venue = [NSString stringWithUTF8String: taglib_tag_album
(tag)];
location = @"None";
}
[tapeObject setValue:[NSString stringWithUTF8String:
taglib_tag_artist(tag)] forKey:@"artist"]; // Artist
[tapeObject setValue:venue forKey:@"venue"];
// Venue
[tapeObject setValue:location forKey:@"location"];
// Location
[tapeObject setValue:[NSString stringWithUTF8String:
taglib_tag_genre(tag)] forKey:@"genre"]; // Genre
[tapeObject setValue:[NSString stringWithFormat:@"%i",
taglib_tag_year(tag)] forKey:@"year"]; // Year
[tapeObject setValue:[NSNumber
numberWithInt:taglib_audioproperties_length(tagAudio)]
forKey:@"length"];
// Length
[tapesArray addObject:tapeObject];
taglib_file_free(tagFile);
taglib_tag_free_strings();
}
NSMutableArray *allTapes = [tapesArray arrangedObjects];
NSLog(@"allTapes:\n %@", allTapes);
//BAD BEGINS
if([allTapes count] == 0) return;
NSString *cur_artist = [[allTapes objectAtIndex:0]
objectForKey:@"artist"];
NSString *cur_venue = [[allTapes objectAtIndex:0]
objectForKey:@"venue"];
NSString *cur_location = [[allTapes objectAtIndex:0]
objectForKey:@"location"];
NSString *cur_genre = [[allTapes objectAtIndex:0]
objectForKey:@"genre"];
NSString *cur_year = [[allTapes objectAtIndex:0]
objectForKey:@"year"];
int cur_length = 0;
int cur_count = 0;
NSMutableArray * bunches = [[NSMutableArray alloc] init];
NSMutableArray * tapeBunch = [[NSMutableArray alloc] init];
bunches = [[bunches retain] autorelease];
tapeBunch = [[tapeBunch retain] autorelease];
int allofthem = [allTapes count];
for(i = 0; i < allofthem; i++){
NSComparisonResult artistResult, venueResult;
NSString *thisArtist = [[allTapes objectAtIndex:i]
objectForKey:@"artist"];
NSString *thisVenue = [[allTapes objectAtIndex:i]
objectForKey:@"venue"];
artistResult = [thisArtist compare:cur_artist];
venueResult = [thisVenue compare:cur_venue];
if(artistResult != NSOrderedSame || venueResult !=
NSOrderedSame ||
i == 0){
cur_artist = [[allTapes objectAtIndex:i]
objectForKey:@"artist"];
cur_venue = [[allTapes objectAtIndex:i]
objectForKey:@"venue"];
cur_location = [[allTapes objectAtIndex:i]
objectForKey:@"location"];
cur_genre = [[allTapes objectAtIndex:i]
objectForKey:@"genre"];
cur_year = [[allTapes objectAtIndex:i]
objectForKey:@"year"];
cur_length = [[[allTapes objectAtIndex:i]
objectForKey:@"length"] intValue];
cur_count = 1;
if(i > 0){ [tapeBunch removeAllObjects]; }
[tapeBunch addObject:cur_artist];
[tapeBunch addObject:cur_venue];
[tapeBunch addObject:cur_location];
[tapeBunch addObject:cur_genre];
[tapeBunch addObject:cur_year];
[tapeBunch addObject:[NSString stringWithFormat:@"%i",
cur_length]];
[tapeBunch addObject:[NSString stringWithFormat:@"%i",
cur_count]];
}
else{
cur_count++;
[tapeBunch replaceObjectAtIndex:6 withObject: [NSString
stringWithFormat:@"%i", cur_count]];
cur_length += [[[allTapes objectAtIndex:i]
objectForKey:@"length"] intValue];
[tapeBunch replaceObjectAtIndex:5 withObject: [NSString
stringWithFormat:@"%i", cur_length]];
}
[bunches addObject:tapeBunch];
}
NSLog(@"bunches:\n %@", bunches);
// BAD ENDS
NSSet *duplicatesRemover = [NSSet
setWithArray:bunches]; //
Create a set of those tapes to be removed
NSMutableArray *uniqueTapes = [duplicatesRemover
allObjects]; //
Create a new array with all of the duplicates remove
NSLog(@"uniqueTapes:\n %@", uniqueTapes);
NSLog(@"Trying to write to file");
// Dump the arrays in the big array to the file as lines
[self writeFile: @"/Users/Shared/temp.txt"
theArray: uniqueTapes
theItemSep: @"\t" // set as tab, not ","
theLineSep: @"\n"]; // or "\r" or "\r\n"
NSLog(@"Done writing to file.");
--
- Matthew
http://eludevisibility.org/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
sweater.com
This email sent to email@hidden