From 61c6cf3285c7ebd34e9af551518847930e4e2899 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Thu, 5 Dec 2019 19:04:46 -0800 Subject: [PATCH] Hopefully fixed metadata parsing for newly added tracks showing up in notifications --- Playlist/PlaylistLoader.h | 3 +++ Playlist/PlaylistLoader.m | 54 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/Playlist/PlaylistLoader.h b/Playlist/PlaylistLoader.h index fd5351034..2da72ad15 100755 --- a/Playlist/PlaylistLoader.h +++ b/Playlist/PlaylistLoader.h @@ -49,6 +49,9 @@ typedef enum { - (void)loadInfoForEntries:(NSArray *)entries; +// To be dispatched on main thread only +- (void)syncLoadInfoForEntries:(NSArray *)entries; + - (NSArray *)acceptableFileTypes; - (NSArray *)acceptablePlaylistTypes; //Only m3u and pls saving - (NSArray *)acceptableContainerTypes; diff --git a/Playlist/PlaylistLoader.m b/Playlist/PlaylistLoader.m index 3d7a57b71..9f57b36a3 100755 --- a/Playlist/PlaylistLoader.m +++ b/Playlist/PlaylistLoader.m @@ -455,7 +455,13 @@ NSMutableDictionary * dictionaryWithPropertiesOfObject(id obj, NSArray * filterL //Clear the selection [playlistController setSelectionIndexes:[NSIndexSet indexSet]]; - [self performSelectorInBackground:@selector(loadInfoForEntries:) withObject:entries]; + + NSArray * firstEntry = [NSArray arrayWithObject:[entries objectAtIndex:0]]; + NSMutableArray * restOfEntries = [NSMutableArray arrayWithArray:entries]; + [restOfEntries removeObjectAtIndex:0]; + + [self performSelectorOnMainThread:@selector(syncLoadInfoForEntries:) withObject:firstEntry waitUntilDone:YES]; + [self performSelectorInBackground:@selector(loadInfoForEntries:) withObject:restOfEntries]; return entries; } @@ -463,6 +469,52 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc dispatch_get_current_queue() == queue ? block() : dispatch_sync(queue, block); } +// To be called on main thread only +- (void)syncLoadInfoForEntries:(NSArray *)entries +{ + NSMutableIndexSet *update_indexes = [[NSMutableIndexSet alloc] init]; + long i; + + i = 0; + for (PlaylistEntry *pe in entries) + { + if ([pe metadataLoaded]) continue; + + [update_indexes addIndex:pe.index]; + + ++i; + } + + if (!i) + { + [self->playlistController updateTotalTime]; + return; + } + + { + for (PlaylistEntry *pe in entries) + { + NSMutableDictionary *entryInfo = [NSMutableDictionary dictionaryWithCapacity:20]; + + NSDictionary *entryProperties = [AudioPropertiesReader propertiesForURL:pe.URL]; + if (entryProperties == nil) + continue; + + [entryInfo addEntriesFromDictionary:entryProperties]; + [entryInfo addEntriesFromDictionary:[AudioMetadataReader metadataForURL:pe.URL]]; + + [pe setMetadata:entryInfo]; + } + } + + [self->playlistController updateTotalTime]; + + { + unsigned long columns = [[[self->playlistView documentView] tableColumns] count]; + [self->playlistView.documentView reloadDataForRowIndexes:update_indexes columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,columns-1)]]; + } +} + - (void)loadInfoForEntries:(NSArray *)entries { NSMutableIndexSet *update_indexes = [[NSMutableIndexSet alloc] init];