2005-06-02 18:16:43 +00:00
|
|
|
//
|
2008-02-10 16:16:45 +00:00
|
|
|
// PlaylistController.m
|
|
|
|
// Cog
|
2005-06-02 18:16:43 +00:00
|
|
|
//
|
2008-02-10 16:16:45 +00:00
|
|
|
// Created by Vincent Spader on 3/18/05.
|
|
|
|
// Copyright 2005 Vincent Spader All rights reserved.
|
2005-06-02 18:16:43 +00:00
|
|
|
//
|
|
|
|
|
2013-10-18 07:17:03 +00:00
|
|
|
#import "PlaylistController.h"
|
2021-01-30 23:14:08 +00:00
|
|
|
#import "PlaybackController.h"
|
2013-10-11 19:33:58 +00:00
|
|
|
#import "PlaylistEntry.h"
|
2007-03-09 01:16:06 +00:00
|
|
|
#import "PlaylistLoader.h"
|
2008-02-19 03:39:43 +00:00
|
|
|
#import "RepeatTransformers.h"
|
2021-01-30 23:14:08 +00:00
|
|
|
#import "Shuffle.h"
|
2009-02-28 06:40:50 +00:00
|
|
|
#import "ShuffleTransformers.h"
|
2021-01-30 23:14:08 +00:00
|
|
|
#import "SpotlightWindowController.h"
|
2008-02-22 02:19:46 +00:00
|
|
|
#import "StatusImageTransformer.h"
|
2008-03-08 23:57:54 +00:00
|
|
|
#import "ToggleQueueTitleTransformer.h"
|
2006-05-07 13:19:23 +00:00
|
|
|
|
2022-02-18 01:07:37 +00:00
|
|
|
#import "NSString+CogSort.h"
|
|
|
|
|
2013-10-11 12:03:55 +00:00
|
|
|
#import "Logging.h"
|
|
|
|
|
2022-06-19 06:00:08 +00:00
|
|
|
#import "Cog-Swift.h"
|
|
|
|
|
2022-06-24 07:29:50 +00:00
|
|
|
#import "AppController.h"
|
|
|
|
#import "SandboxBroker.h"
|
|
|
|
|
2013-10-11 19:33:58 +00:00
|
|
|
#define UNDO_STACK_LIMIT 0
|
|
|
|
|
2022-06-19 08:42:27 +00:00
|
|
|
extern BOOL kAppControllerShuttingDown;
|
|
|
|
|
2022-06-21 07:01:07 +00:00
|
|
|
NSPersistentContainer *kPersistentContainer = nil;
|
2022-06-20 10:35:29 +00:00
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
@implementation PlaylistController
|
|
|
|
|
2008-02-23 19:46:23 +00:00
|
|
|
@synthesize currentEntry;
|
2008-02-24 17:32:50 +00:00
|
|
|
@synthesize totalTime;
|
[Job Queue] Overhauled long action handling
Long actions, such as file opening, playlist loading, metadata loading
and refreshing, etc, are now handled through NSProgress. Additionally,
a new status bar change displays the progress of the task instead of
the total duration of the playlist. Finally, app quit is blocked by a
running task, and if the app is quit while a task is running, it will
be delayed until the task completes, at which time the app will
terminate cleanly.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-15 08:01:45 +00:00
|
|
|
@synthesize currentStatus;
|
2005-06-02 18:16:43 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
static NSArray *cellIdentifiers = nil;
|
2022-01-20 22:59:26 +00:00
|
|
|
|
2022-06-21 07:01:07 +00:00
|
|
|
NSMutableDictionary<NSString *, AlbumArtwork *> *kArtworkDictionary = nil;
|
2022-06-16 14:14:33 +00:00
|
|
|
|
[Job Queue] Overhauled long action handling
Long actions, such as file opening, playlist loading, metadata loading
and refreshing, etc, are now handled through NSProgress. Additionally,
a new status bar change displays the progress of the task instead of
the total duration of the playlist. Finally, app quit is blocked by a
running task, and if the app is quit while a task is running, it will
be delayed until the task completes, at which time the app will
terminate cleanly.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-15 08:01:45 +00:00
|
|
|
static void *playlistControllerContext = &playlistControllerContext;
|
|
|
|
|
2008-02-19 03:39:43 +00:00
|
|
|
+ (void)initialize {
|
2022-02-07 05:49:27 +00:00
|
|
|
cellIdentifiers = @[@"index", @"status", @"title", @"albumartist", @"artist",
|
|
|
|
@"album", @"length", @"year", @"genre", @"track", @"path",
|
2022-06-28 08:55:30 +00:00
|
|
|
@"filename", @"codec", @"rating"];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
NSValueTransformer *repeatNoneTransformer =
|
|
|
|
[[RepeatModeTransformer alloc] initWithMode:RepeatModeNoRepeat];
|
|
|
|
[NSValueTransformer setValueTransformer:repeatNoneTransformer forName:@"RepeatNoneTransformer"];
|
2008-02-19 03:39:43 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSValueTransformer *repeatOneTransformer =
|
|
|
|
[[RepeatModeTransformer alloc] initWithMode:RepeatModeRepeatOne];
|
|
|
|
[NSValueTransformer setValueTransformer:repeatOneTransformer forName:@"RepeatOneTransformer"];
|
2008-02-19 03:39:43 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSValueTransformer *repeatAlbumTransformer =
|
|
|
|
[[RepeatModeTransformer alloc] initWithMode:RepeatModeRepeatAlbum];
|
|
|
|
[NSValueTransformer setValueTransformer:repeatAlbumTransformer
|
|
|
|
forName:@"RepeatAlbumTransformer"];
|
2008-02-19 04:02:05 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSValueTransformer *repeatAllTransformer =
|
|
|
|
[[RepeatModeTransformer alloc] initWithMode:RepeatModeRepeatAll];
|
|
|
|
[NSValueTransformer setValueTransformer:repeatAllTransformer forName:@"RepeatAllTransformer"];
|
2008-02-19 03:39:43 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSValueTransformer *repeatModeImageTransformer = [[RepeatModeImageTransformer alloc] init];
|
|
|
|
[NSValueTransformer setValueTransformer:repeatModeImageTransformer
|
|
|
|
forName:@"RepeatModeImageTransformer"];
|
2009-03-10 04:04:46 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSValueTransformer *shuffleOffTransformer =
|
|
|
|
[[ShuffleModeTransformer alloc] initWithMode:ShuffleOff];
|
|
|
|
[NSValueTransformer setValueTransformer:shuffleOffTransformer forName:@"ShuffleOffTransformer"];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSValueTransformer *shuffleAlbumsTransformer =
|
|
|
|
[[ShuffleModeTransformer alloc] initWithMode:ShuffleAlbums];
|
|
|
|
[NSValueTransformer setValueTransformer:shuffleAlbumsTransformer
|
|
|
|
forName:@"ShuffleAlbumsTransformer"];
|
2009-03-10 04:04:46 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSValueTransformer *shuffleAllTransformer =
|
|
|
|
[[ShuffleModeTransformer alloc] initWithMode:ShuffleAll];
|
|
|
|
[NSValueTransformer setValueTransformer:shuffleAllTransformer forName:@"ShuffleAllTransformer"];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSValueTransformer *shuffleImageTransformer = [[ShuffleImageTransformer alloc] init];
|
|
|
|
[NSValueTransformer setValueTransformer:shuffleImageTransformer
|
|
|
|
forName:@"ShuffleImageTransformer"];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSValueTransformer *statusImageTransformer = [[StatusImageTransformer alloc] init];
|
|
|
|
[NSValueTransformer setValueTransformer:statusImageTransformer
|
|
|
|
forName:@"StatusImageTransformer"];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSValueTransformer *toggleQueueTitleTransformer = [[ToggleQueueTitleTransformer alloc] init];
|
|
|
|
[NSValueTransformer setValueTransformer:toggleQueueTitleTransformer
|
|
|
|
forName:@"ToggleQueueTitleTransformer"];
|
2008-02-19 03:39:43 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)initDefaults {
|
2022-02-07 05:49:27 +00:00
|
|
|
NSDictionary *defaultsDictionary = @{ @"repeat": @(RepeatModeNoRepeat), @"shuffle": @(ShuffleOff) };
|
2008-03-08 23:57:54 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsDictionary];
|
2009-02-28 18:18:56 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (id)initWithCoder:(NSCoder *)decoder {
|
2022-02-07 05:49:27 +00:00
|
|
|
self = [super initWithCoder:decoder];
|
2022-06-16 14:14:33 +00:00
|
|
|
if(!self) return nil;
|
2009-02-28 18:18:56 +00:00
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
shuffleList = [[NSMutableArray alloc] init];
|
|
|
|
queueList = [[NSMutableArray alloc] init];
|
2013-10-11 19:33:58 +00:00
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
undoManager = [[NSUndoManager alloc] init];
|
2013-10-11 19:33:58 +00:00
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
[undoManager setLevelsOfUndo:UNDO_STACK_LIMIT];
|
2013-10-11 19:33:58 +00:00
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
[self initDefaults];
|
|
|
|
|
|
|
|
_persistentContainer = [[NSPersistentContainer alloc] initWithName:@"DataModel"];
|
|
|
|
[self.persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *description, NSError *error) {
|
|
|
|
if(error != nil) {
|
|
|
|
ALog(@"Failed to load Core Data stack: %@", error);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
|
2022-06-21 07:01:07 +00:00
|
|
|
kPersistentContainer = self.persistentContainer;
|
2022-06-16 14:14:33 +00:00
|
|
|
|
|
|
|
self.persistentContainer.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy;
|
|
|
|
|
|
|
|
_persistentArtStorage = [[NSMutableDictionary alloc] init];
|
2022-06-21 07:01:07 +00:00
|
|
|
kArtworkDictionary = self.persistentArtStorage;
|
2005-06-02 18:16:43 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
return self;
|
2021-01-30 23:14:08 +00:00
|
|
|
}
|
2009-02-28 18:18:56 +00:00
|
|
|
|
2022-06-21 07:01:07 +00:00
|
|
|
+ (NSPersistentContainer *)sharedPersistentContainer {
|
|
|
|
return kPersistentContainer;
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)awakeFromNib {
|
2022-02-07 05:49:27 +00:00
|
|
|
[super awakeFromNib];
|
|
|
|
|
|
|
|
statusImageTransformer = [NSValueTransformer valueTransformerForName:@"StatusImageTransformer"];
|
|
|
|
|
|
|
|
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"index" ascending:YES];
|
|
|
|
[self.tableView setSortDescriptors:@[sortDescriptor]];
|
|
|
|
|
|
|
|
[self addObserver:self
|
|
|
|
forKeyPath:@"arrangedObjects"
|
|
|
|
options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld)
|
[Job Queue] Overhauled long action handling
Long actions, such as file opening, playlist loading, metadata loading
and refreshing, etc, are now handled through NSProgress. Additionally,
a new status bar change displays the progress of the task instead of
the total duration of the playlist. Finally, app quit is blocked by a
running task, and if the app is quit while a task is running, it will
be delayed until the task completes, at which time the app will
terminate cleanly.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-15 08:01:45 +00:00
|
|
|
context:playlistControllerContext];
|
|
|
|
[playbackController addObserver:self
|
|
|
|
forKeyPath:@"progressOverall"
|
|
|
|
options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionOld)
|
|
|
|
context:playlistControllerContext];
|
|
|
|
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.fontSize" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:playlistControllerContext];
|
|
|
|
|
|
|
|
observersRegistered = YES;
|
2022-02-10 09:32:09 +00:00
|
|
|
|
|
|
|
[self.tableView setDraggingSourceOperationMask:NSDragOperationCopy forLocal:NO];
|
2008-02-24 17:16:19 +00:00
|
|
|
}
|
|
|
|
|
[Job Queue] Overhauled long action handling
Long actions, such as file opening, playlist loading, metadata loading
and refreshing, etc, are now handled through NSProgress. Additionally,
a new status bar change displays the progress of the task instead of
the total duration of the playlist. Finally, app quit is blocked by a
running task, and if the app is quit while a task is running, it will
be delayed until the task completes, at which time the app will
terminate cleanly.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-15 08:01:45 +00:00
|
|
|
- (void)deinit {
|
|
|
|
if(observersRegistered) {
|
|
|
|
[self removeObserver:self forKeyPath:@"arrangedObjects" context:playlistControllerContext];
|
|
|
|
[playbackController removeObserver:self forKeyPath:@"progressOverall" context:playlistControllerContext];
|
|
|
|
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.fontSize" context:playlistControllerContext];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)startObservingProgress:(NSProgress *)progress {
|
|
|
|
[progress addObserver:self forKeyPath:@"localizedDescription" options:0 context:playlistControllerContext];
|
|
|
|
[progress addObserver:self forKeyPath:@"fractionCompleted" options:0 context:playlistControllerContext];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)stopObservingProgress:(NSProgress *)progress {
|
|
|
|
[progress removeObserver:self forKeyPath:@"localizedDescription" context:playlistControllerContext];
|
|
|
|
[progress removeObserver:self forKeyPath:@"fractionCompleted" context:playlistControllerContext];
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)observeValueForKeyPath:(NSString *)keyPath
|
|
|
|
ofObject:(id)object
|
|
|
|
change:(NSDictionary *)change
|
|
|
|
context:(void *)context {
|
[Job Queue] Overhauled long action handling
Long actions, such as file opening, playlist loading, metadata loading
and refreshing, etc, are now handled through NSProgress. Additionally,
a new status bar change displays the progress of the task instead of
the total duration of the playlist. Finally, app quit is blocked by a
running task, and if the app is quit while a task is running, it will
be delayed until the task completes, at which time the app will
terminate cleanly.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-15 08:01:45 +00:00
|
|
|
if(context == playlistControllerContext) {
|
|
|
|
if([keyPath isEqualToString:@"arrangedObjects"]) {
|
|
|
|
[self updatePlaylistIndexes];
|
|
|
|
[self updateTotalTime];
|
|
|
|
[self.tableView reloadData];
|
|
|
|
} else if([keyPath isEqualToString:@"values.fontSize"]) {
|
|
|
|
[self updateRowSize];
|
|
|
|
} else if([keyPath isEqualToString:@"progressOverall"]) {
|
|
|
|
id objNew = [change objectForKey:NSKeyValueChangeNewKey];
|
|
|
|
id objOld = [change objectForKey:NSKeyValueChangeOldKey];
|
|
|
|
|
|
|
|
NSProgress *progressNew = nil, *progressOld = nil;
|
|
|
|
|
|
|
|
if(objNew && [objNew isKindOfClass:[NSProgress class]])
|
|
|
|
progressNew = (NSProgress *)objNew;
|
|
|
|
if(objOld && [objOld isKindOfClass:[NSProgress class]])
|
|
|
|
progressOld = (NSProgress *)objOld;
|
|
|
|
|
|
|
|
if(progressOld) {
|
|
|
|
[self stopObservingProgress:progressOld];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(progressNew) {
|
|
|
|
[self startObservingProgress:progressNew];
|
|
|
|
}
|
|
|
|
|
|
|
|
[self updateProgressText];
|
|
|
|
} else if([keyPath isEqualToString:@"localizedDescription"] ||
|
|
|
|
[keyPath isEqualToString:@"fractionCompleted"]) {
|
|
|
|
[self updateProgressText];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateProgressText {
|
|
|
|
NSString *description = nil;
|
|
|
|
if(playbackController.progressOverall) {
|
|
|
|
if(playbackController.progressJob) {
|
|
|
|
description = [NSString stringWithFormat:@"%@ - %@", playbackController.progressOverall.localizedDescription, playbackController.progressJob.localizedDescription];
|
|
|
|
} else {
|
|
|
|
description = playbackController.progressOverall.localizedDescription;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(description) {
|
|
|
|
[self setTotalTime:nil];
|
|
|
|
description = [description stringByAppendingFormat:@" - %.2f%% complete", playbackController.progressOverall.fractionCompleted * 100.0];
|
|
|
|
[self setCurrentStatus:description];
|
|
|
|
} else {
|
|
|
|
[self setCurrentStatus:nil];
|
2022-02-07 05:49:27 +00:00
|
|
|
[self updateTotalTime];
|
|
|
|
}
|
2008-02-24 17:32:50 +00:00
|
|
|
}
|
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
- (void)commitPersistentStore {
|
|
|
|
NSError *error = nil;
|
|
|
|
[self.persistentContainer.viewContext save:&error];
|
|
|
|
if(error) {
|
|
|
|
ALog(@"Error committing playlist storage: %@", [error localizedDescription]);
|
[Job Queue] Overhauled long action handling
Long actions, such as file opening, playlist loading, metadata loading
and refreshing, etc, are now handled through NSProgress. Additionally,
a new status bar change displays the progress of the task instead of
the total duration of the playlist. Finally, app quit is blocked by a
running task, and if the app is quit while a task is running, it will
be delayed until the task completes, at which time the app will
terminate cleanly.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-15 08:01:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 06:00:08 +00:00
|
|
|
- (void)updatePlayCountForTrack:(PlaylistEntry *)pe {
|
2022-06-21 02:13:33 +00:00
|
|
|
if(pe.countAdded) return;
|
|
|
|
pe.countAdded = YES;
|
|
|
|
|
2022-06-19 06:00:08 +00:00
|
|
|
PlayCount *pc = pe.playCountItem;
|
|
|
|
|
|
|
|
if(pc) {
|
|
|
|
pc.count += 1;
|
|
|
|
pc.lastPlayed = [NSDate date];
|
|
|
|
} else {
|
|
|
|
pc = [NSEntityDescription insertNewObjectForEntityForName:@"PlayCount" inManagedObjectContext:self.persistentContainer.viewContext];
|
|
|
|
pc.count = 1;
|
|
|
|
pc.firstSeen = pc.lastPlayed = [NSDate date];
|
|
|
|
pc.album = pe.album;
|
|
|
|
pc.artist = pe.artist;
|
|
|
|
pc.title = pe.title;
|
2022-06-26 11:37:41 +00:00
|
|
|
pc.filename = pe.filenameFragment;
|
2022-06-19 06:00:08 +00:00
|
|
|
}
|
|
|
|
|
2022-06-28 04:49:32 +00:00
|
|
|
[self commitPersistentStore];
|
2022-06-19 06:00:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)firstSawTrack:(PlaylistEntry *)pe {
|
|
|
|
PlayCount *pc = pe.playCountItem;
|
|
|
|
|
|
|
|
if(!pc) {
|
|
|
|
pc = [NSEntityDescription insertNewObjectForEntityForName:@"PlayCount" inManagedObjectContext:self.persistentContainer.viewContext];
|
|
|
|
pc.count = 0;
|
|
|
|
pc.firstSeen = [NSDate date];
|
|
|
|
pc.album = pe.album;
|
|
|
|
pc.artist = pe.artist;
|
|
|
|
pc.title = pe.title;
|
2022-06-26 11:37:41 +00:00
|
|
|
pc.filename = pe.filenameFragment;
|
2022-06-19 06:00:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-28 08:55:30 +00:00
|
|
|
- (void)ratingUpdatedWithEntry:(PlaylistEntry *)pe rating:(CGFloat)rating {
|
|
|
|
if(pe && !pe.deLeted) {
|
|
|
|
PlayCount *pc = pe.playCountItem;
|
|
|
|
|
|
|
|
if(!pc) {
|
|
|
|
pc = [NSEntityDescription insertNewObjectForEntityForName:@"PlayCount" inManagedObjectContext:self.persistentContainer.viewContext];
|
|
|
|
pc.count = 0;
|
|
|
|
pc.firstSeen = [NSDate date];
|
|
|
|
pc.album = pe.album;
|
|
|
|
pc.artist = pe.artist;
|
|
|
|
pc.title = pe.title;
|
|
|
|
pc.filename = pe.filenameFragment;
|
|
|
|
}
|
|
|
|
|
|
|
|
pc.rating = rating;
|
|
|
|
|
|
|
|
[self commitPersistentStore];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-28 04:50:14 +00:00
|
|
|
- (void)resetPlayCountForTrack:(PlaylistEntry *)pe {
|
|
|
|
PlayCount *pc = pe.playCountItem;
|
|
|
|
|
|
|
|
if(pc) {
|
|
|
|
pc.count = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-28 08:55:30 +00:00
|
|
|
- (void)removeRatingForTrack:(PlaylistEntry *)pe {
|
|
|
|
PlayCount *pc = pe.playCountItem;
|
|
|
|
|
|
|
|
if(pc) {
|
|
|
|
pc.rating = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)updatePlaylistIndexes {
|
2022-02-07 05:49:27 +00:00
|
|
|
NSArray *arranged = [self arrangedObjects];
|
|
|
|
NSUInteger n = [arranged count];
|
|
|
|
BOOL updated = NO;
|
|
|
|
for(NSUInteger i = 0; i < n; i++) {
|
|
|
|
PlaylistEntry *pe = arranged[i];
|
|
|
|
if(pe.index != i) { // Make sure we don't get into some kind of crazy observing loop...
|
|
|
|
pe.index = i;
|
|
|
|
updated = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(updated) {
|
2022-06-16 14:14:33 +00:00
|
|
|
[self commitPersistentStore];
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
2008-02-24 17:16:19 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)updateTotalTime {
|
2022-02-07 05:49:27 +00:00
|
|
|
double tt = 0;
|
|
|
|
ldiv_t hoursAndMinutes;
|
|
|
|
ldiv_t daysAndHours;
|
|
|
|
ldiv_t weeksAndDays;
|
|
|
|
|
|
|
|
for(PlaylistEntry *pe in [self arrangedObjects]) {
|
|
|
|
if(!isnan([pe.length doubleValue])) tt += [pe.length doubleValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
long sec = (long)(tt);
|
|
|
|
hoursAndMinutes = ldiv(sec / 60, 60);
|
2022-07-01 17:54:39 +00:00
|
|
|
|
|
|
|
NSString *week = NSLocalizedString(@"%1d week(s)", @"week for total");
|
|
|
|
NSString *day = NSLocalizedString(@"%1d day(s)", @"day for total");
|
|
|
|
NSString *hour = NSLocalizedString(@"%1d hour(s)", @"hour for total");
|
|
|
|
NSString *min = NSLocalizedString(@"%1d minute(s)", @"minute for total");
|
|
|
|
NSString *second = NSLocalizedString(@"%1d second(s)", @"second for total");
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
if(hoursAndMinutes.quot >= 24) {
|
|
|
|
daysAndHours = ldiv(hoursAndMinutes.quot, 24);
|
|
|
|
if(daysAndHours.quot >= 7) {
|
|
|
|
weeksAndDays = ldiv(daysAndHours.quot, 7);
|
2022-07-01 17:54:39 +00:00
|
|
|
|
|
|
|
NSString *weekCount = [NSString localizedStringWithFormat:week, weeksAndDays.quot];
|
|
|
|
NSString *dayCount = [NSString localizedStringWithFormat:day, weeksAndDays.rem];
|
|
|
|
NSString *hourCount = [NSString localizedStringWithFormat:hour, daysAndHours.rem];
|
|
|
|
NSString *minuteCount = [NSString localizedStringWithFormat:min, hoursAndMinutes.rem];
|
|
|
|
NSString *secCount = [NSString localizedStringWithFormat:second, sec % 60];
|
|
|
|
|
|
|
|
[self setTotalTime:[NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"wdhms", "weeks, days, hours, minutes and seconds"),
|
|
|
|
weekCount, dayCount, hourCount, minuteCount, secCount]];
|
2022-02-07 05:49:27 +00:00
|
|
|
} else {
|
2022-07-01 17:54:39 +00:00
|
|
|
|
|
|
|
NSString *dayCount = [NSString localizedStringWithFormat:day, daysAndHours.quot];
|
|
|
|
NSString *hourCount = [NSString localizedStringWithFormat:hour, daysAndHours.rem];
|
|
|
|
NSString *minuteCount = [NSString localizedStringWithFormat:min, hoursAndMinutes.rem];
|
|
|
|
NSString *secCount = [NSString localizedStringWithFormat:second, sec % 60];
|
|
|
|
|
|
|
|
[self setTotalTime:[NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"dhms", "days, hours, minutes and seconds"),
|
|
|
|
dayCount, hourCount, minuteCount, secCount]];
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(hoursAndMinutes.quot > 0) {
|
2022-07-01 17:54:39 +00:00
|
|
|
NSString *hourCount = [NSString localizedStringWithFormat:hour, hoursAndMinutes.quot];
|
|
|
|
NSString *minuteCount = [NSString localizedStringWithFormat:min, hoursAndMinutes.rem];
|
|
|
|
NSString *secCount = [NSString localizedStringWithFormat:second, sec % 60];
|
|
|
|
|
|
|
|
[self setTotalTime:[NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"hms", "hours, minutes and seconds"),
|
|
|
|
hourCount, minuteCount, secCount]];
|
2022-02-07 05:49:27 +00:00
|
|
|
} else {
|
|
|
|
if(hoursAndMinutes.rem > 0) {
|
2022-07-01 17:54:39 +00:00
|
|
|
NSString *minuteCount = [NSString localizedStringWithFormat:min, hoursAndMinutes.rem];
|
|
|
|
NSString *secCount = [NSString localizedStringWithFormat:second, sec % 60];
|
|
|
|
|
|
|
|
[self setTotalTime:[NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"ms", "minutes and seconds"),
|
|
|
|
minuteCount, secCount]];
|
2022-02-07 05:49:27 +00:00
|
|
|
} else {
|
2022-07-01 17:54:39 +00:00
|
|
|
NSString *secCount = [NSString localizedStringWithFormat:second, sec];
|
|
|
|
|
|
|
|
[self setTotalTime:secCount];
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSView *_Nullable)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *_Nullable)tableColumn row:(NSInteger)row {
|
|
|
|
NSImage *cellImage = nil;
|
|
|
|
NSString *cellText = @"";
|
|
|
|
NSString *cellIdentifier = @"";
|
|
|
|
NSTextAlignment cellTextAlignment = NSTextAlignmentLeft;
|
|
|
|
|
|
|
|
PlaylistEntry *pe = [[self arrangedObjects] objectAtIndex:row];
|
|
|
|
|
|
|
|
float fontSize = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] floatForKey:@"fontSize"];
|
2022-06-28 08:55:30 +00:00
|
|
|
|
|
|
|
BOOL cellRating = NO;
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
if(pe) {
|
|
|
|
cellIdentifier = [tableColumn identifier];
|
|
|
|
NSUInteger index = [cellIdentifiers indexOfObject:cellIdentifier];
|
|
|
|
|
|
|
|
switch(index) {
|
|
|
|
case 0:
|
2022-06-16 14:14:33 +00:00
|
|
|
cellText = [NSString stringWithFormat:@"%lld", pe.index + 1];
|
2022-02-07 05:49:27 +00:00
|
|
|
cellTextAlignment = NSTextAlignmentRight;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2022-06-16 14:14:33 +00:00
|
|
|
cellImage = [statusImageTransformer transformedValue:pe.status];
|
2022-02-07 05:49:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2022-06-16 14:14:33 +00:00
|
|
|
if([pe title]) cellText = pe.title;
|
2022-02-07 05:49:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2022-06-16 14:14:33 +00:00
|
|
|
if([pe albumartist]) cellText = pe.albumartist;
|
2022-02-07 05:49:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
2022-06-16 14:14:33 +00:00
|
|
|
if([pe artist]) cellText = pe.artist;
|
2022-02-07 05:49:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
2022-06-16 14:14:33 +00:00
|
|
|
if([pe album]) cellText = pe.album;
|
2022-02-07 05:49:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
2022-06-16 14:14:33 +00:00
|
|
|
cellText = pe.lengthText;
|
2022-02-07 05:49:27 +00:00
|
|
|
cellTextAlignment = NSTextAlignmentRight;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:
|
2022-06-16 14:14:33 +00:00
|
|
|
if([pe year]) cellText = pe.yearText;
|
2022-02-07 05:49:27 +00:00
|
|
|
cellTextAlignment = NSTextAlignmentRight;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
2022-06-16 14:14:33 +00:00
|
|
|
if([pe genre]) cellText = pe.genre;
|
2022-02-07 05:49:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 9:
|
2022-06-16 14:14:33 +00:00
|
|
|
if([pe track]) cellText = pe.trackText;
|
2022-02-07 05:49:27 +00:00
|
|
|
cellTextAlignment = NSTextAlignmentRight;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 10:
|
2022-06-16 14:14:33 +00:00
|
|
|
if([pe path]) cellText = pe.path;
|
2022-02-07 05:49:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 11:
|
2022-06-16 14:14:33 +00:00
|
|
|
if([pe filename]) cellText = pe.filename;
|
2022-02-07 05:49:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 12:
|
2022-06-16 14:14:33 +00:00
|
|
|
if([pe codec]) cellText = pe.codec;
|
2022-02-07 05:49:27 +00:00
|
|
|
break;
|
2022-06-28 08:55:30 +00:00
|
|
|
|
|
|
|
case 13:
|
|
|
|
{
|
|
|
|
NSString *filledStar = @"★";
|
|
|
|
NSString *emptyStar = @"☆";
|
|
|
|
NSUInteger rating = (NSUInteger)ceil(pe.rating);
|
|
|
|
if(rating < 0)
|
|
|
|
rating = 0;
|
|
|
|
else if(rating > 5)
|
|
|
|
rating = 5;
|
|
|
|
cellText = [@"" stringByPaddingToLength:rating withString:filledStar startingAtIndex:0];
|
|
|
|
cellText = [cellText stringByPaddingToLength:5 withString:emptyStar startingAtIndex:0];
|
|
|
|
cellRating = YES;
|
|
|
|
break;
|
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NSView *view = [tableView makeViewWithIdentifier:cellIdentifier owner:nil];
|
|
|
|
if(view) {
|
|
|
|
NSTableCellView *cellView = (NSTableCellView *)view;
|
|
|
|
NSRect frameRect = cellView.frame;
|
|
|
|
frameRect.origin.y = 1;
|
|
|
|
frameRect.size.height = tableView.rowHeight;
|
|
|
|
cellView.frame = frameRect;
|
|
|
|
|
|
|
|
if(cellView.textField) {
|
|
|
|
cellView.textField.allowsDefaultTighteningForTruncation = YES;
|
|
|
|
|
2022-06-03 23:46:37 +00:00
|
|
|
NSFont *font = [NSFont monospacedDigitSystemFontOfSize:fontSize weight:NSFontWeightRegular];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
cellView.textField.font = font;
|
|
|
|
cellView.textField.stringValue = cellText;
|
|
|
|
cellView.textField.alignment = cellTextAlignment;
|
|
|
|
|
|
|
|
if(cellView.textField.intrinsicContentSize.width > cellView.textField.frame.size.width - 4)
|
|
|
|
cellView.textField.toolTip = cellText;
|
|
|
|
else
|
|
|
|
cellView.textField.toolTip = [pe statusMessage];
|
|
|
|
|
|
|
|
NSRect cellFrameRect = cellView.textField.frame;
|
|
|
|
cellFrameRect.origin.y = 1;
|
|
|
|
cellFrameRect.size.height = frameRect.size.height;
|
|
|
|
cellView.textField.frame = cellFrameRect;
|
|
|
|
}
|
|
|
|
if(cellView.imageView) {
|
|
|
|
cellView.imageView.image = cellImage;
|
|
|
|
cellView.imageView.toolTip = [pe statusMessage];
|
|
|
|
|
|
|
|
NSRect cellFrameRect = cellView.imageView.frame;
|
|
|
|
cellFrameRect.size.height = frameRect.size.height * 14.0 / 18.0;
|
|
|
|
cellFrameRect.origin.y = (frameRect.size.height - cellFrameRect.size.height) * 0.5;
|
|
|
|
cellView.imageView.frame = cellFrameRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
cellView.rowSizeStyle = NSTableViewRowSizeStyleCustom;
|
|
|
|
}
|
|
|
|
|
|
|
|
return view;
|
2006-04-29 00:03:28 +00:00
|
|
|
}
|
|
|
|
|
2022-06-28 08:55:30 +00:00
|
|
|
- (void)tableView:(NSTableView *)view didClickRow:(NSInteger)clickedRow column:(NSInteger)clickedColumn atPoint:(NSPoint)cellPoint {
|
|
|
|
NSTableColumn *column = [view tableColumns][clickedColumn];
|
|
|
|
NSString *cellIdentifier = [column identifier];
|
|
|
|
NSUInteger index = [cellIdentifiers indexOfObject:cellIdentifier];
|
|
|
|
if(index == 13) {
|
|
|
|
NSInteger rating = ((CGFloat)ceil(cellPoint.x * 5.0 / 64.0));
|
|
|
|
if(rating < 1) rating = 1;
|
|
|
|
else if(rating > 5) rating = 5;
|
|
|
|
|
|
|
|
PlaylistEntry *pe = [[self arrangedObjects] objectAtIndex:clickedRow];
|
|
|
|
|
|
|
|
[self ratingUpdatedWithEntry:pe rating:rating];
|
|
|
|
|
|
|
|
NSIndexSet *refreshRow = [NSIndexSet indexSetWithIndex:clickedRow];
|
|
|
|
NSIndexSet *refreshColumn = [NSIndexSet indexSetWithIndex:clickedColumn];
|
|
|
|
|
|
|
|
[self.tableView reloadDataForRowIndexes:refreshRow columnIndexes:refreshColumn];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-20 22:59:26 +00:00
|
|
|
- (void)updateRowSize {
|
2022-02-07 05:49:27 +00:00
|
|
|
[self.tableView reloadData];
|
|
|
|
if(currentEntry != nil) [self.tableView scrollRowToVisible:currentEntry.index];
|
2022-01-20 22:59:26 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 05:04:17 +00:00
|
|
|
- (void)updateNextAfterDeleted:(PlaylistEntry *)lastEntry withDeleteIndexes:(NSIndexSet *)indexes {
|
|
|
|
__block PlaylistEntry *pe = nil;
|
|
|
|
NSArray *allObjects = [self arrangedObjects];
|
|
|
|
[indexes enumerateRangesUsingBlock:^(NSRange range, BOOL *_Nonnull stop) {
|
|
|
|
if(range.location <= lastEntry.index &&
|
|
|
|
range.location + range.length > lastEntry.index) {
|
|
|
|
NSUInteger index = range.location + range.length;
|
|
|
|
if(index < [allObjects count])
|
|
|
|
pe = [allObjects objectAtIndex:index];
|
|
|
|
else
|
|
|
|
pe = nil;
|
|
|
|
} else if(pe && range.location <= [pe index] &&
|
|
|
|
range.location + range.length > [pe index]) {
|
|
|
|
NSUInteger index = range.location + range.length;
|
|
|
|
if(index < [allObjects count])
|
|
|
|
pe = [allObjects objectAtIndex:index];
|
|
|
|
else
|
|
|
|
pe = nil;
|
|
|
|
} else if(pe && range.location > [pe index]) {
|
|
|
|
*stop = YES;
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
nextEntryAfterDeleted = pe;
|
|
|
|
}
|
|
|
|
|
2022-01-20 22:59:26 +00:00
|
|
|
- (void)tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn {
|
2022-02-07 05:49:27 +00:00
|
|
|
if([self shuffle] != ShuffleOff) [self resetShuffleList];
|
2022-02-18 09:57:19 +00:00
|
|
|
|
|
|
|
NSUInteger index = [cellIdentifiers indexOfObject:[tableColumn identifier]];
|
|
|
|
|
2022-06-11 20:42:42 +00:00
|
|
|
NSSortDescriptor *sortDescriptor;/* = [tableColumn sortDescriptorPrototype];*/
|
|
|
|
NSArray *sortDescriptors;/* = sortDescriptor ? @[sortDescriptor] : @[];*/
|
2022-02-18 09:57:19 +00:00
|
|
|
|
|
|
|
BOOL ascending;
|
|
|
|
|
|
|
|
NSImage *indicatorImage = [tableView indicatorImageInTableColumn:tableColumn];
|
|
|
|
NSImage *sortAscending = [NSImage imageNamed:@"NSAscendingSortIndicator"];
|
|
|
|
NSImage *sortDescending = [NSImage imageNamed:@"NSDescendingSortIndicator"];
|
|
|
|
|
|
|
|
if(indicatorImage == sortAscending) {
|
|
|
|
[tableView setIndicatorImage:sortDescending inTableColumn:tableColumn];
|
|
|
|
ascending = NO;
|
|
|
|
} else {
|
|
|
|
[tableView setIndicatorImage:sortAscending inTableColumn:tableColumn];
|
|
|
|
ascending = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(index) {
|
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
sortDescriptors = @[];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
case 8:
|
|
|
|
case 10:
|
|
|
|
case 11:
|
|
|
|
case 12:
|
|
|
|
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:[tableColumn identifier] ascending:ascending selector:@selector(caseInsensitiveCompare:)];
|
|
|
|
sortDescriptors = @[sortDescriptor];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
case 7:
|
|
|
|
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:[tableColumn identifier] ascending:ascending selector:@selector(compareTrackNumbers:)];
|
|
|
|
sortDescriptors = @[sortDescriptor];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 9: {
|
|
|
|
// Unfortunately, this makes the column header bug out. No way around it.
|
|
|
|
sortDescriptors = @[
|
|
|
|
[[NSSortDescriptor alloc] initWithKey:@"albumartist"
|
|
|
|
ascending:ascending
|
|
|
|
selector:@selector(caseInsensitiveCompare:)],
|
|
|
|
[[NSSortDescriptor alloc] initWithKey:@"album"
|
|
|
|
ascending:ascending
|
|
|
|
selector:@selector(caseInsensitiveCompare:)],
|
2022-02-18 10:23:08 +00:00
|
|
|
[[NSSortDescriptor alloc] initWithKey:@"disc" // Yes, this, even though it's not actually a column
|
|
|
|
ascending:ascending
|
|
|
|
selector:@selector(compareTrackNumbers:)],
|
2022-02-18 09:57:19 +00:00
|
|
|
[[NSSortDescriptor alloc] initWithKey:@"track"
|
|
|
|
ascending:ascending
|
|
|
|
selector:@selector(compareTrackNumbers:)]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[self setSortDescriptors:sortDescriptors];
|
2008-02-22 02:19:46 +00:00
|
|
|
}
|
|
|
|
|
2022-01-21 05:48:23 +00:00
|
|
|
// This action is only needed to revert the one that follows it
|
|
|
|
- (void)moveObjectsFromIndex:(NSUInteger)fromIndex
|
|
|
|
toArrangedObjectIndexes:(NSIndexSet *)indexSet {
|
2022-02-07 05:49:27 +00:00
|
|
|
[[[self undoManager] prepareWithInvocationTarget:self]
|
|
|
|
moveObjectsInArrangedObjectsFromIndexes:indexSet
|
|
|
|
toIndex:fromIndex];
|
|
|
|
NSString *actionName =
|
|
|
|
[NSString stringWithFormat:@"Reordering %lu entries", (unsigned long)[indexSet count]];
|
|
|
|
[[self undoManager] setActionName:actionName];
|
2022-01-21 05:48:23 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[super moveObjectsFromIndex:fromIndex toArrangedObjectIndexes:indexSet];
|
2022-01-21 05:48:23 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[playbackController playlistDidChange:self];
|
2022-01-21 05:48:23 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet *)indexSet
|
2021-04-30 01:16:24 +00:00
|
|
|
toIndex:(NSUInteger)insertIndex {
|
2022-02-07 05:49:27 +00:00
|
|
|
[[[self undoManager] prepareWithInvocationTarget:self]
|
|
|
|
moveObjectsFromIndex:insertIndex
|
|
|
|
toArrangedObjectIndexes:indexSet];
|
|
|
|
NSString *actionName =
|
|
|
|
[NSString stringWithFormat:@"Reordering %lu entries", (unsigned long)[indexSet count]];
|
|
|
|
[[self undoManager] setActionName:actionName];
|
|
|
|
|
|
|
|
[super moveObjectsInArrangedObjectsFromIndexes:indexSet toIndex:insertIndex];
|
2022-01-21 05:48:23 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[playbackController playlistDidChange:self];
|
2008-02-24 15:47:04 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (id<NSPasteboardWriting>)tableView:(NSTableView *)tableView
|
|
|
|
pasteboardWriterForRow:(NSInteger)row {
|
|
|
|
NSPasteboardItem *item = (NSPasteboardItem *)[super tableView:tableView
|
|
|
|
pasteboardWriterForRow:row];
|
|
|
|
if(!item) {
|
|
|
|
item = [[NSPasteboardItem alloc] init];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSMutableArray *filenames = [NSMutableArray array];
|
|
|
|
PlaylistEntry *song = [[self arrangedObjects] objectAtIndex:row];
|
|
|
|
[filenames addObject:[[song path] stringByExpandingTildeInPath]];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-06-23 05:54:32 +00:00
|
|
|
[item setData:[song.url dataRepresentation] forType:NSPasteboardTypeFileURL];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
return item;
|
2008-02-10 19:35:58 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (BOOL)tableView:(NSTableView *)tv
|
2022-02-07 05:49:27 +00:00
|
|
|
acceptDrop:(id<NSDraggingInfo>)info
|
2021-01-30 23:14:08 +00:00
|
|
|
row:(NSInteger)row
|
|
|
|
dropOperation:(NSTableViewDropOperation)op {
|
2022-02-07 05:49:27 +00:00
|
|
|
// Check if DNDArrayController handles it.
|
|
|
|
if([super tableView:tv acceptDrop:info row:row dropOperation:op]) return YES;
|
|
|
|
|
|
|
|
if(row < 0) row = 0;
|
|
|
|
|
|
|
|
// Determine the type of object that was dropped
|
|
|
|
NSArray *supportedTypes =
|
2022-06-23 05:54:32 +00:00
|
|
|
@[CogUrlsPboardType, NSPasteboardTypeFileURL, iTunesDropType];
|
2022-02-07 05:49:27 +00:00
|
|
|
NSPasteboard *pboard = [info draggingPasteboard];
|
|
|
|
NSString *bestType = [pboard availableTypeFromArray:supportedTypes];
|
|
|
|
|
|
|
|
NSMutableArray *acceptedURLs = [[NSMutableArray alloc] init];
|
|
|
|
|
|
|
|
// Get files from an file drawer drop
|
|
|
|
if([bestType isEqualToString:CogUrlsPboardType]) {
|
|
|
|
NSError *error;
|
|
|
|
NSData *data = [pboard dataForType:CogUrlsPboardType];
|
|
|
|
NSArray *urls;
|
|
|
|
if(@available(macOS 11.0, *)) {
|
|
|
|
urls = [NSKeyedUnarchiver unarchivedArrayOfObjectsOfClass:[NSURL class]
|
|
|
|
fromData:data
|
|
|
|
error:&error];
|
|
|
|
} else {
|
2022-06-23 05:54:32 +00:00
|
|
|
NSSet *allowed = [NSSet setWithArray:@[[NSArray class], [NSURL class]]];
|
|
|
|
urls = [NSKeyedUnarchiver unarchivedObjectOfClasses:allowed
|
|
|
|
fromData:data
|
|
|
|
error:&error];
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
|
|
|
if(!urls) {
|
|
|
|
DLog(@"%@", error);
|
|
|
|
} else {
|
|
|
|
DLog(@"URLS: %@", urls);
|
|
|
|
}
|
|
|
|
//[playlistLoader insertURLs: urls atIndex:row sort:YES];
|
|
|
|
[acceptedURLs addObjectsFromArray:urls];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get files from a normal file drop (such as from Finder)
|
2022-06-23 05:54:32 +00:00
|
|
|
if([bestType isEqualToString:NSPasteboardTypeFileURL]) {
|
2022-02-07 05:49:27 +00:00
|
|
|
NSArray<Class> *classes = @[[NSURL class]];
|
|
|
|
NSDictionary *options = @{};
|
|
|
|
NSArray<NSURL *> *files = [pboard readObjectsForClasses:classes options:options];
|
|
|
|
|
|
|
|
//[playlistLoader insertURLs:urls atIndex:row sort:YES];
|
|
|
|
[acceptedURLs addObjectsFromArray:files];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get files from an iTunes drop
|
|
|
|
if([bestType isEqualToString:iTunesDropType]) {
|
|
|
|
NSDictionary *iTunesDict = [pboard propertyListForType:iTunesDropType];
|
|
|
|
NSDictionary *tracks = [iTunesDict valueForKey:@"Tracks"];
|
|
|
|
|
|
|
|
// Convert the iTunes URLs to URLs....MWAHAHAH!
|
|
|
|
NSMutableArray *urls = [[NSMutableArray alloc] init];
|
|
|
|
|
|
|
|
for(NSDictionary *trackInfo in [tracks allValues]) {
|
|
|
|
[urls addObject:[NSURL URLWithString:[trackInfo valueForKey:@"Location"]]];
|
|
|
|
}
|
|
|
|
|
|
|
|
//[playlistLoader insertURLs:urls atIndex:row sort:YES];
|
|
|
|
[acceptedURLs addObjectsFromArray:urls];
|
|
|
|
}
|
|
|
|
|
|
|
|
if([acceptedURLs count]) {
|
|
|
|
[self willInsertURLs:acceptedURLs origin:URLOriginInternal];
|
|
|
|
|
|
|
|
if(![[self content] count]) {
|
|
|
|
row = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSArray *entries = [playlistLoader insertURLs:acceptedURLs atIndex:row sort:YES];
|
|
|
|
[self didInsertURLs:entries origin:URLOriginInternal];
|
|
|
|
}
|
|
|
|
|
|
|
|
if([self shuffle] != ShuffleOff) [self resetShuffleList];
|
|
|
|
|
|
|
|
return YES;
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (NSUndoManager *)undoManager {
|
2022-02-07 05:49:27 +00:00
|
|
|
return undoManager;
|
2008-02-10 16:16:45 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (NSIndexSet *)disarrangeIndexes:(NSIndexSet *)indexes {
|
2022-02-07 05:49:27 +00:00
|
|
|
if([[self arrangedObjects] count] <= [indexes lastIndex]) return indexes;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSMutableIndexSet *disarrangedIndexes = [[NSMutableIndexSet alloc] init];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *_Nonnull stop) {
|
|
|
|
[disarrangedIndexes addIndex:[[self content] indexOfObject:[[self arrangedObjects] objectAtIndex:idx]]];
|
|
|
|
}];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
return disarrangedIndexes;
|
2013-10-18 08:47:48 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (NSArray *)disarrangeObjects:(NSArray *)objects {
|
2022-02-07 05:49:27 +00:00
|
|
|
NSMutableArray *disarrangedObjects = [[NSMutableArray alloc] init];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
for(PlaylistEntry *pe in [self content]) {
|
|
|
|
if([objects containsObject:pe]) [disarrangedObjects addObject:pe];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
return disarrangedObjects;
|
2013-10-18 08:47:48 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (NSIndexSet *)rearrangeIndexes:(NSIndexSet *)indexes {
|
2022-02-07 05:49:27 +00:00
|
|
|
if([[self content] count] <= [indexes lastIndex]) return indexes;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSMutableIndexSet *rearrangedIndexes = [[NSMutableIndexSet alloc] init];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *_Nonnull stop) {
|
|
|
|
[rearrangedIndexes addIndex:[[self arrangedObjects] indexOfObject:[[self content] objectAtIndex:idx]]];
|
|
|
|
}];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
return rearrangedIndexes;
|
2013-10-18 08:47:48 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)insertObjects:(NSArray *)objects atIndexes:(NSIndexSet *)indexes {
|
2022-02-07 05:49:27 +00:00
|
|
|
[self insertObjects:objects atArrangedObjectIndexes:indexes];
|
|
|
|
[self rearrangeObjects];
|
2013-10-18 08:47:48 +00:00
|
|
|
}
|
|
|
|
|
2022-02-11 05:35:13 +00:00
|
|
|
- (void)untrashObjects:(NSArray *)objects atIndexes:(NSIndexSet *)indexes {
|
|
|
|
[self untrashObjects:objects atArrangedObjectIndexes:indexes];
|
|
|
|
[self rearrangeObjects];
|
|
|
|
}
|
|
|
|
|
2021-12-24 09:01:21 +00:00
|
|
|
- (void)insertObjectsUnsynced:(NSArray *)objects atArrangedObjectIndexes:(NSIndexSet *)indexes {
|
2022-02-07 05:49:27 +00:00
|
|
|
[super insertObjects:objects atArrangedObjectIndexes:indexes];
|
2022-06-16 14:14:33 +00:00
|
|
|
[self rearrangeObjects];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
if([self shuffle] != ShuffleOff) [self resetShuffleList];
|
2021-12-24 09:01:21 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)insertObjects:(NSArray *)objects atArrangedObjectIndexes:(NSIndexSet *)indexes {
|
2022-02-07 05:49:27 +00:00
|
|
|
[[[self undoManager] prepareWithInvocationTarget:self]
|
|
|
|
removeObjectsAtIndexes:[self disarrangeIndexes:indexes]];
|
|
|
|
NSString *actionName =
|
|
|
|
[NSString stringWithFormat:@"Adding %lu entries", (unsigned long)[objects count]];
|
|
|
|
[[self undoManager] setActionName:actionName];
|
2013-10-11 19:33:58 +00:00
|
|
|
|
2022-02-10 05:04:17 +00:00
|
|
|
for(PlaylistEntry *pe in objects) {
|
2022-06-16 14:14:33 +00:00
|
|
|
pe.deLeted = NO;
|
2022-02-10 05:04:17 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[super insertObjects:objects atArrangedObjectIndexes:indexes];
|
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
[self commitPersistentStore];
|
[Job Queue] Overhauled long action handling
Long actions, such as file opening, playlist loading, metadata loading
and refreshing, etc, are now handled through NSProgress. Additionally,
a new status bar change displays the progress of the task instead of
the total duration of the playlist. Finally, app quit is blocked by a
running task, and if the app is quit while a task is running, it will
be delayed until the task completes, at which time the app will
terminate cleanly.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-15 08:01:45 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if([self shuffle] != ShuffleOff) [self resetShuffleList];
|
2008-02-10 16:16:45 +00:00
|
|
|
}
|
|
|
|
|
2022-02-11 05:35:13 +00:00
|
|
|
- (void)untrashObjects:(NSArray *)objects atArrangedObjectIndexes:(NSIndexSet *)indexes {
|
|
|
|
[[[self undoManager] prepareWithInvocationTarget:self]
|
|
|
|
trashObjectsAtIndexes:[self disarrangeIndexes:indexes]];
|
|
|
|
NSString *actionName =
|
|
|
|
[NSString stringWithFormat:@"Restoring %lu entries from trash", (unsigned long)[objects count]];
|
|
|
|
[[self undoManager] setActionName:actionName];
|
|
|
|
|
|
|
|
for(PlaylistEntry *pe in objects) {
|
2022-06-16 14:14:33 +00:00
|
|
|
if(pe.deLeted && pe.trashUrl) {
|
2022-02-11 05:35:13 +00:00
|
|
|
NSError *error = nil;
|
2022-06-16 14:14:33 +00:00
|
|
|
[[NSFileManager defaultManager] moveItemAtURL:pe.trashUrl toURL:pe.url error:&error];
|
2022-02-11 05:35:13 +00:00
|
|
|
}
|
2022-06-16 14:14:33 +00:00
|
|
|
pe.deLeted = NO;
|
|
|
|
pe.trashUrl = nil;
|
2022-02-11 05:35:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[super insertObjects:objects atArrangedObjectIndexes:indexes];
|
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
[self commitPersistentStore];
|
[Job Queue] Overhauled long action handling
Long actions, such as file opening, playlist loading, metadata loading
and refreshing, etc, are now handled through NSProgress. Additionally,
a new status bar change displays the progress of the task instead of
the total duration of the playlist. Finally, app quit is blocked by a
running task, and if the app is quit while a task is running, it will
be delayed until the task completes, at which time the app will
terminate cleanly.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-15 08:01:45 +00:00
|
|
|
|
2022-02-11 05:35:13 +00:00
|
|
|
if([self shuffle] != ShuffleOff) [self resetShuffleList];
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)removeObjectsAtIndexes:(NSIndexSet *)indexes {
|
2022-02-07 05:49:27 +00:00
|
|
|
[self removeObjectsAtArrangedObjectIndexes:[self rearrangeIndexes:indexes]];
|
2013-10-18 08:47:48 +00:00
|
|
|
}
|
|
|
|
|
2022-02-11 05:35:13 +00:00
|
|
|
- (void)trashObjectsAtIndexes:(NSIndexSet *)indexes {
|
|
|
|
[self trashObjectsAtArrangedObjectIndexes:[self rearrangeIndexes:indexes]];
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)removeObjectsAtArrangedObjectIndexes:(NSIndexSet *)indexes {
|
2022-02-07 05:49:27 +00:00
|
|
|
NSArray *objects = [[self arrangedObjects] objectsAtIndexes:indexes];
|
|
|
|
[[[self undoManager] prepareWithInvocationTarget:self]
|
|
|
|
insertObjects:[self disarrangeObjects:objects]
|
|
|
|
atIndexes:[self disarrangeIndexes:indexes]];
|
|
|
|
NSString *actionName =
|
|
|
|
[NSString stringWithFormat:@"Removing %lu entries", (unsigned long)[indexes count]];
|
|
|
|
[[self undoManager] setActionName:actionName];
|
|
|
|
|
|
|
|
DLog(@"Removing indexes: %@", indexes);
|
2022-06-16 14:14:33 +00:00
|
|
|
DLog(@"Current index: %lli", currentEntry.index);
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
NSMutableIndexSet *unarrangedIndexes = [[NSMutableIndexSet alloc] init];
|
|
|
|
for(PlaylistEntry *pe in objects) {
|
|
|
|
[unarrangedIndexes addIndex:[pe index]];
|
2022-06-16 14:14:33 +00:00
|
|
|
pe.deLeted = YES;
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if([indexes containsIndex:currentEntry.index]) {
|
2022-02-10 05:04:17 +00:00
|
|
|
[self updateNextAfterDeleted:currentEntry withDeleteIndexes:indexes];
|
|
|
|
} else if(nextEntryAfterDeleted &&
|
|
|
|
[indexes containsIndex:nextEntryAfterDeleted.index]) {
|
|
|
|
[self updateNextAfterDeleted:nextEntryAfterDeleted withDeleteIndexes:indexes];
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(currentEntry.index >= 0 && [unarrangedIndexes containsIndex:currentEntry.index]) {
|
|
|
|
currentEntry.index = -currentEntry.index - 1;
|
2022-06-16 14:14:33 +00:00
|
|
|
DLog(@"Current removed: %lli", currentEntry.index);
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(currentEntry.index < 0) // Need to update the negative index
|
|
|
|
{
|
|
|
|
NSInteger i = -currentEntry.index - 1;
|
|
|
|
DLog(@"I is %li", i);
|
|
|
|
NSInteger j;
|
|
|
|
for(j = i - 1; j >= 0; j--) {
|
|
|
|
if([unarrangedIndexes containsIndex:j]) {
|
|
|
|
DLog(@"Removing 1");
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
currentEntry.index = -i - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
[super removeObjectsAtArrangedObjectIndexes:indexes];
|
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
[self commitPersistentStore];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
if([self shuffle] != ShuffleOff) [self resetShuffleList];
|
[Job Queue] Overhauled long action handling
Long actions, such as file opening, playlist loading, metadata loading
and refreshing, etc, are now handled through NSProgress. Additionally,
a new status bar change displays the progress of the task instead of
the total duration of the playlist. Finally, app quit is blocked by a
running task, and if the app is quit while a task is running, it will
be delayed until the task completes, at which time the app will
terminate cleanly.
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-15 08:01:45 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[playbackController playlistDidChange:self];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2022-02-11 05:35:13 +00:00
|
|
|
- (void)trashObjectsAtArrangedObjectIndexes:(NSIndexSet *)indexes {
|
|
|
|
NSArray *objects = [[self arrangedObjects] objectsAtIndexes:indexes];
|
|
|
|
[[[self undoManager] prepareWithInvocationTarget:self]
|
|
|
|
untrashObjects:[self disarrangeObjects:objects]
|
|
|
|
atIndexes:[self disarrangeIndexes:indexes]];
|
|
|
|
NSString *actionName =
|
|
|
|
[NSString stringWithFormat:@"Trashing %lu entries", (unsigned long)[indexes count]];
|
|
|
|
[[self undoManager] setActionName:actionName];
|
|
|
|
|
|
|
|
DLog(@"Trashing indexes: %@", indexes);
|
2022-06-16 14:14:33 +00:00
|
|
|
DLog(@"Current index: %lli", currentEntry.index);
|
2022-02-11 05:35:13 +00:00
|
|
|
|
|
|
|
NSMutableIndexSet *unarrangedIndexes = [[NSMutableIndexSet alloc] init];
|
|
|
|
for(PlaylistEntry *pe in objects) {
|
|
|
|
[unarrangedIndexes addIndex:[pe index]];
|
2022-06-16 14:14:33 +00:00
|
|
|
pe.deLeted = YES;
|
2022-02-11 05:35:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if([indexes containsIndex:currentEntry.index]) {
|
|
|
|
[self updateNextAfterDeleted:currentEntry withDeleteIndexes:indexes];
|
2022-02-11 05:48:30 +00:00
|
|
|
if(nextEntryAfterDeleted) {
|
|
|
|
[playbackController playEntry:nextEntryAfterDeleted];
|
|
|
|
nextEntryAfterDeleted = nil;
|
|
|
|
} else {
|
|
|
|
[playbackController stop:nil];
|
|
|
|
}
|
2022-02-11 05:35:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[super removeObjectsAtArrangedObjectIndexes:indexes];
|
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
[self commitPersistentStore];
|
|
|
|
|
2022-02-11 05:35:13 +00:00
|
|
|
if([self shuffle] != ShuffleOff) [self resetShuffleList];
|
|
|
|
|
|
|
|
[playbackController playlistDidChange:self];
|
|
|
|
|
|
|
|
for(PlaylistEntry *pe in objects) {
|
2022-06-16 14:14:33 +00:00
|
|
|
if([pe.url isFileURL]) {
|
2022-02-11 05:48:08 +00:00
|
|
|
NSURL *removed = nil;
|
|
|
|
NSError *error = nil;
|
2022-06-16 14:14:33 +00:00
|
|
|
[[NSFileManager defaultManager] trashItemAtURL:pe.url resultingItemURL:&removed error:&error];
|
|
|
|
pe.trashUrl = removed;
|
2022-02-11 05:48:08 +00:00
|
|
|
}
|
2022-02-11 05:35:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)setSortDescriptors:(NSArray *)sortDescriptors {
|
2022-02-07 05:49:27 +00:00
|
|
|
DLog(@"Current: %@, setting: %@", [self sortDescriptors], sortDescriptors);
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
// Cheap hack so the index column isn't sorted
|
2022-02-18 01:07:37 +00:00
|
|
|
if([sortDescriptors count] != 0) {
|
2022-06-08 01:57:19 +00:00
|
|
|
if([[((NSSortDescriptor *)(sortDescriptors[0])) key] caseInsensitiveCompare:@"index"] == NSOrderedSame) {
|
2022-02-18 01:07:37 +00:00
|
|
|
// Remove the sort descriptors
|
|
|
|
[super setSortDescriptors:@[]];
|
|
|
|
[self rearrangeObjects];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[super setSortDescriptors:sortDescriptors];
|
|
|
|
[self rearrangeObjects];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[playbackController playlistDidChange:self];
|
2006-05-12 19:23:17 +00:00
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
- (IBAction)randomizeList:(id)sender {
|
2022-02-07 05:49:27 +00:00
|
|
|
[self setSortDescriptors:@[]];
|
2007-02-18 22:27:55 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSArray *unrandomized = [self content];
|
|
|
|
[[[self undoManager] prepareWithInvocationTarget:self] unrandomizeList:unrandomized];
|
2006-04-30 13:01:33 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[self setContent:[Shuffle shuffleList:[self content]]];
|
2013-10-11 19:33:58 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if([self shuffle] != ShuffleOff) [self resetShuffleList];
|
2013-10-11 19:33:58 +00:00
|
|
|
|
2022-06-18 23:10:18 +00:00
|
|
|
[[self undoManager] setActionName:NSLocalizedString(@"PlaylistRandomizationAction", @"")];
|
2006-04-30 13:01:33 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)unrandomizeList:(NSArray *)entries {
|
2022-02-07 05:49:27 +00:00
|
|
|
[[[self undoManager] prepareWithInvocationTarget:self] randomizeList:self];
|
|
|
|
[self setContent:entries];
|
2006-04-30 13:01:33 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)toggleShuffle:(id)sender {
|
2022-02-07 05:49:27 +00:00
|
|
|
ShuffleMode shuffle = [self shuffle];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if(shuffle == ShuffleOff) {
|
|
|
|
[self setShuffle:ShuffleAlbums];
|
|
|
|
} else if(shuffle == ShuffleAlbums) {
|
|
|
|
[self setShuffle:ShuffleAll];
|
|
|
|
} else if(shuffle == ShuffleAll) {
|
|
|
|
[self setShuffle:ShuffleOff];
|
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
2008-02-19 04:02:05 +00:00
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)toggleRepeat:(id)sender {
|
2022-02-07 05:49:27 +00:00
|
|
|
RepeatMode repeat = [self repeat];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if(repeat == RepeatModeNoRepeat) {
|
|
|
|
[self setRepeat:RepeatModeRepeatOne];
|
|
|
|
} else if(repeat == RepeatModeRepeatOne) {
|
|
|
|
[self setRepeat:RepeatModeRepeatAlbum];
|
|
|
|
} else if(repeat == RepeatModeRepeatAlbum) {
|
|
|
|
[self setRepeat:RepeatModeRepeatAll];
|
|
|
|
} else if(repeat == RepeatModeRepeatAll) {
|
|
|
|
[self setRepeat:RepeatModeNoRepeat];
|
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2021-04-30 01:16:24 +00:00
|
|
|
- (PlaylistEntry *)entryAtIndex:(NSInteger)i {
|
2022-06-13 23:27:32 +00:00
|
|
|
if([[self arrangedObjects] count] == 0) return nil;
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
RepeatMode repeat = [self repeat];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if(i < 0 || i >= [[self arrangedObjects] count]) {
|
|
|
|
if(repeat != RepeatModeRepeatAll) return nil;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
while(i < 0) i += [[self arrangedObjects] count];
|
|
|
|
if(i >= [[self arrangedObjects] count]) i %= [[self arrangedObjects] count];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
return [[self arrangedObjects] objectAtIndex:i];
|
2006-04-15 13:51:40 +00:00
|
|
|
}
|
2007-03-09 01:16:06 +00:00
|
|
|
|
2022-02-11 05:35:13 +00:00
|
|
|
- (IBAction)remove:(id)sender {
|
2022-02-07 05:49:27 +00:00
|
|
|
// It's a kind of magic.
|
|
|
|
// Plain old NSArrayController's remove: isn't working properly for some reason.
|
|
|
|
// The method is definitely called but (overridden) removeObjectsAtArrangedObjectIndexes: isn't
|
|
|
|
// called and no entries are removed. Putting explicit call to
|
|
|
|
// removeObjectsAtArrangedObjectIndexes: here for now.
|
|
|
|
// TODO: figure it out
|
2013-10-11 19:39:05 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSIndexSet *selected = [self selectionIndexes];
|
|
|
|
if([selected count] > 0) {
|
|
|
|
[self removeObjectsAtArrangedObjectIndexes:selected];
|
|
|
|
}
|
2013-10-11 19:39:05 +00:00
|
|
|
}
|
|
|
|
|
2022-02-11 05:35:13 +00:00
|
|
|
- (IBAction)trash:(id)sender {
|
|
|
|
// Someone asked for this, so they're getting it.
|
|
|
|
// Trash the selection, and advance playback to the next untrashed file if necessary.
|
|
|
|
|
|
|
|
NSIndexSet *selected = [self selectionIndexes];
|
|
|
|
if([selected count] > 0) {
|
|
|
|
[self trashObjectsAtArrangedObjectIndexes:selected];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-18 07:13:27 +00:00
|
|
|
- (IBAction)removeDuplicates:(id)sender {
|
2022-02-07 05:49:27 +00:00
|
|
|
NSMutableArray *originals = [[NSMutableArray alloc] init];
|
|
|
|
NSMutableArray *duplicates = [[NSMutableArray alloc] init];
|
|
|
|
|
|
|
|
for(PlaylistEntry *pe in [self content]) {
|
2022-06-16 14:14:33 +00:00
|
|
|
if([originals containsObject:pe.url])
|
2022-02-07 05:49:27 +00:00
|
|
|
[duplicates addObject:pe];
|
|
|
|
else
|
2022-06-16 14:14:33 +00:00
|
|
|
[originals addObject:pe.url];
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if([duplicates count] > 0) {
|
|
|
|
NSArray *arrangedContent = [self arrangedObjects];
|
|
|
|
NSMutableIndexSet *duplicatesIndex = [[NSMutableIndexSet alloc] init];
|
|
|
|
for(PlaylistEntry *pe in duplicates) {
|
|
|
|
[duplicatesIndex addIndex:[arrangedContent indexOfObject:pe]];
|
|
|
|
}
|
|
|
|
[self removeObjectsAtArrangedObjectIndexes:duplicatesIndex];
|
|
|
|
}
|
2013-10-18 07:13:27 +00:00
|
|
|
}
|
|
|
|
|
2013-10-18 07:14:53 +00:00
|
|
|
- (IBAction)removeDeadItems:(id)sender {
|
2022-02-07 05:49:27 +00:00
|
|
|
NSMutableArray *deadItems = [[NSMutableArray alloc] init];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
for(PlaylistEntry *pe in [self content]) {
|
2022-06-16 14:14:33 +00:00
|
|
|
NSURL *url = pe.url;
|
2022-02-07 05:49:27 +00:00
|
|
|
if([url isFileURL])
|
|
|
|
if(![[NSFileManager defaultManager] fileExistsAtPath:[url path]])
|
|
|
|
[deadItems addObject:pe];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if([deadItems count] > 0) {
|
|
|
|
NSArray *arrangedContent = [self arrangedObjects];
|
|
|
|
NSMutableIndexSet *deadItemsIndex = [[NSMutableIndexSet alloc] init];
|
|
|
|
for(PlaylistEntry *pe in deadItems) {
|
|
|
|
[deadItemsIndex addIndex:[arrangedContent indexOfObject:pe]];
|
|
|
|
}
|
|
|
|
[self removeObjectsAtArrangedObjectIndexes:deadItemsIndex];
|
|
|
|
}
|
2013-10-18 07:14:53 +00:00
|
|
|
}
|
|
|
|
|
2021-04-30 01:16:24 +00:00
|
|
|
- (PlaylistEntry *)shuffledEntryAtIndex:(NSInteger)i {
|
2022-02-07 05:49:27 +00:00
|
|
|
RepeatMode repeat = [self repeat];
|
|
|
|
|
|
|
|
while(i < 0) {
|
|
|
|
if(repeat == RepeatModeRepeatAll) {
|
|
|
|
[self addShuffledListToFront];
|
|
|
|
// change i appropriately
|
|
|
|
i += [[self arrangedObjects] count];
|
|
|
|
} else {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while(i >= [shuffleList count]) {
|
|
|
|
if(repeat == RepeatModeRepeatAll) {
|
|
|
|
[self addShuffledListToBack];
|
|
|
|
} else {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return shuffleList[i];
|
2006-04-13 02:51:22 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (PlaylistEntry *)getNextEntry:(PlaylistEntry *)pe {
|
2022-02-07 05:49:27 +00:00
|
|
|
return [self getNextEntry:pe ignoreRepeatOne:NO];
|
2017-12-24 07:55:33 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (PlaylistEntry *)getNextEntry:(PlaylistEntry *)pe ignoreRepeatOne:(BOOL)ignoreRepeatOne {
|
2022-02-07 05:49:27 +00:00
|
|
|
if(!ignoreRepeatOne && [self repeat] == RepeatModeRepeatOne) {
|
|
|
|
return pe;
|
|
|
|
}
|
|
|
|
|
|
|
|
if([queueList count] > 0) {
|
|
|
|
pe = queueList[0];
|
|
|
|
[queueList removeObjectAtIndex:0];
|
|
|
|
pe.queued = NO;
|
|
|
|
[pe setQueuePosition:-1];
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < [queueList count]; i++) {
|
|
|
|
PlaylistEntry *queueItem = queueList[i];
|
|
|
|
[queueItem setQueuePosition:i];
|
|
|
|
}
|
|
|
|
|
2022-06-19 08:42:27 +00:00
|
|
|
[self commitPersistentStore];
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
return pe;
|
|
|
|
}
|
|
|
|
|
|
|
|
if([self shuffle] != ShuffleOff) {
|
|
|
|
return [self shuffledEntryAtIndex:(pe.shuffleIndex + 1)];
|
|
|
|
} else {
|
|
|
|
NSInteger i;
|
2022-02-10 05:04:17 +00:00
|
|
|
|
2022-06-17 11:34:17 +00:00
|
|
|
if(pe.deLeted) // Was a current entry, now removed.
|
2022-02-07 05:49:27 +00:00
|
|
|
{
|
2022-02-10 05:04:17 +00:00
|
|
|
if(nextEntryAfterDeleted)
|
|
|
|
i = nextEntryAfterDeleted.index;
|
|
|
|
else
|
|
|
|
i = 0;
|
|
|
|
nextEntryAfterDeleted = nil;
|
2022-02-07 05:49:27 +00:00
|
|
|
} else {
|
|
|
|
i = pe.index + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if([self repeat] == RepeatModeRepeatAlbum) {
|
|
|
|
PlaylistEntry *next = [self entryAtIndex:i];
|
|
|
|
|
|
|
|
if((i > [[self arrangedObjects] count] - 1) ||
|
|
|
|
([[next album] caseInsensitiveCompare:[pe album]]) || ([next album] == nil)) {
|
|
|
|
NSArray *filtered = [self filterPlaylistOnAlbum:[pe album]];
|
|
|
|
if([pe album] == nil)
|
|
|
|
i--;
|
|
|
|
else
|
|
|
|
i = [(PlaylistEntry *)filtered[0] index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [self entryAtIndex:i];
|
|
|
|
}
|
2006-04-15 13:51:40 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (NSArray *)filterPlaylistOnAlbum:(NSString *)album {
|
2022-06-21 06:18:37 +00:00
|
|
|
NSPredicate *hasUrlPredicate = [NSPredicate predicateWithFormat:@"urlString != nil && urlString != %@", @""];
|
|
|
|
NSPredicate *deletedPredicate = [NSPredicate predicateWithFormat:@"deLeted == NO || deLeted == nil"];
|
|
|
|
|
2022-06-18 00:02:24 +00:00
|
|
|
NSPredicate *searchPredicate;
|
2022-02-07 05:49:27 +00:00
|
|
|
if([album length] > 0)
|
2022-06-18 00:25:42 +00:00
|
|
|
searchPredicate = [NSPredicate predicateWithFormat:@"album == %@", album];
|
2022-02-07 05:49:27 +00:00
|
|
|
else
|
2022-06-18 00:25:42 +00:00
|
|
|
searchPredicate = [NSPredicate predicateWithFormat:@"album == nil || album == %@", @""];
|
2022-06-18 00:02:24 +00:00
|
|
|
|
2022-06-21 06:18:37 +00:00
|
|
|
NSCompoundPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[deletedPredicate, hasUrlPredicate, searchPredicate]];
|
2022-06-18 00:02:24 +00:00
|
|
|
|
2022-06-18 00:20:45 +00:00
|
|
|
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"index" ascending:YES];
|
|
|
|
|
2022-06-18 00:02:24 +00:00
|
|
|
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"PlaylistEntry"];
|
|
|
|
request.predicate = predicate;
|
2022-06-18 00:20:45 +00:00
|
|
|
request.sortDescriptors = @[sortDescriptor];
|
2022-06-18 00:02:24 +00:00
|
|
|
|
|
|
|
NSError *error = nil;
|
|
|
|
NSArray *results = [self.persistentContainer.viewContext executeFetchRequest:request error:&error];
|
|
|
|
|
|
|
|
return results;
|
2008-02-21 19:14:20 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (PlaylistEntry *)getPrevEntry:(PlaylistEntry *)pe {
|
2022-02-07 05:49:27 +00:00
|
|
|
return [self getPrevEntry:pe ignoreRepeatOne:NO];
|
2017-12-24 07:55:33 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (PlaylistEntry *)getPrevEntry:(PlaylistEntry *)pe ignoreRepeatOne:(BOOL)ignoreRepeatOne {
|
2022-02-07 05:49:27 +00:00
|
|
|
if(!ignoreRepeatOne && [self repeat] == RepeatModeRepeatOne) {
|
|
|
|
return pe;
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if([self shuffle] != ShuffleOff) {
|
|
|
|
return [self shuffledEntryAtIndex:(pe.shuffleIndex - 1)];
|
|
|
|
} else {
|
|
|
|
NSInteger i;
|
|
|
|
if(pe.index < 0) // Was a current entry, now removed.
|
|
|
|
{
|
|
|
|
i = -pe.index - 2;
|
|
|
|
} else {
|
|
|
|
i = pe.index - 1;
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
return [self entryAtIndex:i];
|
|
|
|
}
|
2006-04-15 13:51:40 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (BOOL)next {
|
2022-02-07 05:49:27 +00:00
|
|
|
PlaylistEntry *pe;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
pe = [self getNextEntry:[self currentEntry] ignoreRepeatOne:YES];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if(pe == nil) return NO;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[self setCurrentEntry:pe];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
return YES;
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (BOOL)prev {
|
2022-02-07 05:49:27 +00:00
|
|
|
PlaylistEntry *pe;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
pe = [self getPrevEntry:[self currentEntry] ignoreRepeatOne:YES];
|
|
|
|
if(pe == nil) return NO;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[self setCurrentEntry:pe];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
return YES;
|
2021-01-30 23:14:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *)shuffleAlbums {
|
2022-02-07 05:49:27 +00:00
|
|
|
NSArray *newList = [self arrangedObjects];
|
|
|
|
NSMutableArray *temp = [[NSMutableArray alloc] init];
|
2022-06-18 00:03:50 +00:00
|
|
|
NSSortDescriptor *sortDescriptorTrack = [[NSSortDescriptor alloc] initWithKey:@"track"
|
|
|
|
ascending:YES];
|
|
|
|
NSSortDescriptor *sortDescriptorDisc = [[NSSortDescriptor alloc] initWithKey:@"disc"
|
|
|
|
ascending:YES];
|
|
|
|
NSArray *albums = [newList valueForKey:@"album"];
|
|
|
|
albums = [[NSSet setWithArray:albums] allObjects];
|
|
|
|
NSArray *tempList = [Shuffle shuffleList:albums];
|
2022-02-07 05:49:27 +00:00
|
|
|
temp = [[NSMutableArray alloc] init];
|
2022-06-18 00:03:50 +00:00
|
|
|
BOOL blankAdded = NO;
|
|
|
|
for(NSString *album in tempList) {
|
|
|
|
NSString *theAlbum = album;
|
|
|
|
if((id)album == [NSNull null]) {
|
|
|
|
if(blankAdded)
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
theAlbum = @"";
|
|
|
|
blankAdded = YES;
|
|
|
|
} else if([album isEqualToString:@""]) {
|
|
|
|
if(blankAdded) continue;
|
|
|
|
blankAdded = YES;
|
|
|
|
}
|
|
|
|
NSArray *albumContent = [self filterPlaylistOnAlbum:theAlbum];
|
2022-02-07 05:49:27 +00:00
|
|
|
NSArray *sortedContent =
|
2022-06-18 00:03:50 +00:00
|
|
|
[albumContent sortedArrayUsingDescriptors:@[sortDescriptorDisc, sortDescriptorTrack]];
|
2022-02-10 09:14:42 +00:00
|
|
|
if(sortedContent && [sortedContent count])
|
|
|
|
[temp addObjectsFromArray:sortedContent];
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
|
|
|
return temp;
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
2006-04-14 20:34:14 +00:00
|
|
|
|
2022-06-19 09:05:26 +00:00
|
|
|
- (void)readQueueFromDataStore {
|
2022-06-21 06:18:37 +00:00
|
|
|
NSPredicate *hasUrlPredicate = [NSPredicate predicateWithFormat:@"urlString != nil && urlString != %@", @""];
|
|
|
|
NSPredicate *deletedPredicate = [NSPredicate predicateWithFormat:@"deLeted == NO || deLeted == nil"];
|
2022-06-19 09:05:26 +00:00
|
|
|
NSPredicate *queuedPredicate = [NSPredicate predicateWithFormat:@"queued == YES"];
|
|
|
|
|
|
|
|
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"queuePosition" ascending:YES];
|
|
|
|
|
2022-06-21 06:18:37 +00:00
|
|
|
NSCompoundPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[deletedPredicate, hasUrlPredicate, queuedPredicate]];
|
2022-06-19 09:05:26 +00:00
|
|
|
|
|
|
|
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"PlaylistEntry"];
|
|
|
|
request.predicate = predicate;
|
|
|
|
request.sortDescriptors = @[sortDescriptor];
|
|
|
|
|
|
|
|
NSError *error = nil;
|
|
|
|
NSArray *results = [self.persistentContainer.viewContext executeFetchRequest:request error:&error];
|
|
|
|
|
|
|
|
if(results && [results count] > 0) {
|
|
|
|
[queueList removeAllObjects];
|
|
|
|
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [results count])];
|
|
|
|
[queueList insertObjects:results atIndexes:indexSet];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)readShuffleListFromDataStore {
|
2022-06-20 03:04:30 +00:00
|
|
|
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"deLeted == NO || deLeted == nil || urlString == nil"];
|
2022-06-19 09:05:26 +00:00
|
|
|
|
|
|
|
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"shuffleIndex" ascending:YES];
|
|
|
|
|
|
|
|
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"PlaylistEntry"];
|
|
|
|
request.predicate = predicate;
|
|
|
|
request.sortDescriptors = @[sortDescriptor];
|
|
|
|
|
|
|
|
NSError *error = nil;
|
|
|
|
NSArray *results = [self.persistentContainer.viewContext executeFetchRequest:request error:&error];
|
|
|
|
|
|
|
|
if(results && [results count] > 0) {
|
|
|
|
[shuffleList removeAllObjects];
|
|
|
|
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [results count])];
|
|
|
|
[shuffleList insertObjects:results atIndexes:indexSet];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)addShuffledListToFront {
|
2022-02-07 05:49:27 +00:00
|
|
|
NSArray *newList;
|
|
|
|
NSIndexSet *indexSet;
|
2019-10-13 01:27:02 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if([self shuffle] == ShuffleAlbums) {
|
|
|
|
newList = [self shuffleAlbums];
|
|
|
|
} else {
|
|
|
|
newList = [Shuffle shuffleList:[self arrangedObjects]];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [newList count])];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[shuffleList insertObjects:newList atIndexes:indexSet];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
int i;
|
|
|
|
for(i = 0; i < [shuffleList count]; i++) {
|
|
|
|
[shuffleList[i] setShuffleIndex:i];
|
|
|
|
}
|
2022-06-19 08:42:27 +00:00
|
|
|
[self commitPersistentStore];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)addShuffledListToBack {
|
2022-02-07 05:49:27 +00:00
|
|
|
NSArray *newList;
|
|
|
|
NSIndexSet *indexSet;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if([self shuffle] == ShuffleAlbums) {
|
|
|
|
newList = [self shuffleAlbums];
|
|
|
|
} else {
|
|
|
|
newList = [Shuffle shuffleList:[self arrangedObjects]];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
indexSet =
|
|
|
|
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange([shuffleList count], [newList count])];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[shuffleList insertObjects:newList atIndexes:indexSet];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
unsigned long i;
|
|
|
|
for(i = ([shuffleList count] - [newList count]); i < [shuffleList count]; i++) {
|
|
|
|
[shuffleList[i] setShuffleIndex:(int)i];
|
|
|
|
}
|
2022-06-19 08:42:27 +00:00
|
|
|
[self commitPersistentStore];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)resetShuffleList {
|
2022-02-07 05:49:27 +00:00
|
|
|
[shuffleList removeAllObjects];
|
|
|
|
|
|
|
|
[self addShuffledListToFront];
|
|
|
|
|
|
|
|
if(currentEntry && currentEntry.index >= 0) {
|
|
|
|
if([self shuffle] == ShuffleAlbums) {
|
|
|
|
NSString *currentAlbum = currentEntry.album;
|
|
|
|
if(!currentAlbum) currentAlbum = @"";
|
|
|
|
|
|
|
|
NSArray *wholeAlbum = [self filterPlaylistOnAlbum:currentAlbum];
|
|
|
|
|
|
|
|
// First prune the shuffle list of the currently playing album
|
|
|
|
long i, j;
|
|
|
|
for(i = 0; i < [shuffleList count];) {
|
|
|
|
if([wholeAlbum containsObject:shuffleList[i]]) {
|
|
|
|
[shuffleList removeObjectAtIndex:i];
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then insert the playing album at the start
|
|
|
|
NSIndexSet *indexSet =
|
|
|
|
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [wholeAlbum count])];
|
|
|
|
|
|
|
|
[shuffleList insertObjects:wholeAlbum atIndexes:indexSet];
|
|
|
|
|
|
|
|
// Oops, gotta reset the shuffle indexes
|
|
|
|
for(i = 0, j = [shuffleList count]; i < j; ++i) {
|
|
|
|
[shuffleList[i] setShuffleIndex:(int)i];
|
|
|
|
}
|
2022-06-19 08:42:27 +00:00
|
|
|
[self commitPersistentStore];
|
2022-02-07 05:49:27 +00:00
|
|
|
} else {
|
|
|
|
[shuffleList insertObject:currentEntry atIndex:0];
|
|
|
|
[currentEntry setShuffleIndex:0];
|
|
|
|
|
|
|
|
// Need to rejigger so the current entry is at the start now...
|
|
|
|
long i, j;
|
|
|
|
BOOL found = NO;
|
|
|
|
for(i = 1, j = [shuffleList count]; i < j && !found; i++) {
|
|
|
|
if(shuffleList[i] == currentEntry) {
|
|
|
|
found = YES;
|
|
|
|
[shuffleList removeObjectAtIndex:i];
|
|
|
|
} else {
|
|
|
|
[shuffleList[i] setShuffleIndex:(int)i];
|
|
|
|
}
|
|
|
|
}
|
2022-06-19 08:42:27 +00:00
|
|
|
[self commitPersistentStore];
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)setCurrentEntry:(PlaylistEntry *)pe {
|
2022-06-19 08:42:27 +00:00
|
|
|
if(pe == currentEntry || kAppControllerShuttingDown) return;
|
|
|
|
|
|
|
|
if(currentEntry) {
|
|
|
|
currentEntry.current = NO;
|
|
|
|
currentEntry.stopAfter = NO;
|
|
|
|
currentEntry.currentPosition = 0.0;
|
2022-06-21 02:13:33 +00:00
|
|
|
currentEntry.countAdded = NO;
|
2022-06-19 08:42:27 +00:00
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2022-06-19 08:42:27 +00:00
|
|
|
if(pe) {
|
|
|
|
pe.current = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
[self commitPersistentStore];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
NSMutableIndexSet *refreshSet = [[NSMutableIndexSet alloc] init];
|
|
|
|
|
2022-06-18 22:50:25 +00:00
|
|
|
if(currentEntry != nil && !currentEntry.deLeted && currentEntry.index < NSNotFound) [refreshSet addIndex:currentEntry.index];
|
|
|
|
if(pe != nil && !pe.deLeted && pe.index < NSNotFound) [refreshSet addIndex:pe.index];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
// Refresh entire row to refresh tooltips
|
|
|
|
unsigned long columns = [[self.tableView tableColumns] count];
|
|
|
|
[self.tableView reloadDataForRowIndexes:refreshSet columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, columns)]];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if(pe != nil) [self.tableView scrollRowToVisible:pe.index];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
currentEntry = pe;
|
2013-09-30 00:27:55 +00:00
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)setShuffle:(ShuffleMode)s {
|
2022-02-07 05:49:27 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] setInteger:s forKey:@"shuffle"];
|
|
|
|
if(s != ShuffleOff) [self resetShuffleList];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[playbackController playlistDidChange:self];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
- (ShuffleMode)shuffle {
|
2022-02-07 05:49:27 +00:00
|
|
|
return (ShuffleMode)[[NSUserDefaults standardUserDefaults] integerForKey:@"shuffle"];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
- (void)setRepeat:(RepeatMode)r {
|
2022-02-07 05:49:27 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] setInteger:r forKey:@"repeat"];
|
|
|
|
[playbackController playlistDidChange:self];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
- (RepeatMode)repeat {
|
2022-02-07 05:49:27 +00:00
|
|
|
return (RepeatMode)[[NSUserDefaults standardUserDefaults] integerForKey:@"repeat"];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)clear:(id)sender {
|
2022-02-07 05:49:27 +00:00
|
|
|
[self setFilterPredicate:nil];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[self
|
|
|
|
removeObjectsAtArrangedObjectIndexes:
|
|
|
|
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [[self arrangedObjects] count])]];
|
2007-05-26 14:09:03 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)clearFilterPredicate:(id)sender {
|
2022-02-07 05:49:27 +00:00
|
|
|
[self setFilterPredicate:nil];
|
2007-05-26 14:09:03 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)setFilterPredicate:(NSPredicate *)filterPredicate {
|
2022-02-07 05:49:27 +00:00
|
|
|
[super setFilterPredicate:filterPredicate];
|
2006-04-30 15:31:57 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)showEntryInFinder:(id)sender {
|
2022-06-13 23:28:29 +00:00
|
|
|
if([[self selectedObjects] count] == 0) return;
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-06-17 00:43:48 +00:00
|
|
|
NSURL *url = [[self selectedObjects][0] url];
|
2022-02-07 05:49:27 +00:00
|
|
|
if([url isFileURL]) [ws selectFile:[url path] inFileViewerRootedAtPath:[url path]];
|
2006-05-23 15:12:24 +00:00
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2008-11-21 15:14:23 +00:00
|
|
|
/*
|
|
|
|
- (IBAction)showTagEditor:(id)sender
|
|
|
|
{
|
|
|
|
// call the editor & pass the url
|
2021-01-30 23:14:08 +00:00
|
|
|
if ([self selectionIndex] < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NSURL *url = [[[self selectedObjects] objectAtIndex:0] URL];
|
|
|
|
if ([url isFileURL])
|
|
|
|
[TagEditorController openTagEditor:url sender:sender];
|
|
|
|
|
2008-11-21 15:14:23 +00:00
|
|
|
}
|
|
|
|
*/
|
2022-02-07 05:49:27 +00:00
|
|
|
- (IBAction)searchByArtist:(id)sender;
|
|
|
|
{
|
|
|
|
PlaylistEntry *entry = [[self arrangedObjects] objectAtIndex:[self selectionIndex]];
|
|
|
|
[spotlightWindowController searchForArtist:[entry artist]];
|
2008-02-16 16:13:21 +00:00
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (IBAction)searchByAlbum:(id)sender;
|
|
|
|
{
|
|
|
|
PlaylistEntry *entry = [[self arrangedObjects] objectAtIndex:[self selectionIndex]];
|
|
|
|
[spotlightWindowController searchForAlbum:[entry album]];
|
2008-02-16 16:13:21 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (NSMutableArray *)queueList {
|
2022-02-07 05:49:27 +00:00
|
|
|
return queueList;
|
2008-02-21 09:05:06 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)emptyQueueList:(id)sender {
|
2022-02-07 05:49:27 +00:00
|
|
|
[self emptyQueueListUnsynced];
|
2021-12-24 09:01:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)emptyQueueListUnsynced {
|
2022-02-07 05:49:27 +00:00
|
|
|
NSMutableIndexSet *refreshSet = [[NSMutableIndexSet alloc] init];
|
|
|
|
|
|
|
|
for(PlaylistEntry *queueItem in queueList) {
|
|
|
|
queueItem.queued = NO;
|
|
|
|
[queueItem setQueuePosition:-1];
|
|
|
|
[refreshSet addIndex:[queueItem index]];
|
|
|
|
}
|
2008-02-22 02:21:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[queueList removeAllObjects];
|
2022-01-21 01:58:24 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
// Refresh entire row to refresh tooltips
|
|
|
|
unsigned long columns = [[self.tableView tableColumns] count];
|
|
|
|
[self.tableView reloadDataForRowIndexes:refreshSet columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, columns)]];
|
2008-02-21 09:05:06 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)toggleQueued:(id)sender {
|
2022-02-07 05:49:27 +00:00
|
|
|
NSMutableIndexSet *refreshSet = [[NSMutableIndexSet alloc] init];
|
|
|
|
|
|
|
|
for(PlaylistEntry *queueItem in [self selectedObjects]) {
|
|
|
|
if(queueItem.queued) {
|
|
|
|
[queueList removeObjectAtIndex:queueItem.queuePosition];
|
|
|
|
|
|
|
|
queueItem.queued = NO;
|
|
|
|
queueItem.queuePosition = -1;
|
|
|
|
} else {
|
|
|
|
queueItem.queued = YES;
|
|
|
|
queueItem.queuePosition = (int)[queueList count];
|
|
|
|
|
|
|
|
[queueList addObject:queueItem];
|
|
|
|
}
|
|
|
|
|
|
|
|
[refreshSet addIndex:[queueItem index]];
|
|
|
|
|
|
|
|
DLog(@"TOGGLE QUEUED: %i", queueItem.queued);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(PlaylistEntry *queueItem in queueList) {
|
|
|
|
if(![[self selectedObjects] containsObject:queueItem])
|
|
|
|
[refreshSet addIndex:[queueItem index]];
|
|
|
|
}
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
for(PlaylistEntry *cur in queueList) {
|
|
|
|
cur.queuePosition = i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Refresh entire row to refresh tooltips
|
|
|
|
unsigned long columns = [[self.tableView tableColumns] count];
|
|
|
|
[self.tableView reloadDataForRowIndexes:refreshSet columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, columns)]];
|
2008-02-22 15:26:46 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)removeFromQueue:(id)sender {
|
2022-02-07 05:49:27 +00:00
|
|
|
NSMutableIndexSet *refreshSet = [[NSMutableIndexSet alloc] init];
|
|
|
|
|
|
|
|
for(PlaylistEntry *queueItem in [self selectedObjects]) {
|
|
|
|
queueItem.queued = NO;
|
|
|
|
queueItem.queuePosition = -1;
|
|
|
|
|
|
|
|
[queueList removeObject:queueItem];
|
|
|
|
|
|
|
|
[refreshSet addIndex:[queueItem index]];
|
|
|
|
}
|
|
|
|
|
|
|
|
for(PlaylistEntry *queueItem in queueList) {
|
|
|
|
[refreshSet addIndex:[queueItem index]];
|
|
|
|
}
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
for(PlaylistEntry *cur in queueList) {
|
|
|
|
cur.queuePosition = i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Refresh entire row to refresh tooltips
|
|
|
|
unsigned long columns = [[self.tableView tableColumns] count];
|
|
|
|
[self.tableView reloadDataForRowIndexes:refreshSet columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, columns)]];
|
2018-06-28 10:59:59 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)addToQueue:(id)sender {
|
2022-02-07 05:49:27 +00:00
|
|
|
NSMutableIndexSet *refreshSet = [[NSMutableIndexSet alloc] init];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
for(PlaylistEntry *queueItem in [self selectedObjects]) {
|
|
|
|
queueItem.queued = YES;
|
|
|
|
queueItem.queuePosition = (int)[queueList count];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
[queueList addObject:queueItem];
|
|
|
|
}
|
2022-01-20 22:59:26 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
for(PlaylistEntry *queueItem in queueList) {
|
|
|
|
[refreshSet addIndex:[queueItem index]];
|
|
|
|
}
|
2022-01-21 01:54:02 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
int i = 0;
|
|
|
|
for(PlaylistEntry *cur in queueList) {
|
|
|
|
cur.queuePosition = i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Refresh entire row to refresh tooltips
|
|
|
|
unsigned long columns = [[self.tableView tableColumns] count];
|
|
|
|
[self.tableView reloadDataForRowIndexes:refreshSet columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, columns)]];
|
2018-06-28 10:59:59 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)stopAfterCurrent:(id)sender {
|
2022-02-07 05:49:27 +00:00
|
|
|
currentEntry.stopAfter = !currentEntry.stopAfter;
|
2022-06-19 08:42:27 +00:00
|
|
|
[self commitPersistentStore];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
NSIndexSet *refreshSet = [NSIndexSet indexSetWithIndex:[currentEntry index]];
|
2022-01-20 22:59:26 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
// Refresh entire row to refresh tooltips
|
|
|
|
unsigned long columns = [[self.tableView tableColumns] count];
|
|
|
|
[self.tableView reloadDataForRowIndexes:refreshSet columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, columns)]];
|
2022-05-31 05:23:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)stopAfterSelection:(id)sender {
|
|
|
|
NSMutableIndexSet *refreshSet = [[NSMutableIndexSet alloc] init];
|
|
|
|
|
|
|
|
for(PlaylistEntry *pe in [self selectedObjects]) {
|
|
|
|
pe.stopAfter = !pe.stopAfter;
|
|
|
|
[refreshSet addIndex:pe.index];
|
|
|
|
}
|
|
|
|
|
2022-06-19 08:42:27 +00:00
|
|
|
[self commitPersistentStore];
|
|
|
|
|
2022-05-31 05:23:02 +00:00
|
|
|
// Refresh entire row of all affected items to update tooltips
|
|
|
|
unsigned long columns = [[self.tableView tableColumns] count];
|
|
|
|
[self.tableView reloadDataForRowIndexes:refreshSet columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, columns)]];
|
2008-02-25 17:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
|
2022-02-07 05:49:27 +00:00
|
|
|
SEL action = [menuItem action];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if(action == @selector(removeFromQueue:)) {
|
|
|
|
for(PlaylistEntry *q in [self selectedObjects])
|
|
|
|
if(q.queuePosition >= 0) return YES;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if(action == @selector(emptyQueueList:) && ([queueList count] < 1)) return NO;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if(action == @selector(stopAfterCurrent:) && currentEntry.stopAfter) return NO;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
// if nothing is selected, gray out these
|
|
|
|
if([[self selectedObjects] count] < 1) {
|
|
|
|
if(action == @selector(remove:)) return NO;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if(action == @selector(addToQueue:)) return NO;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if(action == @selector(searchByArtist:)) return NO;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if(action == @selector(searchByAlbum:)) return NO;
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
return YES;
|
2008-02-23 22:20:14 +00:00
|
|
|
}
|
|
|
|
|
2008-05-09 21:24:49 +00:00
|
|
|
// Event inlets:
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)willInsertURLs:(NSArray *)urls origin:(URLOrigin)origin {
|
2022-02-07 05:49:27 +00:00
|
|
|
if(![urls count]) return;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
CGEventRef event = CGEventCreate(NULL /*default event source*/);
|
|
|
|
CGEventFlags mods = CGEventGetFlags(event);
|
|
|
|
CFRelease(event);
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
BOOL modifierPressed =
|
|
|
|
((mods & kCGEventFlagMaskCommand) != 0) & ((mods & kCGEventFlagMaskControl) != 0);
|
|
|
|
modifierPressed |= ((mods & kCGEventFlagMaskShift) != 0);
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSString *behavior =
|
|
|
|
[[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesBehavior"];
|
|
|
|
if(modifierPressed) {
|
|
|
|
behavior =
|
|
|
|
[[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesAlteredBehavior"];
|
|
|
|
}
|
2008-05-09 21:24:49 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
BOOL shouldClear =
|
|
|
|
modifierPressed; // By default, internal sources should not clear the playlist
|
|
|
|
if(origin == URLOriginExternal) { // For external insertions, we look at the preference
|
|
|
|
// possible settings are "clearAndPlay", "enqueue", "enqueueAndPlay"
|
|
|
|
shouldClear = [behavior isEqualToString:@"clearAndPlay"];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
if(shouldClear) {
|
|
|
|
[self clear:self];
|
|
|
|
}
|
2008-05-09 21:24:49 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)didInsertURLs:(NSArray *)urls origin:(URLOrigin)origin {
|
2022-02-07 05:49:27 +00:00
|
|
|
if(![urls count]) return;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-06-24 07:29:50 +00:00
|
|
|
NSArray *nsurls = [urls valueForKey:@"url"];
|
|
|
|
if(![[SandboxBroker sharedSandboxBroker] areAllPathsSafe:nsurls]) {
|
|
|
|
[appController showPathSuggester];
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
CGEventRef event = CGEventCreate(NULL);
|
|
|
|
CGEventFlags mods = CGEventGetFlags(event);
|
|
|
|
CFRelease(event);
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
BOOL modifierPressed =
|
|
|
|
((mods & kCGEventFlagMaskCommand) != 0) & ((mods & kCGEventFlagMaskControl) != 0);
|
|
|
|
modifierPressed |= ((mods & kCGEventFlagMaskShift) != 0);
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
NSString *behavior =
|
|
|
|
[[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesBehavior"];
|
|
|
|
if(modifierPressed) {
|
|
|
|
behavior =
|
|
|
|
[[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesAlteredBehavior"];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
BOOL shouldPlay = modifierPressed; // The default is NO for internal insertions
|
|
|
|
if(origin == URLOriginExternal) { // For external insertions, we look at the preference
|
|
|
|
shouldPlay = [behavior isEqualToString:@"clearAndPlay"] ||
|
|
|
|
[behavior isEqualToString:@"enqueueAndPlay"];
|
|
|
|
;
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
// Auto start playback
|
|
|
|
if(shouldPlay && [[self content] count] > 0) {
|
|
|
|
[playbackController playEntry:urls[0]];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
}
|
2008-02-22 15:26:46 +00:00
|
|
|
|
2021-07-03 22:32:13 +00:00
|
|
|
- (IBAction)reloadTags:(id)sender {
|
2022-02-07 05:49:27 +00:00
|
|
|
NSArray *selectedobjects = [self selectedObjects];
|
|
|
|
if([selectedobjects count]) {
|
|
|
|
for(PlaylistEntry *pe in selectedobjects) {
|
|
|
|
pe.metadataLoaded = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
[playlistLoader performSelectorInBackground:@selector(loadInfoForEntries:) withObject:selectedobjects];
|
|
|
|
}
|
2021-07-03 22:32:13 +00:00
|
|
|
}
|
|
|
|
|
2022-06-28 04:50:14 +00:00
|
|
|
- (IBAction)resetPlaycounts:(id)sender {
|
|
|
|
NSArray *selectedobjects = [self selectedObjects];
|
|
|
|
if([selectedobjects count]) {
|
|
|
|
for(PlaylistEntry *pe in selectedobjects) {
|
|
|
|
[self resetPlayCountForTrack:pe];
|
|
|
|
}
|
|
|
|
[self commitPersistentStore];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-28 08:55:30 +00:00
|
|
|
- (IBAction)removeRatings:(id)sender {
|
|
|
|
NSArray *selectedobjects = [self selectedObjects];
|
|
|
|
if([selectedobjects count]) {
|
|
|
|
for(PlaylistEntry *pe in selectedobjects) {
|
|
|
|
[self removeRatingForTrack:pe];
|
|
|
|
}
|
|
|
|
[self commitPersistentStore];
|
|
|
|
|
|
|
|
NSMutableIndexSet *refreshSet = [[NSMutableIndexSet alloc] init];
|
|
|
|
|
|
|
|
for(PlaylistEntry *pe in selectedobjects) {
|
|
|
|
if(pe.index >= 0 && pe.index < NSNotFound) {
|
|
|
|
[refreshSet addIndex:pe.index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Refresh entire row to refresh tooltips
|
|
|
|
unsigned long columns = [[self.tableView tableColumns] count];
|
|
|
|
[self.tableView reloadDataForRowIndexes:refreshSet columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, columns)]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-29 05:58:13 +00:00
|
|
|
- (BOOL)pathSuggesterEmpty {
|
|
|
|
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"SandboxToken"];
|
|
|
|
|
|
|
|
NSError *error = nil;
|
|
|
|
NSArray *results = [self.persistentContainer.viewContext executeFetchRequest:request error:&error];
|
|
|
|
|
|
|
|
if(!results || [results count] < 1) return YES;
|
|
|
|
else return NO;
|
|
|
|
}
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
@end
|