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"
|
2021-12-24 09:01:21 +00:00
|
|
|
#import "SQLiteStore.h"
|
2006-05-07 13:19:23 +00:00
|
|
|
|
2013-10-11 12:03:55 +00:00
|
|
|
#import "Logging.h"
|
|
|
|
|
2013-10-11 19:33:58 +00:00
|
|
|
#define UNDO_STACK_LIMIT 0
|
|
|
|
|
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;
|
2005-06-02 18:16:43 +00:00
|
|
|
|
2008-02-19 03:39:43 +00:00
|
|
|
+ (void)initialize {
|
2021-01-30 23:14:08 +00:00
|
|
|
NSValueTransformer *repeatNoneTransformer =
|
|
|
|
[[RepeatModeTransformer alloc] initWithMode:RepeatModeNoRepeat];
|
|
|
|
[NSValueTransformer setValueTransformer:repeatNoneTransformer forName:@"RepeatNoneTransformer"];
|
2008-02-19 03:39:43 +00:00
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
NSValueTransformer *repeatOneTransformer =
|
|
|
|
[[RepeatModeTransformer alloc] initWithMode:RepeatModeRepeatOne];
|
|
|
|
[NSValueTransformer setValueTransformer:repeatOneTransformer forName:@"RepeatOneTransformer"];
|
2008-02-19 03:39:43 +00:00
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
NSValueTransformer *repeatAlbumTransformer =
|
|
|
|
[[RepeatModeTransformer alloc] initWithMode:RepeatModeRepeatAlbum];
|
2008-02-19 04:02:05 +00:00
|
|
|
[NSValueTransformer setValueTransformer:repeatAlbumTransformer
|
|
|
|
forName:@"RepeatAlbumTransformer"];
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
NSValueTransformer *repeatAllTransformer =
|
|
|
|
[[RepeatModeTransformer alloc] initWithMode:RepeatModeRepeatAll];
|
|
|
|
[NSValueTransformer setValueTransformer:repeatAllTransformer forName:@"RepeatAllTransformer"];
|
2008-02-19 03:39:43 +00:00
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
NSValueTransformer *repeatModeImageTransformer = [[RepeatModeImageTransformer alloc] init];
|
2008-02-19 03:39:43 +00:00
|
|
|
[NSValueTransformer setValueTransformer:repeatModeImageTransformer
|
|
|
|
forName:@"RepeatModeImageTransformer"];
|
2009-03-10 04:04:46 +00:00
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
NSValueTransformer *shuffleOffTransformer =
|
|
|
|
[[ShuffleModeTransformer alloc] initWithMode:ShuffleOff];
|
|
|
|
[NSValueTransformer setValueTransformer:shuffleOffTransformer forName:@"ShuffleOffTransformer"];
|
|
|
|
|
|
|
|
NSValueTransformer *shuffleAlbumsTransformer =
|
|
|
|
[[ShuffleModeTransformer alloc] initWithMode:ShuffleAlbums];
|
2009-03-10 04:04:46 +00:00
|
|
|
[NSValueTransformer setValueTransformer:shuffleAlbumsTransformer
|
|
|
|
forName:@"ShuffleAlbumsTransformer"];
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
NSValueTransformer *shuffleAllTransformer =
|
|
|
|
[[ShuffleModeTransformer alloc] initWithMode:ShuffleAll];
|
|
|
|
[NSValueTransformer setValueTransformer:shuffleAllTransformer forName:@"ShuffleAllTransformer"];
|
|
|
|
|
|
|
|
NSValueTransformer *shuffleImageTransformer = [[ShuffleImageTransformer alloc] init];
|
2009-02-28 06:40:50 +00:00
|
|
|
[NSValueTransformer setValueTransformer:shuffleImageTransformer
|
|
|
|
forName:@"ShuffleImageTransformer"];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
NSValueTransformer *statusImageTransformer = [[StatusImageTransformer alloc] init];
|
2008-02-22 02:19:46 +00:00
|
|
|
[NSValueTransformer setValueTransformer:statusImageTransformer
|
|
|
|
forName:@"StatusImageTransformer"];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
NSValueTransformer *toggleQueueTitleTransformer = [[ToggleQueueTitleTransformer alloc] init];
|
2008-03-08 23:57:54 +00:00
|
|
|
[NSValueTransformer setValueTransformer:toggleQueueTitleTransformer
|
|
|
|
forName:@"ToggleQueueTitleTransformer"];
|
2008-02-19 03:39:43 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)initDefaults {
|
|
|
|
NSDictionary *defaultsDictionary = @{@"repeat": @(RepeatModeNoRepeat), @"shuffle": @(ShuffleOff)};
|
2008-03-08 23:57:54 +00:00
|
|
|
|
2021-01-30 23:14:08 +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 {
|
|
|
|
self = [super initWithCoder:decoder];
|
2009-02-28 18:18:56 +00:00
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
if (self) {
|
|
|
|
shuffleList = [[NSMutableArray alloc] init];
|
|
|
|
queueList = [[NSMutableArray alloc] init];
|
2013-10-11 19:33:58 +00:00
|
|
|
|
|
|
|
undoManager = [[NSUndoManager alloc] init];
|
|
|
|
|
|
|
|
[undoManager setLevelsOfUndo:UNDO_STACK_LIMIT];
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
[self initDefaults];
|
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
return self;
|
|
|
|
}
|
2009-02-28 18:18:56 +00:00
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)awakeFromNib {
|
|
|
|
[super awakeFromNib];
|
2008-02-24 17:16:19 +00:00
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
[self addObserver:self
|
|
|
|
forKeyPath:@"arrangedObjects"
|
|
|
|
options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld)
|
|
|
|
context:nil];
|
2008-02-24 17:16:19 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)observeValueForKeyPath:(NSString *)keyPath
|
|
|
|
ofObject:(id)object
|
|
|
|
change:(NSDictionary *)change
|
|
|
|
context:(void *)context {
|
|
|
|
if ([keyPath isEqualToString:@"arrangedObjects"]) {
|
|
|
|
[self updatePlaylistIndexes];
|
|
|
|
[self updateTotalTime];
|
|
|
|
}
|
2008-02-24 17:32:50 +00:00
|
|
|
}
|
|
|
|
|
2022-01-09 10:10:08 +00:00
|
|
|
static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_block_t block) {
|
|
|
|
if (dispatch_queue_get_label(queue) == dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)) {
|
|
|
|
block();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dispatch_sync(queue, block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setProgressBarStatus:(double)status {
|
|
|
|
dispatch_sync_reentrant(dispatch_get_main_queue(), ^{
|
|
|
|
[self->playbackController setProgressBarStatus:status];
|
|
|
|
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.001]];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)updatePlaylistIndexes {
|
|
|
|
NSArray *arranged = [self arrangedObjects];
|
|
|
|
NSUInteger n = [arranged count];
|
2021-12-24 09:01:21 +00:00
|
|
|
BOOL updated = NO;
|
2021-01-30 23:14:08 +00:00
|
|
|
for (NSUInteger i = 0; i < n; i++) {
|
|
|
|
PlaylistEntry *pe = arranged[i];
|
2021-12-24 09:01:21 +00:00
|
|
|
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-01-09 10:10:08 +00:00
|
|
|
[[SQLiteStore sharedStore] syncPlaylistEntries:arranged progressCall:^(double progress) {
|
|
|
|
[self setProgressBarStatus:progress];
|
|
|
|
}];
|
2021-01-30 23:14:08 +00:00
|
|
|
}
|
2008-02-24 17:16:19 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)updateTotalTime {
|
|
|
|
double tt = 0;
|
|
|
|
ldiv_t hoursAndMinutes;
|
2013-10-21 04:16:07 +00:00
|
|
|
ldiv_t daysAndHours;
|
2021-12-24 09:01:21 +00:00
|
|
|
ldiv_t weeksAndDays;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
for (PlaylistEntry *pe in [self arrangedObjects]) {
|
|
|
|
if (!isnan([pe.length doubleValue])) tt += [pe.length doubleValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
long sec = (long) (tt);
|
|
|
|
hoursAndMinutes = ldiv(sec / 60, 60);
|
|
|
|
|
|
|
|
if (hoursAndMinutes.quot >= 24) {
|
2013-10-21 04:16:07 +00:00
|
|
|
daysAndHours = ldiv(hoursAndMinutes.quot, 24);
|
2021-12-24 09:01:21 +00:00
|
|
|
if (daysAndHours.quot >= 7) {
|
|
|
|
weeksAndDays = ldiv(daysAndHours.quot, 7);
|
|
|
|
[self setTotalTime:[NSString stringWithFormat:@"%ld week%@ %ld day%@ %ld hour%@ %ld minute%@ %ld second%@",
|
|
|
|
weeksAndDays.quot,
|
|
|
|
weeksAndDays.quot != 1 ? @"s" : @"",
|
|
|
|
weeksAndDays.rem,
|
|
|
|
weeksAndDays.rem != 1 ? @"s" : @"",
|
|
|
|
daysAndHours.rem,
|
|
|
|
daysAndHours.rem != 1 ? @"s" : @"",
|
|
|
|
hoursAndMinutes.rem,
|
|
|
|
hoursAndMinutes.rem != 1 ? @"s" : @"",
|
|
|
|
sec % 60,
|
|
|
|
(sec % 60) != 1 ? @"s" : @""]];
|
|
|
|
} else {
|
|
|
|
[self setTotalTime:[NSString stringWithFormat:@"%ld day%@ %ld hour%@ %ld minute%@ %ld second%@",
|
|
|
|
daysAndHours.quot,
|
|
|
|
daysAndHours.quot != 1 ? @"s" : @"",
|
|
|
|
daysAndHours.rem,
|
|
|
|
daysAndHours.rem != 1 ? @"s" : @"",
|
|
|
|
hoursAndMinutes.rem,
|
|
|
|
hoursAndMinutes.rem != 1 ? @"s" : @"",
|
|
|
|
sec % 60,
|
|
|
|
(sec % 60) != 1 ? @"s" : @""]];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
} else {
|
2021-12-24 09:01:21 +00:00
|
|
|
if (hoursAndMinutes.quot > 0) {
|
|
|
|
[self setTotalTime:[NSString stringWithFormat:@"%ld hour%@ %ld minute%@ %ld second%@",
|
|
|
|
hoursAndMinutes.quot,
|
|
|
|
hoursAndMinutes.quot != 1 ? @"s" : @"",
|
|
|
|
hoursAndMinutes.rem,
|
|
|
|
hoursAndMinutes.rem != 1 ? @"s" : @"",
|
|
|
|
sec % 60,
|
|
|
|
(sec % 60) != 1 ? @"s" : @""]];
|
|
|
|
} else {
|
|
|
|
if (hoursAndMinutes.rem > 0) {
|
|
|
|
[self setTotalTime:[NSString stringWithFormat:@"%ld minute%@ %ld second%@",
|
|
|
|
hoursAndMinutes.rem,
|
|
|
|
hoursAndMinutes.rem != 1 ? @"s" : @"",
|
|
|
|
sec % 60,
|
|
|
|
(sec % 60) != 1 ? @"s" : @""]];
|
|
|
|
} else {
|
|
|
|
[self setTotalTime:[NSString stringWithFormat:@"%ld second%@",
|
|
|
|
sec,
|
|
|
|
sec != 1 ? @"s" : @""]];
|
|
|
|
}
|
|
|
|
}
|
2013-10-21 04:16:07 +00:00
|
|
|
}
|
2008-02-24 17:32:50 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn {
|
|
|
|
if ([self shuffle] != ShuffleOff) [self resetShuffleList];
|
2006-04-29 00:03:28 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (NSString *)tableView:(NSTableView *)tv
|
|
|
|
toolTipForCell:(NSCell *)cell
|
|
|
|
rect:(NSRectPointer)rect
|
|
|
|
tableColumn:(NSTableColumn *)tc
|
|
|
|
row:(NSInteger)row
|
|
|
|
mouseLocation:(NSPoint)mouseLocation {
|
2021-04-30 01:16:24 +00:00
|
|
|
DLog(@"GETTING STATUS FOR ROW: %li: %@!", row,
|
2021-01-30 23:14:08 +00:00
|
|
|
[[[self arrangedObjects] objectAtIndex:row] statusMessage]);
|
|
|
|
return [[[self arrangedObjects] objectAtIndex:row] statusMessage];
|
2008-02-22 02:19:46 +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 {
|
2021-01-30 23:14:08 +00:00
|
|
|
[super moveObjectsInArrangedObjectsFromIndexes:indexSet toIndex:insertIndex];
|
|
|
|
|
2021-12-24 09:01:21 +00:00
|
|
|
#if 0 // syncPlaylistEntries is already called for rearrangement
|
|
|
|
[[SQLiteStore sharedStore] playlistMoveObjectsInArrangedObjectsFromIndexes:indexSet toIndex:insertIndex];
|
|
|
|
#endif
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
[playbackController playlistDidChange:self];
|
2008-02-24 15:47:04 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (id <NSPasteboardWriting>)tableView:(NSTableView *)tableView
|
|
|
|
pasteboardWriterForRow:(NSInteger)row {
|
|
|
|
NSPasteboardItem *item = (NSPasteboardItem *) [super tableView:tableView
|
|
|
|
pasteboardWriterForRow:row];
|
|
|
|
if (!item) {
|
|
|
|
item = [[NSPasteboardItem alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableArray *filenames = [NSMutableArray array];
|
|
|
|
PlaylistEntry *song = [[self arrangedObjects] objectAtIndex:row];
|
|
|
|
[filenames addObject:[[song path] stringByExpandingTildeInPath]];
|
|
|
|
|
2021-09-23 07:49:51 +00:00
|
|
|
if (@available(macOS 10.13, *)) {
|
|
|
|
[item setData:[song.URL dataRepresentation] forType:NSPasteboardTypeFileURL];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
[item setPropertyList:@[song.URL] forType:NSFilenamesPboardType];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
return item;
|
2008-02-10 19:35:58 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (BOOL)tableView:(NSTableView *)tv
|
|
|
|
acceptDrop:(id <NSDraggingInfo>)info
|
|
|
|
row:(NSInteger)row
|
|
|
|
dropOperation:(NSTableViewDropOperation)op {
|
|
|
|
// 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
|
2021-09-23 07:49:51 +00:00
|
|
|
NSPasteboardType fileType;
|
|
|
|
if (@available(macOS 10.13, *)) {
|
|
|
|
fileType = NSPasteboardTypeFileURL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fileType = NSFilenamesPboardType;
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
NSArray *supportedTypes =
|
2021-09-23 07:49:51 +00:00
|
|
|
@[CogUrlsPboardType, fileType, iTunesDropType];
|
2021-01-30 23:14:08 +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 {
|
2021-09-23 07:49:51 +00:00
|
|
|
if (@available(macOS 10.13, *)) {
|
|
|
|
NSSet *allowed = [NSSet setWithArray:@[[NSArray class], [NSURL class]]];
|
|
|
|
urls = [NSKeyedUnarchiver unarchivedObjectOfClasses:allowed
|
|
|
|
fromData:data
|
|
|
|
error:&error];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
urls = [NSUnarchiver unarchiveObjectWithData:data];
|
|
|
|
}
|
2021-01-30 23:14:08 +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)
|
2021-09-23 07:49:51 +00:00
|
|
|
if ([bestType isEqualToString:fileType]) {
|
2021-02-06 08:02:55 +00:00
|
|
|
NSArray<Class> *classes = @[[NSURL class]];
|
|
|
|
NSDictionary *options = @{};
|
|
|
|
NSArray<NSURL*> *files = [pboard readObjectsForClasses:classes options:options];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
//[playlistLoader insertURLs:urls atIndex:row sort:YES];
|
2021-02-06 08:02:55 +00:00
|
|
|
[acceptedURLs addObjectsFromArray:files];
|
2021-01-30 23:14:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
return undoManager;
|
2008-02-10 16:16:45 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (NSIndexSet *)disarrangeIndexes:(NSIndexSet *)indexes {
|
|
|
|
if ([[self arrangedObjects] count] <= [indexes lastIndex]) return indexes;
|
|
|
|
|
2016-05-05 20:05:39 +00:00
|
|
|
NSMutableIndexSet *disarrangedIndexes = [[NSMutableIndexSet alloc] init];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2021-12-24 09:01:21 +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
|
|
|
|
2013-10-18 08:47:48 +00:00
|
|
|
return disarrangedIndexes;
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (NSArray *)disarrangeObjects:(NSArray *)objects {
|
2016-05-05 20:05:39 +00:00
|
|
|
NSMutableArray *disarrangedObjects = [[NSMutableArray alloc] init];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
for (PlaylistEntry *pe in [self content]) {
|
|
|
|
if ([objects containsObject:pe]) [disarrangedObjects addObject:pe];
|
2013-10-18 08:47:48 +00:00
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2013-10-18 08:47:48 +00:00
|
|
|
return disarrangedObjects;
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (NSIndexSet *)rearrangeIndexes:(NSIndexSet *)indexes {
|
|
|
|
if ([[self content] count] <= [indexes lastIndex]) return indexes;
|
|
|
|
|
2016-05-05 20:05:39 +00:00
|
|
|
NSMutableIndexSet *rearrangedIndexes = [[NSMutableIndexSet alloc] init];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2021-12-24 09:01:21 +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
|
|
|
|
2013-10-18 08:47:48 +00:00
|
|
|
return rearrangedIndexes;
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)insertObjects:(NSArray *)objects atIndexes:(NSIndexSet *)indexes {
|
2013-10-18 08:47:48 +00:00
|
|
|
[self insertObjects:objects atArrangedObjectIndexes:indexes];
|
|
|
|
[self rearrangeObjects];
|
|
|
|
}
|
|
|
|
|
2021-12-24 09:01:21 +00:00
|
|
|
- (void)insertObjectsUnsynced:(NSArray *)objects atArrangedObjectIndexes:(NSIndexSet *)indexes {
|
|
|
|
[super insertObjects:objects atArrangedObjectIndexes:indexes];
|
|
|
|
|
|
|
|
if ([self shuffle] != ShuffleOff) [self resetShuffleList];
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)insertObjects:(NSArray *)objects atArrangedObjectIndexes:(NSIndexSet *)indexes {
|
|
|
|
[[[self undoManager] prepareWithInvocationTarget:self]
|
|
|
|
removeObjectsAtIndexes:[self disarrangeIndexes:indexes]];
|
|
|
|
NSString *actionName =
|
|
|
|
[NSString stringWithFormat:@"Adding %lu entries", (unsigned long) [objects count]];
|
2013-10-11 19:33:58 +00:00
|
|
|
[[self undoManager] setActionName:actionName];
|
2021-12-24 09:01:21 +00:00
|
|
|
|
2022-01-09 10:10:08 +00:00
|
|
|
[[SQLiteStore sharedStore] playlistInsertTracks:objects atObjectIndexes:indexes progressCall:^(double progress) {
|
|
|
|
[self setProgressBarStatus:progress];
|
|
|
|
}];
|
2013-10-11 19:33:58 +00:00
|
|
|
|
|
|
|
[super insertObjects:objects atArrangedObjectIndexes:indexes];
|
2021-12-24 09:01:21 +00:00
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
if ([self shuffle] != ShuffleOff) [self resetShuffleList];
|
2008-02-10 16:16:45 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)removeObjectsAtIndexes:(NSIndexSet *)indexes {
|
2013-10-18 08:47:48 +00:00
|
|
|
[self removeObjectsAtArrangedObjectIndexes:[self rearrangeIndexes:indexes]];
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)removeObjectsAtArrangedObjectIndexes:(NSIndexSet *)indexes {
|
2013-10-18 07:17:03 +00:00
|
|
|
NSArray *objects = [[self arrangedObjects] objectsAtIndexes:indexes];
|
2021-01-30 23:14:08 +00:00
|
|
|
[[[self undoManager] prepareWithInvocationTarget:self]
|
|
|
|
insertObjects:[self disarrangeObjects:objects]
|
|
|
|
atIndexes:[self disarrangeIndexes:indexes]];
|
|
|
|
NSString *actionName =
|
|
|
|
[NSString stringWithFormat:@"Removing %lu entries", (unsigned long) [indexes count]];
|
2013-10-11 19:33:58 +00:00
|
|
|
[[self undoManager] setActionName:actionName];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2013-10-11 19:33:58 +00:00
|
|
|
DLog(@"Removing indexes: %@", indexes);
|
2021-04-30 01:16:24 +00:00
|
|
|
DLog(@"Current index: %li", currentEntry.index);
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2013-10-18 07:17:03 +00:00
|
|
|
NSMutableIndexSet *unarrangedIndexes = [[NSMutableIndexSet alloc] init];
|
2021-01-30 23:14:08 +00:00
|
|
|
for (PlaylistEntry *pe in objects) {
|
2013-10-18 07:17:03 +00:00
|
|
|
[unarrangedIndexes addIndex:[pe index]];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
if (currentEntry.index >= 0 && [unarrangedIndexes containsIndex:currentEntry.index]) {
|
2013-10-11 19:33:58 +00:00
|
|
|
currentEntry.index = -currentEntry.index - 1;
|
2021-04-30 01:16:24 +00:00
|
|
|
DLog(@"Current removed: %li", currentEntry.index);
|
2013-10-11 19:33:58 +00:00
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
if (currentEntry.index < 0) // Need to update the negative index
|
2013-10-11 19:33:58 +00:00
|
|
|
{
|
2021-04-30 01:16:24 +00:00
|
|
|
NSInteger i = -currentEntry.index - 1;
|
|
|
|
DLog(@"I is %li", i);
|
|
|
|
NSInteger j;
|
2021-01-30 23:14:08 +00:00
|
|
|
for (j = i - 1; j >= 0; j--) {
|
2013-10-18 07:17:03 +00:00
|
|
|
if ([unarrangedIndexes containsIndex:j]) {
|
2013-10-11 19:33:58 +00:00
|
|
|
DLog(@"Removing 1");
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
currentEntry.index = -i - 1;
|
|
|
|
}
|
2021-12-24 09:01:21 +00:00
|
|
|
|
2022-01-09 10:10:08 +00:00
|
|
|
[[SQLiteStore sharedStore] playlistRemoveTracksAtIndexes:unarrangedIndexes progressCall:^(double progress) {
|
|
|
|
[self setProgressBarStatus:progress];
|
|
|
|
}];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2013-10-11 19:33:58 +00:00
|
|
|
[super removeObjectsAtArrangedObjectIndexes:indexes];
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
if ([self shuffle] != ShuffleOff) [self resetShuffleList];
|
2013-10-11 19:33:58 +00:00
|
|
|
|
|
|
|
[playbackController playlistDidChange:self];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)setSortDescriptors:(NSArray *)sortDescriptors {
|
|
|
|
DLog(@"Current: %@, setting: %@", [self sortDescriptors], sortDescriptors);
|
|
|
|
|
|
|
|
// Cheap hack so the index column isn't sorted
|
|
|
|
if (([sortDescriptors count] != 0) && [[sortDescriptors[0] key]
|
|
|
|
caseInsensitiveCompare:@"index"] == NSOrderedSame) {
|
|
|
|
// Remove the sort descriptors
|
|
|
|
[super setSortDescriptors:[NSArray array]];
|
|
|
|
[self rearrangeObjects];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[super setSortDescriptors:sortDescriptors];
|
|
|
|
[self rearrangeObjects];
|
|
|
|
|
|
|
|
[playbackController playlistDidChange:self];
|
2006-05-12 19:23:17 +00:00
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
- (IBAction)randomizeList:(id)sender {
|
|
|
|
[self setSortDescriptors:[NSArray array]];
|
2007-02-18 22:27:55 +00:00
|
|
|
|
2013-10-11 19:33:58 +00:00
|
|
|
NSArray *unrandomized = [self content];
|
|
|
|
[[[self undoManager] prepareWithInvocationTarget:self] unrandomizeList:unrandomized];
|
2006-04-30 13:01:33 +00:00
|
|
|
|
2013-10-11 19:33:58 +00:00
|
|
|
[self setContent:[Shuffle shuffleList:[self content]]];
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
if ([self shuffle] != ShuffleOff) [self resetShuffleList];
|
2013-10-11 19:33:58 +00:00
|
|
|
|
|
|
|
[[self undoManager] setActionName:@"Playlist Randomization"];
|
2006-04-30 13:01:33 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)unrandomizeList:(NSArray *)entries {
|
2013-10-11 19:33:58 +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 {
|
|
|
|
ShuffleMode shuffle = [self shuffle];
|
|
|
|
|
|
|
|
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 {
|
|
|
|
RepeatMode repeat = [self repeat];
|
|
|
|
|
|
|
|
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 {
|
2021-01-30 23:14:08 +00:00
|
|
|
RepeatMode repeat = [self repeat];
|
|
|
|
|
|
|
|
if (i < 0 || i >= [[self arrangedObjects] count]) {
|
|
|
|
if (repeat != RepeatModeRepeatAll) return nil;
|
|
|
|
|
|
|
|
while (i < 0) i += [[self arrangedObjects] count];
|
|
|
|
if (i >= [[self arrangedObjects] count]) i %= [[self arrangedObjects] count];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [[self arrangedObjects] objectAtIndex:i];
|
2006-04-15 13:51:40 +00:00
|
|
|
}
|
2007-03-09 01:16:06 +00:00
|
|
|
|
2013-10-11 19:39:05 +00:00
|
|
|
- (void)remove:(id)sender {
|
|
|
|
// It's a kind of magic.
|
|
|
|
// Plain old NSArrayController's remove: isn't working properly for some reason.
|
2021-01-30 23:14:08 +00:00
|
|
|
// The method is definitely called but (overridden) removeObjectsAtArrangedObjectIndexes: isn't
|
|
|
|
// called and no entries are removed. Putting explicit call to
|
|
|
|
// removeObjectsAtArrangedObjectIndexes: here for now.
|
2013-10-11 19:39:05 +00:00
|
|
|
// TODO: figure it out
|
|
|
|
|
|
|
|
NSIndexSet *selected = [self selectionIndexes];
|
2021-01-30 23:14:08 +00:00
|
|
|
if ([selected count] > 0) {
|
2013-10-11 19:39:05 +00:00
|
|
|
[self removeObjectsAtArrangedObjectIndexes:selected];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-18 07:13:27 +00:00
|
|
|
- (IBAction)removeDuplicates:(id)sender {
|
|
|
|
NSMutableArray *originals = [[NSMutableArray alloc] init];
|
2013-10-18 07:25:37 +00:00
|
|
|
NSMutableArray *duplicates = [[NSMutableArray alloc] init];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
for (PlaylistEntry *pe in [self content]) {
|
2013-10-18 07:13:27 +00:00
|
|
|
if ([originals containsObject:[pe URL]])
|
2013-10-18 07:25:37 +00:00
|
|
|
[duplicates addObject:pe];
|
2013-10-18 07:13:27 +00:00
|
|
|
else
|
|
|
|
[originals addObject:[pe URL]];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
if ([duplicates count] > 0) {
|
|
|
|
NSArray *arrangedContent = [self arrangedObjects];
|
|
|
|
NSMutableIndexSet *duplicatesIndex = [[NSMutableIndexSet alloc] init];
|
|
|
|
for (PlaylistEntry *pe in duplicates) {
|
2013-10-18 07:25:37 +00:00
|
|
|
[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 {
|
2013-10-18 07:25:37 +00:00
|
|
|
NSMutableArray *deadItems = [[NSMutableArray alloc] init];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
for (PlaylistEntry *pe in [self content]) {
|
2013-10-18 07:14:53 +00:00
|
|
|
NSURL *url = [pe URL];
|
|
|
|
if ([url isFileURL])
|
|
|
|
if (![[NSFileManager defaultManager] fileExistsAtPath:[url path]])
|
2013-10-18 07:25:37 +00:00
|
|
|
[deadItems addObject:pe];
|
2013-10-18 07:14:53 +00:00
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
if ([deadItems count] > 0) {
|
|
|
|
NSArray *arrangedContent = [self arrangedObjects];
|
|
|
|
NSMutableIndexSet *deadItemsIndex = [[NSMutableIndexSet alloc] init];
|
|
|
|
for (PlaylistEntry *pe in deadItems) {
|
2013-10-18 07:25:37 +00:00
|
|
|
[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 {
|
2021-01-30 23:14:08 +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 {
|
2017-12-24 07:55:33 +00:00
|
|
|
return [self getNextEntry:pe ignoreRepeatOne:NO];
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (PlaylistEntry *)getNextEntry:(PlaylistEntry *)pe ignoreRepeatOne:(BOOL)ignoreRepeatOne {
|
|
|
|
if (!ignoreRepeatOne && [self repeat] == RepeatModeRepeatOne) {
|
|
|
|
return pe;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([queueList count] > 0) {
|
|
|
|
pe = queueList[0];
|
|
|
|
[queueList removeObjectAtIndex:0];
|
2021-12-24 09:01:21 +00:00
|
|
|
[[SQLiteStore sharedStore] queueRemoveItem:0];
|
2021-01-30 23:14:08 +00:00
|
|
|
pe.queued = NO;
|
|
|
|
[pe setQueuePosition:-1];
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < [queueList count]; i++) {
|
|
|
|
PlaylistEntry *queueItem = queueList[i];
|
|
|
|
[queueItem setQueuePosition:i];
|
|
|
|
}
|
|
|
|
|
2017-12-24 07:55:33 +00:00
|
|
|
return pe;
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
if ([self shuffle] != ShuffleOff) {
|
|
|
|
return [self shuffledEntryAtIndex:(pe.shuffleIndex + 1)];
|
|
|
|
} else {
|
2021-04-30 01:16:24 +00:00
|
|
|
NSInteger i;
|
2021-01-30 23:14:08 +00:00
|
|
|
if (pe.index < 0) // Was a current entry, now removed.
|
|
|
|
{
|
|
|
|
i = -pe.index - 1;
|
|
|
|
} 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 {
|
|
|
|
NSPredicate *predicate;
|
|
|
|
if ([album length] > 0)
|
|
|
|
predicate = [NSPredicate predicateWithFormat:@"album like %@", album];
|
|
|
|
else
|
|
|
|
predicate = [NSPredicate predicateWithFormat:@"album == nil"];
|
|
|
|
return [[self arrangedObjects] filteredArrayUsingPredicate:predicate];
|
2008-02-21 19:14:20 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (PlaylistEntry *)getPrevEntry:(PlaylistEntry *)pe {
|
2017-12-24 07:55:33 +00:00
|
|
|
return [self getPrevEntry:pe ignoreRepeatOne:NO];
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (PlaylistEntry *)getPrevEntry:(PlaylistEntry *)pe ignoreRepeatOne:(BOOL)ignoreRepeatOne {
|
|
|
|
if (!ignoreRepeatOne && [self repeat] == RepeatModeRepeatOne) {
|
|
|
|
return pe;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([self shuffle] != ShuffleOff) {
|
|
|
|
return [self shuffledEntryAtIndex:(pe.shuffleIndex - 1)];
|
|
|
|
} else {
|
2021-04-30 01:16:24 +00:00
|
|
|
NSInteger i;
|
2021-01-30 23:14:08 +00:00
|
|
|
if (pe.index < 0) // Was a current entry, now removed.
|
|
|
|
{
|
|
|
|
i = -pe.index - 2;
|
|
|
|
} else {
|
|
|
|
i = pe.index - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [self entryAtIndex:i];
|
|
|
|
}
|
2006-04-15 13:51:40 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (BOOL)next {
|
|
|
|
PlaylistEntry *pe;
|
|
|
|
|
|
|
|
pe = [self getNextEntry:[self currentEntry] ignoreRepeatOne:YES];
|
|
|
|
|
|
|
|
if (pe == nil) return NO;
|
|
|
|
|
|
|
|
[self setCurrentEntry:pe];
|
|
|
|
|
|
|
|
return YES;
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (BOOL)prev {
|
|
|
|
PlaylistEntry *pe;
|
|
|
|
|
2017-12-24 07:55:33 +00:00
|
|
|
pe = [self getPrevEntry:[self currentEntry] ignoreRepeatOne:YES];
|
2021-01-30 23:14:08 +00:00
|
|
|
if (pe == nil) return NO;
|
|
|
|
|
|
|
|
[self setCurrentEntry:pe];
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *)shuffleAlbums {
|
|
|
|
NSArray *newList = [self arrangedObjects];
|
|
|
|
NSMutableArray *temp = [[NSMutableArray alloc] init];
|
|
|
|
NSMutableArray *albums = [[NSMutableArray alloc] init];
|
|
|
|
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"track"
|
|
|
|
ascending:YES];
|
|
|
|
for (unsigned long i = 0, j = [newList count]; i < j; ++i) {
|
|
|
|
PlaylistEntry *pe = newList[i];
|
|
|
|
NSString *album = [pe album];
|
|
|
|
if (!album) album = @"";
|
|
|
|
if ([albums containsObject:album]) continue;
|
|
|
|
[albums addObject:album];
|
|
|
|
NSArray *albumContent = [self filterPlaylistOnAlbum:album];
|
|
|
|
NSArray *sortedContent =
|
|
|
|
[albumContent sortedArrayUsingDescriptors:@[sortDescriptor]];
|
|
|
|
[temp addObject:sortedContent[0]];
|
|
|
|
}
|
|
|
|
NSArray *tempList = [Shuffle shuffleList:temp];
|
|
|
|
temp = [[NSMutableArray alloc] init];
|
|
|
|
for (unsigned long i = 0, j = [tempList count]; i < j; ++i) {
|
|
|
|
PlaylistEntry *pe = tempList[i];
|
|
|
|
NSString *album = [pe album];
|
|
|
|
NSArray *albumContent = [self filterPlaylistOnAlbum:album];
|
|
|
|
NSArray *sortedContent =
|
|
|
|
[albumContent sortedArrayUsingDescriptors:@[sortDescriptor]];
|
|
|
|
[temp addObjectsFromArray:sortedContent];
|
|
|
|
}
|
|
|
|
return temp;
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
2006-04-14 20:34:14 +00:00
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)addShuffledListToFront {
|
|
|
|
NSArray *newList;
|
|
|
|
NSIndexSet *indexSet;
|
2019-10-13 01:27:02 +00:00
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
if ([self shuffle] == ShuffleAlbums) {
|
|
|
|
newList = [self shuffleAlbums];
|
|
|
|
} else {
|
|
|
|
newList = [Shuffle shuffleList:[self arrangedObjects]];
|
|
|
|
}
|
|
|
|
|
|
|
|
indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [newList count])];
|
|
|
|
|
|
|
|
[shuffleList insertObjects:newList atIndexes:indexSet];
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < [shuffleList count]; i++) {
|
|
|
|
[shuffleList[i] setShuffleIndex:i];
|
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)addShuffledListToBack {
|
|
|
|
NSArray *newList;
|
|
|
|
NSIndexSet *indexSet;
|
|
|
|
|
|
|
|
if ([self shuffle] == ShuffleAlbums) {
|
|
|
|
newList = [self shuffleAlbums];
|
|
|
|
} else {
|
|
|
|
newList = [Shuffle shuffleList:[self arrangedObjects]];
|
|
|
|
}
|
|
|
|
|
|
|
|
indexSet =
|
|
|
|
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange([shuffleList count], [newList count])];
|
|
|
|
|
|
|
|
[shuffleList insertObjects:newList atIndexes:indexSet];
|
|
|
|
|
|
|
|
unsigned long i;
|
|
|
|
for (i = ([shuffleList count] - [newList count]); i < [shuffleList count]; i++) {
|
|
|
|
[shuffleList[i] setShuffleIndex:(int) i];
|
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)resetShuffleList {
|
|
|
|
[shuffleList removeAllObjects];
|
2006-04-15 13:51:40 +00:00
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
[self addShuffledListToFront];
|
2006-04-15 13:51:40 +00:00
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
if (currentEntry && currentEntry.index >= 0) {
|
2019-10-25 00:18:51 +00:00
|
|
|
if ([self shuffle] == ShuffleAlbums) {
|
2021-01-30 23:14:08 +00:00
|
|
|
NSString *currentAlbum = currentEntry.album;
|
|
|
|
if (!currentAlbum) currentAlbum = @"";
|
|
|
|
|
|
|
|
NSArray *wholeAlbum = [self filterPlaylistOnAlbum:currentAlbum];
|
|
|
|
|
2019-10-25 00:18:51 +00:00
|
|
|
// First prune the shuffle list of the currently playing album
|
2019-12-16 02:12:06 +00:00
|
|
|
long i, j;
|
2019-10-25 00:18:51 +00:00
|
|
|
for (i = 0; i < [shuffleList count];) {
|
2021-01-30 23:14:08 +00:00
|
|
|
if ([wholeAlbum containsObject:shuffleList[i]]) {
|
2019-10-25 00:18:51 +00:00
|
|
|
[shuffleList removeObjectAtIndex:i];
|
2021-01-30 23:14:08 +00:00
|
|
|
} else {
|
2019-10-25 00:18:51 +00:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2019-12-16 02:12:06 +00:00
|
|
|
// Then insert the playing album at the start
|
2021-01-30 23:14:08 +00:00
|
|
|
NSIndexSet *indexSet =
|
|
|
|
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [wholeAlbum count])];
|
|
|
|
|
2019-12-16 02:12:06 +00:00
|
|
|
[shuffleList insertObjects:wholeAlbum atIndexes:indexSet];
|
|
|
|
|
|
|
|
// Oops, gotta reset the shuffle indexes
|
|
|
|
for (i = 0, j = [shuffleList count]; i < j; ++i) {
|
2021-01-30 23:14:08 +00:00
|
|
|
[shuffleList[i] setShuffleIndex:(int) i];
|
2019-12-16 02:12:06 +00:00
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
} else {
|
2019-10-25 00:18:51 +00:00
|
|
|
[shuffleList insertObject:currentEntry atIndex:0];
|
|
|
|
[currentEntry setShuffleIndex:0];
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
// Need to rejigger so the current entry is at the start now...
|
2019-12-16 02:12:06 +00:00
|
|
|
long i, j;
|
2019-10-25 00:18:51 +00:00
|
|
|
BOOL found = NO;
|
2021-01-30 23:14:08 +00:00
|
|
|
for (i = 1, j = [shuffleList count]; i < j && !found; i++) {
|
|
|
|
if (shuffleList[i] == currentEntry) {
|
2019-10-25 00:18:51 +00:00
|
|
|
found = YES;
|
|
|
|
[shuffleList removeObjectAtIndex:i];
|
2021-01-30 23:14:08 +00:00
|
|
|
} else {
|
|
|
|
[shuffleList[i] setShuffleIndex:(int) i];
|
2019-10-25 00:18:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
}
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)setCurrentEntry:(PlaylistEntry *)pe {
|
|
|
|
currentEntry.current = NO;
|
|
|
|
currentEntry.stopAfter = NO;
|
|
|
|
|
|
|
|
pe.current = YES;
|
|
|
|
|
|
|
|
if (pe != nil) [self.tableView scrollRowToVisible:pe.index];
|
|
|
|
|
|
|
|
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 {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setInteger:s forKey:@"shuffle"];
|
|
|
|
if (s != ShuffleOff) [self resetShuffleList];
|
|
|
|
|
|
|
|
[playbackController playlistDidChange:self];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
- (ShuffleMode)shuffle {
|
|
|
|
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 {
|
|
|
|
[[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 {
|
|
|
|
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 {
|
|
|
|
[self setFilterPredicate:nil];
|
|
|
|
|
|
|
|
[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 {
|
|
|
|
[self setFilterPredicate:nil];
|
2007-05-26 14:09:03 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (void)setFilterPredicate:(NSPredicate *)filterPredicate {
|
|
|
|
[super setFilterPredicate:filterPredicate];
|
2006-04-30 15:31:57 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)showEntryInFinder:(id)sender {
|
|
|
|
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
|
|
|
|
|
|
|
|
NSURL *url = [[self selectedObjects][0] URL];
|
|
|
|
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
|
|
|
}
|
|
|
|
*/
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)searchByArtist:(id)sender; {
|
2008-02-16 16:13:21 +00:00
|
|
|
PlaylistEntry *entry = [[self arrangedObjects] objectAtIndex:[self selectionIndex]];
|
|
|
|
[spotlightWindowController searchForArtist:[entry artist]];
|
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
|
|
|
- (IBAction)searchByAlbum:(id)sender; {
|
2008-02-16 16:13:21 +00:00
|
|
|
PlaylistEntry *entry = [[self arrangedObjects] objectAtIndex:[self selectionIndex]];
|
|
|
|
[spotlightWindowController searchForAlbum:[entry album]];
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (NSMutableArray *)queueList {
|
|
|
|
return queueList;
|
2008-02-21 09:05:06 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)emptyQueueList:(id)sender {
|
2021-12-24 09:01:21 +00:00
|
|
|
[self emptyQueueListUnsynced];
|
|
|
|
[[SQLiteStore sharedStore] queueEmpty];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)emptyQueueListUnsynced {
|
2021-01-30 23:14:08 +00:00
|
|
|
for (PlaylistEntry *queueItem in queueList) {
|
|
|
|
queueItem.queued = NO;
|
|
|
|
[queueItem setQueuePosition:-1];
|
|
|
|
}
|
2008-02-22 02:21:08 +00:00
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
[queueList removeAllObjects];
|
2008-02-21 09:05:06 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)toggleQueued:(id)sender {
|
2021-12-24 09:01:21 +00:00
|
|
|
SQLiteStore *store = [SQLiteStore sharedStore];
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
for (PlaylistEntry *queueItem in [self selectedObjects]) {
|
|
|
|
if (queueItem.queued) {
|
|
|
|
queueItem.queued = NO;
|
|
|
|
queueItem.queuePosition = -1;
|
2008-02-21 09:05:06 +00:00
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
[queueList removeObject:queueItem];
|
2021-12-24 09:01:21 +00:00
|
|
|
|
|
|
|
[store queueRemovePlaylistItems:[NSArray arrayWithObject:queueItem]];
|
2021-01-30 23:14:08 +00:00
|
|
|
} else {
|
|
|
|
queueItem.queued = YES;
|
|
|
|
queueItem.queuePosition = (int) [queueList count];
|
|
|
|
|
|
|
|
[queueList addObject:queueItem];
|
2021-12-24 09:01:21 +00:00
|
|
|
|
|
|
|
[store queueAddItem:[queueItem index]];
|
2021-01-30 23:14:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DLog(@"TOGGLE QUEUED: %i", queueItem.queued);
|
|
|
|
}
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
for (PlaylistEntry *cur in queueList) {
|
|
|
|
cur.queuePosition = i++;
|
|
|
|
}
|
2008-02-22 15:26:46 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)removeFromQueue:(id)sender {
|
2021-12-24 09:01:21 +00:00
|
|
|
SQLiteStore *store = [SQLiteStore sharedStore];
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
for (PlaylistEntry *queueItem in [self selectedObjects]) {
|
2018-06-28 10:59:59 +00:00
|
|
|
queueItem.queued = NO;
|
|
|
|
queueItem.queuePosition = -1;
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2018-06-28 10:59:59 +00:00
|
|
|
[queueList removeObject:queueItem];
|
2021-12-24 09:01:21 +00:00
|
|
|
[store queueRemovePlaylistItems:[NSArray arrayWithObject:queueItem]];
|
2018-06-28 10:59:59 +00:00
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2018-06-28 10:59:59 +00:00
|
|
|
int i = 0;
|
2021-01-30 23:14:08 +00:00
|
|
|
for (PlaylistEntry *cur in queueList) {
|
2018-06-28 10:59:59 +00:00
|
|
|
cur.queuePosition = i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)addToQueue:(id)sender {
|
2021-12-24 09:01:21 +00:00
|
|
|
SQLiteStore *store = [SQLiteStore sharedStore];
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
for (PlaylistEntry *queueItem in [self selectedObjects]) {
|
2018-06-28 10:59:59 +00:00
|
|
|
queueItem.queued = YES;
|
|
|
|
queueItem.queuePosition = (int) [queueList count];
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2018-06-28 10:59:59 +00:00
|
|
|
[queueList addObject:queueItem];
|
2021-12-24 09:01:21 +00:00
|
|
|
[store queueAddItem:[queueItem index]];
|
2018-06-28 10:59:59 +00:00
|
|
|
}
|
2021-01-30 23:14:08 +00:00
|
|
|
|
2018-06-28 10:59:59 +00:00
|
|
|
int i = 0;
|
2021-01-30 23:14:08 +00:00
|
|
|
for (PlaylistEntry *cur in queueList) {
|
2018-06-28 10:59:59 +00:00
|
|
|
cur.queuePosition = i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (IBAction)stopAfterCurrent:(id)sender {
|
|
|
|
currentEntry.stopAfter = !currentEntry.stopAfter;
|
2008-02-25 17:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:14:08 +00:00
|
|
|
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
|
|
|
|
SEL action = [menuItem action];
|
|
|
|
|
|
|
|
if (action == @selector(removeFromQueue:)) {
|
|
|
|
for (PlaylistEntry *q in [self selectedObjects])
|
|
|
|
if (q.queuePosition >= 0) return YES;
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action == @selector(emptyQueueList:) && ([queueList count] < 1)) return NO;
|
|
|
|
|
|
|
|
if (action == @selector(stopAfterCurrent:) && currentEntry.stopAfter) return NO;
|
|
|
|
|
|
|
|
// if nothing is selected, gray out these
|
|
|
|
if ([[self selectedObjects] count] < 1) {
|
|
|
|
if (action == @selector(remove:)) return NO;
|
|
|
|
|
|
|
|
if (action == @selector(addToQueue:)) return NO;
|
|
|
|
|
|
|
|
if (action == @selector(searchByArtist:)) return NO;
|
|
|
|
|
|
|
|
if (action == @selector(searchByAlbum:)) return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
if (![urls count]) return;
|
|
|
|
|
|
|
|
CGEventRef event = CGEventCreate(NULL /*default event source*/);
|
|
|
|
CGEventFlags mods = CGEventGetFlags(event);
|
|
|
|
CFRelease(event);
|
|
|
|
|
|
|
|
BOOL modifierPressed =
|
|
|
|
((mods & kCGEventFlagMaskCommand) != 0) & ((mods & kCGEventFlagMaskControl) != 0);
|
|
|
|
modifierPressed |= ((mods & kCGEventFlagMaskShift) != 0);
|
|
|
|
|
|
|
|
NSString *behavior =
|
|
|
|
[[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesBehavior"];
|
|
|
|
if (modifierPressed) {
|
|
|
|
behavior =
|
|
|
|
[[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesAlteredBehavior"];
|
|
|
|
}
|
2008-05-09 21:24:49 +00:00
|
|
|
|
2021-01-30 23:14:08 +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"];
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
if (![urls count]) return;
|
|
|
|
|
|
|
|
CGEventRef event = CGEventCreate(NULL);
|
|
|
|
CGEventFlags mods = CGEventGetFlags(event);
|
|
|
|
CFRelease(event);
|
|
|
|
|
|
|
|
BOOL modifierPressed =
|
|
|
|
((mods & kCGEventFlagMaskCommand) != 0) & ((mods & kCGEventFlagMaskControl) != 0);
|
|
|
|
modifierPressed |= ((mods & kCGEventFlagMaskShift) != 0);
|
|
|
|
|
|
|
|
NSString *behavior =
|
|
|
|
[[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesBehavior"];
|
|
|
|
if (modifierPressed) {
|
|
|
|
behavior =
|
|
|
|
[[NSUserDefaults standardUserDefaults] valueForKey:@"openingFilesAlteredBehavior"];
|
|
|
|
}
|
|
|
|
|
|
|
|
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"];;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Auto start playback
|
|
|
|
if (shouldPlay && [[self content] count] > 0) {
|
|
|
|
[playbackController playEntry:urls[0]];
|
|
|
|
}
|
|
|
|
}
|
2008-02-22 15:26:46 +00:00
|
|
|
|
2021-07-03 22:32:13 +00:00
|
|
|
- (IBAction)reloadTags:(id)sender {
|
|
|
|
NSArray * selectedobjects = [self selectedObjects];
|
|
|
|
if ([selectedobjects count]) {
|
|
|
|
for (PlaylistEntry *pe in selectedobjects) {
|
|
|
|
pe.metadataLoaded = NO;
|
|
|
|
}
|
|
|
|
|
2022-01-07 10:12:49 +00:00
|
|
|
[playlistLoader performSelectorInBackground:@selector(loadInfoForEntries:) withObject:selectedobjects];
|
2021-07-03 22:32:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
@end
|