Reformat my own source code with clang-format
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
parent
361f61618a
commit
85c7073649
397 changed files with 2238946 additions and 210159 deletions
176
.clang-format
Normal file
176
.clang-format
Normal file
|
@ -0,0 +1,176 @@
|
||||||
|
# The style used for all options not specifically set in the configuration.
|
||||||
|
BasedOnStyle: LLVM
|
||||||
|
|
||||||
|
# The extra indent or outdent of access modifiers, e.g. public:.
|
||||||
|
AccessModifierOffset: 0
|
||||||
|
|
||||||
|
# If true, aligns escaped newlines as far left as possible. Otherwise puts them into the right-most column.
|
||||||
|
AlignEscapedNewlinesLeft: false
|
||||||
|
|
||||||
|
# If true, aligns trailing comments.
|
||||||
|
AlignTrailingComments: false
|
||||||
|
|
||||||
|
# Allow putting all parameters of a function declaration onto the next line even if BinPackParameters is false.
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
|
||||||
|
# Allows contracting simple braced statements to a single line.
|
||||||
|
AllowShortBlocksOnASingleLine: true
|
||||||
|
|
||||||
|
# If true, short case labels will be contracted to a single line.
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
|
||||||
|
# Dependent on the value, int f() { return 0; } can be put on a single line. Possible values: None, Inline, All.
|
||||||
|
AllowShortFunctionsOnASingleLine: None
|
||||||
|
|
||||||
|
# If true, if (a) return; can be put on a single line.
|
||||||
|
AllowShortIfStatementsOnASingleLine: true
|
||||||
|
|
||||||
|
# If true, while (true) continue; can be put on a single line.
|
||||||
|
AllowShortLoopsOnASingleLine: true
|
||||||
|
|
||||||
|
# If true, always break after function definition return types. More truthfully called ‘break before the identifier following the type in a function definition’.
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: false
|
||||||
|
|
||||||
|
# If true, always break before multiline string literals.
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
|
||||||
|
# If true, always break after the template<...> of a template declaration.
|
||||||
|
AlwaysBreakTemplateDeclarations: true
|
||||||
|
|
||||||
|
# If false, a function call’s arguments will either be all on the same line or will have one line each.
|
||||||
|
#BinPackArguments: true
|
||||||
|
|
||||||
|
# If false, a function declaration’s or function definition’s parameters will either all be on the same line or will have one line each.
|
||||||
|
BinPackParameters: true
|
||||||
|
|
||||||
|
# The way to wrap binary operators. Possible values: None, NonAssignment, All.
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
|
||||||
|
# The brace breaking style to use. Possible values: Attach, Linux, Stroustrup, Allman, GNU.
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
|
||||||
|
# If true, ternary operators will be placed after line breaks.
|
||||||
|
BreakBeforeTernaryOperators: false
|
||||||
|
|
||||||
|
# Always break constructor initializers before commas and align the commas with the colon.
|
||||||
|
BreakConstructorInitializersBeforeComma: false
|
||||||
|
|
||||||
|
# The column limit. A column limit of 0 means that there is no column limit.
|
||||||
|
ColumnLimit: 0
|
||||||
|
|
||||||
|
# A regular expression that describes comments with special meaning, which should not be split into lines or otherwise changed.
|
||||||
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
|
|
||||||
|
# If the constructor initializers don’t fit on a line, put each initializer on its own line.
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
|
|
||||||
|
# The number of characters to use for indentation of constructor initializer lists.
|
||||||
|
ConstructorInitializerIndentWidth: 0
|
||||||
|
|
||||||
|
# Indent width for line continuations.
|
||||||
|
ContinuationIndentWidth: 0
|
||||||
|
|
||||||
|
# If true, format braced lists as best suited for C++11 braced lists.
|
||||||
|
Cpp11BracedListStyle: false
|
||||||
|
|
||||||
|
# If true, analyze the formatted file for the most common alignment of & and *. PointerAlignment is then used only as fallback.
|
||||||
|
DerivePointerAlignment: true
|
||||||
|
|
||||||
|
# Disables formatting at all.
|
||||||
|
DisableFormat: false
|
||||||
|
|
||||||
|
# If true, clang-format detects whether function calls and definitions are formatted with one parameter per line.
|
||||||
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
|
||||||
|
# A vector of macros that should be interpreted as foreach loops instead of as function calls.
|
||||||
|
#ForEachMacros: ''
|
||||||
|
|
||||||
|
# Indent case labels one level from the switch statement. When false, use the same indentation level as for the switch statement. Switch statement body is always indented one level more than case labels.
|
||||||
|
IndentCaseLabels: true
|
||||||
|
|
||||||
|
# The number of columns to use for indentation.
|
||||||
|
IndentWidth: 4
|
||||||
|
|
||||||
|
# Indent if a function definition or declaration is wrapped after the type.
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
|
||||||
|
# If true, empty lines at the start of blocks are kept.
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
|
|
||||||
|
# Language, this format style is targeted at. Possible values: None, Cpp, Java, JavaScript, Proto.
|
||||||
|
# Language: None
|
||||||
|
|
||||||
|
# The maximum number of consecutive empty lines to keep.
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
|
||||||
|
# The indentation used for namespaces. Possible values: None, Inner, All.
|
||||||
|
NamespaceIndentation: All
|
||||||
|
|
||||||
|
# The number of characters to use for indentation of ObjC blocks.
|
||||||
|
ObjCBlockIndentWidth: 4
|
||||||
|
|
||||||
|
# Add a space after @property in Objective-C, i.e. use \@property (readonly) instead of \@property(readonly).
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
|
||||||
|
# Add a space in front of an Objective-C protocol list, i.e. use Foo <Protocol> instead of Foo<Protocol>.
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
|
||||||
|
# The penalty for breaking a function call after “call(”.
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 1000
|
||||||
|
|
||||||
|
# The penalty for each line break introduced inside a comment.
|
||||||
|
PenaltyBreakComment: 1000
|
||||||
|
|
||||||
|
# The penalty for breaking before the first <<.
|
||||||
|
PenaltyBreakFirstLessLess: 1000
|
||||||
|
|
||||||
|
# The penalty for each line break introduced inside a string literal.
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
|
||||||
|
# The penalty for each character outside of the column limit.
|
||||||
|
PenaltyExcessCharacter: 1000
|
||||||
|
|
||||||
|
# Penalty for putting the return type of a function onto its own line.
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 1000
|
||||||
|
|
||||||
|
# Pointer and reference alignment style. Possible values: Left, Right, Middle.
|
||||||
|
PointerAlignment: Left
|
||||||
|
|
||||||
|
# If true, a space may be inserted after C style casts.
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
|
||||||
|
# If false, spaces will be removed before assignment operators.
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
|
||||||
|
# Defines in which cases to put a space before opening parentheses. Possible values: Never, ControlStatements, Always.
|
||||||
|
SpaceBeforeParens: Never
|
||||||
|
|
||||||
|
# If true, spaces may be inserted into ‘()’.
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
|
||||||
|
# The number of spaces before trailing line comments (// - comments).
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
|
||||||
|
# If true, spaces will be inserted after ‘<’ and before ‘>’ in template argument lists.
|
||||||
|
SpacesInAngles: false
|
||||||
|
|
||||||
|
# If true, spaces may be inserted into C style casts.
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
|
||||||
|
# If true, spaces are inserted inside container literals (e.g. ObjC and Javascript array and dict literals).
|
||||||
|
SpacesInContainerLiterals: false
|
||||||
|
|
||||||
|
# If true, spaces will be inserted after ‘(‘ and before ‘)’.
|
||||||
|
SpacesInParentheses: false
|
||||||
|
|
||||||
|
# If true, spaces will be inserted after ‘[‘ and before ‘]’.
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
|
||||||
|
# Format compatible with this standard, e.g. use A<A<int> > instead of A<A<int>> for LS_Cpp03. Possible values: Cpp03, Cpp11, Auto.
|
||||||
|
Standard: Auto
|
||||||
|
|
||||||
|
# The number of columns used for tab stops.
|
||||||
|
TabWidth: 4
|
||||||
|
|
||||||
|
# The way to use tab characters in the resulting file. Possible values: Never, ForIndentation, Always.
|
||||||
|
UseTab: ForIndentation
|
|
@ -9,8 +9,7 @@
|
||||||
@class PlaylistLoader;
|
@class PlaylistLoader;
|
||||||
@class SUUpdater;
|
@class SUUpdater;
|
||||||
|
|
||||||
@interface AppController : NSObject
|
@interface AppController : NSObject {
|
||||||
{
|
|
||||||
IBOutlet NSObjectController *currentEntryController;
|
IBOutlet NSObjectController *currentEntryController;
|
||||||
|
|
||||||
IBOutlet PlaybackController *playbackController;
|
IBOutlet PlaybackController *playbackController;
|
||||||
|
@ -53,15 +52,13 @@
|
||||||
|
|
||||||
NSOperationQueue *queue; // Since we are the app delegate, we take care of the op queue
|
NSOperationQueue *queue; // Since we are the app delegate, we take care of the op queue
|
||||||
|
|
||||||
NSMutableSet* expandedNodes;
|
NSMutableSet *expandedNodes;
|
||||||
|
|
||||||
BOOL miniMode;
|
BOOL miniMode;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@property (strong) IBOutlet NSButton *infoButton;
|
@property(strong) IBOutlet NSButton *infoButton;
|
||||||
@property (strong) IBOutlet NSButton *infoButtonMini;
|
@property(strong) IBOutlet NSButton *infoButtonMini;
|
||||||
|
|
||||||
- (IBAction)openURL:(id)sender;
|
- (IBAction)openURL:(id)sender;
|
||||||
|
|
||||||
|
@ -78,7 +75,7 @@
|
||||||
|
|
||||||
- (void)initDefaults;
|
- (void)initDefaults;
|
||||||
|
|
||||||
//Fun stuff
|
// Fun stuff
|
||||||
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag;
|
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag;
|
||||||
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename;
|
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename;
|
||||||
- (void)application:(NSApplication *)theApplication openFiles:(NSArray *)filenames;
|
- (void)application:(NSApplication *)theApplication openFiles:(NSArray *)filenames;
|
||||||
|
@ -91,23 +88,23 @@
|
||||||
- (void)clickPrev;
|
- (void)clickPrev;
|
||||||
- (void)clickNext;
|
- (void)clickNext;
|
||||||
- (void)clickSpam;
|
- (void)clickSpam;
|
||||||
- (void)clickSeek: (NSTimeInterval)position;
|
- (void)clickSeek:(NSTimeInterval)position;
|
||||||
|
|
||||||
- (IBAction)increaseFontSize:(id)sender;
|
- (IBAction)increaseFontSize:(id)sender;
|
||||||
- (IBAction)decreaseFontSize:(id)sender;
|
- (IBAction)decreaseFontSize:(id)sender;
|
||||||
- (void)changeFontSize:(float)size;
|
- (void)changeFontSize:(float)size;
|
||||||
|
|
||||||
- (void)nodeExpanded:(NSNotification*)notification;
|
- (void)nodeExpanded:(NSNotification *)notification;
|
||||||
- (void)nodeCollapsed:(NSNotification*)notification;
|
- (void)nodeCollapsed:(NSNotification *)notification;
|
||||||
|
|
||||||
- (IBAction)toggleMiniMode:(id)sender;
|
- (IBAction)toggleMiniMode:(id)sender;
|
||||||
- (IBAction)toggleToolbarStyle:(id)sender;
|
- (IBAction)toggleToolbarStyle:(id)sender;
|
||||||
|
|
||||||
@property NSWindow * mainWindow;
|
@property NSWindow *mainWindow;
|
||||||
@property NSWindow * miniWindow;
|
@property NSWindow *miniWindow;
|
||||||
|
|
||||||
@property BOOL miniMode;
|
@property BOOL miniMode;
|
||||||
|
|
||||||
@property (nonatomic) BOOL floatingMiniWindow;
|
@property(nonatomic) BOOL floatingMiniWindow;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -1,31 +1,30 @@
|
||||||
#import "AppController.h"
|
#import "AppController.h"
|
||||||
|
#import "Cog-Swift.h"
|
||||||
#import "FileTreeController.h"
|
#import "FileTreeController.h"
|
||||||
#import "FileTreeViewController.h"
|
|
||||||
#import "FileTreeOutlineView.h"
|
#import "FileTreeOutlineView.h"
|
||||||
|
#import "FileTreeViewController.h"
|
||||||
|
#import "FontSizetoLineHeightTransformer.h"
|
||||||
|
#import "OpenURLPanel.h"
|
||||||
|
#import "PathNode.h"
|
||||||
#import "PlaybackController.h"
|
#import "PlaybackController.h"
|
||||||
#import "PlaylistController.h"
|
#import "PlaylistController.h"
|
||||||
#import "PlaylistView.h"
|
|
||||||
#import "PlaylistEntry.h"
|
#import "PlaylistEntry.h"
|
||||||
#import "PlaylistLoader.h"
|
#import "PlaylistLoader.h"
|
||||||
#import "OpenURLPanel.h"
|
#import "PlaylistView.h"
|
||||||
#import "SpotlightWindowController.h"
|
#import "SpotlightWindowController.h"
|
||||||
#import "StringToURLTransformer.h"
|
#import "StringToURLTransformer.h"
|
||||||
#import "FontSizetoLineHeightTransformer.h"
|
|
||||||
#import "Cog-Swift.h"
|
|
||||||
#import "PathNode.h"
|
|
||||||
#import <CogAudio/Status.h>
|
#import <CogAudio/Status.h>
|
||||||
|
|
||||||
|
#import "DualWindow.h"
|
||||||
#import "Logging.h"
|
#import "Logging.h"
|
||||||
#import "MiniModeMenuTitleTransformer.h"
|
#import "MiniModeMenuTitleTransformer.h"
|
||||||
#import "DualWindow.h"
|
|
||||||
|
|
||||||
#import <MASShortcut/Shortcut.h>
|
|
||||||
#import "Shortcuts.h"
|
#import "Shortcuts.h"
|
||||||
|
#import <MASShortcut/Shortcut.h>
|
||||||
|
|
||||||
#import <Sparkle/Sparkle.h>
|
#import <Sparkle/Sparkle.h>
|
||||||
|
|
||||||
void* kAppControllerContext = &kAppControllerContext;
|
void *kAppControllerContext = &kAppControllerContext;
|
||||||
|
|
||||||
|
|
||||||
@implementation AppController {
|
@implementation AppController {
|
||||||
BOOL _isFullToolbarStyle;
|
BOOL _isFullToolbarStyle;
|
||||||
|
@ -34,8 +33,7 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
@synthesize mainWindow;
|
@synthesize mainWindow;
|
||||||
@synthesize miniWindow;
|
@synthesize miniWindow;
|
||||||
|
|
||||||
+ (void)initialize
|
+ (void)initialize {
|
||||||
{
|
|
||||||
// Register transformers
|
// Register transformers
|
||||||
NSValueTransformer *stringToURLTransformer = [[StringToURLTransformer alloc] init];
|
NSValueTransformer *stringToURLTransformer = [[StringToURLTransformer alloc] init];
|
||||||
[NSValueTransformer setValueTransformer:stringToURLTransformer
|
[NSValueTransformer setValueTransformer:stringToURLTransformer
|
||||||
|
@ -51,22 +49,18 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
forName:@"MiniModeMenuTitleTransformer"];
|
forName:@"MiniModeMenuTitleTransformer"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id)init {
|
||||||
- (id)init
|
|
||||||
{
|
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self)
|
if(self) {
|
||||||
{
|
|
||||||
[self initDefaults];
|
[self initDefaults];
|
||||||
|
|
||||||
queue = [[NSOperationQueue alloc]init];
|
queue = [[NSOperationQueue alloc] init];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)openFiles:(id)sender
|
- (IBAction)openFiles:(id)sender {
|
||||||
{
|
|
||||||
NSOpenPanel *p;
|
NSOpenPanel *p;
|
||||||
|
|
||||||
p = [NSOpenPanel openPanel];
|
p = [NSOpenPanel openPanel];
|
||||||
|
@ -76,8 +70,9 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
[p setAllowsMultipleSelection:YES];
|
[p setAllowsMultipleSelection:YES];
|
||||||
[p setResolvesAliases:YES];
|
[p setResolvesAliases:YES];
|
||||||
|
|
||||||
[p beginSheetModalForWindow:mainWindow completionHandler:^(NSInteger result) {
|
[p beginSheetModalForWindow:mainWindow
|
||||||
if ( result == NSModalResponseOK ) {
|
completionHandler:^(NSInteger result) {
|
||||||
|
if(result == NSModalResponseOK) {
|
||||||
[self->playlistLoader willInsertURLs:[p URLs] origin:URLOriginInternal];
|
[self->playlistLoader willInsertURLs:[p URLs] origin:URLOriginInternal];
|
||||||
[self->playlistLoader didInsertURLs:[self->playlistLoader addURLs:[p URLs] sort:YES] origin:URLOriginInternal];
|
[self->playlistLoader didInsertURLs:[self->playlistLoader addURLs:[p URLs] sort:YES] origin:URLOriginInternal];
|
||||||
} else {
|
} else {
|
||||||
|
@ -86,8 +81,7 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)savePlaylist:(id)sender
|
- (IBAction)savePlaylist:(id)sender {
|
||||||
{
|
|
||||||
NSSavePanel *p;
|
NSSavePanel *p;
|
||||||
|
|
||||||
p = [NSSavePanel savePanel];
|
p = [NSSavePanel savePanel];
|
||||||
|
@ -97,8 +91,9 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
* extension if the user does not supply one. */
|
* extension if the user does not supply one. */
|
||||||
[p setAllowedFileTypes:@[@"m3u", @"pls"]];
|
[p setAllowedFileTypes:@[@"m3u", @"pls"]];
|
||||||
|
|
||||||
[p beginSheetModalForWindow:mainWindow completionHandler:^(NSInteger result) {
|
[p beginSheetModalForWindow:mainWindow
|
||||||
if ( result == NSModalResponseOK ) {
|
completionHandler:^(NSInteger result) {
|
||||||
|
if(result == NSModalResponseOK) {
|
||||||
[self->playlistLoader save:[[p URL] path]];
|
[self->playlistLoader save:[[p URL] path]];
|
||||||
} else {
|
} else {
|
||||||
[p close];
|
[p close];
|
||||||
|
@ -106,8 +101,7 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)openURL:(id)sender
|
- (IBAction)openURL:(id)sender {
|
||||||
{
|
|
||||||
OpenURLPanel *p;
|
OpenURLPanel *p;
|
||||||
|
|
||||||
p = [OpenURLPanel openURLPanel];
|
p = [OpenURLPanel openURLPanel];
|
||||||
|
@ -115,32 +109,26 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
[p beginSheetWithWindow:mainWindow delegate:self didEndSelector:@selector(openURLPanelDidEnd:returnCode:contextInfo:) contextInfo:nil];
|
[p beginSheetWithWindow:mainWindow delegate:self didEndSelector:@selector(openURLPanelDidEnd:returnCode:contextInfo:) contextInfo:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)openURLPanelDidEnd:(OpenURLPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo
|
- (void)openURLPanelDidEnd:(OpenURLPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo {
|
||||||
{
|
if(returnCode == NSModalResponseOK) {
|
||||||
if (returnCode == NSModalResponseOK)
|
|
||||||
{
|
|
||||||
[playlistLoader willInsertURLs:@[[panel url]] origin:URLOriginInternal];
|
[playlistLoader willInsertURLs:@[[panel url]] origin:URLOriginInternal];
|
||||||
[playlistLoader didInsertURLs:[playlistLoader addURLs:@[[panel url]] sort:NO] origin:URLOriginInternal];
|
[playlistLoader didInsertURLs:[playlistLoader addURLs:@[[panel url]] sort:NO] origin:URLOriginInternal];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)delEntries:(id)sender
|
- (IBAction)delEntries:(id)sender {
|
||||||
{
|
|
||||||
[playlistController remove:self];
|
[playlistController remove:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (PlaylistEntry *)currentEntry
|
- (PlaylistEntry *)currentEntry {
|
||||||
{
|
|
||||||
return [playlistController currentEntry];
|
return [playlistController currentEntry];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)application:(NSApplication *)sender delegateHandlesKey:(NSString *)key
|
- (BOOL)application:(NSApplication *)sender delegateHandlesKey:(NSString *)key {
|
||||||
{
|
|
||||||
return [key isEqualToString:@"currentEntry"] || [key isEqualToString:@"play"];
|
return [key isEqualToString:@"currentEntry"] || [key isEqualToString:@"play"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)awakeFromNib
|
- (void)awakeFromNib {
|
||||||
{
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
// Prevent updates automatically in debug builds
|
// Prevent updates automatically in debug builds
|
||||||
[updater setAutomaticallyChecksForUpdates:NO];
|
[updater setAutomaticallyChecksForUpdates:NO];
|
||||||
|
@ -157,7 +145,7 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
|
|
||||||
[self registerHotKeys];
|
[self registerHotKeys];
|
||||||
|
|
||||||
(void) [spotlightWindowController init];
|
(void)[spotlightWindowController init];
|
||||||
|
|
||||||
[[playlistController undoManager] disableUndoRegistration];
|
[[playlistController undoManager] disableUndoRegistration];
|
||||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
||||||
|
@ -168,28 +156,21 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
NSString *oldFilename = @"Default.m3u";
|
NSString *oldFilename = @"Default.m3u";
|
||||||
NSString *newFilename = @"Default.xml";
|
NSString *newFilename = @"Default.xml";
|
||||||
|
|
||||||
if ([[NSFileManager defaultManager] fileExistsAtPath:[basePath stringByAppendingPathComponent:dbFilename]])
|
if([[NSFileManager defaultManager] fileExistsAtPath:[basePath stringByAppendingPathComponent:dbFilename]]) {
|
||||||
{
|
|
||||||
[playlistLoader addDatabase];
|
[playlistLoader addDatabase];
|
||||||
}
|
} else if([[NSFileManager defaultManager] fileExistsAtPath:[basePath stringByAppendingPathComponent:newFilename]]) {
|
||||||
else if ([[NSFileManager defaultManager] fileExistsAtPath:[basePath stringByAppendingPathComponent:newFilename]])
|
|
||||||
{
|
|
||||||
[playlistLoader addURL:[NSURL fileURLWithPath:[basePath stringByAppendingPathComponent:newFilename]]];
|
[playlistLoader addURL:[NSURL fileURLWithPath:[basePath stringByAppendingPathComponent:newFilename]]];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
[playlistLoader addURL:[NSURL fileURLWithPath:[basePath stringByAppendingPathComponent:oldFilename]]];
|
[playlistLoader addURL:[NSURL fileURLWithPath:[basePath stringByAppendingPathComponent:oldFilename]]];
|
||||||
}
|
}
|
||||||
|
|
||||||
[[playlistController undoManager] enableUndoRegistration];
|
[[playlistController undoManager] enableUndoRegistration];
|
||||||
|
|
||||||
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"resumePlaybackOnStartup"])
|
if([[NSUserDefaults standardUserDefaults] boolForKey:@"resumePlaybackOnStartup"]) {
|
||||||
{
|
int lastStatus = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"lastPlaybackStatus"];
|
||||||
int lastStatus = (int) [[NSUserDefaults standardUserDefaults] integerForKey:@"lastPlaybackStatus"];
|
int lastIndex = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"lastTrackPlaying"];
|
||||||
int lastIndex = (int) [[NSUserDefaults standardUserDefaults] integerForKey:@"lastTrackPlaying"];
|
|
||||||
|
|
||||||
if (lastStatus != CogStatusStopped && lastIndex >= 0)
|
if(lastStatus != CogStatusStopped && lastIndex >= 0) {
|
||||||
{
|
|
||||||
[playbackController playEntryAtIndex:lastIndex startPaused:(lastStatus == CogStatusPaused) andSeekTo:[NSNumber numberWithDouble:[[NSUserDefaults standardUserDefaults] floatForKey:@"lastTrackPosition"]]];
|
[playbackController playEntryAtIndex:lastIndex startPaused:(lastStatus == CogStatusPaused) andSeekTo:[NSNumber numberWithDouble:[[NSUserDefaults standardUserDefaults] floatForKey:@"lastTrackPosition"]]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,7 +191,7 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
// but i'm too stupid/tired to figure it out now
|
// but i'm too stupid/tired to figure it out now
|
||||||
[fileTreeViewController view];
|
[fileTreeViewController view];
|
||||||
|
|
||||||
FileTreeOutlineView* outlineView = [fileTreeViewController outlineView];
|
FileTreeOutlineView *outlineView = [fileTreeViewController outlineView];
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nodeExpanded:) name:NSOutlineViewItemDidExpandNotification object:outlineView];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nodeExpanded:) name:NSOutlineViewItemDidExpandNotification object:outlineView];
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nodeCollapsed:) name:NSOutlineViewItemDidCollapseNotification object:outlineView];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nodeCollapsed:) name:NSOutlineViewItemDidCollapseNotification object:outlineView];
|
||||||
|
|
||||||
|
@ -221,12 +202,9 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
|
|
||||||
NSArray *expandedNodesArray = [[NSUserDefaults standardUserDefaults] valueForKey:@"fileTreeViewExpandedNodes"];
|
NSArray *expandedNodesArray = [[NSUserDefaults standardUserDefaults] valueForKey:@"fileTreeViewExpandedNodes"];
|
||||||
|
|
||||||
if (expandedNodesArray)
|
if(expandedNodesArray) {
|
||||||
{
|
|
||||||
expandedNodes = [[NSMutableSet alloc] initWithArray:expandedNodesArray];
|
expandedNodes = [[NSMutableSet alloc] initWithArray:expandedNodesArray];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
expandedNodes = [[NSMutableSet alloc] init];
|
expandedNodes = [[NSMutableSet alloc] init];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,20 +212,17 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
|
|
||||||
DLog(@"Num of rows: %ld", [outlineView numberOfRows]);
|
DLog(@"Num of rows: %ld", [outlineView numberOfRows]);
|
||||||
|
|
||||||
if (!outlineView)
|
if(!outlineView) {
|
||||||
{
|
|
||||||
DLog(@"outlineView is NULL!");
|
DLog(@"outlineView is NULL!");
|
||||||
}
|
}
|
||||||
|
|
||||||
[outlineView reloadData];
|
[outlineView reloadData];
|
||||||
|
|
||||||
for (NSInteger i=0; i<[outlineView numberOfRows]; i++)
|
for(NSInteger i = 0; i < [outlineView numberOfRows]; i++) {
|
||||||
{
|
|
||||||
PathNode *pn = [outlineView itemAtRow:i];
|
PathNode *pn = [outlineView itemAtRow:i];
|
||||||
NSString *str = [[pn URL] absoluteString];
|
NSString *str = [[pn URL] absoluteString];
|
||||||
|
|
||||||
if ([expandedNodes containsObject:str])
|
if([expandedNodes containsObject:str]) {
|
||||||
{
|
|
||||||
[outlineView expandItem:pn];
|
[outlineView expandItem:pn];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,18 +235,18 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
|
|
||||||
- (void)observeValueForKeyPath:(NSString *)keyPath
|
- (void)observeValueForKeyPath:(NSString *)keyPath
|
||||||
ofObject:(id)object
|
ofObject:(id)object
|
||||||
change:(NSDictionary<NSKeyValueChangeKey,id> *)change
|
change:(NSDictionary<NSKeyValueChangeKey, id> *)change
|
||||||
context:(void *)context {
|
context:(void *)context {
|
||||||
if (context != kAppControllerContext) {
|
if(context != kAppControllerContext) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([keyPath isEqualToString:@"playlistController.currentEntry"]) {
|
if([keyPath isEqualToString:@"playlistController.currentEntry"]) {
|
||||||
PlaylistEntry *entry = playlistController.currentEntry;
|
PlaylistEntry *entry = playlistController.currentEntry;
|
||||||
if (!entry) {
|
if(!entry) {
|
||||||
miniWindow.title = @"Cog";
|
miniWindow.title = @"Cog";
|
||||||
mainWindow.title = @"Cog";
|
mainWindow.title = @"Cog";
|
||||||
if (@available(macOS 11.0, *)) {
|
if(@available(macOS 11.0, *)) {
|
||||||
miniWindow.subtitle = @"";
|
miniWindow.subtitle = @"";
|
||||||
mainWindow.subtitle = @"";
|
mainWindow.subtitle = @"";
|
||||||
}
|
}
|
||||||
|
@ -282,7 +257,7 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
self.infoButtonMini.image = [NSImage imageNamed:@"infoTemplate"];
|
self.infoButtonMini.image = [NSImage imageNamed:@"infoTemplate"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry.albumArt) {
|
if(entry.albumArt) {
|
||||||
self.infoButton.imageScaling = NSImageScaleProportionallyUpOrDown;
|
self.infoButton.imageScaling = NSImageScaleProportionallyUpOrDown;
|
||||||
self.infoButton.image = playlistController.currentEntry.albumArt;
|
self.infoButton.image = playlistController.currentEntry.albumArt;
|
||||||
self.infoButtonMini.imageScaling = NSImageScaleProportionallyUpOrDown;
|
self.infoButtonMini.imageScaling = NSImageScaleProportionallyUpOrDown;
|
||||||
|
@ -294,9 +269,9 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
self.infoButtonMini.image = [NSImage imageNamed:@"infoTemplate"];
|
self.infoButtonMini.image = [NSImage imageNamed:@"infoTemplate"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (@available(macOS 11.0, *)) {
|
if(@available(macOS 11.0, *)) {
|
||||||
NSString *title = @"Cog";
|
NSString *title = @"Cog";
|
||||||
if (entry.title) {
|
if(entry.title) {
|
||||||
title = entry.title;
|
title = entry.title;
|
||||||
}
|
}
|
||||||
miniWindow.title = title;
|
miniWindow.title = title;
|
||||||
|
@ -304,14 +279,14 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
|
|
||||||
NSString *subtitle = @"";
|
NSString *subtitle = @"";
|
||||||
NSMutableArray<NSString *> *subtitleItems = [NSMutableArray array];
|
NSMutableArray<NSString *> *subtitleItems = [NSMutableArray array];
|
||||||
if (entry.album && ![entry.album isEqualToString:@""]) {
|
if(entry.album && ![entry.album isEqualToString:@""]) {
|
||||||
[subtitleItems addObject:entry.album];
|
[subtitleItems addObject:entry.album];
|
||||||
}
|
}
|
||||||
if (entry.artist && ![entry.artist isEqualToString:@""]) {
|
if(entry.artist && ![entry.artist isEqualToString:@""]) {
|
||||||
[subtitleItems addObject:entry.artist];
|
[subtitleItems addObject:entry.artist];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([subtitleItems count]) {
|
if([subtitleItems count]) {
|
||||||
subtitle = [subtitleItems componentsJoinedByString:@" - "];
|
subtitle = [subtitleItems componentsJoinedByString:@" - "];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,7 +294,7 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
mainWindow.subtitle = subtitle;
|
mainWindow.subtitle = subtitle;
|
||||||
} else {
|
} else {
|
||||||
NSString *title = @"Cog";
|
NSString *title = @"Cog";
|
||||||
if (entry.display) {
|
if(entry.display) {
|
||||||
title = entry.display;
|
title = entry.display;
|
||||||
}
|
}
|
||||||
miniWindow.title = title;
|
miniWindow.title = title;
|
||||||
|
@ -328,34 +303,30 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)nodeExpanded:(NSNotification*)notification
|
- (void)nodeExpanded:(NSNotification *)notification {
|
||||||
{
|
PathNode *node = [[notification userInfo] objectForKey:@"NSObject"];
|
||||||
PathNode* node = [[notification userInfo] objectForKey:@"NSObject"];
|
NSString *url = [[node URL] absoluteString];
|
||||||
NSString* url = [[node URL] absoluteString];
|
|
||||||
|
|
||||||
[expandedNodes addObject:url];
|
[expandedNodes addObject:url];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)nodeCollapsed:(NSNotification*)notification
|
- (void)nodeCollapsed:(NSNotification *)notification {
|
||||||
{
|
PathNode *node = [[notification userInfo] objectForKey:@"NSObject"];
|
||||||
PathNode* node = [[notification userInfo] objectForKey:@"NSObject"];
|
NSString *url = [[node URL] absoluteString];
|
||||||
NSString* url = [[node URL] absoluteString];
|
|
||||||
|
|
||||||
[expandedNodes removeObject:url];
|
[expandedNodes removeObject:url];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)applicationWillTerminate:(NSNotification *)aNotification
|
- (void)applicationWillTerminate:(NSNotification *)aNotification {
|
||||||
{
|
|
||||||
CogStatus currentStatus = [playbackController playbackStatus];
|
CogStatus currentStatus = [playbackController playbackStatus];
|
||||||
NSInteger lastTrackPlaying = -1;
|
NSInteger lastTrackPlaying = -1;
|
||||||
double lastTrackPosition = 0;
|
double lastTrackPosition = 0;
|
||||||
|
|
||||||
if (currentStatus == CogStatusStopping)
|
if(currentStatus == CogStatusStopping)
|
||||||
currentStatus = CogStatusStopped;
|
currentStatus = CogStatusStopped;
|
||||||
|
|
||||||
if (currentStatus != CogStatusStopped)
|
if(currentStatus != CogStatusStopped) {
|
||||||
{
|
PlaylistEntry *pe = [playlistController currentEntry];
|
||||||
PlaylistEntry * pe = [playlistController currentEntry];
|
|
||||||
lastTrackPlaying = [pe index];
|
lastTrackPlaying = [pe index];
|
||||||
lastTrackPosition = [pe currentPosition];
|
lastTrackPosition = [pe currentPosition];
|
||||||
}
|
}
|
||||||
|
@ -371,14 +342,13 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
||||||
NSString *folder = [[paths firstObject] stringByAppendingPathComponent:@"Cog"];
|
NSString *folder = [[paths firstObject] stringByAppendingPathComponent:@"Cog"];
|
||||||
|
|
||||||
if ([fileManager fileExistsAtPath: folder] == NO)
|
if([fileManager fileExistsAtPath:folder] == NO) {
|
||||||
{
|
[fileManager createDirectoryAtPath:folder withIntermediateDirectories:NO attributes:nil error:nil];
|
||||||
[fileManager createDirectoryAtPath: folder withIntermediateDirectories:NO attributes:nil error:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[playlistController clearFilterPredicate:self];
|
[playlistController clearFilterPredicate:self];
|
||||||
|
|
||||||
NSString * fileName = @"Default.xml";
|
NSString *fileName = @"Default.xml";
|
||||||
|
|
||||||
NSError *error;
|
NSError *error;
|
||||||
[[NSFileManager defaultManager] removeItemAtPath:[folder stringByAppendingPathComponent:fileName] error:&error];
|
[[NSFileManager defaultManager] removeItemAtPath:[folder stringByAppendingPathComponent:fileName] error:&error];
|
||||||
|
@ -395,33 +365,29 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
[miniWindow saveFrameUsingName:@"Mini Window"];
|
[miniWindow saveFrameUsingName:@"Mini Window"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
|
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag {
|
||||||
{
|
if(flag == NO)
|
||||||
if (flag == NO)
|
|
||||||
[mainWindow makeKeyAndOrderFront:self]; // TODO: do we really need this? We never close the main window.
|
[mainWindow makeKeyAndOrderFront:self]; // TODO: do we really need this? We never close the main window.
|
||||||
|
|
||||||
for(NSWindow* win in [NSApp windows]) // Maximizing all windows
|
for(NSWindow *win in [NSApp windows]) // Maximizing all windows
|
||||||
if([win isMiniaturized])
|
if([win isMiniaturized])
|
||||||
[win deminiaturize:self];
|
[win deminiaturize:self];
|
||||||
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
|
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename {
|
||||||
{
|
NSArray *urls = @[[NSURL fileURLWithPath:filename]];
|
||||||
NSArray* urls = @[[NSURL fileURLWithPath:filename]];
|
|
||||||
[playlistLoader willInsertURLs:urls origin:URLOriginExternal];
|
[playlistLoader willInsertURLs:urls origin:URLOriginExternal];
|
||||||
[playlistLoader didInsertURLs:[playlistLoader addURLs:urls sort:NO] origin:URLOriginExternal];
|
[playlistLoader didInsertURLs:[playlistLoader addURLs:urls sort:NO] origin:URLOriginExternal];
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)application:(NSApplication *)theApplication openFiles:(NSArray *)filenames
|
- (void)application:(NSApplication *)theApplication openFiles:(NSArray *)filenames {
|
||||||
{
|
// Need to convert to urls
|
||||||
//Need to convert to urls
|
|
||||||
NSMutableArray *urls = [NSMutableArray array];
|
NSMutableArray *urls = [NSMutableArray array];
|
||||||
|
|
||||||
for (NSString *filename in filenames)
|
for(NSString *filename in filenames) {
|
||||||
{
|
|
||||||
[urls addObject:[NSURL fileURLWithPath:filename]];
|
[urls addObject:[NSURL fileURLWithPath:filename]];
|
||||||
}
|
}
|
||||||
[playlistLoader willInsertURLs:urls origin:URLOriginExternal];
|
[playlistLoader willInsertURLs:urls origin:URLOriginExternal];
|
||||||
|
@ -429,34 +395,30 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
[theApplication replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
|
[theApplication replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)openLiberapayPage:(id)sender
|
- (IBAction)openLiberapayPage:(id)sender {
|
||||||
{
|
|
||||||
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://liberapay.com/kode54"]];
|
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://liberapay.com/kode54"]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)openPaypalPage:(id)sender
|
- (IBAction)openPaypalPage:(id)sender {
|
||||||
{
|
|
||||||
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.paypal.com/paypalme/kode54"]];
|
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.paypal.com/paypalme/kode54"]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)openKofiPage:(id)sender
|
- (IBAction)openKofiPage:(id)sender {
|
||||||
{
|
|
||||||
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://ko-fi.com/kode54"]];
|
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://ko-fi.com/kode54"]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)openPatreonPage:(id)sender
|
- (IBAction)openPatreonPage:(id)sender {
|
||||||
{
|
|
||||||
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.patreon.com/kode54"]];
|
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.patreon.com/kode54"]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (IBAction)feedback:(id)sender {
|
||||||
- (IBAction)feedback:(id)sender
|
|
||||||
{
|
|
||||||
NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
|
NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
|
||||||
|
|
||||||
NSArray<NSURLQueryItem *> *query = @[
|
NSArray<NSURLQueryItem *> *query = @[
|
||||||
[NSURLQueryItem queryItemWithName:@"labels" value:@"bug"],
|
[NSURLQueryItem queryItemWithName:@"labels"
|
||||||
[NSURLQueryItem queryItemWithName:@"template" value:@"bug_report.md"],
|
value:@"bug"],
|
||||||
|
[NSURLQueryItem queryItemWithName:@"template"
|
||||||
|
value:@"bug_report.md"],
|
||||||
[NSURLQueryItem queryItemWithName:@"title"
|
[NSURLQueryItem queryItemWithName:@"title"
|
||||||
value:[NSString stringWithFormat:@"[Cog %@] ", version]]
|
value:[NSString stringWithFormat:@"[Cog %@] ", version]]
|
||||||
];
|
];
|
||||||
|
@ -468,8 +430,7 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
[[NSWorkspace sharedWorkspace] openURL:components.URL];
|
[[NSWorkspace sharedWorkspace] openURL:components.URL];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)initDefaults
|
- (void)initDefaults {
|
||||||
{
|
|
||||||
NSMutableDictionary *userDefaultsValuesDict = [NSMutableDictionary dictionary];
|
NSMutableDictionary *userDefaultsValuesDict = [NSMutableDictionary dictionary];
|
||||||
|
|
||||||
// Font defaults
|
// Font defaults
|
||||||
|
@ -497,11 +458,11 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
|
|
||||||
[userDefaultsValuesDict setObject:[NSNumber numberWithBool:NO] forKey:@"resumePlaybackOnStartup"];
|
[userDefaultsValuesDict setObject:[NSNumber numberWithBool:NO] forKey:@"resumePlaybackOnStartup"];
|
||||||
|
|
||||||
//Register and sync defaults
|
// Register and sync defaults
|
||||||
[[NSUserDefaults standardUserDefaults] registerDefaults:userDefaultsValuesDict];
|
[[NSUserDefaults standardUserDefaults] registerDefaults:userDefaultsValuesDict];
|
||||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||||
|
|
||||||
//And if the existing feed URL is broken due to my ineptitude with the above defaults, fix it
|
// And if the existing feed URL is broken due to my ineptitude with the above defaults, fix it
|
||||||
NSSet<NSString *> *brokenFeedURLs = [NSSet setWithObjects:
|
NSSet<NSString *> *brokenFeedURLs = [NSSet setWithObjects:
|
||||||
@"https://kode54.net/cog/stable.xml",
|
@"https://kode54.net/cog/stable.xml",
|
||||||
@"https://kode54.net/cog/mercury.xml"
|
@"https://kode54.net/cog/mercury.xml"
|
||||||
|
@ -509,108 +470,97 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
@"https://f.losno.co/cog/mercury.xml",
|
@"https://f.losno.co/cog/mercury.xml",
|
||||||
nil];
|
nil];
|
||||||
NSString *feedURL = [[NSUserDefaults standardUserDefaults] stringForKey:@"SUFeedURL"];
|
NSString *feedURL = [[NSUserDefaults standardUserDefaults] stringForKey:@"SUFeedURL"];
|
||||||
if ([brokenFeedURLs containsObject:feedURL]) {
|
if([brokenFeedURLs containsObject:feedURL]) {
|
||||||
[[NSUserDefaults standardUserDefaults] setValue:feedURLdefault forKey:@"SUFeedURL"];
|
[[NSUserDefaults standardUserDefaults] setValue:feedURLdefault forKey:@"SUFeedURL"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"midiPlugin"] isEqualToString:@"BASSMIDI"]) {
|
if([[[NSUserDefaults standardUserDefaults] stringForKey:@"midiPlugin"] isEqualToString:@"BASSMIDI"]) {
|
||||||
[[NSUserDefaults standardUserDefaults] setValue:@"FluidSynth" forKey:@"midiPlugin"];
|
[[NSUserDefaults standardUserDefaults] setValue:@"FluidSynth" forKey:@"midiPlugin"];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSString * oldMidiPlugin = [[NSUserDefaults standardUserDefaults] stringForKey:@"midi.plugin"];
|
NSString *oldMidiPlugin = [[NSUserDefaults standardUserDefaults] stringForKey:@"midi.plugin"];
|
||||||
if (oldMidiPlugin) {
|
if(oldMidiPlugin) {
|
||||||
[[NSUserDefaults standardUserDefaults] setValue:oldMidiPlugin forKey:@"midiPlugin"];
|
[[NSUserDefaults standardUserDefaults] setValue:oldMidiPlugin forKey:@"midiPlugin"];
|
||||||
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"midi.plugin"];
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"midi.plugin"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unassign previous handler first, so dealloc can unregister it from the global map before the new instances are assigned */
|
/* Unassign previous handler first, so dealloc can unregister it from the global map before the new instances are assigned */
|
||||||
- (void)registerHotKeys
|
- (void)registerHotKeys {
|
||||||
{
|
|
||||||
MASShortcutBinder *binder = [MASShortcutBinder sharedBinder];
|
MASShortcutBinder *binder = [MASShortcutBinder sharedBinder];
|
||||||
[binder bindShortcutWithDefaultsKey:CogPlayShortcutKey toAction:^{
|
[binder bindShortcutWithDefaultsKey:CogPlayShortcutKey
|
||||||
|
toAction:^{
|
||||||
[self clickPlay];
|
[self clickPlay];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[binder bindShortcutWithDefaultsKey:CogNextShortcutKey toAction:^{
|
[binder bindShortcutWithDefaultsKey:CogNextShortcutKey
|
||||||
|
toAction:^{
|
||||||
[self clickNext];
|
[self clickNext];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[binder bindShortcutWithDefaultsKey:CogPrevShortcutKey toAction:^{
|
[binder bindShortcutWithDefaultsKey:CogPrevShortcutKey
|
||||||
|
toAction:^{
|
||||||
[self clickPrev];
|
[self clickPrev];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[binder bindShortcutWithDefaultsKey:CogSpamShortcutKey toAction:^{
|
[binder bindShortcutWithDefaultsKey:CogSpamShortcutKey
|
||||||
|
toAction:^{
|
||||||
[self clickSpam];
|
[self clickSpam];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)clickPlay
|
- (void)clickPlay {
|
||||||
{
|
|
||||||
[playbackController playPauseResume:self];
|
[playbackController playPauseResume:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)clickPause
|
- (void)clickPause {
|
||||||
{
|
|
||||||
[playbackController pause:self];
|
[playbackController pause:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)clickStop
|
- (void)clickStop {
|
||||||
{
|
|
||||||
[playbackController stop:self];
|
[playbackController stop:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)clickPrev
|
- (void)clickPrev {
|
||||||
{
|
|
||||||
[playbackController prev:nil];
|
[playbackController prev:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)clickNext
|
- (void)clickNext {
|
||||||
{
|
|
||||||
[playbackController next:nil];
|
[playbackController next:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)clickSpam
|
- (void)clickSpam {
|
||||||
{
|
|
||||||
[playbackController spam:nil];
|
[playbackController spam:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)clickSeek:(NSTimeInterval)position
|
- (void)clickSeek:(NSTimeInterval)position {
|
||||||
{
|
|
||||||
[playbackController seek:self toTime:position];
|
[playbackController seek:self toTime:position];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)changeFontSize:(float)size
|
- (void)changeFontSize:(float)size {
|
||||||
{
|
|
||||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||||
float fCurrentSize = [defaults floatForKey:@"fontSize"];
|
float fCurrentSize = [defaults floatForKey:@"fontSize"];
|
||||||
NSNumber *newSize = [NSNumber numberWithFloat:(fCurrentSize + size)];
|
NSNumber *newSize = [NSNumber numberWithFloat:(fCurrentSize + size)];
|
||||||
[defaults setObject:newSize forKey:@"fontSize"];
|
[defaults setObject:newSize forKey:@"fontSize"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)increaseFontSize:(id)sender
|
- (IBAction)increaseFontSize:(id)sender {
|
||||||
{
|
|
||||||
[self changeFontSize:1];
|
[self changeFontSize:1];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)decreaseFontSize:(id)sender
|
- (IBAction)decreaseFontSize:(id)sender {
|
||||||
{
|
|
||||||
[self changeFontSize:-1];
|
[self changeFontSize:-1];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)toggleMiniMode:(id)sender
|
- (IBAction)toggleMiniMode:(id)sender {
|
||||||
{
|
|
||||||
[self setMiniMode:(!miniMode)];
|
[self setMiniMode:(!miniMode)];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)miniMode
|
- (BOOL)miniMode {
|
||||||
{
|
|
||||||
return miniMode;
|
return miniMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setMiniMode:(BOOL)newMiniMode
|
- (void)setMiniMode:(BOOL)newMiniMode {
|
||||||
{
|
|
||||||
miniMode = newMiniMode;
|
miniMode = newMiniMode;
|
||||||
[[NSUserDefaults standardUserDefaults] setBool:miniMode forKey:@"miniMode"];
|
[[NSUserDefaults standardUserDefaults] setBool:miniMode forKey:@"miniMode"];
|
||||||
|
|
||||||
|
@ -629,7 +579,7 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
[[NSUserDefaults standardUserDefaults] setBool:full forKey:@"toolbarStyleFull"];
|
[[NSUserDefaults standardUserDefaults] setBool:full forKey:@"toolbarStyleFull"];
|
||||||
DLog("Changed toolbar style: %@", (full ? @"full" : @"compact"));
|
DLog("Changed toolbar style: %@", (full ? @"full" : @"compact"));
|
||||||
|
|
||||||
if (@available(macOS 11.0, *)) {
|
if(@available(macOS 11.0, *)) {
|
||||||
NSWindowToolbarStyle style =
|
NSWindowToolbarStyle style =
|
||||||
full ? NSWindowToolbarStyleExpanded : NSWindowToolbarStyleUnified;
|
full ? NSWindowToolbarStyleExpanded : NSWindowToolbarStyleUnified;
|
||||||
mainWindow.toolbarStyle = style;
|
mainWindow.toolbarStyle = style;
|
||||||
|
@ -651,19 +601,17 @@ void* kAppControllerContext = &kAppControllerContext;
|
||||||
[miniWindow setLevel:level];
|
[miniWindow setLevel:level];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)updateDockMenu:(NSNotification *)notification
|
- (void)updateDockMenu:(NSNotification *)notification {
|
||||||
{
|
|
||||||
PlaylistEntry *pe = [playlistController currentEntry];
|
PlaylistEntry *pe = [playlistController currentEntry];
|
||||||
|
|
||||||
BOOL hideItem = NO;
|
BOOL hideItem = NO;
|
||||||
|
|
||||||
if ([[notification name] isEqualToString:CogPlaybackDidStopNotficiation] || !pe || ![pe artist] || [[pe artist] isEqualToString:@""])
|
if([[notification name] isEqualToString:CogPlaybackDidStopNotficiation] || !pe || ![pe artist] || [[pe artist] isEqualToString:@""])
|
||||||
hideItem = YES;
|
hideItem = YES;
|
||||||
|
|
||||||
if (hideItem && [dockMenu indexOfItem:currentArtistItem] == 0) {
|
if(hideItem && [dockMenu indexOfItem:currentArtistItem] == 0) {
|
||||||
[dockMenu removeItem:currentArtistItem];
|
[dockMenu removeItem:currentArtistItem];
|
||||||
}
|
} else if(!hideItem && [dockMenu indexOfItem:currentArtistItem] < 0) {
|
||||||
else if (!hideItem && [dockMenu indexOfItem:currentArtistItem] < 0) {
|
|
||||||
[dockMenu insertItem:currentArtistItem atIndex:0];
|
[dockMenu insertItem:currentArtistItem atIndex:0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,58 +7,49 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "DockIconController.h"
|
#import "DockIconController.h"
|
||||||
#import <CogAudio/Status.h>
|
|
||||||
#import "PlaybackController.h"
|
#import "PlaybackController.h"
|
||||||
|
#import <CogAudio/Status.h>
|
||||||
|
|
||||||
@implementation DockIconController
|
@implementation DockIconController
|
||||||
|
|
||||||
static NSString *DockIconPlaybackStatusObservationContext = @"DockIconPlaybackStatusObservationContext";
|
static NSString *DockIconPlaybackStatusObservationContext = @"DockIconPlaybackStatusObservationContext";
|
||||||
|
|
||||||
- (void)startObserving
|
- (void)startObserving {
|
||||||
{
|
[playbackController addObserver:self forKeyPath:@"playbackStatus" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:(__bridge void *_Nullable)(DockIconPlaybackStatusObservationContext)];
|
||||||
[playbackController addObserver:self forKeyPath:@"playbackStatus" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:(__bridge void * _Nullable)(DockIconPlaybackStatusObservationContext)];
|
[playbackController addObserver:self forKeyPath:@"progressBarStatus" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:(__bridge void *_Nullable)(DockIconPlaybackStatusObservationContext)];
|
||||||
[playbackController addObserver:self forKeyPath:@"progressBarStatus" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:(__bridge void * _Nullable)(DockIconPlaybackStatusObservationContext)];
|
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.colorfulDockIcons" options:0 context:(__bridge void *_Nullable)(DockIconPlaybackStatusObservationContext)];
|
||||||
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.colorfulDockIcons" options:0 context:(__bridge void * _Nullable)(DockIconPlaybackStatusObservationContext)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)stopObserving
|
- (void)stopObserving {
|
||||||
{
|
|
||||||
[playbackController removeObserver:self forKeyPath:@"playbackStatus"];
|
[playbackController removeObserver:self forKeyPath:@"playbackStatus"];
|
||||||
[playbackController removeObserver:self forKeyPath:@"progressBarStatus"];
|
[playbackController removeObserver:self forKeyPath:@"progressBarStatus"];
|
||||||
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.colorfulDockIcons"];
|
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.colorfulDockIcons"];
|
||||||
}
|
}
|
||||||
|
|
||||||
static NSString *getBadgeName(NSString *baseName, BOOL colorfulIcons)
|
static NSString *getBadgeName(NSString *baseName, BOOL colorfulIcons) {
|
||||||
{
|
if(colorfulIcons) {
|
||||||
if (colorfulIcons)
|
|
||||||
{
|
|
||||||
return [baseName stringByAppendingString:@"Colorful"];
|
return [baseName stringByAppendingString:@"Colorful"];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return baseName;
|
return baseName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)refreshDockIcon:(NSInteger)playbackStatus withProgress:(double)progressStatus
|
- (void)refreshDockIcon:(NSInteger)playbackStatus withProgress:(double)progressStatus {
|
||||||
{
|
|
||||||
BOOL displayChanged = NO;
|
BOOL displayChanged = NO;
|
||||||
BOOL drawIcon = NO;
|
BOOL drawIcon = NO;
|
||||||
BOOL removeProgress = NO;
|
BOOL removeProgress = NO;
|
||||||
|
|
||||||
if ( playbackStatus < 0 )
|
if(playbackStatus < 0)
|
||||||
playbackStatus = lastPlaybackStatus;
|
playbackStatus = lastPlaybackStatus;
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
lastPlaybackStatus = playbackStatus;
|
lastPlaybackStatus = playbackStatus;
|
||||||
drawIcon = YES;
|
drawIcon = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( progressStatus < -2 )
|
if(progressStatus < -2)
|
||||||
progressStatus = [lastProgressStatus doubleValue];
|
progressStatus = [lastProgressStatus doubleValue];
|
||||||
else
|
else {
|
||||||
{
|
if(progressStatus < 0 && [lastProgressStatus doubleValue] >= 0)
|
||||||
if (progressStatus < 0 && [lastProgressStatus doubleValue] >= 0)
|
|
||||||
removeProgress = YES;
|
removeProgress = YES;
|
||||||
lastProgressStatus = [NSNumber numberWithDouble:progressStatus];
|
lastProgressStatus = [NSNumber numberWithDouble:progressStatus];
|
||||||
}
|
}
|
||||||
|
@ -69,18 +60,16 @@ static NSString *getBadgeName(NSString *baseName, BOOL colorfulIcons)
|
||||||
|
|
||||||
BOOL colorfulIcons = [[NSUserDefaults standardUserDefaults] boolForKey:@"colorfulDockIcons"];
|
BOOL colorfulIcons = [[NSUserDefaults standardUserDefaults] boolForKey:@"colorfulDockIcons"];
|
||||||
|
|
||||||
if ((colorfulIcons && lastColorfulStatus < 1) ||
|
if((colorfulIcons && lastColorfulStatus < 1) ||
|
||||||
(!colorfulIcons && lastColorfulStatus != 0))
|
(!colorfulIcons && lastColorfulStatus != 0)) {
|
||||||
{
|
|
||||||
lastColorfulStatus = colorfulIcons ? 1 : 0;
|
lastColorfulStatus = colorfulIcons ? 1 : 0;
|
||||||
drawIcon = YES;
|
drawIcon = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSDockTile *dockTile = [NSApp dockTile];
|
NSDockTile *dockTile = [NSApp dockTile];
|
||||||
|
|
||||||
if (drawIcon)
|
if(drawIcon) {
|
||||||
{
|
switch(playbackStatus) {
|
||||||
switch (playbackStatus) {
|
|
||||||
case CogStatusPlaying:
|
case CogStatusPlaying:
|
||||||
badgeImage = [NSImage imageNamed:getBadgeName(@"playDockBadge", colorfulIcons)];
|
badgeImage = [NSImage imageNamed:getBadgeName(@"playDockBadge", colorfulIcons)];
|
||||||
break;
|
break;
|
||||||
|
@ -100,7 +89,8 @@ static NSString *getBadgeName(NSString *baseName, BOOL colorfulIcons)
|
||||||
|
|
||||||
[badgeImage drawInRect:NSMakeRect(0, 0, 128, 128)
|
[badgeImage drawInRect:NSMakeRect(0, 0, 128, 128)
|
||||||
fromRect:NSMakeRect(0, 0, badgeSize.width, badgeSize.height)
|
fromRect:NSMakeRect(0, 0, badgeSize.width, badgeSize.height)
|
||||||
operation:NSCompositingOperationSourceOver fraction:1.0];
|
operation:NSCompositingOperationSourceOver
|
||||||
|
fraction:1.0];
|
||||||
|
|
||||||
[newDockImage unlockFocus];
|
[newDockImage unlockFocus];
|
||||||
|
|
||||||
|
@ -121,17 +111,14 @@ static NSString *getBadgeName(NSString *baseName, BOOL colorfulIcons)
|
||||||
displayChanged = YES;
|
displayChanged = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (displayProgress)
|
if(displayProgress) {
|
||||||
{
|
if(!imageView) {
|
||||||
if (!imageView)
|
|
||||||
{
|
|
||||||
imageView = [[NSImageView alloc] init];
|
imageView = [[NSImageView alloc] init];
|
||||||
[imageView setImage:[NSApp applicationIconImage]];
|
[imageView setImage:[NSApp applicationIconImage]];
|
||||||
[dockTile setContentView:imageView];
|
[dockTile setContentView:imageView];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!progressIndicator)
|
if(!progressIndicator) {
|
||||||
{
|
|
||||||
progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0.0, 0.0, dockTile.size.width, 10.0)];
|
progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0.0, 0.0, dockTile.size.width, 10.0)];
|
||||||
[progressIndicator setIndeterminate:NO];
|
[progressIndicator setIndeterminate:NO];
|
||||||
[progressIndicator setBezeled:YES];
|
[progressIndicator setBezeled:YES];
|
||||||
|
@ -147,47 +134,36 @@ static NSString *getBadgeName(NSString *baseName, BOOL colorfulIcons)
|
||||||
displayChanged = YES;
|
displayChanged = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (removeProgress)
|
if(removeProgress) {
|
||||||
{
|
if(progressIndicator)
|
||||||
if (progressIndicator)
|
|
||||||
[progressIndicator setHidden:YES];
|
[progressIndicator setHidden:YES];
|
||||||
|
|
||||||
displayChanged = YES;
|
displayChanged = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (displayChanged)
|
if(displayChanged)
|
||||||
[dockTile display];
|
[dockTile display];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
|
||||||
{
|
if([DockIconPlaybackStatusObservationContext isEqual:(__bridge id)(context)]) {
|
||||||
if ([DockIconPlaybackStatusObservationContext isEqual:(__bridge id)(context)])
|
if([keyPath isEqualToString:@"playbackStatus"]) {
|
||||||
{
|
|
||||||
if ([keyPath isEqualToString:@"playbackStatus"])
|
|
||||||
{
|
|
||||||
NSInteger playbackStatus = [[change objectForKey:NSKeyValueChangeNewKey] integerValue];
|
NSInteger playbackStatus = [[change objectForKey:NSKeyValueChangeNewKey] integerValue];
|
||||||
|
|
||||||
[self refreshDockIcon:playbackStatus withProgress:-10];
|
[self refreshDockIcon:playbackStatus withProgress:-10];
|
||||||
}
|
} else if([keyPath isEqualToString:@"progressBarStatus"]) {
|
||||||
else if ([keyPath isEqualToString:@"progressBarStatus"])
|
|
||||||
{
|
|
||||||
double progressStatus = [[change objectForKey:NSKeyValueChangeNewKey] doubleValue];
|
double progressStatus = [[change objectForKey:NSKeyValueChangeNewKey] doubleValue];
|
||||||
|
|
||||||
[self refreshDockIcon:-1 withProgress:progressStatus];
|
[self refreshDockIcon:-1 withProgress:progressStatus];
|
||||||
}
|
} else if([keyPath isEqualToString:@"values.colorfulDockIcons"]) {
|
||||||
else if ([keyPath isEqualToString:@"values.colorfulDockIcons"])
|
|
||||||
{
|
|
||||||
[self refreshDockIcon:-1 withProgress:-10];
|
[self refreshDockIcon:-1 withProgress:-10];
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)awakeFromNib
|
- (void)awakeFromNib {
|
||||||
{
|
|
||||||
dockImage = [[NSImage imageNamed:@"icon_blank"] copy];
|
dockImage = [[NSImage imageNamed:@"icon_blank"] copy];
|
||||||
lastColorfulStatus = -1;
|
lastColorfulStatus = -1;
|
||||||
lastProgressStatus = [NSNumber numberWithDouble:-1];
|
lastProgressStatus = [NSNumber numberWithDouble:-1];
|
||||||
|
@ -196,8 +172,7 @@ static NSString *getBadgeName(NSString *baseName, BOOL colorfulIcons)
|
||||||
[self startObserving];
|
[self startObserving];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc {
|
||||||
{
|
|
||||||
[self stopObserving];
|
[self stopObserving];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,4 +11,3 @@
|
||||||
@interface MediaKeysApplication : NSApplication
|
@interface MediaKeysApplication : NSApplication
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,10 @@
|
||||||
#import "AppController.h"
|
#import "AppController.h"
|
||||||
#import "Logging.h"
|
#import "Logging.h"
|
||||||
|
|
||||||
#import <MediaPlayer/MPNowPlayingInfoCenter.h>
|
|
||||||
#import <MediaPlayer/MPRemoteCommandCenter.h>
|
|
||||||
#import <MediaPlayer/MPRemoteCommand.h>
|
|
||||||
#import <MediaPlayer/MPMediaItem.h>
|
#import <MediaPlayer/MPMediaItem.h>
|
||||||
|
#import <MediaPlayer/MPNowPlayingInfoCenter.h>
|
||||||
|
#import <MediaPlayer/MPRemoteCommand.h>
|
||||||
|
#import <MediaPlayer/MPRemoteCommandCenter.h>
|
||||||
#import <MediaPlayer/MPRemoteCommandEvent.h>
|
#import <MediaPlayer/MPRemoteCommandEvent.h>
|
||||||
|
|
||||||
@implementation MediaKeysApplication {
|
@implementation MediaKeysApplication {
|
||||||
|
@ -68,10 +68,9 @@
|
||||||
return MPRemoteCommandHandlerStatusSuccess;
|
return MPRemoteCommandHandlerStatusSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (MPRemoteCommandHandlerStatus)clickSeek: (MPChangePlaybackPositionCommandEvent*)event {
|
- (MPRemoteCommandHandlerStatus)clickSeek:(MPChangePlaybackPositionCommandEvent *)event {
|
||||||
[_appController clickSeek:event.positionTime];
|
[_appController clickSeek:event.positionTime];
|
||||||
return MPRemoteCommandHandlerStatusSuccess;
|
return MPRemoteCommandHandlerStatusSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -2,15 +2,15 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#import "AppController.h"
|
||||||
|
#import "AudioScrobbler.h"
|
||||||
#import "CogAudio/AudioPlayer.h"
|
#import "CogAudio/AudioPlayer.h"
|
||||||
#import "CogAudio/Status.h"
|
#import "CogAudio/Status.h"
|
||||||
#import "TrackingSlider.h"
|
#import "TrackingSlider.h"
|
||||||
#import "AudioScrobbler.h"
|
|
||||||
#import "AppController.h"
|
|
||||||
|
|
||||||
|
#import <AVFoundation/AVFoundation.h>
|
||||||
#import <AudioToolbox/AudioToolbox.h>
|
#import <AudioToolbox/AudioToolbox.h>
|
||||||
#import <AudioUnit/AudioUnit.h>
|
#import <AudioUnit/AudioUnit.h>
|
||||||
#import <AVFoundation/AVFoundation.h>
|
|
||||||
#import <CoreAudio/CoreAudioTypes.h>
|
#import <CoreAudio/CoreAudioTypes.h>
|
||||||
|
|
||||||
#import "AUPlayerView.h"
|
#import "AUPlayerView.h"
|
||||||
|
@ -23,14 +23,13 @@ extern NSString *CogPlaybackDidPauseNotficiation;
|
||||||
extern NSString *CogPlaybackDidResumeNotficiation;
|
extern NSString *CogPlaybackDidResumeNotficiation;
|
||||||
extern NSString *CogPlaybackDidStopNotficiation;
|
extern NSString *CogPlaybackDidStopNotficiation;
|
||||||
|
|
||||||
extern NSDictionary * makeRGInfo(PlaylistEntry *pe);
|
extern NSDictionary *makeRGInfo(PlaylistEntry *pe);
|
||||||
|
|
||||||
@class PlaylistController;
|
@class PlaylistController;
|
||||||
@class PlaylistView;
|
@class PlaylistView;
|
||||||
@class PlaylistLoader;
|
@class PlaylistLoader;
|
||||||
|
|
||||||
@interface PlaybackController : NSObject
|
@interface PlaybackController : NSObject {
|
||||||
{
|
|
||||||
IBOutlet AppController *appController;
|
IBOutlet AppController *appController;
|
||||||
|
|
||||||
IBOutlet PlaylistController *playlistController;
|
IBOutlet PlaylistController *playlistController;
|
||||||
|
@ -58,7 +57,7 @@ extern NSDictionary * makeRGInfo(PlaylistEntry *pe);
|
||||||
BOOL _eqStubbed;
|
BOOL _eqStubbed;
|
||||||
AudioUnit _eq;
|
AudioUnit _eq;
|
||||||
AUPluginUI *_equi;
|
AUPluginUI *_equi;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property CogStatus playbackStatus;
|
@property CogStatus playbackStatus;
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#import "PlaybackController.h"
|
#import "PlaybackController.h"
|
||||||
|
#import "CogAudio/Helper.h"
|
||||||
|
#import "CogAudio/Status.h"
|
||||||
#import "PlaylistView.h"
|
#import "PlaylistView.h"
|
||||||
#import <Foundation/NSTimer.h>
|
#import <Foundation/NSTimer.h>
|
||||||
#import "CogAudio/Status.h"
|
|
||||||
#import "CogAudio/Helper.h"
|
|
||||||
|
|
||||||
#import "PlaylistController.h"
|
#import "PlaylistController.h"
|
||||||
#import "PlaylistEntry.h"
|
#import "PlaylistEntry.h"
|
||||||
|
@ -11,10 +11,10 @@
|
||||||
#import "MainWindow.h"
|
#import "MainWindow.h"
|
||||||
#import "MiniWindow.h"
|
#import "MiniWindow.h"
|
||||||
|
|
||||||
#import <MediaPlayer/MPNowPlayingInfoCenter.h>
|
|
||||||
#import <MediaPlayer/MPRemoteCommandCenter.h>
|
|
||||||
#import <MediaPlayer/MPRemoteCommand.h>
|
|
||||||
#import <MediaPlayer/MPMediaItem.h>
|
#import <MediaPlayer/MPMediaItem.h>
|
||||||
|
#import <MediaPlayer/MPNowPlayingInfoCenter.h>
|
||||||
|
#import <MediaPlayer/MPRemoteCommand.h>
|
||||||
|
#import <MediaPlayer/MPRemoteCommandCenter.h>
|
||||||
#import <MediaPlayer/MPRemoteCommandEvent.h>
|
#import <MediaPlayer/MPRemoteCommandEvent.h>
|
||||||
|
|
||||||
#import "Logging.h"
|
#import "Logging.h"
|
||||||
|
@ -32,16 +32,13 @@ NSString *CogPlaybackDidStopNotficiation = @"CogPlaybackDidStopNotficiation";
|
||||||
|
|
||||||
@synthesize progressBarStatus;
|
@synthesize progressBarStatus;
|
||||||
|
|
||||||
+ (NSSet *)keyPathsForValuesAffectingSeekable
|
+ (NSSet *)keyPathsForValuesAffectingSeekable {
|
||||||
{
|
return [NSSet setWithObjects:@"playlistController.currentEntry", @"playlistController.currentEntry.seekable", nil];
|
||||||
return [NSSet setWithObjects:@"playlistController.currentEntry",@"playlistController.currentEntry.seekable",nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)init
|
- (id)init {
|
||||||
{
|
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self)
|
if(self) {
|
||||||
{
|
|
||||||
[self initDefaults];
|
[self initDefaults];
|
||||||
|
|
||||||
seekable = NO;
|
seekable = NO;
|
||||||
|
@ -53,14 +50,13 @@ NSString *CogPlaybackDidStopNotficiation = @"CogPlaybackDidStopNotficiation";
|
||||||
|
|
||||||
audioPlayer = [[AudioPlayer alloc] init];
|
audioPlayer = [[AudioPlayer alloc] init];
|
||||||
[audioPlayer setDelegate:self];
|
[audioPlayer setDelegate:self];
|
||||||
[self setPlaybackStatus: CogStatusStopped];
|
[self setPlaybackStatus:CogStatusStopped];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)initDefaults
|
- (void)initDefaults {
|
||||||
{
|
|
||||||
NSDictionary *defaultsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
|
NSDictionary *defaultsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||||
[NSNumber numberWithDouble:100.0], @"volume",
|
[NSNumber numberWithDouble:100.0], @"volume",
|
||||||
[NSNumber numberWithBool:NO], @"GraphicEQenable",
|
[NSNumber numberWithBool:NO], @"GraphicEQenable",
|
||||||
|
@ -73,10 +69,7 @@ NSString *CogPlaybackDidStopNotficiation = @"CogPlaybackDidStopNotficiation";
|
||||||
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsDictionary];
|
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsDictionary];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)awakeFromNib {
|
||||||
|
|
||||||
- (void)awakeFromNib
|
|
||||||
{
|
|
||||||
BOOL volumeLimit = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"volumeLimit"];
|
BOOL volumeLimit = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"volumeLimit"];
|
||||||
const double MAX_VOLUME = (volumeLimit) ? 100.0 : 800.0;
|
const double MAX_VOLUME = (volumeLimit) ? 100.0 : 800.0;
|
||||||
|
|
||||||
|
@ -88,48 +81,39 @@ NSString *CogPlaybackDidStopNotficiation = @"CogPlaybackDidStopNotficiation";
|
||||||
[self setSeekable:NO];
|
[self setSeekable:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)playPauseResume:(id)sender
|
- (IBAction)playPauseResume:(id)sender {
|
||||||
{
|
if(playbackStatus == CogStatusStopped || playbackStatus == CogStatusStopping) {
|
||||||
if (playbackStatus == CogStatusStopped || playbackStatus == CogStatusStopping)
|
|
||||||
{
|
|
||||||
[self play:self];
|
[self play:self];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
[self pauseResume:self];
|
[self pauseResume:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self sendMetaData];
|
[self sendMetaData];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)pauseResume:(id)sender
|
- (IBAction)pauseResume:(id)sender {
|
||||||
{
|
if(playbackStatus == CogStatusPaused)
|
||||||
if (playbackStatus == CogStatusPaused)
|
|
||||||
[self resume:self];
|
[self resume:self];
|
||||||
else
|
else
|
||||||
[self pause:self];
|
[self pause:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)pause:(id)sender
|
- (IBAction)pause:(id)sender {
|
||||||
{
|
|
||||||
[[NSUserDefaults standardUserDefaults] setInteger:CogStatusPaused forKey:@"lastPlaybackStatus"];
|
[[NSUserDefaults standardUserDefaults] setInteger:CogStatusPaused forKey:@"lastPlaybackStatus"];
|
||||||
|
|
||||||
[audioPlayer pause];
|
[audioPlayer pause];
|
||||||
[self setPlaybackStatus: CogStatusPaused];
|
[self setPlaybackStatus:CogStatusPaused];
|
||||||
|
|
||||||
[self sendMetaData];
|
[self sendMetaData];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)resume:(id)sender
|
- (IBAction)resume:(id)sender {
|
||||||
{
|
|
||||||
[[NSUserDefaults standardUserDefaults] setInteger:CogStatusPlaying forKey:@"lastPlaybackStatus"];
|
[[NSUserDefaults standardUserDefaults] setInteger:CogStatusPlaying forKey:@"lastPlaybackStatus"];
|
||||||
|
|
||||||
[audioPlayer resume];
|
[audioPlayer resume];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)stop:(id)sender
|
- (IBAction)stop:(id)sender {
|
||||||
{
|
|
||||||
[[NSUserDefaults standardUserDefaults] setInteger:CogStatusStopped forKey:@"lastPlaybackStatus"];
|
[[NSUserDefaults standardUserDefaults] setInteger:CogStatusStopped forKey:@"lastPlaybackStatus"];
|
||||||
|
|
||||||
[self audioPlayer:audioPlayer removeEqualizer:_eq];
|
[self audioPlayer:audioPlayer removeEqualizer:_eq];
|
||||||
|
@ -141,65 +125,56 @@ NSString *CogPlaybackDidStopNotficiation = @"CogPlaybackDidStopNotficiation";
|
||||||
[self removeHDCD:nil];
|
[self removeHDCD:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
//called by double-clicking on table
|
// called by double-clicking on table
|
||||||
- (void)playEntryAtIndex:(NSInteger)i
|
- (void)playEntryAtIndex:(NSInteger)i {
|
||||||
{
|
|
||||||
[self playEntryAtIndex:i startPaused:NO andSeekTo:[NSNumber numberWithDouble:0.0]];
|
[self playEntryAtIndex:i startPaused:NO andSeekTo:[NSNumber numberWithDouble:0.0]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)playEntryAtIndex:(NSInteger)i startPaused:(BOOL)paused
|
- (void)playEntryAtIndex:(NSInteger)i startPaused:(BOOL)paused {
|
||||||
{
|
|
||||||
PlaylistEntry *pe = [playlistController entryAtIndex:i];
|
PlaylistEntry *pe = [playlistController entryAtIndex:i];
|
||||||
|
|
||||||
[self playEntry:pe startPaused:paused andSeekTo:[NSNumber numberWithDouble:0.0]];
|
[self playEntry:pe startPaused:paused andSeekTo:[NSNumber numberWithDouble:0.0]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)playEntryAtIndex:(NSInteger)i startPaused:(BOOL)paused andSeekTo:(id)offset
|
- (void)playEntryAtIndex:(NSInteger)i startPaused:(BOOL)paused andSeekTo:(id)offset {
|
||||||
{
|
|
||||||
PlaylistEntry *pe = [playlistController entryAtIndex:i];
|
PlaylistEntry *pe = [playlistController entryAtIndex:i];
|
||||||
|
|
||||||
[self playEntry:pe startPaused:paused andSeekTo:offset];
|
[self playEntry:pe startPaused:paused andSeekTo:offset];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (IBAction)play:(id)sender {
|
||||||
- (IBAction)play:(id)sender
|
if([playlistView selectedRow] == -1)
|
||||||
{
|
|
||||||
if ([playlistView selectedRow] == -1)
|
|
||||||
[playlistView selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO];
|
[playlistView selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO];
|
||||||
|
|
||||||
if ([playlistView selectedRow] > -1)
|
if([playlistView selectedRow] > -1)
|
||||||
[self playEntryAtIndex:(int)[playlistView selectedRow]];
|
[self playEntryAtIndex:(int)[playlistView selectedRow]];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
NSDictionary *makeRGInfo(PlaylistEntry *pe) {
|
||||||
{
|
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||||
NSMutableDictionary * dictionary = [NSMutableDictionary dictionary];
|
if([pe replayGainAlbumGain] != 0)
|
||||||
if ([pe replayGainAlbumGain] != 0)
|
|
||||||
[dictionary setObject:[NSNumber numberWithFloat:[pe replayGainAlbumGain]] forKey:@"replayGainAlbumGain"];
|
[dictionary setObject:[NSNumber numberWithFloat:[pe replayGainAlbumGain]] forKey:@"replayGainAlbumGain"];
|
||||||
if ([pe replayGainAlbumPeak] != 0)
|
if([pe replayGainAlbumPeak] != 0)
|
||||||
[dictionary setObject:[NSNumber numberWithFloat:[pe replayGainAlbumPeak]] forKey:@"replayGainAlbumPeak"];
|
[dictionary setObject:[NSNumber numberWithFloat:[pe replayGainAlbumPeak]] forKey:@"replayGainAlbumPeak"];
|
||||||
if ([pe replayGainTrackGain] != 0)
|
if([pe replayGainTrackGain] != 0)
|
||||||
[dictionary setObject:[NSNumber numberWithFloat:[pe replayGainTrackGain]] forKey:@"replayGainTrackGain"];
|
[dictionary setObject:[NSNumber numberWithFloat:[pe replayGainTrackGain]] forKey:@"replayGainTrackGain"];
|
||||||
if ([pe replayGainTrackPeak] != 0)
|
if([pe replayGainTrackPeak] != 0)
|
||||||
[dictionary setObject:[NSNumber numberWithFloat:[pe replayGainTrackPeak]] forKey:@"replayGainTrackPeak"];
|
[dictionary setObject:[NSNumber numberWithFloat:[pe replayGainTrackPeak]] forKey:@"replayGainTrackPeak"];
|
||||||
if ([pe volume] != 1)
|
if([pe volume] != 1)
|
||||||
[dictionary setObject:[NSNumber numberWithFloat:[pe volume]] forKey:@"volume"];
|
[dictionary setObject:[NSNumber numberWithFloat:[pe volume]] forKey:@"volume"];
|
||||||
return dictionary;
|
return dictionary;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)playEntry:(PlaylistEntry *)pe
|
- (void)playEntry:(PlaylistEntry *)pe {
|
||||||
{
|
|
||||||
[self playEntry:pe startPaused:NO andSeekTo:[NSNumber numberWithDouble:0.0]];
|
[self playEntry:pe startPaused:NO andSeekTo:[NSNumber numberWithDouble:0.0]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)playEntry:(PlaylistEntry *)pe startPaused:(BOOL)paused
|
- (void)playEntry:(PlaylistEntry *)pe startPaused:(BOOL)paused {
|
||||||
{
|
|
||||||
[self playEntry:pe startPaused:paused andSeekTo:[NSNumber numberWithDouble:0.0]];
|
[self playEntry:pe startPaused:paused andSeekTo:[NSNumber numberWithDouble:0.0]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)playEntry:(PlaylistEntry *)pe startPaused:(BOOL)paused andSeekTo:(id)offset
|
- (void)playEntry:(PlaylistEntry *)pe startPaused:(BOOL)paused andSeekTo:(id)offset {
|
||||||
{
|
if(playbackStatus != CogStatusStopped && playbackStatus != CogStatusStopping)
|
||||||
if (playbackStatus != CogStatusStopped && playbackStatus != CogStatusStopping)
|
|
||||||
[self stop:self];
|
[self stop:self];
|
||||||
|
|
||||||
DLog(@"PLAYLIST CONTROLLER: %@", [playlistController class]);
|
DLog(@"PLAYLIST CONTROLLER: %@", [playlistController class]);
|
||||||
|
@ -209,12 +184,12 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
|
|
||||||
[self setPosition:[offset doubleValue]];
|
[self setPosition:[offset doubleValue]];
|
||||||
|
|
||||||
if (pe == nil)
|
if(pe == nil)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BOOL loadData = YES;
|
BOOL loadData = YES;
|
||||||
NSString * urlScheme = [[pe URL] scheme];
|
NSString *urlScheme = [[pe URL] scheme];
|
||||||
if ([urlScheme isEqualToString:@"http"] ||
|
if([urlScheme isEqualToString:@"http"] ||
|
||||||
[urlScheme isEqualToString:@"https"])
|
[urlScheme isEqualToString:@"https"])
|
||||||
loadData = NO;
|
loadData = NO;
|
||||||
|
|
||||||
|
@ -225,13 +200,13 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
}
|
}
|
||||||
#elif 0
|
#elif 0
|
||||||
// Racing with this version is less likely to jam up the main thread
|
// Racing with this version is less likely to jam up the main thread
|
||||||
if ([pe metadataLoaded] != YES) {
|
if([pe metadataLoaded] != YES) {
|
||||||
NSArray * entries = @[pe];
|
NSArray *entries = @[pe];
|
||||||
[playlistLoader loadInfoForEntries:entries];
|
[playlistLoader loadInfoForEntries:entries];
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// Let's do it this way instead
|
// Let's do it this way instead
|
||||||
if ([pe metadataLoaded] != YES && loadData == YES) {
|
if([pe metadataLoaded] != YES && loadData == YES) {
|
||||||
NSArray *entries = @[pe];
|
NSArray *entries = @[pe];
|
||||||
[playlistLoader performSelectorInBackground:@selector(loadInfoForEntries:) withObject:entries];
|
[playlistLoader performSelectorInBackground:@selector(loadInfoForEntries:) withObject:entries];
|
||||||
}
|
}
|
||||||
|
@ -242,24 +217,21 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
[audioPlayer play:[pe URL] withUserInfo:pe withRGInfo:makeRGInfo(pe) startPaused:paused andSeekTo:[offset doubleValue]];
|
[audioPlayer play:[pe URL] withUserInfo:pe withRGInfo:makeRGInfo(pe) startPaused:paused andSeekTo:[offset doubleValue]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)next:(id)sender
|
- (IBAction)next:(id)sender {
|
||||||
{
|
if([playlistController next] == NO)
|
||||||
if ([playlistController next] == NO)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
[self playEntry:[playlistController currentEntry]];
|
[self playEntry:[playlistController currentEntry]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)prev:(id)sender
|
- (IBAction)prev:(id)sender {
|
||||||
{
|
if([playlistController prev] == NO)
|
||||||
if ([playlistController prev] == NO)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
[self playEntry:[playlistController currentEntry]];
|
[self playEntry:[playlistController currentEntry]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)updatePosition:(id)sender
|
- (void)updatePosition:(id)sender {
|
||||||
{
|
|
||||||
double pos = [audioPlayer amountPlayed];
|
double pos = [audioPlayer amountPlayed];
|
||||||
|
|
||||||
[self setPosition:pos];
|
[self setPosition:pos];
|
||||||
|
@ -267,8 +239,7 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
[[playlistController currentEntry] setCurrentPosition:pos];
|
[[playlistController currentEntry] setCurrentPosition:pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)seek:(id)sender
|
- (IBAction)seek:(id)sender {
|
||||||
{
|
|
||||||
double time = [sender doubleValue];
|
double time = [sender doubleValue];
|
||||||
|
|
||||||
[audioPlayer seekToTime:time];
|
[audioPlayer seekToTime:time];
|
||||||
|
@ -280,8 +251,7 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
[[playlistController currentEntry] setCurrentPosition:time];
|
[[playlistController currentEntry] setCurrentPosition:time];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)seek:(id)sender toTime:(NSTimeInterval)position
|
- (IBAction)seek:(id)sender toTime:(NSTimeInterval)position {
|
||||||
{
|
|
||||||
double time = (double)(position);
|
double time = (double)(position);
|
||||||
|
|
||||||
lastPosition = -10;
|
lastPosition = -10;
|
||||||
|
@ -293,8 +263,7 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
[[playlistController currentEntry] setCurrentPosition:time];
|
[[playlistController currentEntry] setCurrentPosition:time];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)spam:(id)sender
|
- (IBAction)spam:(id)sender {
|
||||||
{
|
|
||||||
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
|
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
|
||||||
|
|
||||||
[pboard clearContents];
|
[pboard clearContents];
|
||||||
|
@ -302,37 +271,30 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
[pboard writeObjects:@[[[playlistController currentEntry] spam]]];
|
[pboard writeObjects:@[[[playlistController currentEntry] spam]]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)eventSeekForward:(id)sender
|
- (IBAction)eventSeekForward:(id)sender {
|
||||||
{
|
|
||||||
[self seekForward:DEFAULT_SEEK];
|
[self seekForward:DEFAULT_SEEK];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)seekForward:(double)amount
|
- (void)seekForward:(double)amount {
|
||||||
{
|
|
||||||
double seekTo = [audioPlayer amountPlayed] + amount;
|
double seekTo = [audioPlayer amountPlayed] + amount;
|
||||||
|
|
||||||
if (seekTo > [[[playlistController currentEntry] length] doubleValue])
|
if(seekTo > [[[playlistController currentEntry] length] doubleValue]) {
|
||||||
{
|
|
||||||
[self next:self];
|
[self next:self];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
lastPosition = -10;
|
lastPosition = -10;
|
||||||
[audioPlayer seekToTime:seekTo];
|
[audioPlayer seekToTime:seekTo];
|
||||||
[self setPosition:seekTo];
|
[self setPosition:seekTo];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)eventSeekBackward:(id)sender
|
- (IBAction)eventSeekBackward:(id)sender {
|
||||||
{
|
|
||||||
[self seekBackward:DEFAULT_SEEK];
|
[self seekBackward:DEFAULT_SEEK];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)seekBackward:(double)amount
|
- (void)seekBackward:(double)amount {
|
||||||
{
|
|
||||||
double seekTo = [audioPlayer amountPlayed] - amount;
|
double seekTo = [audioPlayer amountPlayed] - amount;
|
||||||
|
|
||||||
if (seekTo < 0)
|
if(seekTo < 0)
|
||||||
seekTo = 0;
|
seekTo = 0;
|
||||||
|
|
||||||
lastPosition = -10;
|
lastPosition = -10;
|
||||||
|
@ -355,8 +317,7 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
[playbackButtons setImage:img forSegment:1];
|
[playbackButtons setImage:img forSegment:1];
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
- (IBAction)changeVolume:(id)sender
|
- (IBAction)changeVolume:(id)sender {
|
||||||
{
|
|
||||||
BOOL volumeLimit = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"volumeLimit"];
|
BOOL volumeLimit = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"volumeLimit"];
|
||||||
const double MAX_VOLUME = (volumeLimit) ? 100.0 : 800.0;
|
const double MAX_VOLUME = (volumeLimit) ? 100.0 : 800.0;
|
||||||
|
|
||||||
|
@ -370,84 +331,74 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
/* selector for NSTimer - gets passed the Timer object itself
|
/* selector for NSTimer - gets passed the Timer object itself
|
||||||
and the appropriate userInfo, which in this case is an NSNumber
|
and the appropriate userInfo, which in this case is an NSNumber
|
||||||
containing the current volume before we start fading. */
|
containing the current volume before we start fading. */
|
||||||
- (void)audioFadeDown:(NSTimer *)audioTimer
|
- (void)audioFadeDown:(NSTimer *)audioTimer {
|
||||||
{
|
|
||||||
double volume = [audioPlayer volume];
|
double volume = [audioPlayer volume];
|
||||||
double originalVolume = [[audioTimer userInfo] doubleValue];
|
double originalVolume = [[audioTimer userInfo] doubleValue];
|
||||||
double down = originalVolume/10;
|
double down = originalVolume / 10;
|
||||||
|
|
||||||
DLog(@"VOLUME IS %lf", volume);
|
DLog(@"VOLUME IS %lf", volume);
|
||||||
|
|
||||||
if (volume > 0.0001) //YAY! Roundoff error!
|
if(volume > 0.0001) // YAY! Roundoff error!
|
||||||
{
|
{
|
||||||
[audioPlayer volumeDown:down];
|
[audioPlayer volumeDown:down];
|
||||||
}
|
} else // volume is at 0 or below, we are ready to release the timer and move on
|
||||||
else // volume is at 0 or below, we are ready to release the timer and move on
|
|
||||||
{
|
{
|
||||||
BOOL volumeLimit = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"volumeLimit"];
|
BOOL volumeLimit = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"volumeLimit"];
|
||||||
const double MAX_VOLUME = (volumeLimit) ? 100.0 : 800.0;
|
const double MAX_VOLUME = (volumeLimit) ? 100.0 : 800.0;
|
||||||
|
|
||||||
[audioPlayer pause];
|
[audioPlayer pause];
|
||||||
[audioPlayer setVolume:originalVolume];
|
[audioPlayer setVolume:originalVolume];
|
||||||
[volumeSlider setDoubleValue: logarithmicToLinear(originalVolume, MAX_VOLUME)];
|
[volumeSlider setDoubleValue:logarithmicToLinear(originalVolume, MAX_VOLUME)];
|
||||||
[audioTimer invalidate];
|
[audioTimer invalidate];
|
||||||
|
|
||||||
fading = NO;
|
fading = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)audioFadeUp:(NSTimer *)audioTimer
|
- (void)audioFadeUp:(NSTimer *)audioTimer {
|
||||||
{
|
|
||||||
double volume = [audioPlayer volume];
|
double volume = [audioPlayer volume];
|
||||||
double originalVolume = [[audioTimer userInfo] doubleValue];
|
double originalVolume = [[audioTimer userInfo] doubleValue];
|
||||||
double up = originalVolume/10;
|
double up = originalVolume / 10;
|
||||||
|
|
||||||
DLog(@"VOLUME IS %lf", volume);
|
DLog(@"VOLUME IS %lf", volume);
|
||||||
|
|
||||||
if (originalVolume - volume > 0.0001)
|
if(originalVolume - volume > 0.0001) {
|
||||||
{
|
if((volume + up) > originalVolume)
|
||||||
if ((volume + up) > originalVolume)
|
|
||||||
[audioPlayer volumeUp:(originalVolume - volume)];
|
[audioPlayer volumeUp:(originalVolume - volume)];
|
||||||
else
|
else
|
||||||
[audioPlayer volumeUp:up];
|
[audioPlayer volumeUp:up];
|
||||||
}
|
} else // volume is at or near original level, we are ready to release the timer and move on
|
||||||
else // volume is at or near original level, we are ready to release the timer and move on
|
|
||||||
{
|
{
|
||||||
BOOL volumeLimit = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"volumeLimit"];
|
BOOL volumeLimit = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"volumeLimit"];
|
||||||
const double MAX_VOLUME = (volumeLimit) ? 100.0 : 800.0;
|
const double MAX_VOLUME = (volumeLimit) ? 100.0 : 800.0;
|
||||||
|
|
||||||
[audioPlayer setVolume:originalVolume];
|
[audioPlayer setVolume:originalVolume];
|
||||||
[volumeSlider setDoubleValue: logarithmicToLinear(originalVolume, MAX_VOLUME)];
|
[volumeSlider setDoubleValue:logarithmicToLinear(originalVolume, MAX_VOLUME)];
|
||||||
[audioTimer invalidate];
|
[audioTimer invalidate];
|
||||||
|
|
||||||
fading = NO;
|
fading = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)fade:(id)sender
|
- (IBAction)fade:(id)sender {
|
||||||
{
|
|
||||||
double time = 0.1;
|
double time = 0.1;
|
||||||
|
|
||||||
// we can not allow multiple fade timers to be registered
|
// we can not allow multiple fade timers to be registered
|
||||||
if (YES == fading)
|
if(YES == fading)
|
||||||
return;
|
return;
|
||||||
fading = YES;
|
fading = YES;
|
||||||
|
|
||||||
NSNumber *originalVolume = [NSNumber numberWithDouble: [audioPlayer volume]];
|
NSNumber *originalVolume = [NSNumber numberWithDouble:[audioPlayer volume]];
|
||||||
NSTimer *fadeTimer;
|
NSTimer *fadeTimer;
|
||||||
|
|
||||||
if (playbackStatus == CogStatusPlaying) {
|
if(playbackStatus == CogStatusPlaying) {
|
||||||
fadeTimer = [NSTimer timerWithTimeInterval:time
|
fadeTimer = [NSTimer timerWithTimeInterval:time
|
||||||
target:self
|
target:self
|
||||||
selector:@selector(audioFadeDown:)
|
selector:@selector(audioFadeDown:)
|
||||||
userInfo:originalVolume
|
userInfo:originalVolume
|
||||||
repeats:YES];
|
repeats:YES];
|
||||||
[[NSRunLoop currentRunLoop] addTimer:fadeTimer forMode:NSRunLoopCommonModes];
|
[[NSRunLoop currentRunLoop] addTimer:fadeTimer forMode:NSRunLoopCommonModes];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
[audioPlayer setVolume:0];
|
[audioPlayer setVolume:0];
|
||||||
fadeTimer = [NSTimer timerWithTimeInterval:time
|
fadeTimer = [NSTimer timerWithTimeInterval:time
|
||||||
target:self
|
target:self
|
||||||
|
@ -459,8 +410,7 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)skipToNextAlbum:(id)sender
|
- (IBAction)skipToNextAlbum:(id)sender {
|
||||||
{
|
|
||||||
BOOL found = NO;
|
BOOL found = NO;
|
||||||
|
|
||||||
NSInteger index = [[playlistController currentEntry] index];
|
NSInteger index = [[playlistController currentEntry] index];
|
||||||
|
@ -471,37 +421,32 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
|
|
||||||
PlaylistEntry *pe;
|
PlaylistEntry *pe;
|
||||||
|
|
||||||
for (i = 1; i < [[playlistController arrangedObjects] count]; i++)
|
for(i = 1; i < [[playlistController arrangedObjects] count]; i++) {
|
||||||
{
|
|
||||||
pe = [playlistController entryAtIndex:index + i];
|
pe = [playlistController entryAtIndex:index + i];
|
||||||
if (pe == nil)
|
if(pe == nil)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
curAlbum = [pe album];
|
curAlbum = [pe album];
|
||||||
|
|
||||||
// check for untagged files, and just play the first untagged one
|
// check for untagged files, and just play the first untagged one
|
||||||
// we come across
|
// we come across
|
||||||
if (curAlbum == nil)
|
if(curAlbum == nil) {
|
||||||
{
|
|
||||||
found = YES;
|
found = YES;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([curAlbum caseInsensitiveCompare:origAlbum] != NSOrderedSame)
|
if([curAlbum caseInsensitiveCompare:origAlbum] != NSOrderedSame) {
|
||||||
{
|
|
||||||
found = YES;
|
found = YES;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found)
|
if(found) {
|
||||||
{
|
|
||||||
[self playEntryAtIndex:i + index];
|
[self playEntryAtIndex:i + index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)skipToPreviousAlbum:(id)sender
|
- (IBAction)skipToPreviousAlbum:(id)sender {
|
||||||
{
|
|
||||||
BOOL found = NO;
|
BOOL found = NO;
|
||||||
BOOL foundAlbum = NO;
|
BOOL foundAlbum = NO;
|
||||||
|
|
||||||
|
@ -513,48 +458,39 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
|
|
||||||
PlaylistEntry *pe;
|
PlaylistEntry *pe;
|
||||||
|
|
||||||
for (i = 1; i < [[playlistController arrangedObjects] count]; i++)
|
for(i = 1; i < [[playlistController arrangedObjects] count]; i++) {
|
||||||
{
|
|
||||||
pe = [playlistController entryAtIndex:index - i];
|
pe = [playlistController entryAtIndex:index - i];
|
||||||
if (pe == nil)
|
if(pe == nil)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
curAlbum = [pe album];
|
curAlbum = [pe album];
|
||||||
if (curAlbum == nil)
|
if(curAlbum == nil) {
|
||||||
{
|
|
||||||
found = YES;
|
found = YES;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([curAlbum caseInsensitiveCompare:origAlbum] != NSOrderedSame)
|
if([curAlbum caseInsensitiveCompare:origAlbum] != NSOrderedSame) {
|
||||||
{
|
if(foundAlbum == NO) {
|
||||||
if (foundAlbum == NO)
|
|
||||||
{
|
|
||||||
foundAlbum = YES;
|
foundAlbum = YES;
|
||||||
// now we need to move up to the first song in the album, so we'll
|
// now we need to move up to the first song in the album, so we'll
|
||||||
// go till we either find index 0, or the first song in the album
|
// go till we either find index 0, or the first song in the album
|
||||||
origAlbum = curAlbum;
|
origAlbum = curAlbum;
|
||||||
continue;
|
continue;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
found = YES; // terminate loop
|
found = YES; // terminate loop
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found || foundAlbum)
|
if(found || foundAlbum) {
|
||||||
{
|
if(foundAlbum == YES)
|
||||||
if (foundAlbum == YES)
|
|
||||||
i--;
|
i--;
|
||||||
[self playEntryAtIndex:index - i];
|
[self playEntryAtIndex:index - i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (IBAction)volumeDown:(id)sender {
|
||||||
- (IBAction)volumeDown:(id)sender
|
|
||||||
{
|
|
||||||
BOOL volumeLimit = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"volumeLimit"];
|
BOOL volumeLimit = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"volumeLimit"];
|
||||||
const double MAX_VOLUME = (volumeLimit) ? 100.0 : 800.0;
|
const double MAX_VOLUME = (volumeLimit) ? 100.0 : 800.0;
|
||||||
|
|
||||||
|
@ -562,11 +498,9 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
[volumeSlider setDoubleValue:logarithmicToLinear(newVolume, MAX_VOLUME)];
|
[volumeSlider setDoubleValue:logarithmicToLinear(newVolume, MAX_VOLUME)];
|
||||||
|
|
||||||
[[NSUserDefaults standardUserDefaults] setDouble:[audioPlayer volume] forKey:@"volume"];
|
[[NSUserDefaults standardUserDefaults] setDouble:[audioPlayer volume] forKey:@"volume"];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)volumeUp:(id)sender
|
- (IBAction)volumeUp:(id)sender {
|
||||||
{
|
|
||||||
BOOL volumeLimit = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"volumeLimit"];
|
BOOL volumeLimit = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"volumeLimit"];
|
||||||
const double MAX_VOLUME = (volumeLimit) ? 100.0 : 800.0;
|
const double MAX_VOLUME = (volumeLimit) ? 100.0 : 800.0;
|
||||||
|
|
||||||
|
@ -577,8 +511,7 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
[[NSUserDefaults standardUserDefaults] setDouble:[audioPlayer volume] forKey:@"volume"];
|
[[NSUserDefaults standardUserDefaults] setDouble:[audioPlayer volume] forKey:@"volume"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)eqAlloc
|
- (void)eqAlloc {
|
||||||
{
|
|
||||||
// Show a stopped equalizer as a stub
|
// Show a stopped equalizer as a stub
|
||||||
OSStatus err;
|
OSStatus err;
|
||||||
AudioComponentDescription desc;
|
AudioComponentDescription desc;
|
||||||
|
@ -595,35 +528,30 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
desc.componentSubType = kAudioUnitSubType_GraphicEQ;
|
desc.componentSubType = kAudioUnitSubType_GraphicEQ;
|
||||||
|
|
||||||
comp = AudioComponentFindNext(comp, &desc);
|
comp = AudioComponentFindNext(comp, &desc);
|
||||||
if (!comp)
|
if(!comp)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
err = AudioComponentInstanceNew(comp, &_eq);
|
err = AudioComponentInstanceNew(comp, &_eq);
|
||||||
if (err)
|
if(err)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AudioUnitInitialize(_eq);
|
AudioUnitInitialize(_eq);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)eqDealloc
|
- (void)eqDealloc {
|
||||||
{
|
|
||||||
AudioUnitUninitialize(_eq);
|
AudioUnitUninitialize(_eq);
|
||||||
AudioComponentInstanceDispose(_eq);
|
AudioComponentInstanceDispose(_eq);
|
||||||
_eq = nil;
|
_eq = nil;
|
||||||
_eqStubbed = NO;
|
_eqStubbed = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)showEq:(id)sender
|
- (IBAction)showEq:(id)sender {
|
||||||
{
|
if(_eq) {
|
||||||
if (_eq)
|
if(_equi && [_equi isOpen])
|
||||||
{
|
|
||||||
if (_equi && [_equi isOpen])
|
|
||||||
[_equi bringToFront];
|
[_equi bringToFront];
|
||||||
else
|
else
|
||||||
_equi = [[AUPluginUI alloc] initWithSampler:_eq bringToFront:YES orWindowNumber:0];
|
_equi = [[AUPluginUI alloc] initWithSampler:_eq bringToFront:YES orWindowNumber:0];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
[self eqAlloc];
|
[self eqAlloc];
|
||||||
_eqWasOpen = YES;
|
_eqWasOpen = YES;
|
||||||
[self audioPlayer:nil displayEqualizer:_eq];
|
[self audioPlayer:nil displayEqualizer:_eq];
|
||||||
|
@ -631,23 +559,20 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)audioPlayer:(AudioPlayer *)player displayEqualizer:(AudioUnit)eq
|
- (void)audioPlayer:(AudioPlayer *)player displayEqualizer:(AudioUnit)eq {
|
||||||
{
|
if(_equi) {
|
||||||
if (_equi)
|
|
||||||
{
|
|
||||||
_eqWasOpen = [_equi isOpen];
|
_eqWasOpen = [_equi isOpen];
|
||||||
_equi = nil;
|
_equi = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_eq && _eq != eq) {
|
if(_eq && _eq != eq) {
|
||||||
OSStatus err;
|
OSStatus err;
|
||||||
CFPropertyListRef classData;
|
CFPropertyListRef classData;
|
||||||
UInt32 size;
|
UInt32 size;
|
||||||
|
|
||||||
size = sizeof(classData);
|
size = sizeof(classData);
|
||||||
err = AudioUnitGetProperty(_eq, kAudioUnitProperty_ClassInfo, kAudioUnitScope_Global, 0, &classData, &size);
|
err = AudioUnitGetProperty(_eq, kAudioUnitProperty_ClassInfo, kAudioUnitScope_Global, 0, &classData, &size);
|
||||||
if (err == noErr)
|
if(err == noErr) {
|
||||||
{
|
|
||||||
CFPreferencesSetAppValue(CFSTR("GraphEQ_Preset"), classData, kCFPreferencesCurrentApplication);
|
CFPreferencesSetAppValue(CFSTR("GraphEQ_Preset"), classData, kCFPreferencesCurrentApplication);
|
||||||
CFRelease(classData);
|
CFRelease(classData);
|
||||||
}
|
}
|
||||||
|
@ -668,20 +593,19 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
CFNumberRef cfnum;
|
CFNumberRef cfnum;
|
||||||
|
|
||||||
classData = CFPreferencesCopyAppValue(CFSTR("GraphEQ_Preset"), kCFPreferencesCurrentApplication);
|
classData = CFPreferencesCopyAppValue(CFSTR("GraphEQ_Preset"), kCFPreferencesCurrentApplication);
|
||||||
if (classData)
|
if(classData) {
|
||||||
{
|
dict = (CFDictionaryRef)classData;
|
||||||
dict = (CFDictionaryRef) classData;
|
|
||||||
|
|
||||||
cfnum = (CFNumberRef) (CFDictionaryGetValue(dict, CFSTR("type")));
|
cfnum = (CFNumberRef)(CFDictionaryGetValue(dict, CFSTR("type")));
|
||||||
CFNumberGetValue(cfnum, kCFNumberSInt32Type, &cd.componentType);
|
CFNumberGetValue(cfnum, kCFNumberSInt32Type, &cd.componentType);
|
||||||
cfnum = (CFNumberRef) (CFDictionaryGetValue(dict, CFSTR("subtype")));
|
cfnum = (CFNumberRef)(CFDictionaryGetValue(dict, CFSTR("subtype")));
|
||||||
CFNumberGetValue(cfnum, kCFNumberSInt32Type, &cd.componentSubType);
|
CFNumberGetValue(cfnum, kCFNumberSInt32Type, &cd.componentSubType);
|
||||||
cfnum = (CFNumberRef) (CFDictionaryGetValue(dict, CFSTR("manufacturer")));
|
cfnum = (CFNumberRef)(CFDictionaryGetValue(dict, CFSTR("manufacturer")));
|
||||||
CFNumberGetValue(cfnum, kCFNumberSInt32Type, &cd.componentManufacturer);
|
CFNumberGetValue(cfnum, kCFNumberSInt32Type, &cd.componentManufacturer);
|
||||||
|
|
||||||
if ((cd.componentType == kAudioUnitType_Effect ) &&
|
if((cd.componentType == kAudioUnitType_Effect) &&
|
||||||
(cd.componentSubType == kAudioUnitSubType_GraphicEQ) &&
|
(cd.componentSubType == kAudioUnitSubType_GraphicEQ) &&
|
||||||
(cd.componentManufacturer == kAudioUnitManufacturer_Apple ))
|
(cd.componentManufacturer == kAudioUnitManufacturer_Apple))
|
||||||
err = AudioUnitSetProperty(eq, kAudioUnitProperty_ClassInfo, kAudioUnitScope_Global, 0, &classData, sizeof(classData));
|
err = AudioUnitSetProperty(eq, kAudioUnitProperty_ClassInfo, kAudioUnitScope_Global, 0, &classData, sizeof(classData));
|
||||||
|
|
||||||
CFRelease(classData);
|
CFRelease(classData);
|
||||||
|
@ -690,81 +614,71 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
equalizerLoadPreset(eq);
|
equalizerLoadPreset(eq);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_eqWasOpen)
|
if(_eqWasOpen) {
|
||||||
{
|
NSWindow *window = appController.miniMode ? appController.miniWindow : appController.mainWindow;
|
||||||
NSWindow * window = appController.miniMode ? appController.miniWindow : appController.mainWindow;
|
|
||||||
_equi = [[AUPluginUI alloc] initWithSampler:_eq bringToFront:NO orWindowNumber:window.windowNumber];
|
_equi = [[AUPluginUI alloc] initWithSampler:_eq bringToFront:NO orWindowNumber:window.windowNumber];
|
||||||
_eqWasOpen = NO;
|
_eqWasOpen = NO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)audioPlayer:(AudioPlayer *)player refreshEqualizer:(AudioUnit)eq
|
- (void)audioPlayer:(AudioPlayer *)player refreshEqualizer:(AudioUnit)eq {
|
||||||
{
|
|
||||||
equalizerLoadPreset(eq);
|
equalizerLoadPreset(eq);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)audioPlayer:(AudioPlayer *)player removeEqualizer:(AudioUnit)eq
|
- (void)audioPlayer:(AudioPlayer *)player removeEqualizer:(AudioUnit)eq {
|
||||||
{
|
if(eq == _eq) {
|
||||||
if (eq == _eq)
|
|
||||||
{
|
|
||||||
OSStatus err;
|
OSStatus err;
|
||||||
CFPropertyListRef classData;
|
CFPropertyListRef classData;
|
||||||
UInt32 size;
|
UInt32 size;
|
||||||
|
|
||||||
size = sizeof(classData);
|
size = sizeof(classData);
|
||||||
err = AudioUnitGetProperty(eq, kAudioUnitProperty_ClassInfo, kAudioUnitScope_Global, 0, &classData, &size);
|
err = AudioUnitGetProperty(eq, kAudioUnitProperty_ClassInfo, kAudioUnitScope_Global, 0, &classData, &size);
|
||||||
if (err == noErr)
|
if(err == noErr) {
|
||||||
{
|
|
||||||
CFPreferencesSetAppValue(CFSTR("GraphEQ_Preset"), classData, kCFPreferencesCurrentApplication);
|
CFPreferencesSetAppValue(CFSTR("GraphEQ_Preset"), classData, kCFPreferencesCurrentApplication);
|
||||||
CFRelease(classData);
|
CFRelease(classData);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
|
CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
|
||||||
|
|
||||||
if (_equi)
|
if(_equi) {
|
||||||
{
|
|
||||||
_eqWasOpen = [_equi isOpen];
|
_eqWasOpen = [_equi isOpen];
|
||||||
}
|
}
|
||||||
|
|
||||||
_equi = nil;
|
_equi = nil;
|
||||||
[self eqDealloc];
|
[self eqDealloc];
|
||||||
|
|
||||||
if (_eqWasOpen)
|
if(_eqWasOpen) {
|
||||||
{
|
|
||||||
[self showEq:nil];
|
[self showEq:nil];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)audioPlayer:(AudioPlayer *)player willEndStream:(id)userInfo
|
- (void)audioPlayer:(AudioPlayer *)player willEndStream:(id)userInfo {
|
||||||
{
|
|
||||||
PlaylistEntry *curEntry = (PlaylistEntry *)userInfo;
|
PlaylistEntry *curEntry = (PlaylistEntry *)userInfo;
|
||||||
PlaylistEntry *pe;
|
PlaylistEntry *pe;
|
||||||
|
|
||||||
if (curEntry.stopAfter)
|
if(curEntry.stopAfter)
|
||||||
pe = nil;
|
pe = nil;
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
pe = [playlistController getNextEntry:curEntry];
|
pe = [playlistController getNextEntry:curEntry];
|
||||||
if (pe && [pe metadataLoaded] != YES) {
|
if(pe && [pe metadataLoaded] != YES) {
|
||||||
NSArray * entries = @[pe];
|
NSArray *entries = @[pe];
|
||||||
[playlistLoader performSelectorInBackground:@selector(loadInfoForEntries:) withObject:entries];
|
[playlistLoader performSelectorInBackground:@selector(loadInfoForEntries:) withObject:entries];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pe)
|
if(pe)
|
||||||
[player setNextStream:[pe URL] withUserInfo:pe withRGInfo:makeRGInfo(pe)];
|
[player setNextStream:[pe URL] withUserInfo:pe withRGInfo:makeRGInfo(pe)];
|
||||||
else
|
else
|
||||||
[player setNextStream:nil];
|
[player setNextStream:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)audioPlayer:(AudioPlayer *)player didBeginStream:(id)userInfo
|
- (void)audioPlayer:(AudioPlayer *)player didBeginStream:(id)userInfo {
|
||||||
{
|
|
||||||
PlaylistEntry *pe = (PlaylistEntry *)userInfo;
|
PlaylistEntry *pe = (PlaylistEntry *)userInfo;
|
||||||
|
|
||||||
[playlistController setCurrentEntry:pe];
|
[playlistController setCurrentEntry:pe];
|
||||||
|
|
||||||
if (_eq)
|
if(_eq)
|
||||||
equalizerApplyGenre(_eq, [pe genre]);
|
equalizerApplyGenre(_eq, [pe genre]);
|
||||||
|
|
||||||
lastPosition = -10;
|
lastPosition = -10;
|
||||||
|
@ -776,33 +690,26 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:CogPlaybackDidBeginNotficiation object:pe];
|
[[NSNotificationCenter defaultCenter] postNotificationName:CogPlaybackDidBeginNotficiation object:pe];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)audioPlayer:(AudioPlayer *)player didChangeStatus:(NSNumber *)s userInfo:(id)userInfo
|
- (void)audioPlayer:(AudioPlayer *)player didChangeStatus:(NSNumber *)s userInfo:(id)userInfo {
|
||||||
{
|
|
||||||
int status = [s intValue];
|
int status = [s intValue];
|
||||||
if (status == CogStatusStopped || status == CogStatusPaused)
|
if(status == CogStatusStopped || status == CogStatusPaused) {
|
||||||
{
|
|
||||||
[self removeHDCD:nil];
|
[self removeHDCD:nil];
|
||||||
if (positionTimer)
|
if(positionTimer) {
|
||||||
{
|
|
||||||
[positionTimer invalidate];
|
[positionTimer invalidate];
|
||||||
positionTimer = NULL;
|
positionTimer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == CogStatusStopped)
|
if(status == CogStatusStopped) {
|
||||||
{
|
|
||||||
[self setPosition:0];
|
[self setPosition:0];
|
||||||
[self setSeekable:NO]; // the player stopped, disable the slider
|
[self setSeekable:NO]; // the player stopped, disable the slider
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:CogPlaybackDidStopNotficiation object:nil];
|
[[NSNotificationCenter defaultCenter] postNotificationName:CogPlaybackDidStopNotficiation object:nil];
|
||||||
}
|
} else // paused
|
||||||
else // paused
|
|
||||||
{
|
{
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:CogPlaybackDidPauseNotficiation object:nil];
|
[[NSNotificationCenter defaultCenter] postNotificationName:CogPlaybackDidPauseNotficiation object:nil];
|
||||||
}
|
}
|
||||||
}
|
} else if(status == CogStatusPlaying) {
|
||||||
else if (status == CogStatusPlaying)
|
if(!positionTimer) {
|
||||||
{
|
|
||||||
if (!positionTimer) {
|
|
||||||
positionTimer = [NSTimer timerWithTimeInterval:0.2 target:self selector:@selector(updatePosition:) userInfo:nil repeats:YES];
|
positionTimer = [NSTimer timerWithTimeInterval:0.2 target:self selector:@selector(updatePosition:) userInfo:nil repeats:YES];
|
||||||
[[NSRunLoop currentRunLoop] addTimer:positionTimer forMode:NSRunLoopCommonModes];
|
[[NSRunLoop currentRunLoop] addTimer:positionTimer forMode:NSRunLoopCommonModes];
|
||||||
}
|
}
|
||||||
|
@ -810,14 +717,13 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:CogPlaybackDidResumeNotficiation object:nil];
|
[[NSNotificationCenter defaultCenter] postNotificationName:CogPlaybackDidResumeNotficiation object:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == CogStatusStopped) {
|
if(status == CogStatusStopped) {
|
||||||
[playlistController setCurrentEntry:nil];
|
[playlistController setCurrentEntry:nil];
|
||||||
[self setSeekable:NO]; // the player stopped, disable the slider
|
[self setSeekable:NO]; // the player stopped, disable the slider
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
[self setSeekable:YES];
|
[self setSeekable:YES];
|
||||||
}
|
}
|
||||||
switch (status) {
|
switch(status) {
|
||||||
case CogStatusPlaying:
|
case CogStatusPlaying:
|
||||||
DLog(@"PLAYING!");
|
DLog(@"PLAYING!");
|
||||||
break;
|
break;
|
||||||
|
@ -830,10 +736,10 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == CogStatusStopped) {
|
if(status == CogStatusStopped) {
|
||||||
status = CogStatusStopping;
|
status = CogStatusStopping;
|
||||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
||||||
if ([self playbackStatus] == CogStatusStopping)
|
if([self playbackStatus] == CogStatusStopping)
|
||||||
[self setPlaybackStatus:CogStatusStopped];
|
[self setPlaybackStatus:CogStatusStopped];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -843,32 +749,27 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
[self sendMetaData];
|
[self sendMetaData];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)audioPlayer:(AudioPlayer *)player sustainHDCD:(id)userInfo
|
- (void)audioPlayer:(AudioPlayer *)player sustainHDCD:(id)userInfo {
|
||||||
{
|
MainWindow *mainWindow = (MainWindow *)appController.mainWindow;
|
||||||
MainWindow * mainWindow = (MainWindow *) appController.mainWindow;
|
|
||||||
[mainWindow showHDCDLogo:YES];
|
[mainWindow showHDCDLogo:YES];
|
||||||
MiniWindow * miniWindow = (MiniWindow *) appController.miniWindow;
|
MiniWindow *miniWindow = (MiniWindow *)appController.miniWindow;
|
||||||
[miniWindow showHDCDLogo:YES];
|
[miniWindow showHDCDLogo:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeHDCD:(id)sender
|
- (void)removeHDCD:(id)sender {
|
||||||
{
|
MainWindow *mainWindow = (MainWindow *)appController.mainWindow;
|
||||||
MainWindow * mainWindow = (MainWindow *) appController.mainWindow;
|
|
||||||
[mainWindow showHDCDLogo:NO];
|
[mainWindow showHDCDLogo:NO];
|
||||||
MiniWindow * miniWindow = (MiniWindow *) appController.miniWindow;
|
MiniWindow *miniWindow = (MiniWindow *)appController.miniWindow;
|
||||||
[miniWindow showHDCDLogo:NO];
|
[miniWindow showHDCDLogo:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)playlistDidChange:(PlaylistController *)p
|
- (void)playlistDidChange:(PlaylistController *)p {
|
||||||
{
|
|
||||||
[audioPlayer resetNextStreams];
|
[audioPlayer resetNextStreams];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setPosition:(double)p
|
- (void)setPosition:(double)p {
|
||||||
{
|
if(p > lastPosition && (p - lastPosition) >= 10.0) {
|
||||||
if (p > lastPosition && (p - lastPosition) >= 10.0)
|
PlaylistEntry *pe = [playlistController currentEntry];
|
||||||
{
|
|
||||||
PlaylistEntry * pe = [playlistController currentEntry];
|
|
||||||
NSInteger lastTrackPlaying = [pe index];
|
NSInteger lastTrackPlaying = [pe index];
|
||||||
|
|
||||||
[[NSUserDefaults standardUserDefaults] setInteger:CogStatusPlaying forKey:@"lastPlaybackStatus"];
|
[[NSUserDefaults standardUserDefaults] setInteger:CogStatusPlaying forKey:@"lastPlaybackStatus"];
|
||||||
|
@ -886,39 +787,37 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
[[playlistController currentEntry] setCurrentPosition:p];
|
[[playlistController currentEntry] setCurrentPosition:p];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (double)position
|
- (double)position {
|
||||||
{
|
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setSeekable:(BOOL)s
|
- (void)setSeekable:(BOOL)s {
|
||||||
{
|
|
||||||
seekable = s;
|
seekable = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)seekable
|
- (BOOL)seekable {
|
||||||
{
|
|
||||||
return seekable && [[playlistController currentEntry] seekable];
|
return seekable && [[playlistController currentEntry] seekable];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sendMetaData {
|
- (void)sendMetaData {
|
||||||
MPNowPlayingInfoCenter * defaultCenter = [MPNowPlayingInfoCenter defaultCenter];
|
MPNowPlayingInfoCenter *defaultCenter = [MPNowPlayingInfoCenter defaultCenter];
|
||||||
|
|
||||||
PlaylistEntry * entry = [playlistController currentEntry];
|
PlaylistEntry *entry = [playlistController currentEntry];
|
||||||
NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
|
||||||
|
|
||||||
if (entry) {
|
if(entry) {
|
||||||
if ([entry title])
|
if([entry title])
|
||||||
[songInfo setObject:[entry title] forKey:MPMediaItemPropertyTitle];
|
[songInfo setObject:[entry title] forKey:MPMediaItemPropertyTitle];
|
||||||
if ([entry artist])
|
if([entry artist])
|
||||||
[songInfo setObject:[entry artist] forKey:MPMediaItemPropertyArtist];
|
[songInfo setObject:[entry artist] forKey:MPMediaItemPropertyArtist];
|
||||||
if ([entry album])
|
if([entry album])
|
||||||
[songInfo setObject:[entry album] forKey:MPMediaItemPropertyAlbumTitle];
|
[songInfo setObject:[entry album] forKey:MPMediaItemPropertyAlbumTitle];
|
||||||
if ([entry albumArt]) {
|
if([entry albumArt]) {
|
||||||
// can't do && with @available
|
// can't do && with @available
|
||||||
if (@available(macOS 10.13.2, *)) {
|
if(@available(macOS 10.13.2, *)) {
|
||||||
CGSize artworkSize = CGSizeMake(500, 500);
|
CGSize artworkSize = CGSizeMake(500, 500);
|
||||||
MPMediaItemArtwork *mpArtwork = [[MPMediaItemArtwork alloc] initWithBoundsSize:artworkSize requestHandler:^NSImage * _Nonnull(CGSize size) {
|
MPMediaItemArtwork *mpArtwork = [[MPMediaItemArtwork alloc] initWithBoundsSize:artworkSize
|
||||||
|
requestHandler:^NSImage *_Nonnull(CGSize size) {
|
||||||
return [entry albumArt];
|
return [entry albumArt];
|
||||||
}];
|
}];
|
||||||
[songInfo setObject:mpArtwork forKey:MPMediaItemPropertyArtwork];
|
[songInfo setObject:mpArtwork forKey:MPMediaItemPropertyArtwork];
|
||||||
|
@ -926,9 +825,9 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
}
|
}
|
||||||
// I don't know what NPIC does with these since they aren't exposed in UI, but if we have them, use it.
|
// I don't know what NPIC does with these since they aren't exposed in UI, but if we have them, use it.
|
||||||
// There's a bunch of other metadata, but PlaylistEntry can't represent a lot of it.
|
// There's a bunch of other metadata, but PlaylistEntry can't represent a lot of it.
|
||||||
if ([entry genre])
|
if([entry genre])
|
||||||
[songInfo setObject:[entry genre] forKey:MPMediaItemPropertyGenre];
|
[songInfo setObject:[entry genre] forKey:MPMediaItemPropertyGenre];
|
||||||
if ([entry year]) {
|
if([entry year]) {
|
||||||
// If PlaylistEntry can represent a full date like some tag formats can do, change it
|
// If PlaylistEntry can represent a full date like some tag formats can do, change it
|
||||||
NSCalendar *calendar = [NSCalendar currentCalendar];
|
NSCalendar *calendar = [NSCalendar currentCalendar];
|
||||||
NSDate *releaseYear = [calendar dateWithEra:1 year:[[entry year] intValue] month:0 day:0 hour:0 minute:0 second:0 nanosecond:0];
|
NSDate *releaseYear = [calendar dateWithEra:1 year:[[entry year] intValue] month:0 day:0 hour:0 minute:0 second:0 nanosecond:0];
|
||||||
|
@ -939,7 +838,7 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
[songInfo setObject:[NSNumber numberWithFloat:[entry index]] forKey:MPMediaItemPropertyPersistentID];
|
[songInfo setObject:[NSNumber numberWithFloat:[entry index]] forKey:MPMediaItemPropertyPersistentID];
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (playbackStatus) {
|
switch(playbackStatus) {
|
||||||
case CogStatusPlaying:
|
case CogStatusPlaying:
|
||||||
defaultCenter.playbackState = MPNowPlayingPlaybackStatePlaying;
|
defaultCenter.playbackState = MPNowPlayingPlaybackStatePlaying;
|
||||||
break;
|
break;
|
||||||
|
@ -955,7 +854,4 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
|
||||||
[defaultCenter setNowPlayingInfo:songInfo];
|
[defaultCenter setNowPlayingInfo:songInfo];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
@class AudioScrobbler;
|
@class AudioScrobbler;
|
||||||
|
|
||||||
@interface PlaybackEventController
|
@interface PlaybackEventController
|
||||||
: NSObject <NSUserNotificationCenterDelegate, UNUserNotificationCenterDelegate> {
|
: NSObject <NSUserNotificationCenterDelegate, UNUserNotificationCenterDelegate> {
|
||||||
IBOutlet PlaybackController *playbackController;
|
IBOutlet PlaybackController *playbackController;
|
||||||
|
|
||||||
IBOutlet NSWindow *mainWindow;
|
IBOutlet NSWindow *mainWindow;
|
||||||
|
|
|
@ -20,7 +20,9 @@ NSString *TrackLength = @"Total Time";
|
||||||
NSString *TrackPath = @"Location";
|
NSString *TrackPath = @"Location";
|
||||||
NSString *TrackState = @"Player State";
|
NSString *TrackState = @"Player State";
|
||||||
|
|
||||||
typedef NS_ENUM(NSInteger, TrackStatus) { TrackPlaying, TrackPaused, TrackStopped };
|
typedef NS_ENUM(NSInteger, TrackStatus) { TrackPlaying,
|
||||||
|
TrackPaused,
|
||||||
|
TrackStopped };
|
||||||
|
|
||||||
@implementation PlaybackEventController {
|
@implementation PlaybackEventController {
|
||||||
AudioScrobbler *scrobbler;
|
AudioScrobbler *scrobbler;
|
||||||
|
@ -34,11 +36,11 @@ typedef NS_ENUM(NSInteger, TrackStatus) { TrackPlaying, TrackPaused, TrackStoppe
|
||||||
|
|
||||||
- (void)initDefaults {
|
- (void)initDefaults {
|
||||||
NSDictionary *defaultsDictionary = @{
|
NSDictionary *defaultsDictionary = @{
|
||||||
@"enableAudioScrobbler" : @YES,
|
@"enableAudioScrobbler": @YES,
|
||||||
@"automaticallyLaunchLastFM" : @NO,
|
@"automaticallyLaunchLastFM": @NO,
|
||||||
@"notifications.enable" : @YES,
|
@"notifications.enable": @YES,
|
||||||
@"notifications.itunes-style" : @YES,
|
@"notifications.itunes-style": @YES,
|
||||||
@"notifications.show-album-art" : @YES
|
@"notifications.show-album-art": @YES
|
||||||
};
|
};
|
||||||
|
|
||||||
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsDictionary];
|
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsDictionary];
|
||||||
|
@ -46,19 +48,19 @@ typedef NS_ENUM(NSInteger, TrackStatus) { TrackPlaying, TrackPaused, TrackStoppe
|
||||||
|
|
||||||
- (id)init {
|
- (id)init {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if(self) {
|
||||||
[self initDefaults];
|
[self initDefaults];
|
||||||
|
|
||||||
didGainUN = NO;
|
didGainUN = NO;
|
||||||
|
|
||||||
if (@available(macOS 10.14, *)) {
|
if(@available(macOS 10.14, *)) {
|
||||||
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
||||||
[center
|
[center
|
||||||
requestAuthorizationWithOptions:UNAuthorizationOptionAlert
|
requestAuthorizationWithOptions:UNAuthorizationOptionAlert
|
||||||
completionHandler:^(BOOL granted, NSError *_Nullable error) {
|
completionHandler:^(BOOL granted, NSError *_Nullable error) {
|
||||||
self->didGainUN = granted;
|
self->didGainUN = granted;
|
||||||
|
|
||||||
if (granted) {
|
if(granted) {
|
||||||
UNNotificationAction *skipAction = [UNNotificationAction
|
UNNotificationAction *skipAction = [UNNotificationAction
|
||||||
actionWithIdentifier:@"skip"
|
actionWithIdentifier:@"skip"
|
||||||
title:@"Skip"
|
title:@"Skip"
|
||||||
|
@ -66,7 +68,7 @@ typedef NS_ENUM(NSInteger, TrackStatus) { TrackPlaying, TrackPaused, TrackStoppe
|
||||||
|
|
||||||
UNNotificationCategory *playCategory = [UNNotificationCategory
|
UNNotificationCategory *playCategory = [UNNotificationCategory
|
||||||
categoryWithIdentifier:@"play"
|
categoryWithIdentifier:@"play"
|
||||||
actions:@[ skipAction ]
|
actions:@[skipAction]
|
||||||
intentIdentifiers:@[]
|
intentIdentifiers:@[]
|
||||||
options:UNNotificationCategoryOptionNone];
|
options:UNNotificationCategoryOptionNone];
|
||||||
|
|
||||||
|
@ -94,38 +96,38 @@ typedef NS_ENUM(NSInteger, TrackStatus) { TrackPlaying, TrackPaused, TrackStoppe
|
||||||
willPresentNotification:(UNNotification *)notification
|
willPresentNotification:(UNNotification *)notification
|
||||||
withCompletionHandler:
|
withCompletionHandler:
|
||||||
(void (^)(UNNotificationPresentationOptions options))completionHandler
|
(void (^)(UNNotificationPresentationOptions options))completionHandler
|
||||||
API_AVAILABLE(macos(10.14)) {
|
API_AVAILABLE(macos(10.14)) {
|
||||||
UNNotificationPresentationOptions presentationOptions = UNNotificationPresentationOptionAlert;
|
UNNotificationPresentationOptions presentationOptions = UNNotificationPresentationOptionAlert;
|
||||||
|
|
||||||
completionHandler(presentationOptions);
|
completionHandler(presentationOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
||||||
didReceiveNotificationResponse:(UNNotificationResponse *)response
|
didReceiveNotificationResponse:(UNNotificationResponse *)response
|
||||||
withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(macos(10.14)) {
|
withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(macos(10.14)) {
|
||||||
if ([[response actionIdentifier] isEqualToString:@"skip"]) {
|
if([[response actionIdentifier] isEqualToString:@"skip"]) {
|
||||||
[playbackController next:self];
|
[playbackController next:self];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDictionary *)fillNotificationDictionary:(PlaylistEntry *)pe status:(TrackStatus)status {
|
- (NSDictionary *)fillNotificationDictionary:(PlaylistEntry *)pe status:(TrackStatus)status {
|
||||||
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
|
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
|
||||||
if (pe == nil) return dict;
|
if(pe == nil) return dict;
|
||||||
|
|
||||||
[dict setObject:[[pe URL] absoluteString] forKey:TrackPath];
|
[dict setObject:[[pe URL] absoluteString] forKey:TrackPath];
|
||||||
if ([pe title]) [dict setObject:[pe title] forKey:TrackTitle];
|
if([pe title]) [dict setObject:[pe title] forKey:TrackTitle];
|
||||||
if ([pe artist]) [dict setObject:[pe artist] forKey:TrackArtist];
|
if([pe artist]) [dict setObject:[pe artist] forKey:TrackArtist];
|
||||||
if ([pe album]) [dict setObject:[pe album] forKey:TrackAlbum];
|
if([pe album]) [dict setObject:[pe album] forKey:TrackAlbum];
|
||||||
if ([pe genre]) [dict setObject:[pe genre] forKey:TrackGenre];
|
if([pe genre]) [dict setObject:[pe genre] forKey:TrackGenre];
|
||||||
if ([pe track])
|
if([pe track])
|
||||||
[dict setObject:[pe trackText] forKey:TrackNumber];
|
[dict setObject:[pe trackText] forKey:TrackNumber];
|
||||||
if ([pe length])
|
if([pe length])
|
||||||
[dict setObject:[NSNumber numberWithInteger:(NSInteger)([[pe length] doubleValue] * 1000.0)]
|
[dict setObject:[NSNumber numberWithInteger:(NSInteger)([[pe length] doubleValue] * 1000.0)]
|
||||||
forKey:TrackLength];
|
forKey:TrackLength];
|
||||||
|
|
||||||
NSString *state = nil;
|
NSString *state = nil;
|
||||||
|
|
||||||
switch (status) {
|
switch(status) {
|
||||||
case TrackPlaying:
|
case TrackPlaying:
|
||||||
state = @"Playing";
|
state = @"Playing";
|
||||||
break;
|
break;
|
||||||
|
@ -145,7 +147,7 @@ typedef NS_ENUM(NSInteger, TrackStatus) { TrackPlaying, TrackPaused, TrackStoppe
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)performPlaybackDidBeginActions:(PlaylistEntry *)pe {
|
- (void)performPlaybackDidBeginActions:(PlaylistEntry *)pe {
|
||||||
if (NO == [pe error]) {
|
if(NO == [pe error]) {
|
||||||
entry = pe;
|
entry = pe;
|
||||||
|
|
||||||
[[NSDistributedNotificationCenter defaultCenter]
|
[[NSDistributedNotificationCenter defaultCenter]
|
||||||
|
@ -156,14 +158,14 @@ typedef NS_ENUM(NSInteger, TrackStatus) { TrackPlaying, TrackPaused, TrackStoppe
|
||||||
|
|
||||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||||
|
|
||||||
if ([defaults boolForKey:@"notifications.enable"]) {
|
if([defaults boolForKey:@"notifications.enable"]) {
|
||||||
if ([defaults boolForKey:@"enableAudioScrobbler"]) {
|
if([defaults boolForKey:@"enableAudioScrobbler"]) {
|
||||||
[scrobbler start:pe];
|
[scrobbler start:pe];
|
||||||
if ([AudioScrobbler isRunning]) return;
|
if([AudioScrobbler isRunning]) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (@available(macOS 10.14, *)) {
|
if(@available(macOS 10.14, *)) {
|
||||||
if (didGainUN) {
|
if(didGainUN) {
|
||||||
UNUserNotificationCenter *center =
|
UNUserNotificationCenter *center =
|
||||||
[UNUserNotificationCenter currentNotificationCenter];
|
[UNUserNotificationCenter currentNotificationCenter];
|
||||||
|
|
||||||
|
@ -173,11 +175,11 @@ typedef NS_ENUM(NSInteger, TrackStatus) { TrackPlaying, TrackPaused, TrackStoppe
|
||||||
content.title = @"Now Playing";
|
content.title = @"Now Playing";
|
||||||
|
|
||||||
NSString *subtitle;
|
NSString *subtitle;
|
||||||
if ([pe artist] && [pe album]) {
|
if([pe artist] && [pe album]) {
|
||||||
subtitle = [NSString stringWithFormat:@"%@ - %@", [pe artist], [pe album]];
|
subtitle = [NSString stringWithFormat:@"%@ - %@", [pe artist], [pe album]];
|
||||||
} else if ([pe artist]) {
|
} else if([pe artist]) {
|
||||||
subtitle = [pe artist];
|
subtitle = [pe artist];
|
||||||
} else if ([pe album]) {
|
} else if([pe album]) {
|
||||||
subtitle = [pe album];
|
subtitle = [pe album];
|
||||||
} else {
|
} else {
|
||||||
subtitle = @"";
|
subtitle = @"";
|
||||||
|
@ -188,14 +190,14 @@ typedef NS_ENUM(NSInteger, TrackStatus) { TrackPlaying, TrackPaused, TrackStoppe
|
||||||
content.sound = nil;
|
content.sound = nil;
|
||||||
content.categoryIdentifier = @"play";
|
content.categoryIdentifier = @"play";
|
||||||
|
|
||||||
if ([defaults boolForKey:@"notifications.show-album-art"] &&
|
if([defaults boolForKey:@"notifications.show-album-art"] &&
|
||||||
[pe albumArt]) {
|
[pe albumArt]) {
|
||||||
NSError *error = nil;
|
NSError *error = nil;
|
||||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||||
NSURL *tmpSubFolderURL = [[NSURL fileURLWithPath:NSTemporaryDirectory()]
|
NSURL *tmpSubFolderURL = [[NSURL fileURLWithPath:NSTemporaryDirectory()]
|
||||||
URLByAppendingPathComponent:@"cog-artworks-cache"
|
URLByAppendingPathComponent:@"cog-artworks-cache"
|
||||||
isDirectory:true];
|
isDirectory:true];
|
||||||
if ([fileManager createDirectoryAtPath:[tmpSubFolderURL path]
|
if([fileManager createDirectoryAtPath:[tmpSubFolderURL path]
|
||||||
withIntermediateDirectories:true
|
withIntermediateDirectories:true
|
||||||
attributes:nil
|
attributes:nil
|
||||||
error:&error]) {
|
error:&error]) {
|
||||||
|
@ -209,12 +211,12 @@ typedef NS_ENUM(NSInteger, TrackStatus) { TrackPlaying, TrackPaused, TrackStoppe
|
||||||
context:nil
|
context:nil
|
||||||
hints:nil];
|
hints:nil];
|
||||||
|
|
||||||
if (cgRef) {
|
if(cgRef) {
|
||||||
NSBitmapImageRep *newRep =
|
NSBitmapImageRep *newRep =
|
||||||
[[NSBitmapImageRep alloc] initWithCGImage:cgRef];
|
[[NSBitmapImageRep alloc] initWithCGImage:cgRef];
|
||||||
NSData *jpgData = [newRep
|
NSData *jpgData = [newRep
|
||||||
representationUsingType:NSBitmapImageFileTypeJPEG
|
representationUsingType:NSBitmapImageFileTypeJPEG
|
||||||
properties:@{NSImageCompressionFactor : @0.5f}];
|
properties:@{ NSImageCompressionFactor: @0.5f }];
|
||||||
[jpgData writeToURL:fileURL atomically:YES];
|
[jpgData writeToURL:fileURL atomically:YES];
|
||||||
|
|
||||||
UNNotificationAttachment *icon =
|
UNNotificationAttachment *icon =
|
||||||
|
@ -222,11 +224,11 @@ typedef NS_ENUM(NSInteger, TrackStatus) { TrackPlaying, TrackPaused, TrackStoppe
|
||||||
URL:fileURL
|
URL:fileURL
|
||||||
options:nil
|
options:nil
|
||||||
error:&error];
|
error:&error];
|
||||||
if (error) {
|
if(error) {
|
||||||
// We have size limit of 10MB per image attachment.
|
// We have size limit of 10MB per image attachment.
|
||||||
NSLog(@"%@", error.localizedDescription);
|
NSLog(@"%@", error.localizedDescription);
|
||||||
} else {
|
} else {
|
||||||
content.attachments = @[ icon ];
|
content.attachments = @[icon];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,29 +249,29 @@ typedef NS_ENUM(NSInteger, TrackStatus) { TrackPlaying, TrackPaused, TrackStoppe
|
||||||
notif.title = [pe title];
|
notif.title = [pe title];
|
||||||
|
|
||||||
NSString *subtitle;
|
NSString *subtitle;
|
||||||
if ([pe artist] && [pe album]) {
|
if([pe artist] && [pe album]) {
|
||||||
subtitle = [NSString stringWithFormat:@"%@ - %@", [pe artist], [pe album]];
|
subtitle = [NSString stringWithFormat:@"%@ - %@", [pe artist], [pe album]];
|
||||||
} else if ([pe artist]) {
|
} else if([pe artist]) {
|
||||||
subtitle = [pe artist];
|
subtitle = [pe artist];
|
||||||
} else if ([pe album]) {
|
} else if([pe album]) {
|
||||||
subtitle = [pe album];
|
subtitle = [pe album];
|
||||||
} else {
|
} else {
|
||||||
subtitle = @"";
|
subtitle = @"";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([defaults boolForKey:@"notifications.itunes-style"]) {
|
if([defaults boolForKey:@"notifications.itunes-style"]) {
|
||||||
notif.subtitle = subtitle;
|
notif.subtitle = subtitle;
|
||||||
[notif setValue:@YES forKey:@"_showsButtons"];
|
[notif setValue:@YES forKey:@"_showsButtons"];
|
||||||
} else {
|
} else {
|
||||||
notif.informativeText = subtitle;
|
notif.informativeText = subtitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([notif respondsToSelector:@selector(setContentImage:)]) {
|
if([notif respondsToSelector:@selector(setContentImage:)]) {
|
||||||
if ([defaults boolForKey:@"notifications.show-album-art"] &&
|
if([defaults boolForKey:@"notifications.show-album-art"] &&
|
||||||
[pe albumArtInternal]) {
|
[pe albumArtInternal]) {
|
||||||
NSImage *image = [pe albumArt];
|
NSImage *image = [pe albumArt];
|
||||||
|
|
||||||
if ([defaults boolForKey:@"notifications.itunes-style"]) {
|
if([defaults boolForKey:@"notifications.itunes-style"]) {
|
||||||
[notif setValue:image forKey:@"_identityImage"];
|
[notif setValue:image forKey:@"_identityImage"];
|
||||||
} else {
|
} else {
|
||||||
notif.contentImage = image;
|
notif.contentImage = image;
|
||||||
|
@ -292,7 +294,7 @@ typedef NS_ENUM(NSInteger, TrackStatus) { TrackPlaying, TrackPaused, TrackStoppe
|
||||||
object:nil
|
object:nil
|
||||||
userInfo:[self fillNotificationDictionary:entry status:TrackPaused]
|
userInfo:[self fillNotificationDictionary:entry status:TrackPaused]
|
||||||
deliverImmediately:YES];
|
deliverImmediately:YES];
|
||||||
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
||||||
[scrobbler pause];
|
[scrobbler pause];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -303,7 +305,7 @@ typedef NS_ENUM(NSInteger, TrackStatus) { TrackPlaying, TrackPaused, TrackStoppe
|
||||||
object:nil
|
object:nil
|
||||||
userInfo:[self fillNotificationDictionary:entry status:TrackPlaying]
|
userInfo:[self fillNotificationDictionary:entry status:TrackPlaying]
|
||||||
deliverImmediately:YES];
|
deliverImmediately:YES];
|
||||||
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
||||||
[scrobbler resume];
|
[scrobbler resume];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -315,7 +317,7 @@ typedef NS_ENUM(NSInteger, TrackStatus) { TrackPlaying, TrackPaused, TrackStoppe
|
||||||
userInfo:[self fillNotificationDictionary:entry status:TrackStopped]
|
userInfo:[self fillNotificationDictionary:entry status:TrackStopped]
|
||||||
deliverImmediately:YES];
|
deliverImmediately:YES];
|
||||||
entry = nil;
|
entry = nil;
|
||||||
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
||||||
[scrobbler stop];
|
[scrobbler stop];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -369,15 +371,13 @@ typedef NS_ENUM(NSInteger, TrackStatus) { TrackPlaying, TrackPaused, TrackStoppe
|
||||||
|
|
||||||
- (void)userNotificationCenter:(NSUserNotificationCenter *)center
|
- (void)userNotificationCenter:(NSUserNotificationCenter *)center
|
||||||
didActivateNotification:(NSUserNotification *)notification {
|
didActivateNotification:(NSUserNotification *)notification {
|
||||||
switch (notification.activationType) {
|
switch(notification.activationType) {
|
||||||
case NSUserNotificationActivationTypeActionButtonClicked:
|
case NSUserNotificationActivationTypeActionButtonClicked:
|
||||||
[playbackController next:self];
|
[playbackController next:self];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NSUserNotificationActivationTypeContentsClicked: {
|
case NSUserNotificationActivationTypeContentsClicked: {
|
||||||
NSWindow *window = [[NSUserDefaults standardUserDefaults] boolForKey:@"miniMode"]
|
NSWindow *window = [[NSUserDefaults standardUserDefaults] boolForKey:@"miniMode"] ? miniWindow : mainWindow;
|
||||||
? miniWindow
|
|
||||||
: mainWindow;
|
|
||||||
|
|
||||||
[NSApp activateIgnoringOtherApps:YES];
|
[NSApp activateIgnoringOtherApps:YES];
|
||||||
[window makeKeyAndOrderFront:self];
|
[window makeKeyAndOrderFront:self];
|
||||||
|
|
|
@ -10,9 +10,8 @@
|
||||||
#import <CogAudio/Plugin.h>
|
#import <CogAudio/Plugin.h>
|
||||||
|
|
||||||
@interface AudioContainer : NSObject {
|
@interface AudioContainer : NSObject {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSArray *) urlsForContainerURL:(NSURL *)url;
|
+ (NSArray *)urlsForContainerURL:(NSURL *)url;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -12,8 +12,7 @@
|
||||||
|
|
||||||
@implementation AudioContainer
|
@implementation AudioContainer
|
||||||
|
|
||||||
+ (NSArray *) urlsForContainerURL:(NSURL *)url
|
+ (NSArray *)urlsForContainerURL:(NSURL *)url {
|
||||||
{
|
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
return [[PluginController sharedPluginController] urlsForContainerURL:url];
|
return [[PluginController sharedPluginController] urlsForContainerURL:url];
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
@interface AudioDecoder : NSObject {
|
@interface AudioDecoder : NSObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (id<CogDecoder>)audioDecoderForSource:(id <CogSource>)source;
|
+ (id<CogDecoder>)audioDecoderForSource:(id<CogSource>)source;
|
||||||
+ (id<CogDecoder>)audioDecoderForSource:(id <CogSource>)source skipCue:(BOOL)skip;
|
+ (id<CogDecoder>)audioDecoderForSource:(id<CogSource>)source skipCue:(BOOL)skip;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -12,13 +12,11 @@
|
||||||
|
|
||||||
@implementation AudioDecoder
|
@implementation AudioDecoder
|
||||||
|
|
||||||
+ (id<CogDecoder>) audioDecoderForSource:(id <CogSource>)source
|
+ (id<CogDecoder>)audioDecoderForSource:(id<CogSource>)source {
|
||||||
{
|
|
||||||
return [[PluginController sharedPluginController] audioDecoderForSource:source skipCue:NO];
|
return [[PluginController sharedPluginController] audioDecoderForSource:source skipCue:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (id<CogDecoder>) audioDecoderForSource:(id <CogSource>)source skipCue:(BOOL)skip
|
+ (id<CogDecoder>)audioDecoderForSource:(id<CogSource>)source skipCue:(BOOL)skip {
|
||||||
{
|
|
||||||
return [[PluginController sharedPluginController] audioDecoderForSource:source skipCue:skip];
|
return [[PluginController sharedPluginController] audioDecoderForSource:source skipCue:skip];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,7 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
|
||||||
@interface AudioMetadataReader : NSObject {
|
@interface AudioMetadataReader : NSObject {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSDictionary *)metadataForURL:(NSURL *)url;
|
+ (NSDictionary *)metadataForURL:(NSURL *)url;
|
||||||
|
|
|
@ -11,15 +11,13 @@
|
||||||
|
|
||||||
@implementation AudioMetadataReader
|
@implementation AudioMetadataReader
|
||||||
|
|
||||||
+ (NSDictionary *)metadataForURL:(NSURL *)url
|
+ (NSDictionary *)metadataForURL:(NSURL *)url {
|
||||||
{
|
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
return [[PluginController sharedPluginController] metadataForURL:url skipCue:NO];
|
return [[PluginController sharedPluginController] metadataForURL:url skipCue:NO];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSDictionary *)metadataForURL:(NSURL *)url skipCue:(BOOL)skip
|
+ (NSDictionary *)metadataForURL:(NSURL *)url skipCue:(BOOL)skip {
|
||||||
{
|
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
return [[PluginController sharedPluginController] metadataForURL:url skipCue:skip];
|
return [[PluginController sharedPluginController] metadataForURL:url skipCue:skip];
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,7 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
|
||||||
@interface AudioMetadataWriter : NSObject {
|
@interface AudioMetadataWriter : NSObject {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (int)putMetadataInURL:(NSURL *)url;
|
+ (int)putMetadataInURL:(NSURL *)url;
|
||||||
|
|
|
@ -10,8 +10,7 @@
|
||||||
#import "PluginController.h"
|
#import "PluginController.h"
|
||||||
|
|
||||||
@implementation AudioMetadataWriter
|
@implementation AudioMetadataWriter
|
||||||
+ (int)putMetadataInURL:(NSURL *)url
|
+ (int)putMetadataInURL:(NSURL *)url {
|
||||||
{
|
|
||||||
return [[PluginController sharedPluginController] putMetadataInURL:url];
|
return [[PluginController sharedPluginController] putMetadataInURL:url];
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -10,10 +10,10 @@
|
||||||
|
|
||||||
#import <CogAudio/Semaphore.h>
|
#import <CogAudio/Semaphore.h>
|
||||||
|
|
||||||
#import <CoreAudio/CoreAudio.h>
|
#import <AVFoundation/AVFoundation.h>
|
||||||
#import <AudioToolbox/AudioToolbox.h>
|
#import <AudioToolbox/AudioToolbox.h>
|
||||||
#import <AudioUnit/AudioUnit.h>
|
#import <AudioUnit/AudioUnit.h>
|
||||||
#import <AVFoundation/AVFoundation.h>
|
#import <CoreAudio/CoreAudio.h>
|
||||||
#import <CoreAudio/CoreAudioTypes.h>
|
#import <CoreAudio/CoreAudioTypes.h>
|
||||||
|
|
||||||
#import <stdatomic.h>
|
#import <stdatomic.h>
|
||||||
|
@ -21,8 +21,7 @@
|
||||||
@class BufferChain;
|
@class BufferChain;
|
||||||
@class OutputNode;
|
@class OutputNode;
|
||||||
|
|
||||||
@interface AudioPlayer : NSObject
|
@interface AudioPlayer : NSObject {
|
||||||
{
|
|
||||||
BufferChain *bufferChain;
|
BufferChain *bufferChain;
|
||||||
OutputNode *output;
|
OutputNode *output;
|
||||||
|
|
||||||
|
@ -57,9 +56,9 @@
|
||||||
- (id)delegate;
|
- (id)delegate;
|
||||||
|
|
||||||
- (void)play:(NSURL *)url;
|
- (void)play:(NSURL *)url;
|
||||||
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary*)rgi;
|
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi;
|
||||||
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary*)rgi startPaused:(BOOL)paused;
|
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi startPaused:(BOOL)paused;
|
||||||
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary*)rgi startPaused:(BOOL)paused andSeekTo:(double)time;
|
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi startPaused:(BOOL)paused andSeekTo:(double)time;
|
||||||
|
|
||||||
- (void)stop;
|
- (void)stop;
|
||||||
- (void)pause;
|
- (void)pause;
|
||||||
|
@ -74,7 +73,7 @@
|
||||||
- (double)amountPlayed;
|
- (double)amountPlayed;
|
||||||
|
|
||||||
- (void)setNextStream:(NSURL *)url;
|
- (void)setNextStream:(NSURL *)url;
|
||||||
- (void)setNextStream:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary*)rgi;
|
- (void)setNextStream:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi;
|
||||||
- (void)resetNextStreams;
|
- (void)resetNextStreams;
|
||||||
|
|
||||||
+ (NSArray *)fileTypes;
|
+ (NSArray *)fileTypes;
|
||||||
|
@ -83,10 +82,10 @@
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface AudioPlayer (Private) //Dont use this stuff!
|
@interface AudioPlayer (Private) // Dont use this stuff!
|
||||||
|
|
||||||
- (OutputNode *) output;
|
- (OutputNode *)output;
|
||||||
- (BufferChain *) bufferChain;
|
- (BufferChain *)bufferChain;
|
||||||
- (id)initWithDelegate:(id)d;
|
- (id)initWithDelegate:(id)d;
|
||||||
|
|
||||||
- (void)setPlaybackStatus:(int)status waitUntilDone:(BOOL)wait;
|
- (void)setPlaybackStatus:(int)status waitUntilDone:(BOOL)wait;
|
||||||
|
@ -107,7 +106,7 @@
|
||||||
//- (BufferChain *)bufferChain;
|
//- (BufferChain *)bufferChain;
|
||||||
- (void)launchOutputThread;
|
- (void)launchOutputThread;
|
||||||
- (void)endOfInputPlayed;
|
- (void)endOfInputPlayed;
|
||||||
- (void)sendDelegateMethod:(SEL)selector withVoid:(void*)obj waitUntilDone:(BOOL)wait;
|
- (void)sendDelegateMethod:(SEL)selector withVoid:(void *)obj waitUntilDone:(BOOL)wait;
|
||||||
- (void)sendDelegateMethod:(SEL)selector withObject:(id)obj waitUntilDone:(BOOL)wait;
|
- (void)sendDelegateMethod:(SEL)selector withObject:(id)obj waitUntilDone:(BOOL)wait;
|
||||||
- (void)sendDelegateMethod:(SEL)selector withObject:(id)obj withObject:(id)obj2 waitUntilDone:(BOOL)wait;
|
- (void)sendDelegateMethod:(SEL)selector withObject:(id)obj withObject:(id)obj2 waitUntilDone:(BOOL)wait;
|
||||||
|
|
||||||
|
@ -115,7 +114,7 @@
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@protocol AudioPlayerDelegate
|
@protocol AudioPlayerDelegate
|
||||||
- (void)audioPlayer:(AudioPlayer *)player willEndStream:(id)userInfo; //You must use setNextStream in this method
|
- (void)audioPlayer:(AudioPlayer *)player willEndStream:(id)userInfo; // You must use setNextStream in this method
|
||||||
- (void)audioPlayer:(AudioPlayer *)player didBeginStream:(id)userInfo;
|
- (void)audioPlayer:(AudioPlayer *)player didBeginStream:(id)userInfo;
|
||||||
- (void)audioPlayer:(AudioPlayer *)player didChangeStatus:(id)status userInfo:(id)userInfo;
|
- (void)audioPlayer:(AudioPlayer *)player didChangeStatus:(id)status userInfo:(id)userInfo;
|
||||||
- (void)audioPlayer:(AudioPlayer *)player displayEqualizer:(AudioUnit)eq;
|
- (void)audioPlayer:(AudioPlayer *)player displayEqualizer:(AudioUnit)eq;
|
||||||
|
@ -124,4 +123,3 @@
|
||||||
- (void)audioPlayer:(AudioPlayer *)player sustainHDCD:(id)userInfo;
|
- (void)audioPlayer:(AudioPlayer *)player sustainHDCD:(id)userInfo;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -8,21 +8,18 @@
|
||||||
|
|
||||||
#import "AudioPlayer.h"
|
#import "AudioPlayer.h"
|
||||||
#import "BufferChain.h"
|
#import "BufferChain.h"
|
||||||
#import "OutputNode.h"
|
|
||||||
#import "Status.h"
|
|
||||||
#import "Helper.h"
|
#import "Helper.h"
|
||||||
|
#import "OutputNode.h"
|
||||||
#import "PluginController.h"
|
#import "PluginController.h"
|
||||||
|
#import "Status.h"
|
||||||
|
|
||||||
#import "Logging.h"
|
#import "Logging.h"
|
||||||
|
|
||||||
@implementation AudioPlayer
|
@implementation AudioPlayer
|
||||||
|
|
||||||
- (id)init
|
- (id)init {
|
||||||
{
|
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self)
|
if(self) {
|
||||||
{
|
|
||||||
output = NULL;
|
output = NULL;
|
||||||
bufferChain = nil;
|
bufferChain = nil;
|
||||||
outputLaunched = NO;
|
outputLaunched = NO;
|
||||||
|
@ -39,8 +36,7 @@
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setDelegate:(id)d
|
- (void)setDelegate:(id)d {
|
||||||
{
|
|
||||||
delegate = d;
|
delegate = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,42 +44,36 @@
|
||||||
return delegate;
|
return delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)play:(NSURL *)url
|
- (void)play:(NSURL *)url {
|
||||||
{
|
|
||||||
[self play:url withUserInfo:nil withRGInfo:nil startPaused:NO andSeekTo:0.0];
|
[self play:url withUserInfo:nil withRGInfo:nil startPaused:NO andSeekTo:0.0];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi
|
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi {
|
||||||
{
|
|
||||||
[self play:url withUserInfo:userInfo withRGInfo:rgi startPaused:NO andSeekTo:0.0];
|
[self play:url withUserInfo:userInfo withRGInfo:rgi startPaused:NO andSeekTo:0.0];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi startPaused:(BOOL)paused
|
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi startPaused:(BOOL)paused {
|
||||||
{
|
|
||||||
[self play:url withUserInfo:userInfo withRGInfo:rgi startPaused:paused andSeekTo:0.0];
|
[self play:url withUserInfo:userInfo withRGInfo:rgi startPaused:paused andSeekTo:0.0];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi startPaused:(BOOL)paused andSeekTo:(double)time
|
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi startPaused:(BOOL)paused andSeekTo:(double)time {
|
||||||
{
|
|
||||||
ALog(@"Opening file for playback: %@ at seek offset %f%@", url, time, (paused) ? @", starting paused" : @"");
|
ALog(@"Opening file for playback: %@ at seek offset %f%@", url, time, (paused) ? @", starting paused" : @"");
|
||||||
|
|
||||||
[self waitUntilCallbacksExit];
|
[self waitUntilCallbacksExit];
|
||||||
if (output) {
|
if(output) {
|
||||||
[output setShouldContinue:NO];
|
[output setShouldContinue:NO];
|
||||||
output = nil;
|
output = nil;
|
||||||
}
|
}
|
||||||
output = [[OutputNode alloc] initWithController:self previous:nil];
|
output = [[OutputNode alloc] initWithController:self previous:nil];
|
||||||
[output setup];
|
[output setup];
|
||||||
[output setVolume: volume];
|
[output setVolume:volume];
|
||||||
@synchronized(chainQueue) {
|
@synchronized(chainQueue) {
|
||||||
for (id anObject in chainQueue)
|
for(id anObject in chainQueue) {
|
||||||
{
|
|
||||||
[anObject setShouldContinue:NO];
|
[anObject setShouldContinue:NO];
|
||||||
}
|
}
|
||||||
[chainQueue removeAllObjects];
|
[chainQueue removeAllObjects];
|
||||||
endOfInputReached = NO;
|
endOfInputReached = NO;
|
||||||
if (bufferChain)
|
if(bufferChain) {
|
||||||
{
|
|
||||||
[bufferChain setShouldContinue:NO];
|
[bufferChain setShouldContinue:NO];
|
||||||
|
|
||||||
bufferChain = nil;
|
bufferChain = nil;
|
||||||
|
@ -93,15 +83,13 @@
|
||||||
bufferChain = [[BufferChain alloc] initWithController:self];
|
bufferChain = [[BufferChain alloc] initWithController:self];
|
||||||
[self notifyStreamChanged:userInfo];
|
[self notifyStreamChanged:userInfo];
|
||||||
|
|
||||||
while (![bufferChain open:url withOutputFormat:[output format] withRGInfo:rgi])
|
while(![bufferChain open:url withOutputFormat:[output format] withRGInfo:rgi]) {
|
||||||
{
|
|
||||||
bufferChain = nil;
|
bufferChain = nil;
|
||||||
|
|
||||||
[self requestNextStream: userInfo];
|
[self requestNextStream:userInfo];
|
||||||
|
|
||||||
url = nextStream;
|
url = nextStream;
|
||||||
if (url == nil)
|
if(url == nil) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,8 +103,7 @@
|
||||||
|
|
||||||
[bufferChain setUserInfo:userInfo];
|
[bufferChain setUserInfo:userInfo];
|
||||||
|
|
||||||
if (time > 0.0)
|
if(time > 0.0) {
|
||||||
{
|
|
||||||
[output seek:time];
|
[output seek:time];
|
||||||
[bufferChain seek:time];
|
[bufferChain seek:time];
|
||||||
}
|
}
|
||||||
|
@ -129,44 +116,38 @@
|
||||||
|
|
||||||
[bufferChain launchThreads];
|
[bufferChain launchThreads];
|
||||||
|
|
||||||
if (paused)
|
if(paused)
|
||||||
[self setPlaybackStatus:CogStatusPaused waitUntilDone:YES];
|
[self setPlaybackStatus:CogStatusPaused waitUntilDone:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)stop
|
- (void)stop {
|
||||||
{
|
// Set shouldoContinue to NO on all things
|
||||||
//Set shouldoContinue to NO on all things
|
|
||||||
[self setShouldContinue:NO];
|
[self setShouldContinue:NO];
|
||||||
[self setPlaybackStatus:CogStatusStopped waitUntilDone:YES];
|
[self setPlaybackStatus:CogStatusStopped waitUntilDone:YES];
|
||||||
|
|
||||||
@synchronized(chainQueue) {
|
@synchronized(chainQueue) {
|
||||||
for (id anObject in chainQueue)
|
for(id anObject in chainQueue) {
|
||||||
{
|
|
||||||
[anObject setShouldContinue:NO];
|
[anObject setShouldContinue:NO];
|
||||||
}
|
}
|
||||||
[chainQueue removeAllObjects];
|
[chainQueue removeAllObjects];
|
||||||
endOfInputReached = NO;
|
endOfInputReached = NO;
|
||||||
if (bufferChain)
|
if(bufferChain) {
|
||||||
{
|
|
||||||
bufferChain = nil;
|
bufferChain = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
output = nil;
|
output = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)pause
|
- (void)pause {
|
||||||
{
|
|
||||||
[output pause];
|
[output pause];
|
||||||
|
|
||||||
[self setPlaybackStatus:CogStatusPaused waitUntilDone:YES];
|
[self setPlaybackStatus:CogStatusPaused waitUntilDone:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)resume
|
- (void)resume {
|
||||||
{
|
if(startedPaused) {
|
||||||
if (startedPaused)
|
|
||||||
{
|
|
||||||
startedPaused = NO;
|
startedPaused = NO;
|
||||||
if (initialBufferFilled)
|
if(initialBufferFilled)
|
||||||
[self launchOutputThread];
|
[self launchOutputThread];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,18 +156,16 @@
|
||||||
[self setPlaybackStatus:CogStatusPlaying waitUntilDone:YES];
|
[self setPlaybackStatus:CogStatusPlaying waitUntilDone:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)seekToTime:(double)time
|
- (void)seekToTime:(double)time {
|
||||||
{
|
if(endOfInputReached) {
|
||||||
if (endOfInputReached)
|
|
||||||
{
|
|
||||||
// This is a dirty hack in case the playback has finished with the track
|
// This is a dirty hack in case the playback has finished with the track
|
||||||
// that the user thinks they're seeking into
|
// that the user thinks they're seeking into
|
||||||
CogStatus status = (CogStatus) currentPlaybackStatus;
|
CogStatus status = (CogStatus)currentPlaybackStatus;
|
||||||
NSURL *url;
|
NSURL *url;
|
||||||
id userInfo;
|
id userInfo;
|
||||||
NSDictionary *rgi;
|
NSDictionary *rgi;
|
||||||
|
|
||||||
@synchronized (chainQueue) {
|
@synchronized(chainQueue) {
|
||||||
url = [bufferChain streamURL];
|
url = [bufferChain streamURL];
|
||||||
userInfo = [bufferChain userInfo];
|
userInfo = [bufferChain userInfo];
|
||||||
rgi = [bufferChain rgInfo];
|
rgi = [bufferChain rgInfo];
|
||||||
|
@ -195,36 +174,29 @@
|
||||||
[self stop];
|
[self stop];
|
||||||
|
|
||||||
[self play:url withUserInfo:userInfo withRGInfo:rgi startPaused:(status == CogStatusPaused) andSeekTo:time];
|
[self play:url withUserInfo:userInfo withRGInfo:rgi startPaused:(status == CogStatusPaused) andSeekTo:time];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// Still decoding the current file, safe to seek within it
|
// Still decoding the current file, safe to seek within it
|
||||||
[output seek:time];
|
[output seek:time];
|
||||||
[bufferChain seek:time];
|
[bufferChain seek:time];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setVolume:(double)v
|
- (void)setVolume:(double)v {
|
||||||
{
|
|
||||||
volume = v;
|
volume = v;
|
||||||
|
|
||||||
[output setVolume:v];
|
[output setVolume:v];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (double)volume
|
- (double)volume {
|
||||||
{
|
|
||||||
return volume;
|
return volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is called by the delegate DURING a requestNextStream request.
|
||||||
//This is called by the delegate DURING a requestNextStream request.
|
- (void)setNextStream:(NSURL *)url {
|
||||||
- (void)setNextStream:(NSURL *)url
|
|
||||||
{
|
|
||||||
[self setNextStream:url withUserInfo:nil withRGInfo:nil];
|
[self setNextStream:url withUserInfo:nil withRGInfo:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setNextStream:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi
|
- (void)setNextStream:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi {
|
||||||
{
|
|
||||||
nextStream = url;
|
nextStream = url;
|
||||||
|
|
||||||
nextStreamUserInfo = userInfo;
|
nextStreamUserInfo = userInfo;
|
||||||
|
@ -233,76 +205,66 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when the playlist changed before we actually started playing a requested stream. We will re-request.
|
// Called when the playlist changed before we actually started playing a requested stream. We will re-request.
|
||||||
- (void)resetNextStreams
|
- (void)resetNextStreams {
|
||||||
{
|
|
||||||
[self waitUntilCallbacksExit];
|
[self waitUntilCallbacksExit];
|
||||||
|
|
||||||
@synchronized (chainQueue) {
|
@synchronized(chainQueue) {
|
||||||
for (id anObject in chainQueue) {
|
for(id anObject in chainQueue) {
|
||||||
[anObject setShouldContinue:NO];
|
[anObject setShouldContinue:NO];
|
||||||
}
|
}
|
||||||
[chainQueue removeAllObjects];
|
[chainQueue removeAllObjects];
|
||||||
|
|
||||||
if (endOfInputReached) {
|
if(endOfInputReached) {
|
||||||
[self endOfInputReached:bufferChain];
|
[self endOfInputReached:bufferChain];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setShouldContinue:(BOOL)s
|
- (void)setShouldContinue:(BOOL)s {
|
||||||
{
|
|
||||||
shouldContinue = s;
|
shouldContinue = s;
|
||||||
|
|
||||||
if (bufferChain)
|
if(bufferChain)
|
||||||
[bufferChain setShouldContinue:s];
|
[bufferChain setShouldContinue:s];
|
||||||
|
|
||||||
if (output)
|
if(output)
|
||||||
[output setShouldContinue:s];
|
[output setShouldContinue:s];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (double)amountPlayed
|
- (double)amountPlayed {
|
||||||
{
|
|
||||||
return [output amountPlayed];
|
return [output amountPlayed];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)launchOutputThread
|
- (void)launchOutputThread {
|
||||||
{
|
|
||||||
initialBufferFilled = YES;
|
initialBufferFilled = YES;
|
||||||
if (outputLaunched == NO && startedPaused == NO) {
|
if(outputLaunched == NO && startedPaused == NO) {
|
||||||
[self setPlaybackStatus:CogStatusPlaying];
|
[self setPlaybackStatus:CogStatusPlaying];
|
||||||
[output launchThread];
|
[output launchThread];
|
||||||
outputLaunched = YES;
|
outputLaunched = YES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)requestNextStream:(id)userInfo
|
- (void)requestNextStream:(id)userInfo {
|
||||||
{
|
|
||||||
[self sendDelegateMethod:@selector(audioPlayer:willEndStream:) withObject:userInfo waitUntilDone:YES];
|
[self sendDelegateMethod:@selector(audioPlayer:willEndStream:) withObject:userInfo waitUntilDone:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)notifyStreamChanged:(id)userInfo
|
- (void)notifyStreamChanged:(id)userInfo {
|
||||||
{
|
|
||||||
[self sendDelegateMethod:@selector(audioPlayer:didBeginStream:) withObject:userInfo waitUntilDone:YES];
|
[self sendDelegateMethod:@selector(audioPlayer:didBeginStream:) withObject:userInfo waitUntilDone:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)beginEqualizer:(AudioUnit)eq
|
- (void)beginEqualizer:(AudioUnit)eq {
|
||||||
{
|
|
||||||
[self sendDelegateMethod:@selector(audioPlayer:displayEqualizer:) withVoid:eq waitUntilDone:YES];
|
[self sendDelegateMethod:@selector(audioPlayer:displayEqualizer:) withVoid:eq waitUntilDone:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)refreshEqualizer:(AudioUnit)eq
|
- (void)refreshEqualizer:(AudioUnit)eq {
|
||||||
{
|
|
||||||
[self sendDelegateMethod:@selector(audioPlayer:refreshEqualizer:) withVoid:eq waitUntilDone:YES];
|
[self sendDelegateMethod:@selector(audioPlayer:refreshEqualizer:) withVoid:eq waitUntilDone:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)endEqualizer:(AudioUnit)eq
|
- (void)endEqualizer:(AudioUnit)eq {
|
||||||
{
|
|
||||||
[self sendDelegateMethod:@selector(audioPlayer:removeEqualizer:) withVoid:eq waitUntilDone:YES];
|
[self sendDelegateMethod:@selector(audioPlayer:removeEqualizer:) withVoid:eq waitUntilDone:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)addChainToQueue:(BufferChain *)newChain
|
- (void)addChainToQueue:(BufferChain *)newChain {
|
||||||
{
|
[newChain setUserInfo:nextStreamUserInfo];
|
||||||
[newChain setUserInfo: nextStreamUserInfo];
|
|
||||||
|
|
||||||
[newChain setShouldContinue:YES];
|
[newChain setShouldContinue:YES];
|
||||||
[newChain launchThreads];
|
[newChain launchThreads];
|
||||||
|
@ -310,29 +272,27 @@
|
||||||
[chainQueue insertObject:newChain atIndex:[chainQueue count]];
|
[chainQueue insertObject:newChain atIndex:[chainQueue count]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)endOfInputReached:(BufferChain *)sender //Sender is a BufferChain
|
- (BOOL)endOfInputReached:(BufferChain *)sender // Sender is a BufferChain
|
||||||
{
|
{
|
||||||
BufferChain *newChain = nil;
|
BufferChain *newChain = nil;
|
||||||
|
|
||||||
if (atomic_load_explicit(&resettingNow, memory_order_relaxed))
|
if(atomic_load_explicit(&resettingNow, memory_order_relaxed))
|
||||||
return YES;
|
return YES;
|
||||||
|
|
||||||
atomic_fetch_add(&refCount, 1);
|
atomic_fetch_add(&refCount, 1);
|
||||||
|
|
||||||
@synchronized (chainQueue) {
|
@synchronized(chainQueue) {
|
||||||
// No point in constructing new chain for the next playlist entry
|
// No point in constructing new chain for the next playlist entry
|
||||||
// if there's already one at the head of chainQueue... r-r-right?
|
// if there's already one at the head of chainQueue... r-r-right?
|
||||||
for (BufferChain *chain in chainQueue)
|
for(BufferChain *chain in chainQueue) {
|
||||||
{
|
if([chain isRunning]) {
|
||||||
if ([chain isRunning])
|
|
||||||
{
|
|
||||||
atomic_fetch_sub(&refCount, 1);
|
atomic_fetch_sub(&refCount, 1);
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't want to do this, it may happen with a lot of short files
|
// We don't want to do this, it may happen with a lot of short files
|
||||||
//if ([chainQueue count] >= 5)
|
// if ([chainQueue count] >= 5)
|
||||||
//{
|
//{
|
||||||
// return YES;
|
// return YES;
|
||||||
//}
|
//}
|
||||||
|
@ -340,22 +300,21 @@
|
||||||
|
|
||||||
double duration = 0.0;
|
double duration = 0.0;
|
||||||
|
|
||||||
@synchronized (chainQueue) {
|
@synchronized(chainQueue) {
|
||||||
for (BufferChain *chain in chainQueue) {
|
for(BufferChain *chain in chainQueue) {
|
||||||
duration += [chain secondsBuffered];
|
duration += [chain secondsBuffered];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (duration >= 30.0 && shouldContinue)
|
while(duration >= 30.0 && shouldContinue) {
|
||||||
{
|
|
||||||
[semaphore wait];
|
[semaphore wait];
|
||||||
if (atomic_load_explicit(&resettingNow, memory_order_relaxed)) {
|
if(atomic_load_explicit(&resettingNow, memory_order_relaxed)) {
|
||||||
atomic_fetch_sub(&refCount, 1);
|
atomic_fetch_sub(&refCount, 1);
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
@synchronized (chainQueue) {
|
@synchronized(chainQueue) {
|
||||||
duration = 0.0;
|
duration = 0.0;
|
||||||
for (BufferChain *chain in chainQueue) {
|
for(BufferChain *chain in chainQueue) {
|
||||||
duration += [chain secondsBuffered];
|
duration += [chain secondsBuffered];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -366,49 +325,41 @@
|
||||||
nextStreamRGInfo = [sender rgInfo];
|
nextStreamRGInfo = [sender rgInfo];
|
||||||
|
|
||||||
// This call can sometimes lead to invoking a chainQueue block on another thread
|
// This call can sometimes lead to invoking a chainQueue block on another thread
|
||||||
[self requestNextStream: nextStreamUserInfo];
|
[self requestNextStream:nextStreamUserInfo];
|
||||||
|
|
||||||
if (!nextStream) {
|
if(!nextStream) {
|
||||||
atomic_fetch_sub(&refCount, 1);
|
atomic_fetch_sub(&refCount, 1);
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
@synchronized (chainQueue) {
|
@synchronized(chainQueue) {
|
||||||
newChain = [[BufferChain alloc] initWithController:self];
|
newChain = [[BufferChain alloc] initWithController:self];
|
||||||
|
|
||||||
endOfInputReached = YES;
|
endOfInputReached = YES;
|
||||||
|
|
||||||
BufferChain *lastChain = [chainQueue lastObject];
|
BufferChain *lastChain = [chainQueue lastObject];
|
||||||
if (lastChain == nil) {
|
if(lastChain == nil) {
|
||||||
lastChain = bufferChain;
|
lastChain = bufferChain;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL pathsEqual = NO;
|
BOOL pathsEqual = NO;
|
||||||
|
|
||||||
if ([nextStream isFileURL] && [[lastChain streamURL] isFileURL])
|
if([nextStream isFileURL] && [[lastChain streamURL] isFileURL]) {
|
||||||
{
|
|
||||||
NSMutableString *unixPathNext = [[nextStream path] mutableCopy];
|
NSMutableString *unixPathNext = [[nextStream path] mutableCopy];
|
||||||
NSMutableString *unixPathPrev = [[[lastChain streamURL] path] mutableCopy];
|
NSMutableString *unixPathPrev = [[[lastChain streamURL] path] mutableCopy];
|
||||||
|
|
||||||
if ([unixPathNext isEqualToString:unixPathPrev])
|
if([unixPathNext isEqualToString:unixPathPrev])
|
||||||
pathsEqual = YES;
|
pathsEqual = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pathsEqual || ([[nextStream scheme] isEqualToString:[[lastChain streamURL] scheme]]
|
if(pathsEqual || ([[nextStream scheme] isEqualToString:[[lastChain streamURL] scheme]] && (([nextStream host] == nil && [[lastChain streamURL] host] == nil) || [[nextStream host] isEqualToString:[[lastChain streamURL] host]]) && [[nextStream path] isEqualToString:[[lastChain streamURL] path]])) {
|
||||||
&& (([nextStream host] == nil &&
|
if([lastChain setTrack:nextStream] && [newChain openWithInput:[lastChain inputNode] withOutputFormat:[output format] withRGInfo:nextStreamRGInfo]) {
|
||||||
[[lastChain streamURL] host] == nil)
|
|
||||||
|| [[nextStream host] isEqualToString:[[lastChain streamURL] host]])
|
|
||||||
&& [[nextStream path] isEqualToString:[[lastChain streamURL] path]]))
|
|
||||||
{
|
|
||||||
if ([lastChain setTrack:nextStream]
|
|
||||||
&& [newChain openWithInput:[lastChain inputNode] withOutputFormat:[output format] withRGInfo:nextStreamRGInfo])
|
|
||||||
{
|
|
||||||
[newChain setStreamURL:nextStream];
|
[newChain setStreamURL:nextStream];
|
||||||
[newChain setUserInfo:nextStreamUserInfo];
|
[newChain setUserInfo:nextStreamUserInfo];
|
||||||
|
|
||||||
[self addChainToQueue:newChain];
|
[self addChainToQueue:newChain];
|
||||||
DLog(@"TRACK SET!!! %@", newChain);
|
DLog(@"TRACK SET!!! %@", newChain);
|
||||||
//Keep on-playin
|
// Keep on-playin
|
||||||
newChain = nil;
|
newChain = nil;
|
||||||
|
|
||||||
atomic_fetch_sub(&refCount, 1);
|
atomic_fetch_sub(&refCount, 1);
|
||||||
|
@ -418,17 +369,15 @@
|
||||||
|
|
||||||
lastChain = nil;
|
lastChain = nil;
|
||||||
|
|
||||||
while (shouldContinue && ![newChain open:nextStream withOutputFormat:[output format] withRGInfo:nextStreamRGInfo])
|
while(shouldContinue && ![newChain open:nextStream withOutputFormat:[output format] withRGInfo:nextStreamRGInfo]) {
|
||||||
{
|
if(nextStream == nil) {
|
||||||
if (nextStream == nil)
|
|
||||||
{
|
|
||||||
newChain = nil;
|
newChain = nil;
|
||||||
atomic_fetch_sub(&refCount, 1);
|
atomic_fetch_sub(&refCount, 1);
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
newChain = nil;
|
newChain = nil;
|
||||||
[self requestNextStream: nextStreamUserInfo];
|
[self requestNextStream:nextStreamUserInfo];
|
||||||
|
|
||||||
newChain = [[BufferChain alloc] initWithController:self];
|
newChain = [[BufferChain alloc] initWithController:self];
|
||||||
}
|
}
|
||||||
|
@ -453,8 +402,7 @@
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)endOfInputPlayed
|
- (void)endOfInputPlayed {
|
||||||
{
|
|
||||||
// Once we get here:
|
// Once we get here:
|
||||||
// - the buffer chain for the next playlist entry (started in endOfInputReached) have been working for some time
|
// - the buffer chain for the next playlist entry (started in endOfInputReached) have been working for some time
|
||||||
// already, so that there is some decoded and converted data to play
|
// already, so that there is some decoded and converted data to play
|
||||||
|
@ -463,9 +411,8 @@
|
||||||
@synchronized(chainQueue) {
|
@synchronized(chainQueue) {
|
||||||
endOfInputReached = NO;
|
endOfInputReached = NO;
|
||||||
|
|
||||||
if ([chainQueue count] <= 0)
|
if([chainQueue count] <= 0) {
|
||||||
{
|
// End of playlist
|
||||||
//End of playlist
|
|
||||||
[self stop];
|
[self stop];
|
||||||
|
|
||||||
bufferChain = nil;
|
bufferChain = nil;
|
||||||
|
@ -486,44 +433,40 @@
|
||||||
[output setEndOfStream:NO];
|
[output setEndOfStream:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)chainQueueHasTracks
|
- (BOOL)chainQueueHasTracks {
|
||||||
{
|
@synchronized(chainQueue) {
|
||||||
@synchronized (chainQueue) {
|
|
||||||
return [chainQueue count] > 0;
|
return [chainQueue count] > 0;
|
||||||
}
|
}
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sendDelegateMethod:(SEL)selector withVoid:(void*)obj waitUntilDone:(BOOL)wait
|
- (void)sendDelegateMethod:(SEL)selector withVoid:(void *)obj waitUntilDone:(BOOL)wait {
|
||||||
{
|
|
||||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[delegate methodSignatureForSelector:selector]];
|
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[delegate methodSignatureForSelector:selector]];
|
||||||
[invocation setTarget:delegate];
|
[invocation setTarget:delegate];
|
||||||
[invocation setSelector:selector];
|
[invocation setSelector:selector];
|
||||||
[invocation setArgument:(void*)&self atIndex:2];
|
[invocation setArgument:(void *)&self atIndex:2];
|
||||||
[invocation setArgument:&obj atIndex:3];
|
[invocation setArgument:&obj atIndex:3];
|
||||||
[invocation retainArguments];
|
[invocation retainArguments];
|
||||||
|
|
||||||
[invocation performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:wait];
|
[invocation performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:wait];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sendDelegateMethod:(SEL)selector withObject:(id)obj waitUntilDone:(BOOL)wait
|
- (void)sendDelegateMethod:(SEL)selector withObject:(id)obj waitUntilDone:(BOOL)wait {
|
||||||
{
|
|
||||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[delegate methodSignatureForSelector:selector]];
|
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[delegate methodSignatureForSelector:selector]];
|
||||||
[invocation setTarget:delegate];
|
[invocation setTarget:delegate];
|
||||||
[invocation setSelector:selector];
|
[invocation setSelector:selector];
|
||||||
[invocation setArgument:(void*)&self atIndex:2];
|
[invocation setArgument:(void *)&self atIndex:2];
|
||||||
[invocation setArgument:&obj atIndex:3];
|
[invocation setArgument:&obj atIndex:3];
|
||||||
[invocation retainArguments];
|
[invocation retainArguments];
|
||||||
|
|
||||||
[invocation performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:wait];
|
[invocation performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:wait];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sendDelegateMethod:(SEL)selector withObject:(id)obj withObject:(id)obj2 waitUntilDone:(BOOL)wait
|
- (void)sendDelegateMethod:(SEL)selector withObject:(id)obj withObject:(id)obj2 waitUntilDone:(BOOL)wait {
|
||||||
{
|
|
||||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[delegate methodSignatureForSelector:selector]];
|
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[delegate methodSignatureForSelector:selector]];
|
||||||
[invocation setTarget:delegate];
|
[invocation setTarget:delegate];
|
||||||
[invocation setSelector:selector];
|
[invocation setSelector:selector];
|
||||||
[invocation setArgument:(void*)&self atIndex:2];
|
[invocation setArgument:(void *)&self atIndex:2];
|
||||||
[invocation setArgument:&obj atIndex:3];
|
[invocation setArgument:&obj atIndex:3];
|
||||||
[invocation setArgument:&obj2 atIndex:4];
|
[invocation setArgument:&obj2 atIndex:4];
|
||||||
[invocation retainArguments];
|
[invocation retainArguments];
|
||||||
|
@ -531,41 +474,33 @@
|
||||||
[invocation performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:wait];
|
[invocation performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:wait];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)setPlaybackStatus:(int)status waitUntilDone:(BOOL)wait {
|
||||||
- (void)setPlaybackStatus:(int)status waitUntilDone:(BOOL)wait
|
|
||||||
{
|
|
||||||
currentPlaybackStatus = status;
|
currentPlaybackStatus = status;
|
||||||
|
|
||||||
[self sendDelegateMethod:@selector(audioPlayer:didChangeStatus:userInfo:) withObject:[NSNumber numberWithInt:status] withObject:[bufferChain userInfo] waitUntilDone:wait];
|
[self sendDelegateMethod:@selector(audioPlayer:didChangeStatus:userInfo:) withObject:[NSNumber numberWithInt:status] withObject:[bufferChain userInfo] waitUntilDone:wait];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sustainHDCD
|
- (void)sustainHDCD {
|
||||||
{
|
|
||||||
[self sendDelegateMethod:@selector(audioPlayer:sustainHDCD:) withObject:[bufferChain userInfo] waitUntilDone:NO];
|
[self sendDelegateMethod:@selector(audioPlayer:sustainHDCD:) withObject:[bufferChain userInfo] waitUntilDone:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setPlaybackStatus:(int)status
|
- (void)setPlaybackStatus:(int)status {
|
||||||
{
|
|
||||||
[self setPlaybackStatus:status waitUntilDone:NO];
|
[self setPlaybackStatus:status waitUntilDone:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BufferChain *)bufferChain
|
- (BufferChain *)bufferChain {
|
||||||
{
|
|
||||||
return bufferChain;
|
return bufferChain;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (OutputNode *) output
|
- (OutputNode *)output {
|
||||||
{
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSArray *)containerTypes
|
+ (NSArray *)containerTypes {
|
||||||
{
|
|
||||||
return [[[PluginController sharedPluginController] containers] allKeys];
|
return [[[PluginController sharedPluginController] containers] allKeys];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSArray *)fileTypes
|
+ (NSArray *)fileTypes {
|
||||||
{
|
|
||||||
PluginController *pluginController = [PluginController sharedPluginController];
|
PluginController *pluginController = [PluginController sharedPluginController];
|
||||||
|
|
||||||
NSArray *containerTypes = [[pluginController containers] allKeys];
|
NSArray *containerTypes = [[pluginController containers] allKeys];
|
||||||
|
@ -583,20 +518,18 @@
|
||||||
return [types allObjects];
|
return [types allObjects];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSArray *)schemes
|
+ (NSArray *)schemes {
|
||||||
{
|
|
||||||
PluginController *pluginController = [PluginController sharedPluginController];
|
PluginController *pluginController = [PluginController sharedPluginController];
|
||||||
|
|
||||||
return [[pluginController sources] allKeys];
|
return [[pluginController sources] allKeys];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (double)volumeUp:(double)amount
|
- (double)volumeUp:(double)amount {
|
||||||
{
|
|
||||||
BOOL volumeLimit = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"volumeLimit"];
|
BOOL volumeLimit = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"volumeLimit"];
|
||||||
const double MAX_VOLUME = (volumeLimit) ? 100.0 : 800.0;
|
const double MAX_VOLUME = (volumeLimit) ? 100.0 : 800.0;
|
||||||
|
|
||||||
double newVolume = linearToLogarithmic(logarithmicToLinear(volume + amount, MAX_VOLUME), MAX_VOLUME);
|
double newVolume = linearToLogarithmic(logarithmicToLinear(volume + amount, MAX_VOLUME), MAX_VOLUME);
|
||||||
if (newVolume > MAX_VOLUME)
|
if(newVolume > MAX_VOLUME)
|
||||||
newVolume = MAX_VOLUME;
|
newVolume = MAX_VOLUME;
|
||||||
|
|
||||||
[self setVolume:newVolume];
|
[self setVolume:newVolume];
|
||||||
|
@ -606,13 +539,12 @@
|
||||||
return newVolume;
|
return newVolume;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (double)volumeDown:(double)amount
|
- (double)volumeDown:(double)amount {
|
||||||
{
|
|
||||||
BOOL volumeLimit = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"volumeLimit"];
|
BOOL volumeLimit = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"volumeLimit"];
|
||||||
const double MAX_VOLUME = (volumeLimit) ? 100.0 : 800.0;
|
const double MAX_VOLUME = (volumeLimit) ? 100.0 : 800.0;
|
||||||
|
|
||||||
double newVolume;
|
double newVolume;
|
||||||
if (amount > volume)
|
if(amount > volume)
|
||||||
newVolume = 0.0;
|
newVolume = 0.0;
|
||||||
else
|
else
|
||||||
newVolume = linearToLogarithmic(logarithmicToLinear(volume - amount, MAX_VOLUME), MAX_VOLUME);
|
newVolume = linearToLogarithmic(logarithmicToLinear(volume - amount, MAX_VOLUME), MAX_VOLUME);
|
||||||
|
@ -621,17 +553,16 @@
|
||||||
return newVolume;
|
return newVolume;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)waitUntilCallbacksExit
|
- (void)waitUntilCallbacksExit {
|
||||||
{
|
|
||||||
// This sucks! And since the thread that's inside the function can be calling
|
// This sucks! And since the thread that's inside the function can be calling
|
||||||
// event dispatches, we have to pump the message queue if we're on the main
|
// event dispatches, we have to pump the message queue if we're on the main
|
||||||
// thread. Damn.
|
// thread. Damn.
|
||||||
if (atomic_load_explicit(&refCount, memory_order_relaxed) != 0) {
|
if(atomic_load_explicit(&refCount, memory_order_relaxed) != 0) {
|
||||||
BOOL mainThread = (dispatch_queue_get_label(dispatch_get_main_queue()) == dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL));
|
BOOL mainThread = (dispatch_queue_get_label(dispatch_get_main_queue()) == dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL));
|
||||||
atomic_store(&resettingNow, true);
|
atomic_store(&resettingNow, true);
|
||||||
while (atomic_load_explicit(&refCount, memory_order_relaxed) != 0) {
|
while(atomic_load_explicit(&refCount, memory_order_relaxed) != 0) {
|
||||||
[semaphore signal]; // Gotta poke this periodically
|
[semaphore signal]; // Gotta poke this periodically
|
||||||
if (mainThread)
|
if(mainThread)
|
||||||
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.001]];
|
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.001]];
|
||||||
else
|
else
|
||||||
usleep(500);
|
usleep(500);
|
||||||
|
@ -640,5 +571,4 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -8,9 +8,7 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
|
||||||
@interface AudioPropertiesReader : NSObject {
|
@interface AudioPropertiesReader : NSObject {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSDictionary *)propertiesForURL:(NSURL *)url;
|
+ (NSDictionary *)propertiesForURL:(NSURL *)url;
|
||||||
|
|
|
@ -13,8 +13,7 @@
|
||||||
|
|
||||||
@implementation AudioPropertiesReader
|
@implementation AudioPropertiesReader
|
||||||
|
|
||||||
+ (NSDictionary *)propertiesForURL:(NSURL *)url
|
+ (NSDictionary *)propertiesForURL:(NSURL *)url {
|
||||||
{
|
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
return [[PluginController sharedPluginController] propertiesForURL:url];
|
return [[PluginController sharedPluginController] propertiesForURL:url];
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,6 @@
|
||||||
@interface AudioSource : NSObject {
|
@interface AudioSource : NSObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (id<CogSource>) audioSourceForURL:(NSURL *)url;
|
+ (id<CogSource>)audioSourceForURL:(NSURL *)url;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -8,11 +8,9 @@
|
||||||
|
|
||||||
#import "AudioSource.h"
|
#import "AudioSource.h"
|
||||||
|
|
||||||
|
|
||||||
@implementation AudioSource
|
@implementation AudioSource
|
||||||
|
|
||||||
+ (id<CogSource>) audioSourceForURL:(NSURL *)url
|
+ (id<CogSource>)audioSourceForURL:(NSURL *)url {
|
||||||
{
|
|
||||||
return [[PluginController sharedPluginController] audioSourceForURL:url];
|
return [[PluginController sharedPluginController] audioSourceForURL:url];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,14 +8,14 @@
|
||||||
#ifndef AudioChunk_h
|
#ifndef AudioChunk_h
|
||||||
#define AudioChunk_h
|
#define AudioChunk_h
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#import <CoreAudio/CoreAudio.h>
|
#import <CoreAudio/CoreAudio.h>
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@interface AudioChunk : NSObject {
|
@interface AudioChunk : NSObject {
|
||||||
AudioStreamBasicDescription format;
|
AudioStreamBasicDescription format;
|
||||||
NSMutableData * chunkData;
|
NSMutableData *chunkData;
|
||||||
BOOL formatAssigned;
|
BOOL formatAssigned;
|
||||||
BOOL lossless;
|
BOOL lossless;
|
||||||
}
|
}
|
||||||
|
@ -23,17 +23,17 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
@property AudioStreamBasicDescription format;
|
@property AudioStreamBasicDescription format;
|
||||||
@property BOOL lossless;
|
@property BOOL lossless;
|
||||||
|
|
||||||
- (id) init;
|
- (id)init;
|
||||||
|
|
||||||
- (void) assignSamples:(const void *)data frameCount:(size_t)count;
|
- (void)assignSamples:(const void *)data frameCount:(size_t)count;
|
||||||
|
|
||||||
- (NSData *) removeSamples:(size_t)frameCount;
|
- (NSData *)removeSamples:(size_t)frameCount;
|
||||||
|
|
||||||
- (BOOL) isEmpty;
|
- (BOOL)isEmpty;
|
||||||
|
|
||||||
- (size_t) frameCount;
|
- (size_t)frameCount;
|
||||||
|
|
||||||
- (double) duration;
|
- (double)duration;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,10 @@
|
||||||
|
|
||||||
@implementation AudioChunk
|
@implementation AudioChunk
|
||||||
|
|
||||||
- (id) init {
|
- (id)init {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
if (self) {
|
if(self) {
|
||||||
chunkData = [[NSMutableData alloc] init];
|
chunkData = [[NSMutableData alloc] init];
|
||||||
formatAssigned = NO;
|
formatAssigned = NO;
|
||||||
lossless = NO;
|
lossless = NO;
|
||||||
|
@ -23,47 +23,47 @@
|
||||||
|
|
||||||
@synthesize lossless;
|
@synthesize lossless;
|
||||||
|
|
||||||
- (AudioStreamBasicDescription) format {
|
- (AudioStreamBasicDescription)format {
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setFormat:(AudioStreamBasicDescription)informat {
|
- (void)setFormat:(AudioStreamBasicDescription)informat {
|
||||||
formatAssigned = YES;
|
formatAssigned = YES;
|
||||||
format = informat;
|
format = informat;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) assignSamples:(const void *)data frameCount:(size_t)count {
|
- (void)assignSamples:(const void *)data frameCount:(size_t)count {
|
||||||
if (formatAssigned) {
|
if(formatAssigned) {
|
||||||
const size_t bytesPerPacket = format.mBytesPerPacket;
|
const size_t bytesPerPacket = format.mBytesPerPacket;
|
||||||
[chunkData appendBytes:data length:bytesPerPacket * count];
|
[chunkData appendBytes:data length:bytesPerPacket * count];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSData *) removeSamples:(size_t)frameCount {
|
- (NSData *)removeSamples:(size_t)frameCount {
|
||||||
if (formatAssigned) {
|
if(formatAssigned) {
|
||||||
const size_t bytesPerPacket = format.mBytesPerPacket;
|
const size_t bytesPerPacket = format.mBytesPerPacket;
|
||||||
const size_t byteCount = bytesPerPacket * frameCount;
|
const size_t byteCount = bytesPerPacket * frameCount;
|
||||||
NSData * ret = [chunkData subdataWithRange:NSMakeRange(0, byteCount)];
|
NSData *ret = [chunkData subdataWithRange:NSMakeRange(0, byteCount)];
|
||||||
[chunkData replaceBytesInRange:NSMakeRange(0, byteCount) withBytes:NULL length:0];
|
[chunkData replaceBytesInRange:NSMakeRange(0, byteCount) withBytes:NULL length:0];
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
return [NSData data];
|
return [NSData data];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) isEmpty {
|
- (BOOL)isEmpty {
|
||||||
return [chunkData length] == 0;
|
return [chunkData length] == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (size_t) frameCount {
|
- (size_t)frameCount {
|
||||||
if (formatAssigned) {
|
if(formatAssigned) {
|
||||||
const size_t bytesPerPacket = format.mBytesPerPacket;
|
const size_t bytesPerPacket = format.mBytesPerPacket;
|
||||||
return [chunkData length] / bytesPerPacket;
|
return [chunkData length] / bytesPerPacket;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (double) duration {
|
- (double)duration {
|
||||||
if (formatAssigned) {
|
if(formatAssigned) {
|
||||||
const size_t bytesPerPacket = format.mBytesPerPacket;
|
const size_t bytesPerPacket = format.mBytesPerPacket;
|
||||||
const double sampleRate = format.mSampleRate;
|
const double sampleRate = format.mSampleRate;
|
||||||
return (double)([chunkData length] / bytesPerPacket) / sampleRate;
|
return (double)([chunkData length] / bytesPerPacket) / sampleRate;
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
#import "InputNode.h"
|
|
||||||
#import "ConverterNode.h"
|
|
||||||
#import "AudioPlayer.h"
|
#import "AudioPlayer.h"
|
||||||
|
#import "ConverterNode.h"
|
||||||
|
#import "InputNode.h"
|
||||||
|
|
||||||
@interface BufferChain : NSObject {
|
@interface BufferChain : NSObject {
|
||||||
InputNode *inputNode;
|
InputNode *inputNode;
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
id userInfo;
|
id userInfo;
|
||||||
NSDictionary *rgInfo;
|
NSDictionary *rgInfo;
|
||||||
|
|
||||||
id finalNode; //Final buffer in the chain.
|
id finalNode; // Final buffer in the chain.
|
||||||
|
|
||||||
id controller;
|
id controller;
|
||||||
}
|
}
|
||||||
|
@ -30,15 +30,15 @@
|
||||||
- (id)initWithController:(id)c;
|
- (id)initWithController:(id)c;
|
||||||
- (void)buildChain;
|
- (void)buildChain;
|
||||||
|
|
||||||
- (BOOL)open:(NSURL *)url withOutputFormat:(AudioStreamBasicDescription)outputFormat withRGInfo:(NSDictionary*)rgi;
|
- (BOOL)open:(NSURL *)url withOutputFormat:(AudioStreamBasicDescription)outputFormat withRGInfo:(NSDictionary *)rgi;
|
||||||
|
|
||||||
//Used when changing tracks to reuse the same decoder
|
// Used when changing tracks to reuse the same decoder
|
||||||
- (BOOL)openWithInput:(InputNode *)i withOutputFormat:(AudioStreamBasicDescription)outputFormat withRGInfo:(NSDictionary*)rgi;
|
- (BOOL)openWithInput:(InputNode *)i withOutputFormat:(AudioStreamBasicDescription)outputFormat withRGInfo:(NSDictionary *)rgi;
|
||||||
|
|
||||||
//Used when resetting the decoder on seek
|
// Used when resetting the decoder on seek
|
||||||
- (BOOL)openWithDecoder:(id<CogDecoder>)decoder
|
- (BOOL)openWithDecoder:(id<CogDecoder>)decoder
|
||||||
withOutputFormat:(AudioStreamBasicDescription)outputFormat
|
withOutputFormat:(AudioStreamBasicDescription)outputFormat
|
||||||
withRGInfo:(NSDictionary*)rgi;
|
withRGInfo:(NSDictionary *)rgi;
|
||||||
|
|
||||||
- (void)seek:(double)time;
|
- (void)seek:(double)time;
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@
|
||||||
- (id)userInfo;
|
- (id)userInfo;
|
||||||
- (void)setUserInfo:(id)i;
|
- (void)setUserInfo:(id)i;
|
||||||
|
|
||||||
- (NSDictionary*)rgInfo;
|
- (NSDictionary *)rgInfo;
|
||||||
- (void)setRGInfo:(NSDictionary *)rgi;
|
- (void)setRGInfo:(NSDictionary *)rgi;
|
||||||
|
|
||||||
- (NSURL *)streamURL;
|
- (NSURL *)streamURL;
|
||||||
|
|
|
@ -7,19 +7,17 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "BufferChain.h"
|
#import "BufferChain.h"
|
||||||
#import "OutputNode.h"
|
|
||||||
#import "AudioSource.h"
|
#import "AudioSource.h"
|
||||||
#import "CoreAudioUtils.h"
|
#import "CoreAudioUtils.h"
|
||||||
|
#import "OutputNode.h"
|
||||||
|
|
||||||
#import "Logging.h"
|
#import "Logging.h"
|
||||||
|
|
||||||
@implementation BufferChain
|
@implementation BufferChain
|
||||||
|
|
||||||
- (id)initWithController:(id)c
|
- (id)initWithController:(id)c {
|
||||||
{
|
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self)
|
if(self) {
|
||||||
{
|
|
||||||
controller = c;
|
controller = c;
|
||||||
streamURL = nil;
|
streamURL = nil;
|
||||||
userInfo = nil;
|
userInfo = nil;
|
||||||
|
@ -32,8 +30,7 @@
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)buildChain
|
- (void)buildChain {
|
||||||
{
|
|
||||||
inputNode = nil;
|
inputNode = nil;
|
||||||
converterNode = nil;
|
converterNode = nil;
|
||||||
|
|
||||||
|
@ -43,27 +40,25 @@
|
||||||
finalNode = converterNode;
|
finalNode = converterNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)open:(NSURL *)url withOutputFormat:(AudioStreamBasicDescription)outputFormat withRGInfo:(NSDictionary *)rgi
|
- (BOOL)open:(NSURL *)url withOutputFormat:(AudioStreamBasicDescription)outputFormat withRGInfo:(NSDictionary *)rgi {
|
||||||
{
|
|
||||||
[self setStreamURL:url];
|
[self setStreamURL:url];
|
||||||
|
|
||||||
[self buildChain];
|
[self buildChain];
|
||||||
|
|
||||||
id<CogSource> source = [AudioSource audioSourceForURL:url];
|
id<CogSource> source = [AudioSource audioSourceForURL:url];
|
||||||
DLog(@"Opening: %@", url);
|
DLog(@"Opening: %@", url);
|
||||||
if (!source || ![source open:url])
|
if(!source || ![source open:url]) {
|
||||||
{
|
|
||||||
DLog(@"Couldn't open source...");
|
DLog(@"Couldn't open source...");
|
||||||
url = [NSURL URLWithString:@"silence://10"];
|
url = [NSURL URLWithString:@"silence://10"];
|
||||||
source = [AudioSource audioSourceForURL:url];
|
source = [AudioSource audioSourceForURL:url];
|
||||||
if (![source open:url])
|
if(![source open:url])
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (![inputNode openWithSource:source])
|
if(![inputNode openWithSource:source])
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
NSDictionary * properties = [inputNode properties];
|
NSDictionary *properties = [inputNode properties];
|
||||||
|
|
||||||
inputFormat = [inputNode nodeFormat];
|
inputFormat = [inputNode nodeFormat];
|
||||||
|
|
||||||
|
@ -71,25 +66,24 @@
|
||||||
outputFormat.mBytesPerFrame = ((outputFormat.mBitsPerChannel + 7) / 8) * outputFormat.mChannelsPerFrame;
|
outputFormat.mBytesPerFrame = ((outputFormat.mBitsPerChannel + 7) / 8) * outputFormat.mChannelsPerFrame;
|
||||||
outputFormat.mBytesPerPacket = outputFormat.mBytesPerFrame * outputFormat.mFramesPerPacket;
|
outputFormat.mBytesPerPacket = outputFormat.mBytesPerFrame * outputFormat.mFramesPerPacket;
|
||||||
|
|
||||||
if (![converterNode setupWithInputFormat:inputFormat outputFormat:outputFormat isLossless:[[properties valueForKey:@"encoding"] isEqualToString:@"lossless"]])
|
if(![converterNode setupWithInputFormat:inputFormat outputFormat:outputFormat isLossless:[[properties valueForKey:@"encoding"] isEqualToString:@"lossless"]])
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
[self setRGInfo:rgi];
|
[self setRGInfo:rgi];
|
||||||
|
|
||||||
// return NO;
|
// return NO;
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)openWithInput:(InputNode *)i withOutputFormat:(AudioStreamBasicDescription)outputFormat withRGInfo:(NSDictionary *)rgi
|
- (BOOL)openWithInput:(InputNode *)i withOutputFormat:(AudioStreamBasicDescription)outputFormat withRGInfo:(NSDictionary *)rgi {
|
||||||
{
|
|
||||||
DLog(@"New buffer chain!");
|
DLog(@"New buffer chain!");
|
||||||
[self buildChain];
|
[self buildChain];
|
||||||
|
|
||||||
if (![inputNode openWithDecoder:[i decoder]])
|
if(![inputNode openWithDecoder:[i decoder]])
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
NSDictionary * properties = [inputNode properties];
|
NSDictionary *properties = [inputNode properties];
|
||||||
|
|
||||||
inputFormat = [inputNode nodeFormat];
|
inputFormat = [inputNode nodeFormat];
|
||||||
|
|
||||||
|
@ -98,7 +92,7 @@
|
||||||
outputFormat.mBytesPerPacket = outputFormat.mBytesPerFrame * outputFormat.mFramesPerPacket;
|
outputFormat.mBytesPerPacket = outputFormat.mBytesPerFrame * outputFormat.mFramesPerPacket;
|
||||||
|
|
||||||
DLog(@"Input Properties: %@", properties);
|
DLog(@"Input Properties: %@", properties);
|
||||||
if (![converterNode setupWithInputFormat:inputFormat outputFormat:outputFormat isLossless:[[properties objectForKey:@"encoding"] isEqualToString:@"lossless"]])
|
if(![converterNode setupWithInputFormat:inputFormat outputFormat:outputFormat isLossless:[[properties objectForKey:@"encoding"] isEqualToString:@"lossless"]])
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
[self setRGInfo:rgi];
|
[self setRGInfo:rgi];
|
||||||
|
@ -108,15 +102,15 @@
|
||||||
|
|
||||||
- (BOOL)openWithDecoder:(id<CogDecoder>)decoder
|
- (BOOL)openWithDecoder:(id<CogDecoder>)decoder
|
||||||
withOutputFormat:(AudioStreamBasicDescription)outputFormat
|
withOutputFormat:(AudioStreamBasicDescription)outputFormat
|
||||||
withRGInfo:(NSDictionary*)rgi;
|
withRGInfo:(NSDictionary *)rgi;
|
||||||
{
|
{
|
||||||
DLog(@"New buffer chain!");
|
DLog(@"New buffer chain!");
|
||||||
[self buildChain];
|
[self buildChain];
|
||||||
|
|
||||||
if (![inputNode openWithDecoder:decoder])
|
if(![inputNode openWithDecoder:decoder])
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
NSDictionary * properties = [inputNode properties];
|
NSDictionary *properties = [inputNode properties];
|
||||||
|
|
||||||
DLog(@"Input Properties: %@", properties);
|
DLog(@"Input Properties: %@", properties);
|
||||||
|
|
||||||
|
@ -126,7 +120,7 @@
|
||||||
outputFormat.mBytesPerFrame = ((outputFormat.mBitsPerChannel + 7) / 8) * outputFormat.mChannelsPerFrame;
|
outputFormat.mBytesPerFrame = ((outputFormat.mBitsPerChannel + 7) / 8) * outputFormat.mChannelsPerFrame;
|
||||||
outputFormat.mBytesPerPacket = outputFormat.mBytesPerFrame * outputFormat.mFramesPerPacket;
|
outputFormat.mBytesPerPacket = outputFormat.mBytesPerFrame * outputFormat.mFramesPerPacket;
|
||||||
|
|
||||||
if (![converterNode setupWithInputFormat:inputFormat outputFormat:outputFormat isLossless:[[properties objectForKey:@"encoding"] isEqualToString:@"lossless"]])
|
if(![converterNode setupWithInputFormat:inputFormat outputFormat:outputFormat isLossless:[[properties objectForKey:@"encoding"] isEqualToString:@"lossless"]])
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
[self setRGInfo:rgi];
|
[self setRGInfo:rgi];
|
||||||
|
@ -134,37 +128,31 @@
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)launchThreads
|
- (void)launchThreads {
|
||||||
{
|
|
||||||
DLog(@"Properties: %@", [inputNode properties]);
|
DLog(@"Properties: %@", [inputNode properties]);
|
||||||
|
|
||||||
[inputNode launchThread];
|
[inputNode launchThread];
|
||||||
[converterNode launchThread];
|
[converterNode launchThread];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setUserInfo:(id)i
|
- (void)setUserInfo:(id)i {
|
||||||
{
|
|
||||||
userInfo = i;
|
userInfo = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)userInfo
|
- (id)userInfo {
|
||||||
{
|
|
||||||
return userInfo;
|
return userInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setRGInfo:(NSDictionary *)rgi
|
- (void)setRGInfo:(NSDictionary *)rgi {
|
||||||
{
|
|
||||||
rgInfo = rgi;
|
rgInfo = rgi;
|
||||||
[converterNode setRGInfo:rgi];
|
[converterNode setRGInfo:rgi];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDictionary *)rgInfo
|
- (NSDictionary *)rgInfo {
|
||||||
{
|
|
||||||
return rgInfo;
|
return rgInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc {
|
||||||
{
|
|
||||||
[inputNode setShouldContinue:NO];
|
[inputNode setShouldContinue:NO];
|
||||||
[[inputNode exitAtTheEndOfTheStream] signal];
|
[[inputNode exitAtTheEndOfTheStream] signal];
|
||||||
[[inputNode semaphore] signal];
|
[[inputNode semaphore] signal];
|
||||||
|
@ -173,103 +161,85 @@
|
||||||
DLog(@"Bufferchain dealloc");
|
DLog(@"Bufferchain dealloc");
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)seek:(double)time
|
- (void)seek:(double)time {
|
||||||
{
|
long frame = (long)round(time * [[[inputNode properties] objectForKey:@"sampleRate"] floatValue]);
|
||||||
long frame = (long) round(time * [[[inputNode properties] objectForKey:@"sampleRate"] floatValue]);
|
|
||||||
|
|
||||||
[inputNode seek:frame];
|
[inputNode seek:frame];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)endOfInputReached
|
- (BOOL)endOfInputReached {
|
||||||
{
|
|
||||||
return [controller endOfInputReached:self];
|
return [controller endOfInputReached:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)setTrack: (NSURL *)track
|
- (BOOL)setTrack:(NSURL *)track {
|
||||||
{
|
|
||||||
return [inputNode setTrack:track];
|
return [inputNode setTrack:track];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)initialBufferFilled:(id)sender
|
- (void)initialBufferFilled:(id)sender {
|
||||||
{
|
|
||||||
DLog(@"INITIAL BUFFER FILLED");
|
DLog(@"INITIAL BUFFER FILLED");
|
||||||
[controller launchOutputThread];
|
[controller launchOutputThread];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)inputFormatDidChange:(AudioStreamBasicDescription)format
|
- (void)inputFormatDidChange:(AudioStreamBasicDescription)format {
|
||||||
{
|
|
||||||
DLog(@"FORMAT DID CHANGE!");
|
DLog(@"FORMAT DID CHANGE!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (InputNode *)inputNode {
|
||||||
- (InputNode *)inputNode
|
|
||||||
{
|
|
||||||
return inputNode;
|
return inputNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)finalNode
|
- (id)finalNode {
|
||||||
{
|
|
||||||
return finalNode;
|
return finalNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURL *)streamURL
|
- (NSURL *)streamURL {
|
||||||
{
|
|
||||||
return streamURL;
|
return streamURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setStreamURL:(NSURL *)url
|
- (void)setStreamURL:(NSURL *)url {
|
||||||
{
|
|
||||||
streamURL = url;
|
streamURL = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setShouldContinue:(BOOL)s
|
- (void)setShouldContinue:(BOOL)s {
|
||||||
{
|
|
||||||
[inputNode setShouldContinue:s];
|
[inputNode setShouldContinue:s];
|
||||||
[converterNode setShouldContinue:s];
|
[converterNode setShouldContinue:s];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)isRunning
|
- (BOOL)isRunning {
|
||||||
{
|
|
||||||
InputNode *node = [self inputNode];
|
InputNode *node = [self inputNode];
|
||||||
if (nil != node && [node shouldContinue] && ![node endOfStream])
|
if(nil != node && [node shouldContinue] && ![node endOfStream]) {
|
||||||
{
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)controller
|
- (id)controller {
|
||||||
{
|
|
||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (ConverterNode *)converter
|
- (ConverterNode *)converter {
|
||||||
{
|
|
||||||
return converterNode;
|
return converterNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (AudioStreamBasicDescription)inputFormat
|
- (AudioStreamBasicDescription)inputFormat {
|
||||||
{
|
|
||||||
return inputFormat;
|
return inputFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (double)secondsBuffered
|
- (double)secondsBuffered {
|
||||||
{
|
|
||||||
double duration = 0.0;
|
double duration = 0.0;
|
||||||
OutputNode * outputNode = (OutputNode *) [controller output];
|
OutputNode *outputNode = (OutputNode *)[controller output];
|
||||||
duration += [outputNode secondsBuffered];
|
duration += [outputNode secondsBuffered];
|
||||||
|
|
||||||
Node * node = [self finalNode];
|
Node *node = [self finalNode];
|
||||||
while (node) {
|
while(node) {
|
||||||
duration += [node secondsBuffered];
|
duration += [node secondsBuffered];
|
||||||
node = [node previousNode];
|
node = [node previousNode];
|
||||||
}
|
}
|
||||||
return duration;
|
return duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sustainHDCD
|
- (void)sustainHDCD {
|
||||||
{
|
OutputNode *outputNode = (OutputNode *)[controller output];
|
||||||
OutputNode * outputNode = (OutputNode *) [controller output];
|
|
||||||
[outputNode sustainHDCD];
|
[outputNode sustainHDCD];
|
||||||
[controller sustainHDCD];
|
[controller sustainHDCD];
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
// Created by Christopher Snowhill on 2/5/22.
|
// Created by Christopher Snowhill on 2/5/22.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#import <CoreAudio/CoreAudio.h>
|
#import <CoreAudio/CoreAudio.h>
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
#import "AudioChunk.h"
|
#import "AudioChunk.h"
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@interface ChunkList : NSObject {
|
@interface ChunkList : NSObject {
|
||||||
NSMutableArray<AudioChunk *> * chunkList;
|
NSMutableArray<AudioChunk *> *chunkList;
|
||||||
double listDuration;
|
double listDuration;
|
||||||
double maxDuration;
|
double maxDuration;
|
||||||
|
|
||||||
|
@ -24,18 +24,18 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
BOOL stopping;
|
BOOL stopping;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property (readonly) double listDuration;
|
@property(readonly) double listDuration;
|
||||||
@property (readonly) double maxDuration;
|
@property(readonly) double maxDuration;
|
||||||
|
|
||||||
- (id) initWithMaximumDuration:(double)duration;
|
- (id)initWithMaximumDuration:(double)duration;
|
||||||
|
|
||||||
- (void) reset;
|
- (void)reset;
|
||||||
|
|
||||||
- (BOOL) isEmpty;
|
- (BOOL)isEmpty;
|
||||||
- (BOOL) isFull;
|
- (BOOL)isFull;
|
||||||
|
|
||||||
- (void) addChunk:(AudioChunk *)chunk;
|
- (void)addChunk:(AudioChunk *)chunk;
|
||||||
- (AudioChunk *) removeSamples:(size_t)maxFrameCount;
|
- (AudioChunk *)removeSamples:(size_t)maxFrameCount;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,10 @@
|
||||||
@synthesize listDuration;
|
@synthesize listDuration;
|
||||||
@synthesize maxDuration;
|
@synthesize maxDuration;
|
||||||
|
|
||||||
- (id) initWithMaximumDuration:(double)duration {
|
- (id)initWithMaximumDuration:(double)duration {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
if (self) {
|
if(self) {
|
||||||
chunkList = [[NSMutableArray alloc] init];
|
chunkList = [[NSMutableArray alloc] init];
|
||||||
listDuration = 0.0;
|
listDuration = 0.0;
|
||||||
maxDuration = duration;
|
maxDuration = duration;
|
||||||
|
@ -28,32 +28,32 @@
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) dealloc {
|
- (void)dealloc {
|
||||||
stopping = YES;
|
stopping = YES;
|
||||||
while (inAdder || inRemover) {
|
while(inAdder || inRemover) {
|
||||||
usleep(500);
|
usleep(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) reset {
|
- (void)reset {
|
||||||
@synchronized (chunkList) {
|
@synchronized(chunkList) {
|
||||||
[chunkList removeAllObjects];
|
[chunkList removeAllObjects];
|
||||||
listDuration = 0.0;
|
listDuration = 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) isEmpty {
|
- (BOOL)isEmpty {
|
||||||
@synchronized (chunkList) {
|
@synchronized(chunkList) {
|
||||||
return [chunkList count] == 0;
|
return [chunkList count] == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) isFull {
|
- (BOOL)isFull {
|
||||||
return listDuration >= maxDuration;
|
return listDuration >= maxDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) addChunk:(AudioChunk *)chunk {
|
- (void)addChunk:(AudioChunk *)chunk {
|
||||||
if (stopping) return;
|
if(stopping) return;
|
||||||
|
|
||||||
inAdder = YES;
|
inAdder = YES;
|
||||||
|
|
||||||
|
@ -67,24 +67,24 @@
|
||||||
inAdder = NO;
|
inAdder = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (AudioChunk *) removeSamples:(size_t)maxFrameCount {
|
- (AudioChunk *)removeSamples:(size_t)maxFrameCount {
|
||||||
if (stopping) {
|
if(stopping) {
|
||||||
return [[AudioChunk alloc] init];
|
return [[AudioChunk alloc] init];
|
||||||
}
|
}
|
||||||
|
|
||||||
@synchronized (chunkList) {
|
@synchronized(chunkList) {
|
||||||
inRemover = YES;
|
inRemover = YES;
|
||||||
if (![chunkList count])
|
if(![chunkList count])
|
||||||
return [[AudioChunk alloc] init];
|
return [[AudioChunk alloc] init];
|
||||||
AudioChunk * chunk = [chunkList objectAtIndex:0];
|
AudioChunk *chunk = [chunkList objectAtIndex:0];
|
||||||
if ([chunk frameCount] <= maxFrameCount) {
|
if([chunk frameCount] <= maxFrameCount) {
|
||||||
[chunkList removeObjectAtIndex:0];
|
[chunkList removeObjectAtIndex:0];
|
||||||
listDuration -= [chunk duration];
|
listDuration -= [chunk duration];
|
||||||
inRemover = NO;
|
inRemover = NO;
|
||||||
return chunk;
|
return chunk;
|
||||||
}
|
}
|
||||||
NSData * removedData = [chunk removeSamples:maxFrameCount];
|
NSData *removedData = [chunk removeSamples:maxFrameCount];
|
||||||
AudioChunk * ret = [[AudioChunk alloc] init];
|
AudioChunk *ret = [[AudioChunk alloc] init];
|
||||||
[ret setFormat:[chunk format]];
|
[ret setFormat:[chunk format]];
|
||||||
[ret assignSamples:[removedData bytes] frameCount:maxFrameCount];
|
[ret assignSamples:[removedData bytes] frameCount:maxFrameCount];
|
||||||
listDuration -= [ret duration];
|
listDuration -= [ret duration];
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
#import <CoreAudio/AudioHardware.h>
|
|
||||||
#import <AudioToolbox/AudioToolbox.h>
|
#import <AudioToolbox/AudioToolbox.h>
|
||||||
#import <AudioUnit/AudioUnit.h>
|
#import <AudioUnit/AudioUnit.h>
|
||||||
|
#import <CoreAudio/AudioHardware.h>
|
||||||
|
|
||||||
#import <soxr.h>
|
#import <soxr.h>
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
#import "HeadphoneFilter.h"
|
#import "HeadphoneFilter.h"
|
||||||
|
|
||||||
@interface ConverterNode : Node {
|
@interface ConverterNode : Node {
|
||||||
NSDictionary * rgInfo;
|
NSDictionary *rgInfo;
|
||||||
|
|
||||||
soxr_t soxr;
|
soxr_t soxr;
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -6,8 +6,8 @@
|
||||||
// Copyright 2022 __LoSnoCo__. All rights reserved.
|
// Copyright 2022 __LoSnoCo__. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#import <CoreAudio/CoreAudio.h>
|
#import <CoreAudio/CoreAudio.h>
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
#import "HeadphoneFilter.h"
|
#import "HeadphoneFilter.h"
|
||||||
|
|
||||||
|
@ -18,9 +18,8 @@
|
||||||
AudioStreamBasicDescription outputFormat;
|
AudioStreamBasicDescription outputFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithInputFormat:(AudioStreamBasicDescription)inf andOutputFormat:(AudioStreamBasicDescription)outf;
|
- (id)initWithInputFormat:(AudioStreamBasicDescription)inf andOutputFormat:(AudioStreamBasicDescription)outf;
|
||||||
|
|
||||||
- (void) process:(const void*)inBuffer frameCount:(size_t)frames output:(void *)outBuffer;
|
- (void)process:(const void *)inBuffer frameCount:(size_t)frames output:(void *)outBuffer;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -10,45 +10,59 @@
|
||||||
|
|
||||||
#import "Logging.h"
|
#import "Logging.h"
|
||||||
|
|
||||||
static const float STEREO_DOWNMIX[8-2][8][2]={
|
static const float STEREO_DOWNMIX[8 - 2][8][2] = {
|
||||||
/*3.0*/
|
/*3.0*/
|
||||||
{
|
{
|
||||||
{0.5858F,0.0F},{0.0F,0.5858F},{0.4142F,0.4142F}
|
{ 0.5858F, 0.0F },
|
||||||
},
|
{ 0.0F, 0.5858F },
|
||||||
|
{ 0.4142F, 0.4142F } },
|
||||||
/*quadrophonic*/
|
/*quadrophonic*/
|
||||||
{
|
{
|
||||||
{0.4226F,0.0F},{0.0F,0.4226F},{0.366F,0.2114F},{0.2114F,0.336F}
|
{ 0.4226F, 0.0F },
|
||||||
},
|
{ 0.0F, 0.4226F },
|
||||||
|
{ 0.366F, 0.2114F },
|
||||||
|
{ 0.2114F, 0.336F } },
|
||||||
/*5.0*/
|
/*5.0*/
|
||||||
{
|
{
|
||||||
{0.651F,0.0F},{0.0F,0.651F},{0.46F,0.46F},{0.5636F,0.3254F},
|
{ 0.651F, 0.0F },
|
||||||
{0.3254F,0.5636F}
|
{ 0.0F, 0.651F },
|
||||||
},
|
{ 0.46F, 0.46F },
|
||||||
|
{ 0.5636F, 0.3254F },
|
||||||
|
{ 0.3254F, 0.5636F } },
|
||||||
/*5.1*/
|
/*5.1*/
|
||||||
{
|
{
|
||||||
{0.529F,0.0F},{0.0F,0.529F},{0.3741F,0.3741F},{0.3741F,0.3741F},{0.4582F,0.2645F},
|
{ 0.529F, 0.0F },
|
||||||
{0.2645F,0.4582F}
|
{ 0.0F, 0.529F },
|
||||||
},
|
{ 0.3741F, 0.3741F },
|
||||||
|
{ 0.3741F, 0.3741F },
|
||||||
|
{ 0.4582F, 0.2645F },
|
||||||
|
{ 0.2645F, 0.4582F } },
|
||||||
/*6.1*/
|
/*6.1*/
|
||||||
{
|
{
|
||||||
{0.4553F,0.0F},{0.0F,0.4553F},{0.322F,0.322F},{0.322F,0.322F},{0.2788F,0.2788F},
|
{ 0.4553F, 0.0F },
|
||||||
{0.3943F,0.2277F},{0.2277F,0.3943F}
|
{ 0.0F, 0.4553F },
|
||||||
},
|
{ 0.322F, 0.322F },
|
||||||
|
{ 0.322F, 0.322F },
|
||||||
|
{ 0.2788F, 0.2788F },
|
||||||
|
{ 0.3943F, 0.2277F },
|
||||||
|
{ 0.2277F, 0.3943F } },
|
||||||
/*7.1*/
|
/*7.1*/
|
||||||
{
|
{
|
||||||
{0.3886F,0.0F},{0.0F,0.3886F},{0.2748F,0.2748F},{0.2748F,0.2748F},{0.3366F,0.1943F},
|
{ 0.3886F, 0.0F },
|
||||||
{0.1943F,0.3366F},{0.3366F,0.1943F},{0.1943F,0.3366F}
|
{ 0.0F, 0.3886F },
|
||||||
}
|
{ 0.2748F, 0.2748F },
|
||||||
|
{ 0.2748F, 0.2748F },
|
||||||
|
{ 0.3366F, 0.1943F },
|
||||||
|
{ 0.1943F, 0.3366F },
|
||||||
|
{ 0.3366F, 0.1943F },
|
||||||
|
{ 0.1943F, 0.3366F } }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void downmix_to_stereo(const float * inBuffer, int channels, float * outBuffer, size_t count)
|
static void downmix_to_stereo(const float *inBuffer, int channels, float *outBuffer, size_t count) {
|
||||||
{
|
if(channels >= 3 && channels <= 8)
|
||||||
if (channels >= 3 && channels <= 8)
|
for(size_t i = 0; i < count; ++i) {
|
||||||
for (size_t i = 0; i < count; ++i)
|
|
||||||
{
|
|
||||||
float left = 0, right = 0;
|
float left = 0, right = 0;
|
||||||
for (int j = 0; j < channels; ++j)
|
for(int j = 0; j < channels; ++j) {
|
||||||
{
|
|
||||||
left += inBuffer[i * channels + j] * STEREO_DOWNMIX[channels - 3][j][0];
|
left += inBuffer[i * channels + j] * STEREO_DOWNMIX[channels - 3][j][0];
|
||||||
right += inBuffer[i * channels + j] * STEREO_DOWNMIX[channels - 3][j][1];
|
right += inBuffer[i * channels + j] * STEREO_DOWNMIX[channels - 3][j][1];
|
||||||
}
|
}
|
||||||
|
@ -57,63 +71,48 @@ static void downmix_to_stereo(const float * inBuffer, int channels, float * outB
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void downmix_to_mono(const float * inBuffer, int channels, float * outBuffer, size_t count)
|
static void downmix_to_mono(const float *inBuffer, int channels, float *outBuffer, size_t count) {
|
||||||
{
|
|
||||||
float tempBuffer[count * 2];
|
float tempBuffer[count * 2];
|
||||||
if (channels >= 3 && channels <= 8)
|
if(channels >= 3 && channels <= 8) {
|
||||||
{
|
|
||||||
downmix_to_stereo(inBuffer, channels, tempBuffer, count);
|
downmix_to_stereo(inBuffer, channels, tempBuffer, count);
|
||||||
inBuffer = tempBuffer;
|
inBuffer = tempBuffer;
|
||||||
channels = 2;
|
channels = 2;
|
||||||
}
|
}
|
||||||
float invchannels = 1.0 / (float)channels;
|
float invchannels = 1.0 / (float)channels;
|
||||||
for (size_t i = 0; i < count; ++i)
|
for(size_t i = 0; i < count; ++i) {
|
||||||
{
|
|
||||||
float sample = 0;
|
float sample = 0;
|
||||||
for (int j = 0; j < channels; ++j)
|
for(int j = 0; j < channels; ++j) {
|
||||||
{
|
|
||||||
sample += inBuffer[i * channels + j];
|
sample += inBuffer[i * channels + j];
|
||||||
}
|
}
|
||||||
outBuffer[i] = sample * invchannels;
|
outBuffer[i] = sample * invchannels;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void upmix(const float * inBuffer, int inchannels, float * outBuffer, int outchannels, size_t count)
|
static void upmix(const float *inBuffer, int inchannels, float *outBuffer, int outchannels, size_t count) {
|
||||||
{
|
for(ssize_t i = 0; i < count; ++i) {
|
||||||
for (ssize_t i = 0; i < count; ++i)
|
if(inchannels == 1 && outchannels == 2) {
|
||||||
{
|
|
||||||
if (inchannels == 1 && outchannels == 2)
|
|
||||||
{
|
|
||||||
// upmix mono to stereo
|
// upmix mono to stereo
|
||||||
float sample = inBuffer[i];
|
float sample = inBuffer[i];
|
||||||
outBuffer[i * 2 + 0] = sample;
|
outBuffer[i * 2 + 0] = sample;
|
||||||
outBuffer[i * 2 + 1] = sample;
|
outBuffer[i * 2 + 1] = sample;
|
||||||
}
|
} else if(inchannels == 1 && outchannels == 4) {
|
||||||
else if (inchannels == 1 && outchannels == 4)
|
|
||||||
{
|
|
||||||
// upmix mono to quad
|
// upmix mono to quad
|
||||||
float sample = inBuffer[i];
|
float sample = inBuffer[i];
|
||||||
outBuffer[i * 4 + 0] = sample;
|
outBuffer[i * 4 + 0] = sample;
|
||||||
outBuffer[i * 4 + 1] = sample;
|
outBuffer[i * 4 + 1] = sample;
|
||||||
outBuffer[i * 4 + 2] = 0;
|
outBuffer[i * 4 + 2] = 0;
|
||||||
outBuffer[i * 4 + 3] = 0;
|
outBuffer[i * 4 + 3] = 0;
|
||||||
}
|
} else if(inchannels == 1 && (outchannels == 3 || outchannels >= 5)) {
|
||||||
else if (inchannels == 1 && (outchannels == 3 || outchannels >= 5))
|
|
||||||
{
|
|
||||||
// upmix mono to center channel
|
// upmix mono to center channel
|
||||||
float sample = inBuffer[i];
|
float sample = inBuffer[i];
|
||||||
outBuffer[i * outchannels + 2] = sample;
|
outBuffer[i * outchannels + 2] = sample;
|
||||||
for (int j = 0; j < 2; ++j)
|
for(int j = 0; j < 2; ++j) {
|
||||||
{
|
|
||||||
outBuffer[i * outchannels + j] = 0;
|
outBuffer[i * outchannels + j] = 0;
|
||||||
}
|
}
|
||||||
for (int j = 3; j < outchannels; ++j)
|
for(int j = 3; j < outchannels; ++j) {
|
||||||
{
|
|
||||||
outBuffer[i * outchannels + j] = 0;
|
outBuffer[i * outchannels + j] = 0;
|
||||||
}
|
}
|
||||||
}
|
} else if(inchannels == 4 && outchannels >= 5) {
|
||||||
else if (inchannels == 4 && outchannels >= 5)
|
|
||||||
{
|
|
||||||
float fl = inBuffer[i * 4 + 0];
|
float fl = inBuffer[i * 4 + 0];
|
||||||
float fr = inBuffer[i * 4 + 1];
|
float fr = inBuffer[i * 4 + 1];
|
||||||
float bl = inBuffer[i * 4 + 2];
|
float bl = inBuffer[i * 4 + 2];
|
||||||
|
@ -123,17 +122,13 @@ static void upmix(const float * inBuffer, int inchannels, float * outBuffer, int
|
||||||
outBuffer[i * outchannels + 1] = fr;
|
outBuffer[i * outchannels + 1] = fr;
|
||||||
outBuffer[i * outchannels + skipclfe + 2] = bl;
|
outBuffer[i * outchannels + skipclfe + 2] = bl;
|
||||||
outBuffer[i * outchannels + skipclfe + 3] = br;
|
outBuffer[i * outchannels + skipclfe + 3] = br;
|
||||||
for (int j = 0; j < skipclfe; ++j)
|
for(int j = 0; j < skipclfe; ++j) {
|
||||||
{
|
|
||||||
outBuffer[i * outchannels + 2 + j] = 0;
|
outBuffer[i * outchannels + 2 + j] = 0;
|
||||||
}
|
}
|
||||||
for (int j = 4 + skipclfe; j < outchannels; ++j)
|
for(int j = 4 + skipclfe; j < outchannels; ++j) {
|
||||||
{
|
|
||||||
outBuffer[i * outchannels + j] = 0;
|
outBuffer[i * outchannels + j] = 0;
|
||||||
}
|
}
|
||||||
}
|
} else if(inchannels == 5 && outchannels >= 6) {
|
||||||
else if (inchannels == 5 && outchannels >= 6)
|
|
||||||
{
|
|
||||||
float fl = inBuffer[i * 5 + 0];
|
float fl = inBuffer[i * 5 + 0];
|
||||||
float fr = inBuffer[i * 5 + 1];
|
float fr = inBuffer[i * 5 + 1];
|
||||||
float c = inBuffer[i * 5 + 2];
|
float c = inBuffer[i * 5 + 2];
|
||||||
|
@ -145,13 +140,10 @@ static void upmix(const float * inBuffer, int inchannels, float * outBuffer, int
|
||||||
outBuffer[i * outchannels + 3] = 0;
|
outBuffer[i * outchannels + 3] = 0;
|
||||||
outBuffer[i * outchannels + 4] = bl;
|
outBuffer[i * outchannels + 4] = bl;
|
||||||
outBuffer[i * outchannels + 5] = br;
|
outBuffer[i * outchannels + 5] = br;
|
||||||
for (int j = 6; j < outchannels; ++j)
|
for(int j = 6; j < outchannels; ++j) {
|
||||||
{
|
|
||||||
outBuffer[i * outchannels + j] = 0;
|
outBuffer[i * outchannels + j] = 0;
|
||||||
}
|
}
|
||||||
}
|
} else if(inchannels == 7 && outchannels == 8) {
|
||||||
else if (inchannels == 7 && outchannels == 8)
|
|
||||||
{
|
|
||||||
float fl = inBuffer[i * 7 + 0];
|
float fl = inBuffer[i * 7 + 0];
|
||||||
float fr = inBuffer[i * 7 + 1];
|
float fr = inBuffer[i * 7 + 1];
|
||||||
float c = inBuffer[i * 7 + 2];
|
float c = inBuffer[i * 7 + 2];
|
||||||
|
@ -167,21 +159,16 @@ static void upmix(const float * inBuffer, int inchannels, float * outBuffer, int
|
||||||
outBuffer[i * 8 + 5] = bc;
|
outBuffer[i * 8 + 5] = bc;
|
||||||
outBuffer[i * 8 + 6] = sl;
|
outBuffer[i * 8 + 6] = sl;
|
||||||
outBuffer[i * 8 + 7] = sr;
|
outBuffer[i * 8 + 7] = sr;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// upmix N channels to N channels plus silence the empty channels
|
// upmix N channels to N channels plus silence the empty channels
|
||||||
float samples[inchannels];
|
float samples[inchannels];
|
||||||
for (int j = 0; j < inchannels; ++j)
|
for(int j = 0; j < inchannels; ++j) {
|
||||||
{
|
|
||||||
samples[j] = inBuffer[i * inchannels + j];
|
samples[j] = inBuffer[i * inchannels + j];
|
||||||
}
|
}
|
||||||
for (int j = 0; j < inchannels; ++j)
|
for(int j = 0; j < inchannels; ++j) {
|
||||||
{
|
|
||||||
outBuffer[i * outchannels + j] = samples[j];
|
outBuffer[i * outchannels + j] = samples[j];
|
||||||
}
|
}
|
||||||
for (int j = inchannels; j < outchannels; ++j)
|
for(int j = inchannels; j < outchannels; ++j) {
|
||||||
{
|
|
||||||
outBuffer[i * outchannels + j] = 0;
|
outBuffer[i * outchannels + j] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,18 +177,18 @@ static void upmix(const float * inBuffer, int inchannels, float * outBuffer, int
|
||||||
|
|
||||||
@implementation DownmixProcessor
|
@implementation DownmixProcessor
|
||||||
|
|
||||||
- (id) initWithInputFormat:(AudioStreamBasicDescription)inf andOutputFormat:(AudioStreamBasicDescription)outf {
|
- (id)initWithInputFormat:(AudioStreamBasicDescription)inf andOutputFormat:(AudioStreamBasicDescription)outf {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
if (self) {
|
if(self) {
|
||||||
if (inf.mFormatID != kAudioFormatLinearPCM ||
|
if(inf.mFormatID != kAudioFormatLinearPCM ||
|
||||||
(inf.mFormatFlags & kAudioFormatFlagsNativeFloatPacked) != kAudioFormatFlagsNativeFloatPacked ||
|
(inf.mFormatFlags & kAudioFormatFlagsNativeFloatPacked) != kAudioFormatFlagsNativeFloatPacked ||
|
||||||
inf.mBitsPerChannel != 32 ||
|
inf.mBitsPerChannel != 32 ||
|
||||||
inf.mBytesPerFrame != (4 * inf.mChannelsPerFrame) ||
|
inf.mBytesPerFrame != (4 * inf.mChannelsPerFrame) ||
|
||||||
inf.mBytesPerPacket != inf.mFramesPerPacket * inf.mBytesPerFrame)
|
inf.mBytesPerPacket != inf.mFramesPerPacket * inf.mBytesPerFrame)
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
if (outf.mFormatID != kAudioFormatLinearPCM ||
|
if(outf.mFormatID != kAudioFormatLinearPCM ||
|
||||||
(outf.mFormatFlags & kAudioFormatFlagsNativeFloatPacked) != kAudioFormatFlagsNativeFloatPacked ||
|
(outf.mFormatFlags & kAudioFormatFlagsNativeFloatPacked) != kAudioFormatFlagsNativeFloatPacked ||
|
||||||
outf.mBitsPerChannel != 32 ||
|
outf.mBitsPerChannel != 32 ||
|
||||||
outf.mBytesPerFrame != (4 * outf.mChannelsPerFrame) ||
|
outf.mBytesPerFrame != (4 * outf.mChannelsPerFrame) ||
|
||||||
|
@ -220,39 +207,39 @@ static void upmix(const float * inBuffer, int inchannels, float * outBuffer, int
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) dealloc {
|
- (void)dealloc {
|
||||||
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.headphoneVirtualization"];
|
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.headphoneVirtualization"];
|
||||||
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.hrirPath"];
|
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.hrirPath"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setupVirt {
|
- (void)setupVirt {
|
||||||
@synchronized(hFilter) {
|
@synchronized(hFilter) {
|
||||||
hFilter = nil;
|
hFilter = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL hVirt = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"headphoneVirtualization"];
|
BOOL hVirt = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"headphoneVirtualization"];
|
||||||
|
|
||||||
if (hVirt &&
|
if(hVirt &&
|
||||||
outputFormat.mChannelsPerFrame == 2 &&
|
outputFormat.mChannelsPerFrame == 2 &&
|
||||||
inputFormat.mChannelsPerFrame >= 1 &&
|
inputFormat.mChannelsPerFrame >= 1 &&
|
||||||
inputFormat.mChannelsPerFrame <= 8) {
|
inputFormat.mChannelsPerFrame <= 8) {
|
||||||
NSString * userPreset = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] stringForKey:@"hrirPath"];
|
NSString *userPreset = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] stringForKey:@"hrirPath"];
|
||||||
|
|
||||||
NSURL * presetUrl = nil;
|
NSURL *presetUrl = nil;
|
||||||
|
|
||||||
if (userPreset && ![userPreset isEqualToString:@""]) {
|
if(userPreset && ![userPreset isEqualToString:@""]) {
|
||||||
presetUrl = [NSURL fileURLWithPath:userPreset];
|
presetUrl = [NSURL fileURLWithPath:userPreset];
|
||||||
if (![HeadphoneFilter validateImpulseFile:presetUrl])
|
if(![HeadphoneFilter validateImpulseFile:presetUrl])
|
||||||
presetUrl = nil;
|
presetUrl = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!presetUrl) {
|
if(!presetUrl) {
|
||||||
presetUrl = [[NSBundle mainBundle] URLForResource:@"gsx" withExtension:@"wv"];
|
presetUrl = [[NSBundle mainBundle] URLForResource:@"gsx" withExtension:@"wv"];
|
||||||
if (![HeadphoneFilter validateImpulseFile:presetUrl])
|
if(![HeadphoneFilter validateImpulseFile:presetUrl])
|
||||||
presetUrl = nil;
|
presetUrl = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (presetUrl) {
|
if(presetUrl) {
|
||||||
@synchronized(hFilter) {
|
@synchronized(hFilter) {
|
||||||
hFilter = [[HeadphoneFilter alloc] initWithImpulseFile:presetUrl forSampleRate:outputFormat.mSampleRate withInputChannels:inputFormat.mChannelsPerFrame];
|
hFilter = [[HeadphoneFilter alloc] initWithImpulseFile:presetUrl forSampleRate:outputFormat.mSampleRate withInputChannels:inputFormat.mChannelsPerFrame];
|
||||||
}
|
}
|
||||||
|
@ -263,41 +250,32 @@ static void upmix(const float * inBuffer, int inchannels, float * outBuffer, int
|
||||||
- (void)observeValueForKeyPath:(NSString *)keyPath
|
- (void)observeValueForKeyPath:(NSString *)keyPath
|
||||||
ofObject:(id)object
|
ofObject:(id)object
|
||||||
change:(NSDictionary *)change
|
change:(NSDictionary *)change
|
||||||
context:(void *)context
|
context:(void *)context {
|
||||||
{
|
|
||||||
DLog(@"SOMETHING CHANGED!");
|
DLog(@"SOMETHING CHANGED!");
|
||||||
if ([keyPath isEqualToString:@"values.headphoneVirtualization"] ||
|
if([keyPath isEqualToString:@"values.headphoneVirtualization"] ||
|
||||||
[keyPath isEqualToString:@"values.hrirPath"]) {
|
[keyPath isEqualToString:@"values.hrirPath"]) {
|
||||||
// Reset the converter, without rebuffering
|
// Reset the converter, without rebuffering
|
||||||
[self setupVirt];
|
[self setupVirt];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) process:(const void *)inBuffer frameCount:(size_t)frames output:(void *)outBuffer {
|
- (void)process:(const void *)inBuffer frameCount:(size_t)frames output:(void *)outBuffer {
|
||||||
@synchronized (hFilter) {
|
@synchronized(hFilter) {
|
||||||
if ( hFilter ) {
|
if(hFilter) {
|
||||||
[hFilter process:(const float *) inBuffer sampleCount:frames toBuffer:(float *) outBuffer];
|
[hFilter process:(const float *)inBuffer sampleCount:frames toBuffer:(float *)outBuffer];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( inputFormat.mChannelsPerFrame > 2 && outputFormat.mChannelsPerFrame == 2 )
|
if(inputFormat.mChannelsPerFrame > 2 && outputFormat.mChannelsPerFrame == 2) {
|
||||||
{
|
downmix_to_stereo((const float *)inBuffer, inputFormat.mChannelsPerFrame, (float *)outBuffer, frames);
|
||||||
downmix_to_stereo( (const float*) inBuffer, inputFormat.mChannelsPerFrame, (float*) outBuffer, frames );
|
} else if(inputFormat.mChannelsPerFrame > 1 && outputFormat.mChannelsPerFrame == 1) {
|
||||||
}
|
downmix_to_mono((const float *)inBuffer, inputFormat.mChannelsPerFrame, (float *)outBuffer, frames);
|
||||||
else if ( inputFormat.mChannelsPerFrame > 1 && outputFormat.mChannelsPerFrame == 1 )
|
} else if(inputFormat.mChannelsPerFrame < outputFormat.mChannelsPerFrame) {
|
||||||
{
|
upmix((const float *)inBuffer, inputFormat.mChannelsPerFrame, (float *)outBuffer, outputFormat.mChannelsPerFrame, frames);
|
||||||
downmix_to_mono( (const float*) inBuffer, inputFormat.mChannelsPerFrame, (float*) outBuffer, frames );
|
} else if(inputFormat.mChannelsPerFrame == outputFormat.mChannelsPerFrame) {
|
||||||
}
|
|
||||||
else if ( inputFormat.mChannelsPerFrame < outputFormat.mChannelsPerFrame )
|
|
||||||
{
|
|
||||||
upmix( (const float*) inBuffer, inputFormat.mChannelsPerFrame, (float*) outBuffer, outputFormat.mChannelsPerFrame, frames );
|
|
||||||
}
|
|
||||||
else if ( inputFormat.mChannelsPerFrame == outputFormat.mChannelsPerFrame )
|
|
||||||
{
|
|
||||||
memcpy(outBuffer, inBuffer, frames * outputFormat.mBytesPerPacket);
|
memcpy(outBuffer, inBuffer, frames * outputFormat.mBytesPerPacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
#ifndef HeadphoneFilter_h
|
#ifndef HeadphoneFilter_h
|
||||||
#define HeadphoneFilter_h
|
#define HeadphoneFilter_h
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
|
||||||
#import <Accelerate/Accelerate.h>
|
#import <Accelerate/Accelerate.h>
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
@interface HeadphoneFilter : NSObject {
|
@interface HeadphoneFilter : NSObject {
|
||||||
FFTSetup fftSetup;
|
FFTSetup fftSetup;
|
||||||
|
@ -24,18 +24,18 @@
|
||||||
|
|
||||||
COMPLEX_SPLIT signal_fft;
|
COMPLEX_SPLIT signal_fft;
|
||||||
COMPLEX_SPLIT input_filtered_signal_per_channel[2];
|
COMPLEX_SPLIT input_filtered_signal_per_channel[2];
|
||||||
COMPLEX_SPLIT * impulse_responses;
|
COMPLEX_SPLIT *impulse_responses;
|
||||||
|
|
||||||
float * left_result;
|
float *left_result;
|
||||||
float * right_result;
|
float *right_result;
|
||||||
|
|
||||||
float * left_mix_result;
|
float *left_mix_result;
|
||||||
float * right_mix_result;
|
float *right_mix_result;
|
||||||
|
|
||||||
float * paddedSignal;
|
float *paddedSignal;
|
||||||
|
|
||||||
float * prevOverlapLeft;
|
float *prevOverlapLeft;
|
||||||
float * prevOverlapRight;
|
float *prevOverlapRight;
|
||||||
|
|
||||||
int prevOverlapLength;
|
int prevOverlapLength;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@
|
||||||
|
|
||||||
- (id)initWithImpulseFile:(NSURL *)url forSampleRate:(double)sampleRate withInputChannels:(size_t)channels;
|
- (id)initWithImpulseFile:(NSURL *)url forSampleRate:(double)sampleRate withInputChannels:(size_t)channels;
|
||||||
|
|
||||||
- (void)process:(const float*)inBuffer sampleCount:(size_t)count toBuffer:(float *)outBuffer;
|
- (void)process:(const float *)inBuffer sampleCount:(size_t)count toBuffer:(float *)outBuffer;
|
||||||
|
|
||||||
- (void)reset;
|
- (void)reset;
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,11 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "HeadphoneFilter.h"
|
#import "HeadphoneFilter.h"
|
||||||
#import "AudioSource.h"
|
|
||||||
#import "AudioDecoder.h"
|
#import "AudioDecoder.h"
|
||||||
|
#import "AudioSource.h"
|
||||||
|
|
||||||
#import <soxr.h>
|
|
||||||
#import <mm_malloc.h>
|
#import <mm_malloc.h>
|
||||||
|
#import <soxr.h>
|
||||||
|
|
||||||
#import "lpc.h"
|
#import "lpc.h"
|
||||||
#import "util.h"
|
#import "util.h"
|
||||||
|
@ -59,22 +59,21 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
|
|
||||||
+ (BOOL)validateImpulseFile:(NSURL *)url {
|
+ (BOOL)validateImpulseFile:(NSURL *)url {
|
||||||
id<CogSource> source = [AudioSource audioSourceForURL:url];
|
id<CogSource> source = [AudioSource audioSourceForURL:url];
|
||||||
if (!source)
|
if(!source)
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
if (![source open:url])
|
if(![source open:url])
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
id<CogDecoder> decoder = [AudioDecoder audioDecoderForSource:source];
|
id<CogDecoder> decoder = [AudioDecoder audioDecoderForSource:source];
|
||||||
|
|
||||||
if (decoder == nil) {
|
if(decoder == nil) {
|
||||||
[source close];
|
[source close];
|
||||||
source = nil;
|
source = nil;
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (![decoder open:source])
|
if(![decoder open:source]) {
|
||||||
{
|
|
||||||
decoder = nil;
|
decoder = nil;
|
||||||
[source close];
|
[source close];
|
||||||
source = nil;
|
source = nil;
|
||||||
|
@ -90,7 +89,7 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
|
|
||||||
int impulseChannels = [[properties objectForKey:@"channels"] intValue];
|
int impulseChannels = [[properties objectForKey:@"channels"] intValue];
|
||||||
|
|
||||||
if ([[properties objectForKey:@"floatingPoint"] boolValue] != YES ||
|
if([[properties objectForKey:@"floatingPoint"] boolValue] != YES ||
|
||||||
[[properties objectForKey:@"bitsPerSample"] intValue] != 32 ||
|
[[properties objectForKey:@"bitsPerSample"] intValue] != 32 ||
|
||||||
!([[properties objectForKey:@"endian"] isEqualToString:@"host"] ||
|
!([[properties objectForKey:@"endian"] isEqualToString:@"host"] ||
|
||||||
[[properties objectForKey:@"endian"] isEqualToString:@"little"]) ||
|
[[properties objectForKey:@"endian"] isEqualToString:@"little"]) ||
|
||||||
|
@ -103,24 +102,23 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
- (id)initWithImpulseFile:(NSURL *)url forSampleRate:(double)sampleRate withInputChannels:(size_t)channels {
|
- (id)initWithImpulseFile:(NSURL *)url forSampleRate:(double)sampleRate withInputChannels:(size_t)channels {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
if (self) {
|
if(self) {
|
||||||
id<CogSource> source = [AudioSource audioSourceForURL:url];
|
id<CogSource> source = [AudioSource audioSourceForURL:url];
|
||||||
if (!source)
|
if(!source)
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
if (![source open:url])
|
if(![source open:url])
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
id<CogDecoder> decoder = [AudioDecoder audioDecoderForSource:source];
|
id<CogDecoder> decoder = [AudioDecoder audioDecoderForSource:source];
|
||||||
|
|
||||||
if (decoder == nil) {
|
if(decoder == nil) {
|
||||||
[source close];
|
[source close];
|
||||||
source = nil;
|
source = nil;
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (![decoder open:source])
|
if(![decoder open:source]) {
|
||||||
{
|
|
||||||
decoder = nil;
|
decoder = nil;
|
||||||
[source close];
|
[source close];
|
||||||
source = nil;
|
source = nil;
|
||||||
|
@ -134,7 +132,7 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
int sampleCount = [[properties objectForKey:@"totalFrames"] intValue];
|
int sampleCount = [[properties objectForKey:@"totalFrames"] intValue];
|
||||||
int impulseChannels = [[properties objectForKey:@"channels"] intValue];
|
int impulseChannels = [[properties objectForKey:@"channels"] intValue];
|
||||||
|
|
||||||
if ([[properties objectForKey:@"floatingPoint"] boolValue] != YES ||
|
if([[properties objectForKey:@"floatingPoint"] boolValue] != YES ||
|
||||||
[[properties objectForKey:@"bitsPerSample"] intValue] != 32 ||
|
[[properties objectForKey:@"bitsPerSample"] intValue] != 32 ||
|
||||||
!([[properties objectForKey:@"endian"] isEqualToString:@"host"] ||
|
!([[properties objectForKey:@"endian"] isEqualToString:@"host"] ||
|
||||||
[[properties objectForKey:@"endian"] isEqualToString:@"little"]) ||
|
[[properties objectForKey:@"endian"] isEqualToString:@"little"]) ||
|
||||||
|
@ -146,8 +144,8 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
float * impulseBuffer = (float *) malloc(sampleCount * sizeof(float) * impulseChannels);
|
float *impulseBuffer = (float *)malloc(sampleCount * sizeof(float) * impulseChannels);
|
||||||
if (!impulseBuffer) {
|
if(!impulseBuffer) {
|
||||||
[decoder close];
|
[decoder close];
|
||||||
decoder = nil;
|
decoder = nil;
|
||||||
[source close];
|
[source close];
|
||||||
|
@ -155,7 +153,7 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([decoder readAudio:impulseBuffer frames:sampleCount] != sampleCount) {
|
if([decoder readAudio:impulseBuffer frames:sampleCount] != sampleCount) {
|
||||||
[decoder close];
|
[decoder close];
|
||||||
decoder = nil;
|
decoder = nil;
|
||||||
[source close];
|
[source close];
|
||||||
|
@ -168,7 +166,7 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
[source close];
|
[source close];
|
||||||
source = nil;
|
source = nil;
|
||||||
|
|
||||||
if (sampleRateOfSource != sampleRate) {
|
if(sampleRateOfSource != sampleRate) {
|
||||||
double sampleRatio = sampleRate / sampleRateOfSource;
|
double sampleRatio = sampleRate / sampleRateOfSource;
|
||||||
int resampledCount = (int)ceil((double)sampleCount * sampleRatio);
|
int resampledCount = (int)ceil((double)sampleCount * sampleRatio);
|
||||||
|
|
||||||
|
@ -178,20 +176,20 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
|
|
||||||
soxr_error_t error;
|
soxr_error_t error;
|
||||||
|
|
||||||
unsigned long PRIME_LEN_ = MAX(sampleRateOfSource/20, 1024u);
|
unsigned long PRIME_LEN_ = MAX(sampleRateOfSource / 20, 1024u);
|
||||||
PRIME_LEN_ = MIN(PRIME_LEN_, 16384u);
|
PRIME_LEN_ = MIN(PRIME_LEN_, 16384u);
|
||||||
PRIME_LEN_ = MAX(PRIME_LEN_, 2*LPC_ORDER + 1);
|
PRIME_LEN_ = MAX(PRIME_LEN_, 2 * LPC_ORDER + 1);
|
||||||
|
|
||||||
unsigned int N_samples_to_add_ = sampleRateOfSource;
|
unsigned int N_samples_to_add_ = sampleRateOfSource;
|
||||||
unsigned int N_samples_to_drop_ = sampleRate;
|
unsigned int N_samples_to_drop_ = sampleRate;
|
||||||
|
|
||||||
samples_len(&N_samples_to_add_, &N_samples_to_drop_, 20, 8192u);
|
samples_len(&N_samples_to_add_, &N_samples_to_drop_, 20, 8192u);
|
||||||
|
|
||||||
int resamplerLatencyIn = (int) N_samples_to_add_;
|
int resamplerLatencyIn = (int)N_samples_to_add_;
|
||||||
int resamplerLatencyOut = (int) N_samples_to_drop_;
|
int resamplerLatencyOut = (int)N_samples_to_drop_;
|
||||||
|
|
||||||
float * tempImpulse = (float *) realloc(impulseBuffer, (sampleCount + resamplerLatencyIn * 2 + 1024) * sizeof(float) * impulseChannels);
|
float *tempImpulse = (float *)realloc(impulseBuffer, (sampleCount + resamplerLatencyIn * 2 + 1024) * sizeof(float) * impulseChannels);
|
||||||
if (!tempImpulse) {
|
if(!tempImpulse) {
|
||||||
free(impulseBuffer);
|
free(impulseBuffer);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
@ -200,15 +198,15 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
|
|
||||||
resampledCount += resamplerLatencyOut * 2 + 1024;
|
resampledCount += resamplerLatencyOut * 2 + 1024;
|
||||||
|
|
||||||
float * resampledImpulse = (float *) malloc(resampledCount * sizeof(float) * impulseChannels);
|
float *resampledImpulse = (float *)malloc(resampledCount * sizeof(float) * impulseChannels);
|
||||||
if (!resampledImpulse) {
|
if(!resampledImpulse) {
|
||||||
free(impulseBuffer);
|
free(impulseBuffer);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t prime = MIN(sampleCount, PRIME_LEN_);
|
size_t prime = MIN(sampleCount, PRIME_LEN_);
|
||||||
|
|
||||||
void * extrapolate_buffer = NULL;
|
void *extrapolate_buffer = NULL;
|
||||||
size_t extrapolate_buffer_size = 0;
|
size_t extrapolate_buffer_size = 0;
|
||||||
|
|
||||||
memmove(impulseBuffer + resamplerLatencyIn * impulseChannels, impulseBuffer, sampleCount * sizeof(float) * impulseChannels);
|
memmove(impulseBuffer + resamplerLatencyIn * impulseChannels, impulseBuffer, sampleCount * sizeof(float) * impulseChannels);
|
||||||
|
@ -221,7 +219,7 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
|
|
||||||
error = soxr_oneshot(sampleRateOfSource, sampleRate, impulseChannels, impulseBuffer, sampleCount + N_samples_to_add_ * 2, &inputDone, resampledImpulse, resampledCount, &outputDone, &io_spec, &q_spec, &runtime_spec);
|
error = soxr_oneshot(sampleRateOfSource, sampleRate, impulseChannels, impulseBuffer, sampleCount + N_samples_to_add_ * 2, &inputDone, resampledImpulse, resampledCount, &outputDone, &io_spec, &q_spec, &runtime_spec);
|
||||||
|
|
||||||
if (error) {
|
if(error) {
|
||||||
free(resampledImpulse);
|
free(resampledImpulse);
|
||||||
free(impulseBuffer);
|
free(impulseBuffer);
|
||||||
return nil;
|
return nil;
|
||||||
|
@ -233,7 +231,7 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
|
|
||||||
free(impulseBuffer);
|
free(impulseBuffer);
|
||||||
impulseBuffer = resampledImpulse;
|
impulseBuffer = resampledImpulse;
|
||||||
sampleCount = (int) outputDone;
|
sampleCount = (int)outputDone;
|
||||||
}
|
}
|
||||||
|
|
||||||
channelCount = channels;
|
channelCount = channels;
|
||||||
|
@ -242,16 +240,19 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
fftSize = sampleCount + bufferSize;
|
fftSize = sampleCount + bufferSize;
|
||||||
|
|
||||||
int pow = 1;
|
int pow = 1;
|
||||||
while (fftSize > 2) { pow++; fftSize /= 2; }
|
while(fftSize > 2) {
|
||||||
|
pow++;
|
||||||
|
fftSize /= 2;
|
||||||
|
}
|
||||||
fftSize = 2 << pow;
|
fftSize = 2 << pow;
|
||||||
|
|
||||||
float * deinterleavedImpulseBuffer = (float *) _mm_malloc(fftSize * sizeof(float) * impulseChannels, 16);
|
float *deinterleavedImpulseBuffer = (float *)_mm_malloc(fftSize * sizeof(float) * impulseChannels, 16);
|
||||||
if (!deinterleavedImpulseBuffer) {
|
if(!deinterleavedImpulseBuffer) {
|
||||||
free(impulseBuffer);
|
free(impulseBuffer);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < impulseChannels; ++i) {
|
for(size_t i = 0; i < impulseChannels; ++i) {
|
||||||
cblas_scopy(sampleCount, impulseBuffer + i, impulseChannels, deinterleavedImpulseBuffer + i * fftSize, 1);
|
cblas_scopy(sampleCount, impulseBuffer + i, impulseChannels, deinterleavedImpulseBuffer + i * fftSize, 1);
|
||||||
vDSP_vclr(deinterleavedImpulseBuffer + i * fftSize + sampleCount, 1, fftSize - sampleCount);
|
vDSP_vclr(deinterleavedImpulseBuffer + i * fftSize + sampleCount, 1, fftSize - sampleCount);
|
||||||
}
|
}
|
||||||
|
@ -264,53 +265,53 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
log2nhalf = log2n / 2;
|
log2nhalf = log2n / 2;
|
||||||
|
|
||||||
fftSetup = vDSP_create_fftsetup(log2n, FFT_RADIX2);
|
fftSetup = vDSP_create_fftsetup(log2n, FFT_RADIX2);
|
||||||
if (!fftSetup) {
|
if(!fftSetup) {
|
||||||
_mm_free(deinterleavedImpulseBuffer);
|
_mm_free(deinterleavedImpulseBuffer);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
paddedSignal = (float *) _mm_malloc(sizeof(float) * paddedBufferSize, 16);
|
paddedSignal = (float *)_mm_malloc(sizeof(float) * paddedBufferSize, 16);
|
||||||
if (!paddedSignal) {
|
if(!paddedSignal) {
|
||||||
_mm_free(deinterleavedImpulseBuffer);
|
_mm_free(deinterleavedImpulseBuffer);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
signal_fft.realp = (float *) _mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
signal_fft.realp = (float *)_mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
||||||
signal_fft.imagp = (float *) _mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
signal_fft.imagp = (float *)_mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
||||||
if (!signal_fft.realp || !signal_fft.imagp) {
|
if(!signal_fft.realp || !signal_fft.imagp) {
|
||||||
_mm_free(deinterleavedImpulseBuffer);
|
_mm_free(deinterleavedImpulseBuffer);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
input_filtered_signal_per_channel[0].realp = (float *) _mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
input_filtered_signal_per_channel[0].realp = (float *)_mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
||||||
input_filtered_signal_per_channel[0].imagp = (float *) _mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
input_filtered_signal_per_channel[0].imagp = (float *)_mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
||||||
if (!input_filtered_signal_per_channel[0].realp ||
|
if(!input_filtered_signal_per_channel[0].realp ||
|
||||||
!input_filtered_signal_per_channel[0].imagp) {
|
!input_filtered_signal_per_channel[0].imagp) {
|
||||||
_mm_free(deinterleavedImpulseBuffer);
|
_mm_free(deinterleavedImpulseBuffer);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
input_filtered_signal_per_channel[1].realp = (float *) _mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
input_filtered_signal_per_channel[1].realp = (float *)_mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
||||||
input_filtered_signal_per_channel[1].imagp = (float *) _mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
input_filtered_signal_per_channel[1].imagp = (float *)_mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
||||||
if (!input_filtered_signal_per_channel[1].realp ||
|
if(!input_filtered_signal_per_channel[1].realp ||
|
||||||
!input_filtered_signal_per_channel[1].imagp) {
|
!input_filtered_signal_per_channel[1].imagp) {
|
||||||
_mm_free(deinterleavedImpulseBuffer);
|
_mm_free(deinterleavedImpulseBuffer);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
impulse_responses = (COMPLEX_SPLIT *) calloc(sizeof(COMPLEX_SPLIT), channels * 2);
|
impulse_responses = (COMPLEX_SPLIT *)calloc(sizeof(COMPLEX_SPLIT), channels * 2);
|
||||||
if (!impulse_responses) {
|
if(!impulse_responses) {
|
||||||
_mm_free(deinterleavedImpulseBuffer);
|
_mm_free(deinterleavedImpulseBuffer);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < channels; ++i) {
|
for(size_t i = 0; i < channels; ++i) {
|
||||||
impulse_responses[i * 2 + 0].realp = (float *) _mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
impulse_responses[i * 2 + 0].realp = (float *)_mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
||||||
impulse_responses[i * 2 + 0].imagp = (float *) _mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
impulse_responses[i * 2 + 0].imagp = (float *)_mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
||||||
impulse_responses[i * 2 + 1].realp = (float *) _mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
impulse_responses[i * 2 + 1].realp = (float *)_mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
||||||
impulse_responses[i * 2 + 1].imagp = (float *) _mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
impulse_responses[i * 2 + 1].imagp = (float *)_mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
||||||
|
|
||||||
if (!impulse_responses[i * 2 + 0].realp || !impulse_responses[i * 2 + 0].imagp ||
|
if(!impulse_responses[i * 2 + 0].realp || !impulse_responses[i * 2 + 0].imagp ||
|
||||||
!impulse_responses[i * 2 + 1].realp || !impulse_responses[i * 2 + 1].imagp) {
|
!impulse_responses[i * 2 + 1].realp || !impulse_responses[i * 2 + 1].imagp) {
|
||||||
_mm_free(deinterleavedImpulseBuffer);
|
_mm_free(deinterleavedImpulseBuffer);
|
||||||
return nil;
|
return nil;
|
||||||
|
@ -319,20 +320,19 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
int leftInChannel;
|
int leftInChannel;
|
||||||
int rightInChannel;
|
int rightInChannel;
|
||||||
|
|
||||||
if (impulseChannels == 7) {
|
if(impulseChannels == 7) {
|
||||||
leftInChannel = speakers_to_hesuvi_7[channels-1][0][i];
|
leftInChannel = speakers_to_hesuvi_7[channels - 1][0][i];
|
||||||
rightInChannel = speakers_to_hesuvi_7[channels-1][1][i];
|
rightInChannel = speakers_to_hesuvi_7[channels - 1][1][i];
|
||||||
}
|
} else {
|
||||||
else {
|
leftInChannel = speakers_to_hesuvi_14[channels - 1][0][i];
|
||||||
leftInChannel = speakers_to_hesuvi_14[channels-1][0][i];
|
rightInChannel = speakers_to_hesuvi_14[channels - 1][1][i];
|
||||||
rightInChannel = speakers_to_hesuvi_14[channels-1][1][i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (leftInChannel == -1 || rightInChannel == -1) {
|
if(leftInChannel == -1 || rightInChannel == -1) {
|
||||||
float * temp;
|
float *temp;
|
||||||
if (impulseChannels == 7) {
|
if(impulseChannels == 7) {
|
||||||
temp = (float *) malloc(sizeof(float) * fftSize);
|
temp = (float *)malloc(sizeof(float) * fftSize);
|
||||||
if (!temp) {
|
if(!temp) {
|
||||||
_mm_free(deinterleavedImpulseBuffer);
|
_mm_free(deinterleavedImpulseBuffer);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
@ -342,10 +342,9 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
|
|
||||||
vDSP_ctoz((DSPComplex *)temp, 2, &impulse_responses[i * 2 + 0], 1, fftSizeOver2);
|
vDSP_ctoz((DSPComplex *)temp, 2, &impulse_responses[i * 2 + 0], 1, fftSizeOver2);
|
||||||
vDSP_ctoz((DSPComplex *)temp, 2, &impulse_responses[i * 2 + 1], 1, fftSizeOver2);
|
vDSP_ctoz((DSPComplex *)temp, 2, &impulse_responses[i * 2 + 1], 1, fftSizeOver2);
|
||||||
}
|
} else {
|
||||||
else {
|
temp = (float *)malloc(sizeof(float) * fftSize * 2);
|
||||||
temp = (float *) malloc(sizeof(float) * fftSize * 2);
|
if(!temp) {
|
||||||
if (!temp) {
|
|
||||||
_mm_free(deinterleavedImpulseBuffer);
|
_mm_free(deinterleavedImpulseBuffer);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
@ -361,8 +360,7 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
}
|
}
|
||||||
|
|
||||||
free(temp);
|
free(temp);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
vDSP_ctoz((DSPComplex *)(deinterleavedImpulseBuffer + leftInChannel * fftSize), 2, &impulse_responses[i * 2 + 0], 1, fftSizeOver2);
|
vDSP_ctoz((DSPComplex *)(deinterleavedImpulseBuffer + leftInChannel * fftSize), 2, &impulse_responses[i * 2 + 0], 1, fftSizeOver2);
|
||||||
vDSP_ctoz((DSPComplex *)(deinterleavedImpulseBuffer + rightInChannel * fftSize), 2, &impulse_responses[i * 2 + 1], 1, fftSizeOver2);
|
vDSP_ctoz((DSPComplex *)(deinterleavedImpulseBuffer + rightInChannel * fftSize), 2, &impulse_responses[i * 2 + 1], 1, fftSizeOver2);
|
||||||
}
|
}
|
||||||
|
@ -373,19 +371,19 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
|
|
||||||
_mm_free(deinterleavedImpulseBuffer);
|
_mm_free(deinterleavedImpulseBuffer);
|
||||||
|
|
||||||
left_result = (float *) _mm_malloc(sizeof(float) * fftSize, 16);
|
left_result = (float *)_mm_malloc(sizeof(float) * fftSize, 16);
|
||||||
right_result = (float *) _mm_malloc(sizeof(float) * fftSize, 16);
|
right_result = (float *)_mm_malloc(sizeof(float) * fftSize, 16);
|
||||||
if (!left_result || !right_result)
|
if(!left_result || !right_result)
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
prevOverlapLeft = (float *) _mm_malloc(sizeof(float) * fftSize, 16);
|
prevOverlapLeft = (float *)_mm_malloc(sizeof(float) * fftSize, 16);
|
||||||
prevOverlapRight = (float *) _mm_malloc(sizeof(float) * fftSize, 16);
|
prevOverlapRight = (float *)_mm_malloc(sizeof(float) * fftSize, 16);
|
||||||
if (!prevOverlapLeft || !prevOverlapRight)
|
if(!prevOverlapLeft || !prevOverlapRight)
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
left_mix_result = (float *) _mm_malloc(sizeof(float) * fftSize, 16);
|
left_mix_result = (float *)_mm_malloc(sizeof(float) * fftSize, 16);
|
||||||
right_mix_result = (float *) _mm_malloc(sizeof(float) * fftSize, 16);
|
right_mix_result = (float *)_mm_malloc(sizeof(float) * fftSize, 16);
|
||||||
if (!left_mix_result || !right_mix_result)
|
if(!left_mix_result || !right_mix_result)
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
prevOverlapLength = 0;
|
prevOverlapLength = 0;
|
||||||
|
@ -395,7 +393,7 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
if (fftSetup) vDSP_destroy_fftsetup(fftSetup);
|
if(fftSetup) vDSP_destroy_fftsetup(fftSetup);
|
||||||
|
|
||||||
_mm_free(paddedSignal);
|
_mm_free(paddedSignal);
|
||||||
|
|
||||||
|
@ -407,8 +405,8 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
_mm_free(input_filtered_signal_per_channel[1].realp);
|
_mm_free(input_filtered_signal_per_channel[1].realp);
|
||||||
_mm_free(input_filtered_signal_per_channel[1].imagp);
|
_mm_free(input_filtered_signal_per_channel[1].imagp);
|
||||||
|
|
||||||
if (impulse_responses) {
|
if(impulse_responses) {
|
||||||
for (size_t i = 0; i < channelCount * 2; ++i) {
|
for(size_t i = 0; i < channelCount * 2; ++i) {
|
||||||
_mm_free(impulse_responses[i].realp);
|
_mm_free(impulse_responses[i].realp);
|
||||||
_mm_free(impulse_responses[i].imagp);
|
_mm_free(impulse_responses[i].imagp);
|
||||||
}
|
}
|
||||||
|
@ -425,16 +423,16 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
_mm_free(right_mix_result);
|
_mm_free(right_mix_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)process:(const float*)inBuffer sampleCount:(size_t)count toBuffer:(float *)outBuffer {
|
- (void)process:(const float *)inBuffer sampleCount:(size_t)count toBuffer:(float *)outBuffer {
|
||||||
const float scale = 1.0 / (8.0 * (float)fftSize);
|
const float scale = 1.0 / (8.0 * (float)fftSize);
|
||||||
|
|
||||||
while (count > 0) {
|
while(count > 0) {
|
||||||
size_t countToDo = (count > bufferSize) ? bufferSize : count;
|
size_t countToDo = (count > bufferSize) ? bufferSize : count;
|
||||||
|
|
||||||
vDSP_vclr(left_mix_result, 1, fftSize);
|
vDSP_vclr(left_mix_result, 1, fftSize);
|
||||||
vDSP_vclr(right_mix_result, 1, fftSize);
|
vDSP_vclr(right_mix_result, 1, fftSize);
|
||||||
|
|
||||||
for (size_t i = 0; i < channelCount; ++i) {
|
for(size_t i = 0; i < channelCount; ++i) {
|
||||||
cblas_scopy((int)countToDo, inBuffer + i, (int)channelCount, paddedSignal, 1);
|
cblas_scopy((int)countToDo, inBuffer + i, (int)channelCount, paddedSignal, 1);
|
||||||
|
|
||||||
vDSP_vclr(paddedSignal + countToDo, 1, paddedBufferSize - countToDo);
|
vDSP_vclr(paddedSignal + countToDo, 1, paddedBufferSize - countToDo);
|
||||||
|
@ -474,7 +472,7 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Integrate previous overlap
|
// Integrate previous overlap
|
||||||
if (prevOverlapLength) {
|
if(prevOverlapLength) {
|
||||||
vDSP_vadd(prevOverlapLeft, 1, left_mix_result, 1, left_mix_result, 1, prevOverlapLength);
|
vDSP_vadd(prevOverlapLeft, 1, left_mix_result, 1, left_mix_result, 1, prevOverlapLength);
|
||||||
vDSP_vadd(prevOverlapRight, 1, right_mix_result, 1, right_mix_result, 1, prevOverlapLength);
|
vDSP_vadd(prevOverlapRight, 1, right_mix_result, 1, right_mix_result, 1, prevOverlapLength);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
#import <CoreAudio/AudioHardware.h>
|
|
||||||
#import <AudioToolbox/AudioToolbox.h>
|
#import <AudioToolbox/AudioToolbox.h>
|
||||||
#import <AudioUnit/AudioUnit.h>
|
#import <AudioUnit/AudioUnit.h>
|
||||||
|
#import <CoreAudio/AudioHardware.h>
|
||||||
|
|
||||||
#import "AudioDecoder.h"
|
#import "AudioDecoder.h"
|
||||||
#import "Node.h"
|
#import "Node.h"
|
||||||
|
@ -36,16 +36,16 @@
|
||||||
@property(readonly) Semaphore *exitAtTheEndOfTheStream;
|
@property(readonly) Semaphore *exitAtTheEndOfTheStream;
|
||||||
|
|
||||||
- (BOOL)openWithSource:(id<CogSource>)source;
|
- (BOOL)openWithSource:(id<CogSource>)source;
|
||||||
- (BOOL)openWithDecoder:(id<CogDecoder>) d;
|
- (BOOL)openWithDecoder:(id<CogDecoder>)d;
|
||||||
|
|
||||||
- (void)process;
|
- (void)process;
|
||||||
- (NSDictionary *) properties;
|
- (NSDictionary *)properties;
|
||||||
- (void)seek:(long)frame;
|
- (void)seek:(long)frame;
|
||||||
|
|
||||||
- (void)registerObservers;
|
- (void)registerObservers;
|
||||||
|
|
||||||
- (BOOL)setTrack:(NSURL *)track;
|
- (BOOL)setTrack:(NSURL *)track;
|
||||||
|
|
||||||
- (id<CogDecoder>) decoder;
|
- (id<CogDecoder>)decoder;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -7,40 +7,35 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "InputNode.h"
|
#import "InputNode.h"
|
||||||
#import "BufferChain.h"
|
|
||||||
#import "Plugin.h"
|
|
||||||
#import "CoreAudioUtils.h"
|
|
||||||
#import "AudioPlayer.h"
|
#import "AudioPlayer.h"
|
||||||
|
#import "BufferChain.h"
|
||||||
|
#import "CoreAudioUtils.h"
|
||||||
#import "OutputNode.h"
|
#import "OutputNode.h"
|
||||||
|
#import "Plugin.h"
|
||||||
|
|
||||||
#import "Logging.h"
|
#import "Logging.h"
|
||||||
|
|
||||||
@implementation InputNode
|
@implementation InputNode
|
||||||
@synthesize exitAtTheEndOfTheStream;
|
@synthesize exitAtTheEndOfTheStream;
|
||||||
|
|
||||||
|
|
||||||
- (id)initWithController:(id)c previous:(id)p {
|
- (id)initWithController:(id)c previous:(id)p {
|
||||||
self = [super initWithController:c previous:p];
|
self = [super initWithController:c previous:p];
|
||||||
if (self) {
|
if(self) {
|
||||||
exitAtTheEndOfTheStream = [[Semaphore alloc] init];
|
exitAtTheEndOfTheStream = [[Semaphore alloc] init];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)openWithSource:(id<CogSource>)source {
|
||||||
- (BOOL)openWithSource:(id<CogSource>)source
|
|
||||||
{
|
|
||||||
decoder = [AudioDecoder audioDecoderForSource:source];
|
decoder = [AudioDecoder audioDecoderForSource:source];
|
||||||
|
|
||||||
if (decoder == nil)
|
if(decoder == nil)
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
[self registerObservers];
|
[self registerObservers];
|
||||||
|
|
||||||
if (![decoder open:source])
|
if(![decoder open:source]) {
|
||||||
{
|
|
||||||
ALog(@"Couldn't open decoder...");
|
ALog(@"Couldn't open decoder...");
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
@ -60,8 +55,7 @@
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)openWithDecoder:(id<CogDecoder>) d
|
- (BOOL)openWithDecoder:(id<CogDecoder>)d {
|
||||||
{
|
|
||||||
DLog(@"Opening with old decoder: %@", d);
|
DLog(@"Opening with old decoder: %@", d);
|
||||||
decoder = d;
|
decoder = d;
|
||||||
|
|
||||||
|
@ -83,9 +77,7 @@
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)registerObservers {
|
||||||
- (void)registerObservers
|
|
||||||
{
|
|
||||||
DLog(@"REGISTERING OBSERVERS");
|
DLog(@"REGISTERING OBSERVERS");
|
||||||
[decoder addObserver:self
|
[decoder addObserver:self
|
||||||
forKeyPath:@"properties"
|
forKeyPath:@"properties"
|
||||||
|
@ -103,33 +95,28 @@
|
||||||
- (void)observeValueForKeyPath:(NSString *)keyPath
|
- (void)observeValueForKeyPath:(NSString *)keyPath
|
||||||
ofObject:(id)object
|
ofObject:(id)object
|
||||||
change:(NSDictionary *)change
|
change:(NSDictionary *)change
|
||||||
context:(void *)context
|
context:(void *)context {
|
||||||
{
|
|
||||||
DLog(@"SOMETHING CHANGED!");
|
DLog(@"SOMETHING CHANGED!");
|
||||||
if ([keyPath isEqual:@"properties"]) {
|
if([keyPath isEqual:@"properties"]) {
|
||||||
DLog(@"Input format changed");
|
DLog(@"Input format changed");
|
||||||
// Converter may need resetting, it'll do that when it reaches the new chunks
|
// Converter may need resetting, it'll do that when it reaches the new chunks
|
||||||
NSDictionary * properties = [decoder properties];
|
NSDictionary *properties = [decoder properties];
|
||||||
nodeFormat = propertiesToASBD(properties);
|
nodeFormat = propertiesToASBD(properties);
|
||||||
nodeLossless = [[properties valueForKey:@"encoding"] isEqualToString:@"lossless"];
|
nodeLossless = [[properties valueForKey:@"encoding"] isEqualToString:@"lossless"];
|
||||||
}
|
} else if([keyPath isEqual:@"metadata"]) {
|
||||||
else if ([keyPath isEqual:@"metadata"]) {
|
// Inform something of metadata change
|
||||||
//Inform something of metadata change
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)process
|
- (void)process {
|
||||||
{
|
|
||||||
int amountInBuffer = 0;
|
int amountInBuffer = 0;
|
||||||
void *inputBuffer = malloc(CHUNK_SIZE);
|
void *inputBuffer = malloc(CHUNK_SIZE);
|
||||||
|
|
||||||
BOOL shouldClose = YES;
|
BOOL shouldClose = YES;
|
||||||
BOOL seekError = NO;
|
BOOL seekError = NO;
|
||||||
|
|
||||||
while ([self shouldContinue] == YES && [self endOfStream] == NO)
|
while([self shouldContinue] == YES && [self endOfStream] == NO) {
|
||||||
{
|
if(shouldSeek == YES) {
|
||||||
if (shouldSeek == YES)
|
|
||||||
{
|
|
||||||
ConverterNode *converter = [[[controller controller] bufferChain] converter];
|
ConverterNode *converter = [[[controller controller] bufferChain] converter];
|
||||||
DLog(@"SEEKING! Resetting Buffer");
|
DLog(@"SEEKING! Resetting Buffer");
|
||||||
|
|
||||||
|
@ -149,47 +136,41 @@
|
||||||
initialBufferFilled = NO;
|
initialBufferFilled = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (amountInBuffer < CHUNK_SIZE) {
|
if(amountInBuffer < CHUNK_SIZE) {
|
||||||
int framesToRead = (CHUNK_SIZE - amountInBuffer)/bytesPerFrame;
|
int framesToRead = (CHUNK_SIZE - amountInBuffer) / bytesPerFrame;
|
||||||
int framesRead = [decoder readAudio:((char *)inputBuffer) + amountInBuffer frames:framesToRead];
|
int framesRead = [decoder readAudio:((char *)inputBuffer) + amountInBuffer frames:framesToRead];
|
||||||
|
|
||||||
if (framesRead > 0 && !seekError)
|
if(framesRead > 0 && !seekError) {
|
||||||
{
|
|
||||||
amountInBuffer += (framesRead * bytesPerFrame);
|
amountInBuffer += (framesRead * bytesPerFrame);
|
||||||
[self writeData:inputBuffer amount:amountInBuffer];
|
[self writeData:inputBuffer amount:amountInBuffer];
|
||||||
amountInBuffer = 0;
|
amountInBuffer = 0;
|
||||||
}
|
} else {
|
||||||
else
|
if(initialBufferFilled == NO) {
|
||||||
{
|
|
||||||
if (initialBufferFilled == NO) {
|
|
||||||
[controller initialBufferFilled:self];
|
[controller initialBufferFilled:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
DLog(@"End of stream? %@", [self properties]);
|
DLog(@"End of stream? %@", [self properties]);
|
||||||
|
|
||||||
endOfStream = YES;
|
endOfStream = YES;
|
||||||
shouldClose = [controller endOfInputReached]; //Lets us know if we should keep going or not (occassionally, for track changes within a file)
|
shouldClose = [controller endOfInputReached]; // Lets us know if we should keep going or not (occassionally, for track changes within a file)
|
||||||
DLog(@"closing? is %i", shouldClose);
|
DLog(@"closing? is %i", shouldClose);
|
||||||
|
|
||||||
// wait before exiting, as we might still get seeking request
|
// wait before exiting, as we might still get seeking request
|
||||||
DLog("InputNode: Before wait")
|
DLog("InputNode: Before wait")
|
||||||
[exitAtTheEndOfTheStream waitIndefinitely];
|
[exitAtTheEndOfTheStream waitIndefinitely];
|
||||||
DLog("InputNode: After wait, should seek = %d", shouldSeek)
|
DLog("InputNode: After wait, should seek = %d", shouldSeek) if(shouldSeek) {
|
||||||
if (shouldSeek)
|
|
||||||
{
|
|
||||||
endOfStream = NO;
|
endOfStream = NO;
|
||||||
shouldClose = NO;
|
shouldClose = NO;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldClose)
|
if(shouldClose)
|
||||||
[decoder close];
|
[decoder close];
|
||||||
|
|
||||||
free(inputBuffer);
|
free(inputBuffer);
|
||||||
|
@ -199,22 +180,19 @@
|
||||||
DLog("Input node thread stopping");
|
DLog("Input node thread stopping");
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)seek:(long)frame
|
- (void)seek:(long)frame {
|
||||||
{
|
|
||||||
seekFrame = frame;
|
seekFrame = frame;
|
||||||
shouldSeek = YES;
|
shouldSeek = YES;
|
||||||
DLog(@"Should seek!");
|
DLog(@"Should seek!");
|
||||||
[semaphore signal];
|
[semaphore signal];
|
||||||
|
|
||||||
if (endOfStream)
|
if(endOfStream) {
|
||||||
{
|
|
||||||
[exitAtTheEndOfTheStream signal];
|
[exitAtTheEndOfTheStream signal];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)setTrack:(NSURL *)track
|
- (BOOL)setTrack:(NSURL *)track {
|
||||||
{
|
if([decoder respondsToSelector:@selector(setTrack:)] && [decoder setTrack:track]) {
|
||||||
if ([decoder respondsToSelector:@selector(setTrack:)] && [decoder setTrack:track]) {
|
|
||||||
DLog(@"SET TRACK!");
|
DLog(@"SET TRACK!");
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
|
@ -223,41 +201,34 @@
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeObservers
|
- (void)removeObservers {
|
||||||
{
|
if(observersAdded) {
|
||||||
if (observersAdded)
|
|
||||||
{
|
|
||||||
[decoder removeObserver:self forKeyPath:@"properties"];
|
[decoder removeObserver:self forKeyPath:@"properties"];
|
||||||
[decoder removeObserver:self forKeyPath:@"metadata"];
|
[decoder removeObserver:self forKeyPath:@"metadata"];
|
||||||
observersAdded = NO;
|
observersAdded = NO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setShouldContinue:(BOOL)s
|
- (void)setShouldContinue:(BOOL)s {
|
||||||
{
|
|
||||||
[super setShouldContinue:s];
|
[super setShouldContinue:s];
|
||||||
if (!s)
|
if(!s)
|
||||||
[self removeObservers];
|
[self removeObservers];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc {
|
||||||
{
|
|
||||||
DLog(@"Input Node dealloc");
|
DLog(@"Input Node dealloc");
|
||||||
[self removeObservers];
|
[self removeObservers];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDictionary *) properties
|
- (NSDictionary *)properties {
|
||||||
{
|
|
||||||
return [decoder properties];
|
return [decoder properties];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id<CogDecoder>) decoder
|
- (id<CogDecoder>)decoder {
|
||||||
{
|
|
||||||
return decoder;
|
return decoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (double) secondsBuffered
|
- (double)secondsBuffered {
|
||||||
{
|
|
||||||
return [buffer listDuration];
|
return [buffer listDuration];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
// Copyright 2006 Vincent Spader. All rights reserved.
|
// Copyright 2006 Vincent Spader. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
|
||||||
#import "ChunkList.h"
|
#import "ChunkList.h"
|
||||||
#import "Semaphore.h"
|
#import "Semaphore.h"
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
#define BUFFER_SIZE 1024 * 1024
|
#define BUFFER_SIZE 1024 * 1024
|
||||||
#define CHUNK_SIZE 16 * 1024
|
#define CHUNK_SIZE 16 * 1024
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
BOOL shouldReset;
|
BOOL shouldReset;
|
||||||
|
|
||||||
BOOL shouldContinue;
|
BOOL shouldContinue;
|
||||||
BOOL endOfStream; //All data is now in buffer
|
BOOL endOfStream; // All data is now in buffer
|
||||||
BOOL initialBufferFilled;
|
BOOL initialBufferFilled;
|
||||||
|
|
||||||
AudioStreamBasicDescription nodeFormat;
|
AudioStreamBasicDescription nodeFormat;
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
- (void)writeData:(const void *)ptr amount:(size_t)a;
|
- (void)writeData:(const void *)ptr amount:(size_t)a;
|
||||||
- (AudioChunk *)readChunk:(size_t)maxFrames;
|
- (AudioChunk *)readChunk:(size_t)maxFrames;
|
||||||
|
|
||||||
- (void)process; //Should be overwriten by subclass
|
- (void)process; // Should be overwriten by subclass
|
||||||
- (void)threadEntry:(id)arg;
|
- (void)threadEntry:(id)arg;
|
||||||
|
|
||||||
- (void)launchThread;
|
- (void)launchThread;
|
||||||
|
@ -51,7 +51,7 @@
|
||||||
- (void)setShouldContinue:(BOOL)s;
|
- (void)setShouldContinue:(BOOL)s;
|
||||||
|
|
||||||
- (ChunkList *)buffer;
|
- (ChunkList *)buffer;
|
||||||
- (void)resetBuffer; //WARNING! DANGER WILL ROBINSON!
|
- (void)resetBuffer; // WARNING! DANGER WILL ROBINSON!
|
||||||
|
|
||||||
- (AudioStreamBasicDescription)nodeFormat;
|
- (AudioStreamBasicDescription)nodeFormat;
|
||||||
- (BOOL)nodeLossless;
|
- (BOOL)nodeLossless;
|
||||||
|
|
|
@ -8,16 +8,14 @@
|
||||||
|
|
||||||
#import "Node.h"
|
#import "Node.h"
|
||||||
|
|
||||||
#import "Logging.h"
|
|
||||||
#import "BufferChain.h"
|
#import "BufferChain.h"
|
||||||
|
#import "Logging.h"
|
||||||
|
|
||||||
@implementation Node
|
@implementation Node
|
||||||
|
|
||||||
- (id)initWithController:(id)c previous:(id)p
|
- (id)initWithController:(id)c previous:(id)p {
|
||||||
{
|
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self)
|
if(self) {
|
||||||
{
|
|
||||||
buffer = [[ChunkList alloc] initWithMaximumDuration:3.0];
|
buffer = [[ChunkList alloc] initWithMaximumDuration:3.0];
|
||||||
semaphore = [[Semaphore alloc] init];
|
semaphore = [[Semaphore alloc] init];
|
||||||
|
|
||||||
|
@ -37,21 +35,18 @@
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (AudioStreamBasicDescription)nodeFormat
|
- (AudioStreamBasicDescription)nodeFormat {
|
||||||
{
|
|
||||||
return nodeFormat;
|
return nodeFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)nodeLossless
|
- (BOOL)nodeLossless {
|
||||||
{
|
|
||||||
return nodeLossless;
|
return nodeLossless;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)writeData:(const void *)ptr amount:(size_t)amount
|
- (void)writeData:(const void *)ptr amount:(size_t)amount {
|
||||||
{
|
|
||||||
[accessLock lock];
|
[accessLock lock];
|
||||||
|
|
||||||
AudioChunk * chunk = [[AudioChunk alloc] init];
|
AudioChunk *chunk = [[AudioChunk alloc] init];
|
||||||
[chunk setFormat:nodeFormat];
|
[chunk setFormat:nodeFormat];
|
||||||
[chunk setLossless:nodeLossless];
|
[chunk setLossless:nodeLossless];
|
||||||
[chunk assignSamples:ptr frameCount:amount / nodeFormat.mBytesPerPacket];
|
[chunk assignSamples:ptr frameCount:amount / nodeFormat.mBytesPerPacket];
|
||||||
|
@ -59,17 +54,16 @@
|
||||||
const double chunkDuration = [chunk duration];
|
const double chunkDuration = [chunk duration];
|
||||||
double durationLeft = [buffer maxDuration] - [buffer listDuration];
|
double durationLeft = [buffer maxDuration] - [buffer listDuration];
|
||||||
|
|
||||||
while (shouldContinue == YES && chunkDuration > durationLeft)
|
while(shouldContinue == YES && chunkDuration > durationLeft) {
|
||||||
{
|
if(durationLeft < chunkDuration) {
|
||||||
if (durationLeft < chunkDuration) {
|
if(initialBufferFilled == NO) {
|
||||||
if (initialBufferFilled == NO) {
|
|
||||||
initialBufferFilled = YES;
|
initialBufferFilled = YES;
|
||||||
if ([controller respondsToSelector:@selector(initialBufferFilled:)])
|
if([controller respondsToSelector:@selector(initialBufferFilled:)])
|
||||||
[controller performSelector:@selector(initialBufferFilled:) withObject:self];
|
[controller performSelector:@selector(initialBufferFilled:) withObject:self];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (durationLeft < chunkDuration || shouldReset) {
|
if(durationLeft < chunkDuration || shouldReset) {
|
||||||
[accessLock unlock];
|
[accessLock unlock];
|
||||||
[semaphore wait];
|
[semaphore wait];
|
||||||
[accessLock lock];
|
[accessLock lock];
|
||||||
|
@ -83,119 +77,100 @@
|
||||||
[accessLock unlock];
|
[accessLock unlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
//Should be overwriten by subclass.
|
// Should be overwriten by subclass.
|
||||||
- (void)process
|
- (void)process {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)threadEntry:(id)arg
|
- (void)threadEntry:(id)arg {
|
||||||
{
|
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
[self process];
|
[self process];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (AudioChunk *)readChunk:(size_t)maxFrames
|
- (AudioChunk *)readChunk:(size_t)maxFrames {
|
||||||
{
|
|
||||||
[accessLock lock];
|
[accessLock lock];
|
||||||
|
|
||||||
if ([[previousNode buffer] isEmpty] && [previousNode endOfStream] == YES)
|
if([[previousNode buffer] isEmpty] && [previousNode endOfStream] == YES) {
|
||||||
{
|
|
||||||
endOfStream = YES;
|
endOfStream = YES;
|
||||||
[accessLock unlock];
|
[accessLock unlock];
|
||||||
return [[AudioChunk alloc] init];
|
return [[AudioChunk alloc] init];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([previousNode shouldReset] == YES) {
|
if([previousNode shouldReset] == YES) {
|
||||||
[buffer reset];
|
[buffer reset];
|
||||||
|
|
||||||
shouldReset = YES;
|
shouldReset = YES;
|
||||||
[previousNode setShouldReset: NO];
|
[previousNode setShouldReset:NO];
|
||||||
|
|
||||||
[[previousNode semaphore] signal];
|
[[previousNode semaphore] signal];
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioChunk * ret = [[previousNode buffer] removeSamples:maxFrames];
|
AudioChunk *ret = [[previousNode buffer] removeSamples:maxFrames];
|
||||||
|
|
||||||
[accessLock unlock];
|
[accessLock unlock];
|
||||||
|
|
||||||
if ([ret frameCount])
|
if([ret frameCount]) {
|
||||||
{
|
|
||||||
[[previousNode semaphore] signal];
|
[[previousNode semaphore] signal];
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)launchThread
|
- (void)launchThread {
|
||||||
{
|
|
||||||
[NSThread detachNewThreadSelector:@selector(threadEntry:) toTarget:self withObject:nil];
|
[NSThread detachNewThreadSelector:@selector(threadEntry:) toTarget:self withObject:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setPreviousNode:(id)p
|
- (void)setPreviousNode:(id)p {
|
||||||
{
|
|
||||||
previousNode = p;
|
previousNode = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)previousNode
|
- (id)previousNode {
|
||||||
{
|
|
||||||
return previousNode;
|
return previousNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)shouldContinue
|
- (BOOL)shouldContinue {
|
||||||
{
|
|
||||||
return shouldContinue;
|
return shouldContinue;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setShouldContinue:(BOOL)s
|
- (void)setShouldContinue:(BOOL)s {
|
||||||
{
|
|
||||||
shouldContinue = s;
|
shouldContinue = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (ChunkList *)buffer
|
- (ChunkList *)buffer {
|
||||||
{
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)resetBuffer
|
- (void)resetBuffer {
|
||||||
{
|
shouldReset = YES; // Will reset on next write.
|
||||||
shouldReset = YES; //Will reset on next write.
|
if(previousNode == nil) {
|
||||||
if (previousNode == nil) {
|
|
||||||
[accessLock lock];
|
[accessLock lock];
|
||||||
[buffer reset];
|
[buffer reset];
|
||||||
[accessLock unlock];
|
[accessLock unlock];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (Semaphore *)semaphore
|
- (Semaphore *)semaphore {
|
||||||
{
|
|
||||||
return semaphore;
|
return semaphore;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)endOfStream
|
- (BOOL)endOfStream {
|
||||||
{
|
|
||||||
return endOfStream;
|
return endOfStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setEndOfStream:(BOOL)e
|
- (void)setEndOfStream:(BOOL)e {
|
||||||
{
|
|
||||||
endOfStream = e;
|
endOfStream = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setShouldReset:(BOOL)s
|
- (void)setShouldReset:(BOOL)s {
|
||||||
{
|
|
||||||
shouldReset = s;
|
shouldReset = s;
|
||||||
}
|
}
|
||||||
- (BOOL)shouldReset
|
- (BOOL)shouldReset {
|
||||||
{
|
|
||||||
return shouldReset;
|
return shouldReset;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Buffering nodes should implement this
|
// Buffering nodes should implement this
|
||||||
- (double)secondsBuffered
|
- (double)secondsBuffered {
|
||||||
{
|
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
#import <CoreAudio/AudioHardware.h>
|
|
||||||
#import <AudioToolbox/AudioToolbox.h>
|
#import <AudioToolbox/AudioToolbox.h>
|
||||||
#import <AudioUnit/AudioUnit.h>
|
#import <AudioUnit/AudioUnit.h>
|
||||||
|
#import <CoreAudio/AudioHardware.h>
|
||||||
|
|
||||||
#import "Node.h"
|
#import "Node.h"
|
||||||
#import "OutputCoreAudio.h"
|
#import "OutputCoreAudio.h"
|
||||||
|
@ -49,9 +49,9 @@
|
||||||
- (AudioChunk *)readChunk:(size_t)amount;
|
- (AudioChunk *)readChunk:(size_t)amount;
|
||||||
|
|
||||||
- (void)setFormat:(AudioStreamBasicDescription *)f;
|
- (void)setFormat:(AudioStreamBasicDescription *)f;
|
||||||
- (AudioStreamBasicDescription) format;
|
- (AudioStreamBasicDescription)format;
|
||||||
|
|
||||||
- (void)setVolume:(double) v;
|
- (void)setVolume:(double)v;
|
||||||
|
|
||||||
- (void)setShouldContinue:(BOOL)s;
|
- (void)setShouldContinue:(BOOL)s;
|
||||||
|
|
||||||
|
|
|
@ -7,16 +7,15 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "OutputNode.h"
|
#import "OutputNode.h"
|
||||||
#import "OutputCoreAudio.h"
|
|
||||||
#import "AudioPlayer.h"
|
#import "AudioPlayer.h"
|
||||||
#import "BufferChain.h"
|
#import "BufferChain.h"
|
||||||
|
#import "OutputCoreAudio.h"
|
||||||
|
|
||||||
#import "Logging.h"
|
#import "Logging.h"
|
||||||
|
|
||||||
@implementation OutputNode
|
@implementation OutputNode
|
||||||
|
|
||||||
- (void)setup
|
- (void)setup {
|
||||||
{
|
|
||||||
amountPlayed = 0.0;
|
amountPlayed = 0.0;
|
||||||
sampleRatio = 0.0;
|
sampleRatio = 0.0;
|
||||||
|
|
||||||
|
@ -28,94 +27,79 @@
|
||||||
[output setup];
|
[output setup];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)seek:(double)time
|
- (void)seek:(double)time {
|
||||||
{
|
// [output pause];
|
||||||
// [output pause];
|
|
||||||
[self resetBuffer];
|
[self resetBuffer];
|
||||||
|
|
||||||
amountPlayed = time;
|
amountPlayed = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)process
|
- (void)process {
|
||||||
{
|
|
||||||
paused = NO;
|
paused = NO;
|
||||||
[output start];
|
[output start];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)pause
|
- (void)pause {
|
||||||
{
|
|
||||||
paused = YES;
|
paused = YES;
|
||||||
[output pause];
|
[output pause];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)resume
|
- (void)resume {
|
||||||
{
|
|
||||||
paused = NO;
|
paused = NO;
|
||||||
[output resume];
|
[output resume];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)incrementAmountPlayed:(double)seconds
|
- (void)incrementAmountPlayed:(double)seconds {
|
||||||
{
|
|
||||||
amountPlayed += seconds;
|
amountPlayed += seconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)resetAmountPlayed
|
- (void)resetAmountPlayed {
|
||||||
{
|
|
||||||
amountPlayed = 0;
|
amountPlayed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)endOfInputPlayed
|
- (void)endOfInputPlayed {
|
||||||
{
|
|
||||||
[controller endOfInputPlayed];
|
[controller endOfInputPlayed];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)chainQueueHasTracks
|
- (BOOL)chainQueueHasTracks {
|
||||||
{
|
|
||||||
return [controller chainQueueHasTracks];
|
return [controller chainQueueHasTracks];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (double)secondsBuffered
|
- (double)secondsBuffered {
|
||||||
{
|
|
||||||
return [buffer listDuration];
|
return [buffer listDuration];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (AudioChunk *)readChunk:(size_t)amount
|
- (AudioChunk *)readChunk:(size_t)amount {
|
||||||
{
|
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
[self setPreviousNode:[[controller bufferChain] finalNode]];
|
[self setPreviousNode:[[controller bufferChain] finalNode]];
|
||||||
|
|
||||||
AudioChunk * ret = [super readChunk:amount];
|
AudioChunk *ret = [super readChunk:amount];
|
||||||
|
|
||||||
/* if (n == 0) {
|
/* if (n == 0) {
|
||||||
DLog(@"Output Buffer dry!");
|
DLog(@"Output Buffer dry!");
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (double)amountPlayed
|
- (double)amountPlayed {
|
||||||
{
|
|
||||||
return amountPlayed;
|
return amountPlayed;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (AudioStreamBasicDescription) format
|
- (AudioStreamBasicDescription)format {
|
||||||
{
|
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setFormat:(AudioStreamBasicDescription *)f
|
- (void)setFormat:(AudioStreamBasicDescription *)f {
|
||||||
{
|
|
||||||
format = *f;
|
format = *f;
|
||||||
// Calculate a ratio and add to double(seconds) instead, as format may change
|
// Calculate a ratio and add to double(seconds) instead, as format may change
|
||||||
// double oldSampleRatio = sampleRatio;
|
// double oldSampleRatio = sampleRatio;
|
||||||
sampleRatio = 1.0 / (format.mSampleRate * format.mBytesPerPacket);
|
sampleRatio = 1.0 / (format.mSampleRate * format.mBytesPerPacket);
|
||||||
BufferChain *bufferChain = [controller bufferChain];
|
BufferChain *bufferChain = [controller bufferChain];
|
||||||
if (bufferChain)
|
if(bufferChain) {
|
||||||
{
|
|
||||||
ConverterNode *converter = [bufferChain converter];
|
ConverterNode *converter = [bufferChain converter];
|
||||||
if (converter)
|
if(converter) {
|
||||||
{
|
|
||||||
// This clears the resampler buffer, but not the input buffer
|
// This clears the resampler buffer, but not the input buffer
|
||||||
// We also have to jump the play position ahead accounting for
|
// We also have to jump the play position ahead accounting for
|
||||||
// the data we are flushing
|
// the data we are flushing
|
||||||
|
@ -132,47 +116,39 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)close
|
- (void)close {
|
||||||
{
|
|
||||||
[output stop];
|
[output stop];
|
||||||
output = nil;
|
output = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setVolume:(double) v
|
- (void)setVolume:(double)v {
|
||||||
{
|
|
||||||
[output setVolume:v];
|
[output setVolume:v];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setShouldContinue:(BOOL)s
|
- (void)setShouldContinue:(BOOL)s {
|
||||||
{
|
|
||||||
[super setShouldContinue:s];
|
[super setShouldContinue:s];
|
||||||
|
|
||||||
// if (s == NO)
|
// if (s == NO)
|
||||||
// [output stop];
|
// [output stop];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)isPaused
|
- (BOOL)isPaused {
|
||||||
{
|
|
||||||
return paused;
|
return paused;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)beginEqualizer:(AudioUnit)eq
|
- (void)beginEqualizer:(AudioUnit)eq {
|
||||||
{
|
|
||||||
[controller beginEqualizer:eq];
|
[controller beginEqualizer:eq];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)refreshEqualizer:(AudioUnit)eq
|
- (void)refreshEqualizer:(AudioUnit)eq {
|
||||||
{
|
|
||||||
[controller refreshEqualizer:eq];
|
[controller refreshEqualizer:eq];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)endEqualizer:(AudioUnit)eq
|
- (void)endEqualizer:(AudioUnit)eq {
|
||||||
{
|
|
||||||
[controller endEqualizer:eq];
|
[controller endEqualizer:eq];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sustainHDCD
|
- (void)sustainHDCD {
|
||||||
{
|
|
||||||
[output sustainHDCD];
|
[output sustainHDCD];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
#import <CoreAudio/AudioHardware.h>
|
|
||||||
#import <AudioToolbox/AudioToolbox.h>
|
#import <AudioToolbox/AudioToolbox.h>
|
||||||
#import <AudioUnit/AudioUnit.h>
|
#import <AudioUnit/AudioUnit.h>
|
||||||
|
#import <CoreAudio/AudioHardware.h>
|
||||||
|
|
||||||
#import "Node.h"
|
#import "Node.h"
|
||||||
#import "Plugin.h"
|
#import "Plugin.h"
|
||||||
|
@ -21,6 +21,6 @@
|
||||||
// This node just slaps pre-converted data into its buffer for re-buffering
|
// This node just slaps pre-converted data into its buffer for re-buffering
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setFormat:(AudioStreamBasicDescription)format;
|
- (void)setFormat:(AudioStreamBasicDescription)format;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -6,18 +6,16 @@
|
||||||
// Copyright 2022 __LoSnoCo__. All rights reserved.
|
// Copyright 2022 __LoSnoCo__. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "Plugin.h"
|
|
||||||
#import "RefillNode.h"
|
#import "RefillNode.h"
|
||||||
|
#import "Plugin.h"
|
||||||
|
|
||||||
#import "Logging.h"
|
#import "Logging.h"
|
||||||
|
|
||||||
@implementation RefillNode
|
@implementation RefillNode
|
||||||
|
|
||||||
- (id)initWithController:(id)c previous:(id)p
|
- (id)initWithController:(id)c previous:(id)p {
|
||||||
{
|
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self)
|
if(self) {
|
||||||
{
|
|
||||||
// This special node should be able to handle up to four buffers
|
// This special node should be able to handle up to four buffers
|
||||||
buffer = [[ChunkList alloc] initWithMaximumDuration:12.0];
|
buffer = [[ChunkList alloc] initWithMaximumDuration:12.0];
|
||||||
semaphore = [[Semaphore alloc] init];
|
semaphore = [[Semaphore alloc] init];
|
||||||
|
@ -36,13 +34,11 @@
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc {
|
||||||
{
|
|
||||||
DLog(@"Refill Node dealloc");
|
DLog(@"Refill Node dealloc");
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setFormat:(AudioStreamBasicDescription)format
|
- (void)setFormat:(AudioStreamBasicDescription)format {
|
||||||
{
|
|
||||||
nodeFormat = format;
|
nodeFormat = format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
|
||||||
#import "Plugin.h"
|
#import "Plugin.h"
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
@interface CogDecoderMulti : NSObject <CogDecoder> {
|
@interface CogDecoderMulti : NSObject <CogDecoder> {
|
||||||
NSArray *theDecoders;
|
NSArray *theDecoders;
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
NSMutableArray *cachedObservers;
|
NSMutableArray *cachedObservers;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(id)initWithDecoders:(NSArray *)decoders;
|
- (id)initWithDecoders:(NSArray *)decoders;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,10 @@
|
||||||
|
|
||||||
#import "CogPluginMulti.h"
|
#import "CogPluginMulti.h"
|
||||||
|
|
||||||
NSArray * sortClassesByPriority(NSArray * theClasses)
|
NSArray *sortClassesByPriority(NSArray *theClasses) {
|
||||||
{
|
|
||||||
NSMutableArray *sortedClasses = [NSMutableArray arrayWithArray:theClasses];
|
NSMutableArray *sortedClasses = [NSMutableArray arrayWithArray:theClasses];
|
||||||
[sortedClasses sortUsingComparator:
|
[sortedClasses sortUsingComparator:
|
||||||
^NSComparisonResult(id obj1, id obj2)
|
^NSComparisonResult(id obj1, id obj2) {
|
||||||
{
|
|
||||||
NSString *classString1 = (NSString *)obj1;
|
NSString *classString1 = (NSString *)obj1;
|
||||||
NSString *classString2 = (NSString *)obj2;
|
NSString *classString2 = (NSString *)obj2;
|
||||||
|
|
||||||
|
@ -23,27 +21,27 @@ NSArray * sortClassesByPriority(NSArray * theClasses)
|
||||||
float priority1 = [class1 priority];
|
float priority1 = [class1 priority];
|
||||||
float priority2 = [class2 priority];
|
float priority2 = [class2 priority];
|
||||||
|
|
||||||
if (priority1 == priority2) return NSOrderedSame;
|
if(priority1 == priority2)
|
||||||
else if (priority1 > priority2) return NSOrderedAscending;
|
return NSOrderedSame;
|
||||||
else return NSOrderedDescending;
|
else if(priority1 > priority2)
|
||||||
|
return NSOrderedAscending;
|
||||||
|
else
|
||||||
|
return NSOrderedDescending;
|
||||||
}];
|
}];
|
||||||
return sortedClasses;
|
return sortedClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
@implementation CogDecoderMulti
|
@implementation CogDecoderMulti
|
||||||
|
|
||||||
+ (NSArray *)mimeTypes
|
+ (NSArray *)mimeTypes {
|
||||||
{
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSArray *)fileTypes
|
+ (NSArray *)fileTypes {
|
||||||
{
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (float)priority
|
+ (float)priority {
|
||||||
{
|
|
||||||
return -1.0;
|
return -1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,11 +49,9 @@ NSArray * sortClassesByPriority(NSArray * theClasses)
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithDecoders:(NSArray *)decoders
|
- (id)initWithDecoders:(NSArray *)decoders {
|
||||||
{
|
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if ( self )
|
if(self) {
|
||||||
{
|
|
||||||
theDecoders = sortClassesByPriority(decoders);
|
theDecoders = sortClassesByPriority(decoders);
|
||||||
theDecoder = nil;
|
theDecoder = nil;
|
||||||
cachedObservers = [[NSMutableArray alloc] init];
|
cachedObservers = [[NSMutableArray alloc] init];
|
||||||
|
@ -63,52 +59,46 @@ NSArray * sortClassesByPriority(NSArray * theClasses)
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDictionary *)properties
|
- (NSDictionary *)properties {
|
||||||
{
|
if(theDecoder != nil) return [theDecoder properties];
|
||||||
if ( theDecoder != nil ) return [theDecoder properties];
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)readAudio:(void *)buffer frames:(UInt32)frames
|
- (int)readAudio:(void *)buffer frames:(UInt32)frames {
|
||||||
{
|
if(theDecoder != nil) return [theDecoder readAudio:buffer frames:frames];
|
||||||
if ( theDecoder != nil ) return [theDecoder readAudio:buffer frames:frames];
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)open:(id<CogSource>)source
|
- (BOOL)open:(id<CogSource>)source {
|
||||||
{
|
for(NSString *classString in theDecoders) {
|
||||||
for (NSString *classString in theDecoders)
|
|
||||||
{
|
|
||||||
Class decoder = NSClassFromString(classString);
|
Class decoder = NSClassFromString(classString);
|
||||||
theDecoder = [[decoder alloc] init];
|
theDecoder = [[decoder alloc] init];
|
||||||
for (NSDictionary *obsItem in cachedObservers) {
|
for(NSDictionary *obsItem in cachedObservers) {
|
||||||
[theDecoder addObserver:[obsItem objectForKey:@"observer"]
|
[theDecoder addObserver:[obsItem objectForKey:@"observer"]
|
||||||
forKeyPath:[obsItem objectForKey:@"keyPath"]
|
forKeyPath:[obsItem objectForKey:@"keyPath"]
|
||||||
options:[[obsItem objectForKey:@"options"] unsignedIntegerValue]
|
options:[[obsItem objectForKey:@"options"] unsignedIntegerValue]
|
||||||
context:(__bridge void *)([obsItem objectForKey:@"context"])];
|
context:(__bridge void *)([obsItem objectForKey:@"context"])];
|
||||||
}
|
}
|
||||||
if ([theDecoder open:source])
|
if([theDecoder open:source])
|
||||||
return YES;
|
return YES;
|
||||||
for (NSDictionary *obsItem in cachedObservers) {
|
for(NSDictionary *obsItem in cachedObservers) {
|
||||||
[theDecoder removeObserver:[obsItem objectForKey:@"observer"] forKeyPath:[obsItem objectForKey:@"keyPath"]];
|
[theDecoder removeObserver:[obsItem objectForKey:@"observer"] forKeyPath:[obsItem objectForKey:@"keyPath"]];
|
||||||
}
|
}
|
||||||
if ([source seekable])
|
if([source seekable])
|
||||||
[source seek:0 whence:SEEK_SET];
|
[source seek:0 whence:SEEK_SET];
|
||||||
}
|
}
|
||||||
theDecoder = nil;
|
theDecoder = nil;
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (long)seek:(long)frame
|
- (long)seek:(long)frame {
|
||||||
{
|
if(theDecoder != nil) return [theDecoder seek:frame];
|
||||||
if ( theDecoder != nil ) return [theDecoder seek:frame];
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)close
|
- (void)close {
|
||||||
{
|
if(theDecoder != nil) {
|
||||||
if ( theDecoder != nil ) {
|
for(NSDictionary *obsItem in cachedObservers) {
|
||||||
for (NSDictionary *obsItem in cachedObservers) {
|
|
||||||
[theDecoder removeObserver:[obsItem objectForKey:@"observer"] forKeyPath:[obsItem objectForKey:@"keyPath"]];
|
[theDecoder removeObserver:[obsItem objectForKey:@"observer"] forKeyPath:[obsItem objectForKey:@"keyPath"]];
|
||||||
}
|
}
|
||||||
[cachedObservers removeAllObjects];
|
[cachedObservers removeAllObjects];
|
||||||
|
@ -117,52 +107,46 @@ NSArray * sortClassesByPriority(NSArray * theClasses)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)setTrack:(NSURL *)track
|
- (BOOL)setTrack:(NSURL *)track {
|
||||||
{
|
if(theDecoder != nil && [theDecoder respondsToSelector:@selector(setTrack:)]) return [theDecoder setTrack:track];
|
||||||
if ( theDecoder != nil && [theDecoder respondsToSelector: @selector(setTrack:)] ) return [theDecoder setTrack:track];
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* By the current design, the core adds its observers to decoders before they are opened */
|
/* By the current design, the core adds its observers to decoders before they are opened */
|
||||||
- (void)addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context
|
- (void)addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context {
|
||||||
{
|
|
||||||
if(context != nil) {
|
if(context != nil) {
|
||||||
[cachedObservers addObject:[NSDictionary dictionaryWithObjectsAndKeys:observer, @"observer", keyPath, @"keyPath", @(options), @"options", context, @"context", nil]];
|
[cachedObservers addObject:[NSDictionary dictionaryWithObjectsAndKeys:observer, @"observer", keyPath, @"keyPath", @(options), @"options", context, @"context", nil]];
|
||||||
} else {
|
} else {
|
||||||
[cachedObservers addObject:[NSDictionary dictionaryWithObjectsAndKeys:observer, @"observer", keyPath, @"keyPath", @(options), @"options", nil]];
|
[cachedObservers addObject:[NSDictionary dictionaryWithObjectsAndKeys:observer, @"observer", keyPath, @"keyPath", @(options), @"options", nil]];
|
||||||
}
|
}
|
||||||
if (theDecoder) {
|
if(theDecoder) {
|
||||||
[theDecoder addObserver:observer forKeyPath:keyPath options:options context:context];
|
[theDecoder addObserver:observer forKeyPath:keyPath options:options context:context];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* And this is currently called after the decoder is closed */
|
/* And this is currently called after the decoder is closed */
|
||||||
- (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath
|
- (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath {
|
||||||
{
|
for(NSDictionary *obsItem in cachedObservers) {
|
||||||
for (NSDictionary *obsItem in cachedObservers) {
|
if([obsItem objectForKey:@"observer"] == observer && [keyPath isEqualToString:[obsItem objectForKey:@"keyPath"]]) {
|
||||||
if ([obsItem objectForKey:@"observer"] == observer && [keyPath isEqualToString:[obsItem objectForKey:@"keyPath"]]) {
|
|
||||||
[cachedObservers removeObject:obsItem];
|
[cachedObservers removeObject:obsItem];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (theDecoder) {
|
if(theDecoder) {
|
||||||
[theDecoder removeObserver:observer forKeyPath:keyPath];
|
[theDecoder removeObserver:observer forKeyPath:keyPath];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation CogContainerMulti
|
@implementation CogContainerMulti
|
||||||
|
|
||||||
+ (NSArray *)urlsForContainerURL:(NSURL *)url containers:(NSArray *)containers
|
+ (NSArray *)urlsForContainerURL:(NSURL *)url containers:(NSArray *)containers {
|
||||||
{
|
NSArray *sortedContainers = sortClassesByPriority(containers);
|
||||||
NSArray * sortedContainers = sortClassesByPriority(containers);
|
for(NSString *classString in sortedContainers) {
|
||||||
for (NSString *classString in sortedContainers)
|
|
||||||
{
|
|
||||||
Class container = NSClassFromString(classString);
|
Class container = NSClassFromString(classString);
|
||||||
NSArray * urls = [container urlsForContainerURL:url];
|
NSArray *urls = [container urlsForContainerURL:url];
|
||||||
if ([urls count])
|
if([urls count])
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
return nil;
|
return nil;
|
||||||
|
@ -172,14 +156,12 @@ NSArray * sortClassesByPriority(NSArray * theClasses)
|
||||||
|
|
||||||
@implementation CogMetadataReaderMulti
|
@implementation CogMetadataReaderMulti
|
||||||
|
|
||||||
+ (NSDictionary *)metadataForURL:(NSURL *)url readers:(NSArray *)readers
|
+ (NSDictionary *)metadataForURL:(NSURL *)url readers:(NSArray *)readers {
|
||||||
{
|
NSArray *sortedReaders = sortClassesByPriority(readers);
|
||||||
NSArray * sortedReaders = sortClassesByPriority(readers);
|
for(NSString *classString in sortedReaders) {
|
||||||
for (NSString *classString in sortedReaders)
|
|
||||||
{
|
|
||||||
Class reader = NSClassFromString(classString);
|
Class reader = NSClassFromString(classString);
|
||||||
NSDictionary * data = [reader metadataForURL:url];
|
NSDictionary *data = [reader metadataForURL:url];
|
||||||
if ([data count])
|
if([data count])
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
return nil;
|
return nil;
|
||||||
|
@ -189,16 +171,14 @@ NSArray * sortClassesByPriority(NSArray * theClasses)
|
||||||
|
|
||||||
@implementation CogPropertiesReaderMulti
|
@implementation CogPropertiesReaderMulti
|
||||||
|
|
||||||
+ (NSDictionary *)propertiesForSource:(id<CogSource>)source readers:(NSArray *)readers
|
+ (NSDictionary *)propertiesForSource:(id<CogSource>)source readers:(NSArray *)readers {
|
||||||
{
|
NSArray *sortedReaders = sortClassesByPriority(readers);
|
||||||
NSArray * sortedReaders = sortClassesByPriority(readers);
|
for(NSString *classString in sortedReaders) {
|
||||||
for (NSString *classString in sortedReaders)
|
|
||||||
{
|
|
||||||
Class reader = NSClassFromString(classString);
|
Class reader = NSClassFromString(classString);
|
||||||
NSDictionary * data = [reader propertiesForSource:source];
|
NSDictionary *data = [reader propertiesForSource:source];
|
||||||
if ([data count])
|
if([data count])
|
||||||
return data;
|
return data;
|
||||||
if ([source seekable])
|
if([source seekable])
|
||||||
[source seek:0 whence:SEEK_SET];
|
[source seek:0 whence:SEEK_SET];
|
||||||
}
|
}
|
||||||
return nil;
|
return nil;
|
||||||
|
|
|
@ -7,21 +7,19 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
#include "Helper.h"
|
#include "Helper.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
//These functions are helpers for the process of converting volume from a linear to logarithmic scale.
|
// These functions are helpers for the process of converting volume from a linear to logarithmic scale.
|
||||||
//Numbers that goes in to audioPlayer should be logarithmic. Numbers that are displayed to the user should be linear.
|
// Numbers that goes in to audioPlayer should be logarithmic. Numbers that are displayed to the user should be linear.
|
||||||
//Here's why: http://www.dr-lex.34sp.com/info-stuff/volumecontrols.html
|
// Here's why: http://www.dr-lex.34sp.com/info-stuff/volumecontrols.html
|
||||||
//We are using the approximation of X^4.
|
// We are using the approximation of X^4.
|
||||||
//Input/Output values are in percents.
|
// Input/Output values are in percents.
|
||||||
double logarithmicToLinear(double logarithmic, double MAX_VOLUME)
|
double logarithmicToLinear(double logarithmic, double MAX_VOLUME) {
|
||||||
{
|
return (MAX_VOLUME == 100.0) ? logarithmic : pow((logarithmic / MAX_VOLUME), 0.25) * 100.0;
|
||||||
return (MAX_VOLUME == 100.0) ? logarithmic : pow((logarithmic/MAX_VOLUME), 0.25) * 100.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double linearToLogarithmic(double linear, double MAX_VOLUME)
|
double linearToLogarithmic(double linear, double MAX_VOLUME) {
|
||||||
{
|
return (MAX_VOLUME == 100.0) ? linear : (linear / 100.0) * (linear / 100.0) * (linear / 100.0) * (linear / 100.0) * MAX_VOLUME;
|
||||||
return (MAX_VOLUME == 100.0) ? linear : (linear/100.0) * (linear/100.0) * (linear/100.0) * (linear/100.0) * MAX_VOLUME;
|
|
||||||
}
|
}
|
||||||
//End helper volume function thingies. ONWARDS TO GLORY!
|
// End helper volume function thingies. ONWARDS TO GLORY!
|
||||||
|
|
|
@ -9,10 +9,10 @@
|
||||||
#import <AssertMacros.h>
|
#import <AssertMacros.h>
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
#import <CoreAudio/AudioHardware.h>
|
#import <AVFoundation/AVFoundation.h>
|
||||||
#import <AudioToolbox/AudioToolbox.h>
|
#import <AudioToolbox/AudioToolbox.h>
|
||||||
#import <AudioUnit/AudioUnit.h>
|
#import <AudioUnit/AudioUnit.h>
|
||||||
#import <AVFoundation/AVFoundation.h>
|
#import <CoreAudio/AudioHardware.h>
|
||||||
#import <CoreAudio/CoreAudioTypes.h>
|
#import <CoreAudio/CoreAudioTypes.h>
|
||||||
|
|
||||||
#import <stdatomic.h>
|
#import <stdatomic.h>
|
||||||
|
@ -29,10 +29,10 @@
|
||||||
@class OutputNode;
|
@class OutputNode;
|
||||||
|
|
||||||
@interface OutputCoreAudio : NSObject {
|
@interface OutputCoreAudio : NSObject {
|
||||||
OutputNode * outputController;
|
OutputNode *outputController;
|
||||||
|
|
||||||
Semaphore * writeSemaphore;
|
Semaphore *writeSemaphore;
|
||||||
Semaphore * readSemaphore;
|
Semaphore *readSemaphore;
|
||||||
|
|
||||||
BOOL stopInvoked;
|
BOOL stopInvoked;
|
||||||
BOOL running;
|
BOOL running;
|
||||||
|
@ -65,7 +65,7 @@
|
||||||
|
|
||||||
AudioUnit _eq;
|
AudioUnit _eq;
|
||||||
|
|
||||||
DownmixProcessor * downmixer;
|
DownmixProcessor *downmixer;
|
||||||
|
|
||||||
#ifdef OUTPUT_LOG
|
#ifdef OUTPUT_LOG
|
||||||
FILE *_logFile;
|
FILE *_logFile;
|
||||||
|
@ -82,7 +82,7 @@
|
||||||
- (void)resume;
|
- (void)resume;
|
||||||
- (void)stop;
|
- (void)stop;
|
||||||
|
|
||||||
- (void)setVolume:(double) v;
|
- (void)setVolume:(double)v;
|
||||||
|
|
||||||
- (void)setEqualizerEnabled:(BOOL)enabled;
|
- (void)setEqualizerEnabled:(BOOL)enabled;
|
||||||
|
|
||||||
|
|
|
@ -11,22 +11,19 @@
|
||||||
|
|
||||||
#import "Logging.h"
|
#import "Logging.h"
|
||||||
|
|
||||||
extern void scale_by_volume(float * buffer, size_t count, float volume);
|
extern void scale_by_volume(float *buffer, size_t count, float volume);
|
||||||
|
|
||||||
static NSString *CogPlaybackDidBeginNotficiation = @"CogPlaybackDidBeginNotficiation";
|
static NSString *CogPlaybackDidBeginNotficiation = @"CogPlaybackDidBeginNotficiation";
|
||||||
|
|
||||||
@implementation OutputCoreAudio
|
@implementation OutputCoreAudio
|
||||||
|
|
||||||
static void fillBuffers(AudioBufferList *ioData, float * inbuffer, size_t count, size_t offset)
|
static void fillBuffers(AudioBufferList *ioData, float *inbuffer, size_t count, size_t offset) {
|
||||||
{
|
|
||||||
const size_t channels = ioData->mNumberBuffers;
|
const size_t channels = ioData->mNumberBuffers;
|
||||||
for (int i = 0; i < channels; ++i)
|
for(int i = 0; i < channels; ++i) {
|
||||||
{
|
|
||||||
const size_t maxCount = (ioData->mBuffers[i].mDataByteSize / sizeof(float)) - offset;
|
const size_t maxCount = (ioData->mBuffers[i].mDataByteSize / sizeof(float)) - offset;
|
||||||
float * output = ((float *)ioData->mBuffers[i].mData) + offset;
|
float *output = ((float *)ioData->mBuffers[i].mData) + offset;
|
||||||
const float * input = inbuffer + i;
|
const float *input = inbuffer + i;
|
||||||
for (size_t j = 0, k = (count > maxCount) ? maxCount : count; j < k; ++j)
|
for(size_t j = 0, k = (count > maxCount) ? maxCount : count; j < k; ++j) {
|
||||||
{
|
|
||||||
*output = *input;
|
*output = *input;
|
||||||
output++;
|
output++;
|
||||||
input += channels;
|
input += channels;
|
||||||
|
@ -35,29 +32,23 @@ static void fillBuffers(AudioBufferList *ioData, float * inbuffer, size_t count,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void clearBuffers(AudioBufferList *ioData, size_t count, size_t offset)
|
static void clearBuffers(AudioBufferList *ioData, size_t count, size_t offset) {
|
||||||
{
|
for(int i = 0; i < ioData->mNumberBuffers; ++i) {
|
||||||
for (int i = 0; i < ioData->mNumberBuffers; ++i)
|
|
||||||
{
|
|
||||||
memset(ioData->mBuffers[i].mData + offset * sizeof(float), 0, count * sizeof(float));
|
memset(ioData->mBuffers[i].mData + offset * sizeof(float), 0, count * sizeof(float));
|
||||||
ioData->mBuffers[i].mNumberChannels = 1;
|
ioData->mBuffers[i].mNumberChannels = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void scaleBuffersByVolume(AudioBufferList *ioData, float volume)
|
static void scaleBuffersByVolume(AudioBufferList *ioData, float volume) {
|
||||||
{
|
if(volume != 1.0) {
|
||||||
if (volume != 1.0)
|
for(int i = 0; i < ioData->mNumberBuffers; ++i) {
|
||||||
{
|
scale_by_volume((float *)ioData->mBuffers[i].mData, ioData->mBuffers[i].mDataByteSize / sizeof(float), volume);
|
||||||
for (int i = 0; i < ioData->mNumberBuffers; ++i)
|
|
||||||
{
|
|
||||||
scale_by_volume((float*)ioData->mBuffers[i].mData, ioData->mBuffers[i].mDataByteSize / sizeof(float), volume);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static OSStatus renderCallback( void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData )
|
static OSStatus renderCallback(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData) {
|
||||||
{
|
OutputCoreAudio *_self = (__bridge OutputCoreAudio *)inRefCon;
|
||||||
OutputCoreAudio * _self = (__bridge OutputCoreAudio *) inRefCon;
|
|
||||||
|
|
||||||
const int channels = _self->deviceFormat.mChannelsPerFrame;
|
const int channels = _self->deviceFormat.mChannelsPerFrame;
|
||||||
const int bytesPerPacket = channels * sizeof(float);
|
const int bytesPerPacket = channels * sizeof(float);
|
||||||
|
@ -66,8 +57,7 @@ static OSStatus renderCallback( void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
||||||
|
|
||||||
amountToRead = inNumberFrames * bytesPerPacket;
|
amountToRead = inNumberFrames * bytesPerPacket;
|
||||||
|
|
||||||
if (_self->stopping == YES || [_self->outputController shouldContinue] == NO)
|
if(_self->stopping == YES || [_self->outputController shouldContinue] == NO) {
|
||||||
{
|
|
||||||
// Chain is dead, fill out the serial number pointer forever with silence
|
// Chain is dead, fill out the serial number pointer forever with silence
|
||||||
clearBuffers(ioData, amountToRead / bytesPerPacket, 0);
|
clearBuffers(ioData, amountToRead / bytesPerPacket, 0);
|
||||||
atomic_fetch_add(&_self->bytesRendered, amountToRead);
|
atomic_fetch_add(&_self->bytesRendered, amountToRead);
|
||||||
|
@ -75,21 +65,20 @@ static OSStatus renderCallback( void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([[_self->outputController buffer] isEmpty] && ![_self->outputController chainQueueHasTracks])
|
if([[_self->outputController buffer] isEmpty] && ![_self->outputController chainQueueHasTracks]) {
|
||||||
{
|
|
||||||
// Hit end of last track, pad with silence until queue event stops us
|
// Hit end of last track, pad with silence until queue event stops us
|
||||||
clearBuffers(ioData, amountToRead / bytesPerPacket, 0);
|
clearBuffers(ioData, amountToRead / bytesPerPacket, 0);
|
||||||
atomic_fetch_add(&_self->bytesRendered, amountToRead);
|
atomic_fetch_add(&_self->bytesRendered, amountToRead);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioChunk * chunk = [[_self->outputController buffer] removeSamples:(amountToRead / bytesPerPacket)];
|
AudioChunk *chunk = [[_self->outputController buffer] removeSamples:(amountToRead / bytesPerPacket)];
|
||||||
|
|
||||||
size_t frameCount = [chunk frameCount];
|
size_t frameCount = [chunk frameCount];
|
||||||
AudioStreamBasicDescription format = [chunk format];
|
AudioStreamBasicDescription format = [chunk format];
|
||||||
|
|
||||||
if (frameCount) {
|
if(frameCount) {
|
||||||
if (!_self->streamFormatStarted || memcmp(&_self->streamFormat, &format, sizeof(format)) != 0) {
|
if(!_self->streamFormatStarted || memcmp(&_self->streamFormat, &format, sizeof(format)) != 0) {
|
||||||
_self->streamFormat = format;
|
_self->streamFormat = format;
|
||||||
_self->streamFormatStarted = YES;
|
_self->streamFormatStarted = YES;
|
||||||
_self->downmixer = [[DownmixProcessor alloc] initWithInputFormat:format andOutputFormat:_self->deviceFormat];
|
_self->downmixer = [[DownmixProcessor alloc] initWithInputFormat:format andOutputFormat:_self->deviceFormat];
|
||||||
|
@ -97,7 +86,7 @@ static OSStatus renderCallback( void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
||||||
|
|
||||||
double chunkDuration = [chunk duration];
|
double chunkDuration = [chunk duration];
|
||||||
|
|
||||||
NSData * samples = [chunk removeSamples:frameCount];
|
NSData *samples = [chunk removeSamples:frameCount];
|
||||||
|
|
||||||
float downmixedData[frameCount * channels];
|
float downmixedData[frameCount * channels];
|
||||||
[_self->downmixer process:[samples bytes] frameCount:frameCount output:downmixedData];
|
[_self->downmixer process:[samples bytes] frameCount:frameCount output:downmixedData];
|
||||||
|
@ -111,20 +100,19 @@ static OSStatus renderCallback( void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
||||||
|
|
||||||
// Try repeatedly! Buffer wraps can cause a slight data shortage, as can
|
// Try repeatedly! Buffer wraps can cause a slight data shortage, as can
|
||||||
// unexpected track changes.
|
// unexpected track changes.
|
||||||
while ((amountRead < amountToRead) && [_self->outputController shouldContinue] == YES)
|
while((amountRead < amountToRead) && [_self->outputController shouldContinue] == YES) {
|
||||||
{
|
|
||||||
chunk = [[_self->outputController buffer] removeSamples:((amountToRead - amountRead) / bytesPerPacket)];
|
chunk = [[_self->outputController buffer] removeSamples:((amountToRead - amountRead) / bytesPerPacket)];
|
||||||
frameCount = [chunk frameCount];
|
frameCount = [chunk frameCount];
|
||||||
format = [chunk format];
|
format = [chunk format];
|
||||||
if (frameCount) {
|
if(frameCount) {
|
||||||
if (!_self->streamFormatStarted || memcmp(&_self->streamFormat, &format, sizeof(format)) != 0) {
|
if(!_self->streamFormatStarted || memcmp(&_self->streamFormat, &format, sizeof(format)) != 0) {
|
||||||
_self->streamFormat = format;
|
_self->streamFormat = format;
|
||||||
_self->streamFormatStarted = YES;
|
_self->streamFormatStarted = YES;
|
||||||
_self->downmixer = [[DownmixProcessor alloc] initWithInputFormat:format andOutputFormat:_self->deviceFormat];
|
_self->downmixer = [[DownmixProcessor alloc] initWithInputFormat:format andOutputFormat:_self->deviceFormat];
|
||||||
}
|
}
|
||||||
atomic_fetch_add(&_self->bytesRendered, frameCount * bytesPerPacket);
|
atomic_fetch_add(&_self->bytesRendered, frameCount * bytesPerPacket);
|
||||||
double chunkDuration = [chunk duration];
|
double chunkDuration = [chunk duration];
|
||||||
NSData * samples = [chunk removeSamples:frameCount];
|
NSData *samples = [chunk removeSamples:frameCount];
|
||||||
float downmixedData[frameCount * channels];
|
float downmixedData[frameCount * channels];
|
||||||
[_self->downmixer process:[samples bytes] frameCount:frameCount output:downmixedData];
|
[_self->downmixer process:[samples bytes] frameCount:frameCount output:downmixedData];
|
||||||
fillBuffers(ioData, downmixedData, frameCount, amountRead / bytesPerPacket);
|
fillBuffers(ioData, downmixedData, frameCount, amountRead / bytesPerPacket);
|
||||||
|
@ -133,19 +121,17 @@ static OSStatus renderCallback( void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
||||||
|
|
||||||
amountRead += frameCount * bytesPerPacket;
|
amountRead += frameCount * bytesPerPacket;
|
||||||
[_self->writeSemaphore signal];
|
[_self->writeSemaphore signal];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
[_self->readSemaphore timedWait:500];
|
[_self->readSemaphore timedWait:500];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float volumeScale = 1.0;
|
float volumeScale = 1.0;
|
||||||
long sustained = atomic_load_explicit(&_self->bytesHdcdSustained, memory_order_relaxed);
|
long sustained = atomic_load_explicit(&_self->bytesHdcdSustained, memory_order_relaxed);
|
||||||
if (sustained) {
|
if(sustained) {
|
||||||
if (sustained < amountRead) {
|
if(sustained < amountRead) {
|
||||||
atomic_store(&_self->bytesHdcdSustained, 0);
|
atomic_store(&_self->bytesHdcdSustained, 0);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
atomic_fetch_sub(&_self->bytesHdcdSustained, amountRead);
|
atomic_fetch_sub(&_self->bytesHdcdSustained, amountRead);
|
||||||
}
|
}
|
||||||
volumeScale = 0.5;
|
volumeScale = 0.5;
|
||||||
|
@ -153,8 +139,7 @@ static OSStatus renderCallback( void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
||||||
|
|
||||||
scaleBuffersByVolume(ioData, _self->volume * volumeScale);
|
scaleBuffersByVolume(ioData, _self->volume * volumeScale);
|
||||||
|
|
||||||
if (amountRead < amountToRead)
|
if(amountRead < amountToRead) {
|
||||||
{
|
|
||||||
// Either underrun, or no data at all. Caller output tends to just
|
// Either underrun, or no data at all. Caller output tends to just
|
||||||
// buffer loop if it doesn't get anything, so always produce a full
|
// buffer loop if it doesn't get anything, so always produce a full
|
||||||
// buffer, and silence anything we couldn't supply.
|
// buffer, and silence anything we couldn't supply.
|
||||||
|
@ -164,11 +149,9 @@ static OSStatus renderCallback( void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
- (id)initWithController:(OutputNode *)c
|
- (id)initWithController:(OutputNode *)c {
|
||||||
{
|
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self)
|
if(self) {
|
||||||
{
|
|
||||||
outputController = c;
|
outputController = c;
|
||||||
_au = nil;
|
_au = nil;
|
||||||
_eq = NULL;
|
_eq = NULL;
|
||||||
|
@ -197,35 +180,29 @@ static OSStatus renderCallback( void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
||||||
}
|
}
|
||||||
|
|
||||||
static OSStatus
|
static OSStatus
|
||||||
default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const AudioObjectPropertyAddress *inAddresses, void *inUserData)
|
default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const AudioObjectPropertyAddress *inAddresses, void *inUserData) {
|
||||||
{
|
OutputCoreAudio *this = (__bridge OutputCoreAudio *)inUserData;
|
||||||
OutputCoreAudio *this = (__bridge OutputCoreAudio *) inUserData;
|
|
||||||
return [this setOutputDeviceByID:-1];
|
return [this setOutputDeviceByID:-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
|
||||||
{
|
if([keyPath isEqualToString:@"values.outputDevice"]) {
|
||||||
if ([keyPath isEqualToString:@"values.outputDevice"]) {
|
|
||||||
|
|
||||||
NSDictionary *device = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"outputDevice"];
|
NSDictionary *device = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"outputDevice"];
|
||||||
|
|
||||||
[self setOutputDeviceWithDeviceDict:device];
|
[self setOutputDeviceWithDeviceDict:device];
|
||||||
}
|
} else if([keyPath isEqualToString:@"values.GraphicEQenable"]) {
|
||||||
else if ([keyPath isEqualToString:@"values.GraphicEQenable"]) {
|
|
||||||
BOOL enabled = [[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"GraphicEQenable"] boolValue];
|
BOOL enabled = [[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"GraphicEQenable"] boolValue];
|
||||||
|
|
||||||
[self setEqualizerEnabled:enabled];
|
[self setEqualizerEnabled:enabled];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)signalEndOfStream
|
- (void)signalEndOfStream {
|
||||||
{
|
|
||||||
[outputController resetAmountPlayed];
|
[outputController resetAmountPlayed];
|
||||||
[outputController endOfInputPlayed];
|
[outputController endOfInputPlayed];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)threadEntry:(id)arg
|
- (void)threadEntry:(id)arg {
|
||||||
{
|
|
||||||
running = YES;
|
running = YES;
|
||||||
started = NO;
|
started = NO;
|
||||||
stopNext = NO;
|
stopNext = NO;
|
||||||
|
@ -233,82 +210,77 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
atomic_store(&bytesRendered, 0);
|
atomic_store(&bytesRendered, 0);
|
||||||
NSMutableArray *delayedEvents = [[NSMutableArray alloc] init];
|
NSMutableArray *delayedEvents = [[NSMutableArray alloc] init];
|
||||||
BOOL delayedEventsPopped = YES;
|
BOOL delayedEventsPopped = YES;
|
||||||
while (!stopping) {
|
while(!stopping) {
|
||||||
if (++eventCount == 128) {
|
if(++eventCount == 128) {
|
||||||
[self updateDeviceFormat];
|
[self updateDeviceFormat];
|
||||||
eventCount = 0;
|
eventCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([outputController shouldReset]) {
|
if([outputController shouldReset]) {
|
||||||
[[outputController buffer] reset];
|
[[outputController buffer] reset];
|
||||||
[outputController setShouldReset:NO];
|
[outputController setShouldReset:NO];
|
||||||
[delayedEvents removeAllObjects];
|
[delayedEvents removeAllObjects];
|
||||||
delayedEventsPopped = YES;
|
delayedEventsPopped = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ([delayedEvents count]) {
|
while([delayedEvents count]) {
|
||||||
size_t localBytesRendered = atomic_load_explicit(&bytesRendered, memory_order_relaxed);
|
size_t localBytesRendered = atomic_load_explicit(&bytesRendered, memory_order_relaxed);
|
||||||
double secondsRendered = (double)localBytesRendered / (double)(deviceFormat.mBytesPerPacket * deviceFormat.mSampleRate);
|
double secondsRendered = (double)localBytesRendered / (double)(deviceFormat.mBytesPerPacket * deviceFormat.mSampleRate);
|
||||||
if (secondsRendered >= [[delayedEvents objectAtIndex:0] doubleValue]) {
|
if(secondsRendered >= [[delayedEvents objectAtIndex:0] doubleValue]) {
|
||||||
if ([outputController chainQueueHasTracks])
|
if([outputController chainQueueHasTracks])
|
||||||
delayedEventsPopped = YES;
|
delayedEventsPopped = YES;
|
||||||
[self signalEndOfStream];
|
[self signalEndOfStream];
|
||||||
[delayedEvents removeObjectAtIndex:0];
|
[delayedEvents removeObjectAtIndex:0];
|
||||||
}
|
} else
|
||||||
else break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stopping)
|
if(stopping)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
size_t frameCount = 0;
|
size_t frameCount = 0;
|
||||||
|
|
||||||
if (![[outputController buffer] isFull]) {
|
if(![[outputController buffer] isFull]) {
|
||||||
AudioChunk * chunk = [outputController readChunk:512];
|
AudioChunk *chunk = [outputController readChunk:512];
|
||||||
frameCount = [chunk frameCount];
|
frameCount = [chunk frameCount];
|
||||||
if (frameCount) {
|
if(frameCount) {
|
||||||
[[outputController buffer] addChunk:chunk];
|
[[outputController buffer] addChunk:chunk];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frameCount) {
|
if(frameCount) {
|
||||||
[readSemaphore signal];
|
[readSemaphore signal];
|
||||||
continue;
|
continue;
|
||||||
}
|
} else if([outputController shouldContinue] == NO)
|
||||||
else if ([outputController shouldContinue] == NO)
|
|
||||||
break;
|
break;
|
||||||
else if ([[outputController buffer] isFull]) {
|
else if([[outputController buffer] isFull]) {
|
||||||
if (!started) {
|
if(!started) {
|
||||||
started = YES;
|
started = YES;
|
||||||
if (!paused) {
|
if(!paused) {
|
||||||
NSError *err;
|
NSError *err;
|
||||||
[_au startHardwareAndReturnError:&err];
|
[_au startHardwareAndReturnError:&err];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// End of input possibly reached
|
// End of input possibly reached
|
||||||
if (delayedEventsPopped && [outputController endOfStream] == YES)
|
if(delayedEventsPopped && [outputController endOfStream] == YES) {
|
||||||
{
|
|
||||||
double secondsBuffered = [[outputController buffer] listDuration];
|
double secondsBuffered = [[outputController buffer] listDuration];
|
||||||
size_t _bytesRendered = atomic_load_explicit(&bytesRendered, memory_order_relaxed);
|
size_t _bytesRendered = atomic_load_explicit(&bytesRendered, memory_order_relaxed);
|
||||||
secondsBuffered += (double)_bytesRendered / (double)(deviceFormat.mBytesPerPacket * deviceFormat.mSampleRate);
|
secondsBuffered += (double)_bytesRendered / (double)(deviceFormat.mBytesPerPacket * deviceFormat.mSampleRate);
|
||||||
if ([outputController chainQueueHasTracks])
|
if([outputController chainQueueHasTracks]) {
|
||||||
{
|
if(secondsBuffered <= 0.005)
|
||||||
if (secondsBuffered <= 0.005)
|
|
||||||
secondsBuffered = 0.0;
|
secondsBuffered = 0.0;
|
||||||
else
|
else
|
||||||
secondsBuffered -= 0.005;
|
secondsBuffered -= 0.005;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
stopNext = YES;
|
stopNext = YES;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
[delayedEvents addObject:[NSNumber numberWithDouble:secondsBuffered]];
|
[delayedEvents addObject:[NSNumber numberWithDouble:secondsBuffered]];
|
||||||
delayedEventsPopped = NO;
|
delayedEventsPopped = NO;
|
||||||
if (!started) {
|
if(!started) {
|
||||||
started = YES;
|
started = YES;
|
||||||
if (!paused) {
|
if(!paused) {
|
||||||
NSError *err;
|
NSError *err;
|
||||||
[_au startHardwareAndReturnError:&err];
|
[_au startHardwareAndReturnError:&err];
|
||||||
}
|
}
|
||||||
|
@ -319,12 +291,11 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
[writeSemaphore timedWait:5000];
|
[writeSemaphore timedWait:5000];
|
||||||
}
|
}
|
||||||
stopped = YES;
|
stopped = YES;
|
||||||
if (!stopInvoked)
|
if(!stopInvoked)
|
||||||
[self stop];
|
[self stop];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (OSStatus)setOutputDeviceByID:(AudioDeviceID)deviceID
|
- (OSStatus)setOutputDeviceByID:(AudioDeviceID)deviceID {
|
||||||
{
|
|
||||||
OSStatus err;
|
OSStatus err;
|
||||||
BOOL defaultDevice = NO;
|
BOOL defaultDevice = NO;
|
||||||
AudioObjectPropertyAddress theAddress = {
|
AudioObjectPropertyAddress theAddress = {
|
||||||
|
@ -333,47 +304,46 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
.mElement = kAudioObjectPropertyElementMaster
|
.mElement = kAudioObjectPropertyElementMaster
|
||||||
};
|
};
|
||||||
|
|
||||||
if (deviceID == -1) {
|
if(deviceID == -1) {
|
||||||
defaultDevice = YES;
|
defaultDevice = YES;
|
||||||
UInt32 size = sizeof(AudioDeviceID);
|
UInt32 size = sizeof(AudioDeviceID);
|
||||||
err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress, 0, NULL, &size, &deviceID);
|
err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress, 0, NULL, &size, &deviceID);
|
||||||
|
|
||||||
if (err != noErr) {
|
if(err != noErr) {
|
||||||
DLog(@"THERE'S NO DEFAULT OUTPUT DEVICE");
|
DLog(@"THERE'S NO DEFAULT OUTPUT DEVICE");
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_au) {
|
if(_au) {
|
||||||
AudioObjectPropertyAddress defaultDeviceAddress = theAddress;
|
AudioObjectPropertyAddress defaultDeviceAddress = theAddress;
|
||||||
|
|
||||||
if (listenerapplied && !defaultDevice) {
|
if(listenerapplied && !defaultDevice) {
|
||||||
AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &defaultDeviceAddress, default_device_changed, (__bridge void * _Nullable)(self));
|
AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &defaultDeviceAddress, default_device_changed, (__bridge void *_Nullable)(self));
|
||||||
listenerapplied = NO;
|
listenerapplied = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outputDeviceID != deviceID) {
|
if(outputDeviceID != deviceID) {
|
||||||
DLog(@"Device: %i\n", deviceID);
|
DLog(@"Device: %i\n", deviceID);
|
||||||
outputDeviceID = deviceID;
|
outputDeviceID = deviceID;
|
||||||
|
|
||||||
NSError *nserr;
|
NSError *nserr;
|
||||||
[_au setDeviceID:outputDeviceID error:&nserr];
|
[_au setDeviceID:outputDeviceID error:&nserr];
|
||||||
if (nserr != nil) {
|
if(nserr != nil) {
|
||||||
return (OSErr)[nserr code];
|
return (OSErr)[nserr code];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!listenerapplied && defaultDevice) {
|
if(!listenerapplied && defaultDevice) {
|
||||||
AudioObjectAddPropertyListener(kAudioObjectSystemObject, &defaultDeviceAddress, default_device_changed, (__bridge void * _Nullable)(self));
|
AudioObjectAddPropertyListener(kAudioObjectSystemObject, &defaultDeviceAddress, default_device_changed, (__bridge void *_Nullable)(self));
|
||||||
listenerapplied = YES;
|
listenerapplied = YES;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
err = noErr;
|
err = noErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err != noErr) {
|
if(err != noErr) {
|
||||||
DLog(@"No output device with ID %d could be found.", deviceID);
|
DLog(@"No output device with ID %d could be found.", deviceID);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
@ -382,20 +352,19 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)setOutputDeviceWithDeviceDict:(NSDictionary *)deviceDict
|
- (BOOL)setOutputDeviceWithDeviceDict:(NSDictionary *)deviceDict {
|
||||||
{
|
|
||||||
NSNumber *deviceIDNum = [deviceDict objectForKey:@"deviceID"];
|
NSNumber *deviceIDNum = [deviceDict objectForKey:@"deviceID"];
|
||||||
AudioDeviceID outputDeviceID = [deviceIDNum unsignedIntValue] ?: -1;
|
AudioDeviceID outputDeviceID = [deviceIDNum unsignedIntValue] ?: -1;
|
||||||
|
|
||||||
__block OSStatus err = [self setOutputDeviceByID:outputDeviceID];
|
__block OSStatus err = [self setOutputDeviceByID:outputDeviceID];
|
||||||
|
|
||||||
if (err != noErr) {
|
if(err != noErr) {
|
||||||
// Try matching by name.
|
// Try matching by name.
|
||||||
NSString *userDeviceName = deviceDict[@"name"];
|
NSString *userDeviceName = deviceDict[@"name"];
|
||||||
|
|
||||||
[self enumerateAudioOutputsUsingBlock:
|
[self enumerateAudioOutputsUsingBlock:
|
||||||
^(NSString *deviceName, AudioDeviceID deviceID, AudioDeviceID systemDefaultID, BOOL *stop) {
|
^(NSString *deviceName, AudioDeviceID deviceID, AudioDeviceID systemDefaultID, BOOL *stop) {
|
||||||
if ([deviceName isEqualToString:userDeviceName]) {
|
if([deviceName isEqualToString:userDeviceName]) {
|
||||||
err = [self setOutputDeviceByID:deviceID];
|
err = [self setOutputDeviceByID:deviceID];
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -415,8 +384,7 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err != noErr) {
|
if(err != noErr) {
|
||||||
|
|
||||||
ALog(@"No output device could be found, your random error code is %d. Have a nice day!", err);
|
ALog(@"No output device could be found, your random error code is %d. Have a nice day!", err);
|
||||||
|
|
||||||
return NO;
|
return NO;
|
||||||
|
@ -427,8 +395,7 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
|
|
||||||
// The following is largely a copy pasta of -awakeFromNib from "OutputsArrayController.m".
|
// The following is largely a copy pasta of -awakeFromNib from "OutputsArrayController.m".
|
||||||
// TODO: Share the code. (How to do this across xcodeproj?)
|
// TODO: Share the code. (How to do this across xcodeproj?)
|
||||||
- (void)enumerateAudioOutputsUsingBlock:(void (NS_NOESCAPE ^ _Nonnull)(NSString *deviceName, AudioDeviceID deviceID, AudioDeviceID systemDefaultID, BOOL *stop))block
|
- (void)enumerateAudioOutputsUsingBlock:(void(NS_NOESCAPE ^ _Nonnull)(NSString *deviceName, AudioDeviceID deviceID, AudioDeviceID systemDefaultID, BOOL *stop))block {
|
||||||
{
|
|
||||||
UInt32 propsize;
|
UInt32 propsize;
|
||||||
AudioObjectPropertyAddress theAddress = {
|
AudioObjectPropertyAddress theAddress = {
|
||||||
.mSelector = kAudioHardwarePropertyDevices,
|
.mSelector = kAudioHardwarePropertyDevices,
|
||||||
|
@ -448,7 +415,7 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
|
|
||||||
theAddress.mScope = kAudioDevicePropertyScopeOutput;
|
theAddress.mScope = kAudioDevicePropertyScopeOutput;
|
||||||
|
|
||||||
for (UInt32 i = 0; i < nDevices; ++i) {
|
for(UInt32 i = 0; i < nDevices; ++i) {
|
||||||
CFStringRef name = NULL;
|
CFStringRef name = NULL;
|
||||||
propsize = sizeof(name);
|
propsize = sizeof(name);
|
||||||
theAddress.mSelector = kAudioDevicePropertyDeviceNameCFString;
|
theAddress.mSelector = kAudioDevicePropertyDeviceNameCFString;
|
||||||
|
@ -458,17 +425,17 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
theAddress.mSelector = kAudioDevicePropertyStreamConfiguration;
|
theAddress.mSelector = kAudioDevicePropertyStreamConfiguration;
|
||||||
__Verify_noErr(AudioObjectGetPropertyDataSize(devids[i], &theAddress, 0, NULL, &propsize));
|
__Verify_noErr(AudioObjectGetPropertyDataSize(devids[i], &theAddress, 0, NULL, &propsize));
|
||||||
|
|
||||||
if (propsize < sizeof(UInt32)) {
|
if(propsize < sizeof(UInt32)) {
|
||||||
CFRelease(name);
|
CFRelease(name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioBufferList * bufferList = (AudioBufferList *) malloc(propsize);
|
AudioBufferList *bufferList = (AudioBufferList *)malloc(propsize);
|
||||||
__Verify_noErr(AudioObjectGetPropertyData(devids[i], &theAddress, 0, NULL, &propsize, bufferList));
|
__Verify_noErr(AudioObjectGetPropertyData(devids[i], &theAddress, 0, NULL, &propsize, bufferList));
|
||||||
UInt32 bufferCount = bufferList->mNumberBuffers;
|
UInt32 bufferCount = bufferList->mNumberBuffers;
|
||||||
free(bufferList);
|
free(bufferList);
|
||||||
|
|
||||||
if (!bufferCount) {
|
if(!bufferCount) {
|
||||||
CFRelease(name);
|
CFRelease(name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -481,7 +448,7 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
|
|
||||||
CFRelease(name);
|
CFRelease(name);
|
||||||
|
|
||||||
if (stop) {
|
if(stop) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -489,12 +456,10 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
free(devids);
|
free(devids);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)updateDeviceFormat
|
- (BOOL)updateDeviceFormat {
|
||||||
{
|
|
||||||
AVAudioFormat *format = _au.outputBusses[0].format;
|
AVAudioFormat *format = _au.outputBusses[0].format;
|
||||||
|
|
||||||
if (!_deviceFormat || ![_deviceFormat isEqual:format])
|
if(!_deviceFormat || ![_deviceFormat isEqual:format]) {
|
||||||
{
|
|
||||||
NSError *err;
|
NSError *err;
|
||||||
AVAudioFormat *renderFormat;
|
AVAudioFormat *renderFormat;
|
||||||
|
|
||||||
|
@ -504,20 +469,20 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
_deviceFormat = format;
|
_deviceFormat = format;
|
||||||
deviceFormat = *(format.streamDescription);
|
deviceFormat = *(format.streamDescription);
|
||||||
|
|
||||||
///Seems some 3rd party devices return incorrect stuff...or I just don't like noninterleaved data.
|
/// Seems some 3rd party devices return incorrect stuff...or I just don't like noninterleaved data.
|
||||||
deviceFormat.mFormatFlags &= ~kLinearPCMFormatFlagIsNonInterleaved;
|
deviceFormat.mFormatFlags &= ~kLinearPCMFormatFlagIsNonInterleaved;
|
||||||
// deviceFormat.mFormatFlags &= ~kLinearPCMFormatFlagIsFloat;
|
// deviceFormat.mFormatFlags &= ~kLinearPCMFormatFlagIsFloat;
|
||||||
// deviceFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger;
|
// deviceFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger;
|
||||||
// We don't want more than 8 channels
|
// We don't want more than 8 channels
|
||||||
if (deviceFormat.mChannelsPerFrame > 8) {
|
if(deviceFormat.mChannelsPerFrame > 8) {
|
||||||
deviceFormat.mChannelsPerFrame = 8;
|
deviceFormat.mChannelsPerFrame = 8;
|
||||||
}
|
}
|
||||||
deviceFormat.mBytesPerFrame = deviceFormat.mChannelsPerFrame*(deviceFormat.mBitsPerChannel/8);
|
deviceFormat.mBytesPerFrame = deviceFormat.mChannelsPerFrame * (deviceFormat.mBitsPerChannel / 8);
|
||||||
deviceFormat.mBytesPerPacket = deviceFormat.mBytesPerFrame * deviceFormat.mFramesPerPacket;
|
deviceFormat.mBytesPerPacket = deviceFormat.mBytesPerFrame * deviceFormat.mFramesPerPacket;
|
||||||
|
|
||||||
/* Set the channel layout for the audio queue */
|
/* Set the channel layout for the audio queue */
|
||||||
AudioChannelLayoutTag tag = 0;
|
AudioChannelLayoutTag tag = 0;
|
||||||
switch (deviceFormat.mChannelsPerFrame) {
|
switch(deviceFormat.mChannelsPerFrame) {
|
||||||
case 1:
|
case 1:
|
||||||
tag = kAudioChannelLayoutTag_Mono;
|
tag = kAudioChannelLayoutTag_Mono;
|
||||||
break;
|
break;
|
||||||
|
@ -546,7 +511,7 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
|
|
||||||
renderFormat = [[AVAudioFormat alloc] initWithStreamDescription:&deviceFormat channelLayout:[[AVAudioChannelLayout alloc] initWithLayoutTag:tag]];
|
renderFormat = [[AVAudioFormat alloc] initWithStreamDescription:&deviceFormat channelLayout:[[AVAudioChannelLayout alloc] initWithLayoutTag:tag]];
|
||||||
[_au.inputBusses[0] setFormat:renderFormat error:&err];
|
[_au.inputBusses[0] setFormat:renderFormat error:&err];
|
||||||
if (err != nil)
|
if(err != nil)
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
[outputController setFormat:&deviceFormat];
|
[outputController setFormat:&deviceFormat];
|
||||||
|
@ -555,15 +520,15 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
|
|
||||||
asbd.mFormatFlags &= ~kAudioFormatFlagIsPacked;
|
asbd.mFormatFlags &= ~kAudioFormatFlagIsPacked;
|
||||||
|
|
||||||
AudioUnitSetProperty (_eq, kAudioUnitProperty_StreamFormat,
|
AudioUnitSetProperty(_eq, kAudioUnitProperty_StreamFormat,
|
||||||
kAudioUnitScope_Input, 0, &asbd, sizeof (asbd));
|
kAudioUnitScope_Input, 0, &asbd, sizeof(asbd));
|
||||||
|
|
||||||
AudioUnitSetProperty (_eq, kAudioUnitProperty_StreamFormat,
|
AudioUnitSetProperty(_eq, kAudioUnitProperty_StreamFormat,
|
||||||
kAudioUnitScope_Output, 0, &asbd, sizeof (asbd));
|
kAudioUnitScope_Output, 0, &asbd, sizeof(asbd));
|
||||||
AudioUnitReset (_eq, kAudioUnitScope_Input, 0);
|
AudioUnitReset(_eq, kAudioUnitScope_Input, 0);
|
||||||
AudioUnitReset (_eq, kAudioUnitScope_Output, 0);
|
AudioUnitReset(_eq, kAudioUnitScope_Output, 0);
|
||||||
|
|
||||||
AudioUnitReset (_eq, kAudioUnitScope_Global, 0);
|
AudioUnitReset(_eq, kAudioUnitScope_Global, 0);
|
||||||
|
|
||||||
eqEnabled = [[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"GraphicEQenable"] boolValue];
|
eqEnabled = [[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"GraphicEQenable"] boolValue];
|
||||||
}
|
}
|
||||||
|
@ -571,9 +536,8 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)setup
|
- (BOOL)setup {
|
||||||
{
|
if(_au)
|
||||||
if (_au)
|
|
||||||
[self stop];
|
[self stop];
|
||||||
|
|
||||||
stopInvoked = NO;
|
stopInvoked = NO;
|
||||||
|
@ -596,21 +560,20 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
desc.componentFlagsMask = 0;
|
desc.componentFlagsMask = 0;
|
||||||
|
|
||||||
_au = [[AUAudioUnit alloc] initWithComponentDescription:desc error:&err];
|
_au = [[AUAudioUnit alloc] initWithComponentDescription:desc error:&err];
|
||||||
if (err != nil)
|
if(err != nil)
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
// Setup the output device before mucking with settings
|
// Setup the output device before mucking with settings
|
||||||
NSDictionary *device = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"outputDevice"];
|
NSDictionary *device = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"outputDevice"];
|
||||||
if (device) {
|
if(device) {
|
||||||
BOOL ok = [self setOutputDeviceWithDeviceDict:device];
|
BOOL ok = [self setOutputDeviceWithDeviceDict:device];
|
||||||
if (!ok) {
|
if(!ok) {
|
||||||
//Ruh roh.
|
// Ruh roh.
|
||||||
[self setOutputDeviceWithDeviceDict:nil];
|
[self setOutputDeviceWithDeviceDict:nil];
|
||||||
|
|
||||||
[[[NSUserDefaultsController sharedUserDefaultsController] defaults] removeObjectForKey:@"outputDevice"];
|
[[[NSUserDefaultsController sharedUserDefaultsController] defaults] removeObjectForKey:@"outputDevice"];
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
[self setOutputDeviceWithDeviceDict:nil];
|
[self setOutputDeviceWithDeviceDict:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -622,11 +585,11 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
desc.componentSubType = kAudioUnitSubType_GraphicEQ;
|
desc.componentSubType = kAudioUnitSubType_GraphicEQ;
|
||||||
|
|
||||||
comp = AudioComponentFindNext(comp, &desc);
|
comp = AudioComponentFindNext(comp, &desc);
|
||||||
if (!comp)
|
if(!comp)
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
OSStatus _err = AudioComponentInstanceNew(comp, &_eq);
|
OSStatus _err = AudioComponentInstanceNew(comp, &_eq);
|
||||||
if (err)
|
if(err)
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
[self updateDeviceFormat];
|
[self updateDeviceFormat];
|
||||||
|
@ -640,21 +603,20 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
__block FILE *logFile = _logFile;
|
__block FILE *logFile = _logFile;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_au.outputProvider = ^AUAudioUnitStatus(AudioUnitRenderActionFlags * _Nonnull actionFlags, const AudioTimeStamp * _Nonnull timestamp, AUAudioFrameCount frameCount, NSInteger inputBusNumber, AudioBufferList * _Nonnull inputData)
|
_au.outputProvider = ^AUAudioUnitStatus(AudioUnitRenderActionFlags *_Nonnull actionFlags, const AudioTimeStamp *_Nonnull timestamp, AUAudioFrameCount frameCount, NSInteger inputBusNumber, AudioBufferList *_Nonnull inputData) {
|
||||||
{
|
|
||||||
// This expects multiple buffers, so:
|
// This expects multiple buffers, so:
|
||||||
int i;
|
int i;
|
||||||
const int channels = format->mChannelsPerFrame;
|
const int channels = format->mChannelsPerFrame;
|
||||||
const int channelsminusone = channels - 1;
|
const int channelsminusone = channels - 1;
|
||||||
float buffers[frameCount * format->mChannelsPerFrame];
|
float buffers[frameCount * format->mChannelsPerFrame];
|
||||||
uint8_t bufferlistbuffer[sizeof(AudioBufferList) + sizeof(AudioBuffer) * channelsminusone];
|
uint8_t bufferlistbuffer[sizeof(AudioBufferList) + sizeof(AudioBuffer) * channelsminusone];
|
||||||
AudioBufferList * ioData = (AudioBufferList *)(bufferlistbuffer);
|
AudioBufferList *ioData = (AudioBufferList *)(bufferlistbuffer);
|
||||||
|
|
||||||
ioData->mNumberBuffers = channels;
|
ioData->mNumberBuffers = channels;
|
||||||
|
|
||||||
memset(buffers, 0, sizeof(buffers));
|
memset(buffers, 0, sizeof(buffers));
|
||||||
|
|
||||||
for (i = 0; i < channels; ++i) {
|
for(i = 0; i < channels; ++i) {
|
||||||
ioData->mBuffers[i].mNumberChannels = 1;
|
ioData->mBuffers[i].mNumberChannels = 1;
|
||||||
ioData->mBuffers[i].mData = buffers + frameCount * i;
|
ioData->mBuffers[i].mData = buffers + frameCount * i;
|
||||||
ioData->mBuffers[i].mDataByteSize = frameCount * sizeof(float);
|
ioData->mBuffers[i].mDataByteSize = frameCount * sizeof(float);
|
||||||
|
@ -662,19 +624,19 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
|
|
||||||
OSStatus ret;
|
OSStatus ret;
|
||||||
|
|
||||||
if (*eqEnabled)
|
if(*eqEnabled)
|
||||||
ret = AudioUnitRender(eq, actionFlags, timestamp, (UInt32) inputBusNumber, frameCount, ioData);
|
ret = AudioUnitRender(eq, actionFlags, timestamp, (UInt32)inputBusNumber, frameCount, ioData);
|
||||||
else
|
else
|
||||||
ret = renderCallback(refCon, actionFlags, timestamp, (UInt32) inputBusNumber, frameCount, ioData);
|
ret = renderCallback(refCon, actionFlags, timestamp, (UInt32)inputBusNumber, frameCount, ioData);
|
||||||
|
|
||||||
if (ret)
|
if(ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
for (i = 0; i < channels; ++i) {
|
for(i = 0; i < channels; ++i) {
|
||||||
float * outBuffer = ((float*)inputData->mBuffers[0].mData) + i;
|
float *outBuffer = ((float *)inputData->mBuffers[0].mData) + i;
|
||||||
const float * inBuffer = ((float*)ioData->mBuffers[i].mData);
|
const float *inBuffer = ((float *)ioData->mBuffers[i].mData);
|
||||||
const int frameCount = ioData->mBuffers[i].mDataByteSize / sizeof(float);
|
const int frameCount = ioData->mBuffers[i].mDataByteSize / sizeof(float);
|
||||||
for (int j = 0; j < frameCount; ++j) {
|
for(int j = 0; j < frameCount; ++j) {
|
||||||
*outBuffer = *inBuffer;
|
*outBuffer = *inBuffer;
|
||||||
inBuffer++;
|
inBuffer++;
|
||||||
outBuffer += channels;
|
outBuffer += channels;
|
||||||
|
@ -682,7 +644,7 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef OUTPUT_LOG
|
#ifdef OUTPUT_LOG
|
||||||
if (logFile) {
|
if(logFile) {
|
||||||
fwrite(inputData->mBuffers[0].mData, 1, inputData->mBuffers[0].mDataByteSize, logFile);
|
fwrite(inputData->mBuffers[0].mData, 1, inputData->mBuffers[0].mDataByteSize, logFile);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -698,26 +660,26 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
UInt32 size = sizeof(value);
|
UInt32 size = sizeof(value);
|
||||||
|
|
||||||
value = CHUNK_SIZE;
|
value = CHUNK_SIZE;
|
||||||
AudioUnitSetProperty (_eq, kAudioUnitProperty_MaximumFramesPerSlice,
|
AudioUnitSetProperty(_eq, kAudioUnitProperty_MaximumFramesPerSlice,
|
||||||
kAudioUnitScope_Global, 0, &value, size);
|
kAudioUnitScope_Global, 0, &value, size);
|
||||||
|
|
||||||
value = 127;
|
value = 127;
|
||||||
AudioUnitSetProperty (_eq, kAudioUnitProperty_RenderQuality,
|
AudioUnitSetProperty(_eq, kAudioUnitProperty_RenderQuality,
|
||||||
kAudioUnitScope_Global, 0, &value, size);
|
kAudioUnitScope_Global, 0, &value, size);
|
||||||
|
|
||||||
AURenderCallbackStruct callbackStruct;
|
AURenderCallbackStruct callbackStruct;
|
||||||
callbackStruct.inputProcRefCon = (__bridge void *)self;
|
callbackStruct.inputProcRefCon = (__bridge void *)self;
|
||||||
callbackStruct.inputProc = renderCallback;
|
callbackStruct.inputProc = renderCallback;
|
||||||
AudioUnitSetProperty (_eq, kAudioUnitProperty_SetRenderCallback,
|
AudioUnitSetProperty(_eq, kAudioUnitProperty_SetRenderCallback,
|
||||||
kAudioUnitScope_Input, 0, &callbackStruct, sizeof(callbackStruct));
|
kAudioUnitScope_Input, 0, &callbackStruct, sizeof(callbackStruct));
|
||||||
|
|
||||||
AudioUnitReset (_eq, kAudioUnitScope_Input, 0);
|
AudioUnitReset(_eq, kAudioUnitScope_Input, 0);
|
||||||
AudioUnitReset (_eq, kAudioUnitScope_Output, 0);
|
AudioUnitReset(_eq, kAudioUnitScope_Output, 0);
|
||||||
|
|
||||||
AudioUnitReset (_eq, kAudioUnitScope_Global, 0);
|
AudioUnitReset(_eq, kAudioUnitScope_Global, 0);
|
||||||
|
|
||||||
_err = AudioUnitInitialize(_eq);
|
_err = AudioUnitInitialize(_eq);
|
||||||
if (_err)
|
if(_err)
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
[self setEqualizerEnabled:[[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"GraphicEQenable"] boolValue]];
|
[self setEqualizerEnabled:[[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"GraphicEQenable"] boolValue]];
|
||||||
|
@ -733,45 +695,41 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
return (err == nil);
|
return (err == nil);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setVolume:(double)v
|
- (void)setVolume:(double)v {
|
||||||
{
|
|
||||||
volume = v * 0.01f;
|
volume = v * 0.01f;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setEqualizerEnabled:(BOOL)enabled
|
- (void)setEqualizerEnabled:(BOOL)enabled {
|
||||||
{
|
if(enabled && !eqEnabled) {
|
||||||
if (enabled && !eqEnabled) {
|
if(_eq) {
|
||||||
if (_eq) {
|
AudioUnitReset(_eq, kAudioUnitScope_Input, 0);
|
||||||
AudioUnitReset (_eq, kAudioUnitScope_Input, 0);
|
AudioUnitReset(_eq, kAudioUnitScope_Output, 0);
|
||||||
AudioUnitReset (_eq, kAudioUnitScope_Output, 0);
|
AudioUnitReset(_eq, kAudioUnitScope_Global, 0);
|
||||||
AudioUnitReset (_eq, kAudioUnitScope_Global, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eqEnabled = enabled;
|
eqEnabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)start
|
- (void)start {
|
||||||
{
|
|
||||||
[self threadEntry:nil];
|
[self threadEntry:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)stop
|
- (void)stop {
|
||||||
{
|
|
||||||
stopInvoked = YES;
|
stopInvoked = YES;
|
||||||
if (observersapplied) {
|
if(observersapplied) {
|
||||||
observersapplied = NO;
|
observersapplied = NO;
|
||||||
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.outputDevice"];
|
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.outputDevice"];
|
||||||
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.GraphicEQenable"];
|
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.GraphicEQenable"];
|
||||||
}
|
}
|
||||||
if (stopNext && started && !paused) {
|
if(stopNext && started && !paused) {
|
||||||
while (![[outputController buffer] isEmpty]) {
|
while(![[outputController buffer] isEmpty]) {
|
||||||
[writeSemaphore signal];
|
[writeSemaphore signal];
|
||||||
[readSemaphore signal];
|
[readSemaphore signal];
|
||||||
usleep(500);
|
usleep(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (stopNext) {
|
if(stopNext) {
|
||||||
stopNext = NO;
|
stopNext = NO;
|
||||||
[self signalEndOfStream];
|
[self signalEndOfStream];
|
||||||
}
|
}
|
||||||
|
@ -779,40 +737,36 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
paused = NO;
|
paused = NO;
|
||||||
[writeSemaphore signal];
|
[writeSemaphore signal];
|
||||||
[readSemaphore signal];
|
[readSemaphore signal];
|
||||||
if (listenerapplied) {
|
if(listenerapplied) {
|
||||||
AudioObjectPropertyAddress theAddress = {
|
AudioObjectPropertyAddress theAddress = {
|
||||||
.mSelector = kAudioHardwarePropertyDefaultOutputDevice,
|
.mSelector = kAudioHardwarePropertyDefaultOutputDevice,
|
||||||
.mScope = kAudioObjectPropertyScopeGlobal,
|
.mScope = kAudioObjectPropertyScopeGlobal,
|
||||||
.mElement = kAudioObjectPropertyElementMaster
|
.mElement = kAudioObjectPropertyElementMaster
|
||||||
};
|
};
|
||||||
AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &theAddress, default_device_changed, (__bridge void * _Nullable)(self));
|
AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &theAddress, default_device_changed, (__bridge void *_Nullable)(self));
|
||||||
listenerapplied = NO;
|
listenerapplied = NO;
|
||||||
}
|
}
|
||||||
if (_au) {
|
if(_au) {
|
||||||
if (started)
|
if(started)
|
||||||
[_au stopHardware];
|
[_au stopHardware];
|
||||||
_au = nil;
|
_au = nil;
|
||||||
}
|
}
|
||||||
if (running)
|
if(running)
|
||||||
while (!stopped)
|
while(!stopped) {
|
||||||
{
|
|
||||||
stopping = YES;
|
stopping = YES;
|
||||||
[readSemaphore signal];
|
[readSemaphore signal];
|
||||||
[writeSemaphore timedWait:5000];
|
[writeSemaphore timedWait:5000];
|
||||||
}
|
}
|
||||||
if (_eq)
|
if(_eq) {
|
||||||
{
|
|
||||||
// This takes the EQ and frees it after disposing of any present UIs
|
// This takes the EQ and frees it after disposing of any present UIs
|
||||||
[outputController endEqualizer:_eq];
|
[outputController endEqualizer:_eq];
|
||||||
_eq = NULL;
|
_eq = NULL;
|
||||||
}
|
}
|
||||||
if (downmixer)
|
if(downmixer) {
|
||||||
{
|
|
||||||
downmixer = nil;
|
downmixer = nil;
|
||||||
}
|
}
|
||||||
#ifdef OUTPUT_LOG
|
#ifdef OUTPUT_LOG
|
||||||
if (_logFile)
|
if(_logFile) {
|
||||||
{
|
|
||||||
fclose(_logFile);
|
fclose(_logFile);
|
||||||
_logFile = NULL;
|
_logFile = NULL;
|
||||||
}
|
}
|
||||||
|
@ -820,29 +774,25 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
outputController = nil;
|
outputController = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc {
|
||||||
{
|
if(!stopInvoked)
|
||||||
if (!stopInvoked)
|
|
||||||
[self stop];
|
[self stop];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)pause
|
- (void)pause {
|
||||||
{
|
|
||||||
paused = YES;
|
paused = YES;
|
||||||
if (started)
|
if(started)
|
||||||
[_au stopHardware];
|
[_au stopHardware];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)resume
|
- (void)resume {
|
||||||
{
|
|
||||||
NSError *err;
|
NSError *err;
|
||||||
[_au startHardwareAndReturnError:&err];
|
[_au startHardwareAndReturnError:&err];
|
||||||
paused = NO;
|
paused = NO;
|
||||||
started = YES;
|
started = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sustainHDCD
|
- (void)sustainHDCD {
|
||||||
{
|
|
||||||
atomic_store(&bytesHdcdSustained, deviceFormat.mSampleRate * 10 * sizeof(float) * 2);
|
atomic_store(&bytesHdcdSustained, deviceFormat.mSampleRate * 10 * sizeof(float) * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//Plugins! HOORAY!
|
// Plugins! HOORAY!
|
||||||
|
|
||||||
@protocol CogSource <NSObject>
|
@protocol CogSource <NSObject>
|
||||||
+ (NSArray *)schemes; //http, file, etc
|
+ (NSArray *)schemes; // http, file, etc
|
||||||
|
|
||||||
- (NSURL *)url;
|
- (NSURL *)url;
|
||||||
- (NSString *)mimeType;
|
- (NSString *)mimeType;
|
||||||
|
@ -10,7 +10,7 @@
|
||||||
- (BOOL)seekable;
|
- (BOOL)seekable;
|
||||||
- (BOOL)seek:(long)position whence:(int)whence;
|
- (BOOL)seek:(long)position whence:(int)whence;
|
||||||
- (long)tell;
|
- (long)tell;
|
||||||
- (long)read:(void *)buffer amount:(long)amount; //reads UP TO amount, returns amount read.
|
- (long)read:(void *)buffer amount:(long)amount; // reads UP TO amount, returns amount read.
|
||||||
- (void)close;
|
- (void)close;
|
||||||
- (void)dealloc;
|
- (void)dealloc;
|
||||||
@end
|
@end
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@protocol CogContainer <NSObject>
|
@protocol CogContainer <NSObject>
|
||||||
+ (NSArray *)fileTypes; //mp3, ogg, etc
|
+ (NSArray *)fileTypes; // mp3, ogg, etc
|
||||||
+ (NSArray *)mimeTypes;
|
+ (NSArray *)mimeTypes;
|
||||||
+ (float)priority;
|
+ (float)priority;
|
||||||
|
|
||||||
|
@ -30,11 +30,11 @@
|
||||||
@protocol CogDecoder <NSObject>
|
@protocol CogDecoder <NSObject>
|
||||||
@required
|
@required
|
||||||
+ (NSArray *)mimeTypes;
|
+ (NSArray *)mimeTypes;
|
||||||
+ (NSArray *)fileTypes; //mp3, ogg, etc
|
+ (NSArray *)fileTypes; // mp3, ogg, etc
|
||||||
+ (NSArray *)fileTypeAssociations; // array of NSArray of NSString, where first item in array is the type name, the second is the icon name, and the rest are the extensions
|
+ (NSArray *)fileTypeAssociations; // array of NSArray of NSString, where first item in array is the type name, the second is the icon name, and the rest are the extensions
|
||||||
+ (float)priority; // should be 0.0 ... 1.0, higher means you get selected first, should default to 1.0 unless you know a reason why any of your extensions may behave badly, ie. greedily taking over some file type extension without performing any header validation on it
|
+ (float)priority; // should be 0.0 ... 1.0, higher means you get selected first, should default to 1.0 unless you know a reason why any of your extensions may behave badly, ie. greedily taking over some file type extension without performing any header validation on it
|
||||||
|
|
||||||
//For KVO
|
// For KVO
|
||||||
//- (void)setProperties:(NSDictionary *)p;
|
//- (void)setProperties:(NSDictionary *)p;
|
||||||
- (NSDictionary *)properties;
|
- (NSDictionary *)properties;
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@
|
||||||
|
|
||||||
- (BOOL)setTrack:(NSURL *)track;
|
- (BOOL)setTrack:(NSURL *)track;
|
||||||
|
|
||||||
//These are in NSObject, so as long as you are a subclass of that, you are ok.
|
// These are in NSObject, so as long as you are a subclass of that, you are ok.
|
||||||
- (void)addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context;
|
- (void)addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context;
|
||||||
- (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath;
|
- (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath;
|
||||||
@end
|
@end
|
||||||
|
@ -87,14 +87,11 @@
|
||||||
- (NSDictionary *)decodersByExtension;
|
- (NSDictionary *)decodersByExtension;
|
||||||
- (NSDictionary *)decodersByMimeType;
|
- (NSDictionary *)decodersByMimeType;
|
||||||
|
|
||||||
- (id<CogSource>) audioSourceForURL:(NSURL *)url;
|
- (id<CogSource>)audioSourceForURL:(NSURL *)url;
|
||||||
- (NSArray *) urlsForContainerURL:(NSURL *)url;
|
- (NSArray *)urlsForContainerURL:(NSURL *)url;
|
||||||
- (NSDictionary *) metadataForURL:(NSURL *)url skipCue:(BOOL)skip;
|
- (NSDictionary *)metadataForURL:(NSURL *)url skipCue:(BOOL)skip;
|
||||||
- (NSDictionary *) propertiesForURL:(NSURL *)url;
|
- (NSDictionary *)propertiesForURL:(NSURL *)url;
|
||||||
- (id<CogDecoder>) audioDecoderForSource:(id<CogSource>)source skipCue:(BOOL)skip;
|
- (id<CogDecoder>)audioDecoderForSource:(id<CogSource>)source skipCue:(BOOL)skip;
|
||||||
|
|
||||||
- (int) putMetadataInURL:(NSURL *)url;
|
- (int)putMetadataInURL:(NSURL *)url;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,8 @@
|
||||||
|
|
||||||
#import "Plugin.h"
|
#import "Plugin.h"
|
||||||
|
|
||||||
//Singletonish
|
// Singletonish
|
||||||
@interface PluginController : NSObject <CogPluginController>
|
@interface PluginController : NSObject <CogPluginController> {
|
||||||
{
|
|
||||||
NSMutableDictionary *sources;
|
NSMutableDictionary *sources;
|
||||||
NSMutableDictionary *containers;
|
NSMutableDictionary *containers;
|
||||||
NSMutableDictionary *metadataReaders;
|
NSMutableDictionary *metadataReaders;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#import "PluginController.h"
|
#import "PluginController.h"
|
||||||
#import "Plugin.h"
|
|
||||||
#import "CogPluginMulti.h"
|
#import "CogPluginMulti.h"
|
||||||
|
#import "Plugin.h"
|
||||||
|
|
||||||
#import "Logging.h"
|
#import "Logging.h"
|
||||||
|
|
||||||
|
@ -22,10 +22,9 @@
|
||||||
|
|
||||||
static PluginController *sharedPluginController = nil;
|
static PluginController *sharedPluginController = nil;
|
||||||
|
|
||||||
+ (id<CogPluginController>)sharedPluginController
|
+ (id<CogPluginController>)sharedPluginController {
|
||||||
{
|
|
||||||
@synchronized(self) {
|
@synchronized(self) {
|
||||||
if (sharedPluginController == nil) {
|
if(sharedPluginController == nil) {
|
||||||
sharedPluginController = [[self alloc] init];
|
sharedPluginController = [[self alloc] init];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,10 +32,9 @@ static PluginController *sharedPluginController = nil;
|
||||||
return sharedPluginController;
|
return sharedPluginController;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (id)init {
|
- (id)init {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if(self) {
|
||||||
self.sources = [[NSMutableDictionary alloc] init];
|
self.sources = [[NSMutableDictionary alloc] init];
|
||||||
self.containers = [[NSMutableDictionary alloc] init];
|
self.containers = [[NSMutableDictionary alloc] init];
|
||||||
|
|
||||||
|
@ -54,9 +52,8 @@ static PluginController *sharedPluginController = nil;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setup
|
- (void)setup {
|
||||||
{
|
if(self.configured == NO) {
|
||||||
if (self.configured == NO) {
|
|
||||||
self.configured = YES;
|
self.configured = YES;
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bundleDidLoad:) name:NSBundleDidLoadNotification object:nil];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bundleDidLoad:) name:NSBundleDidLoadNotification object:nil];
|
||||||
|
@ -66,63 +63,54 @@ static PluginController *sharedPluginController = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)bundleDidLoad:(NSNotification *)notification
|
- (void)bundleDidLoad:(NSNotification *)notification {
|
||||||
{
|
|
||||||
NSArray *classNames = [[notification userInfo] objectForKey:@"NSLoadedClasses"];
|
NSArray *classNames = [[notification userInfo] objectForKey:@"NSLoadedClasses"];
|
||||||
for (NSString *className in classNames)
|
for(NSString *className in classNames) {
|
||||||
{
|
|
||||||
Class bundleClass = NSClassFromString(className);
|
Class bundleClass = NSClassFromString(className);
|
||||||
if ([bundleClass conformsToProtocol:@protocol(CogVersionCheck)]) {
|
if([bundleClass conformsToProtocol:@protocol(CogVersionCheck)]) {
|
||||||
DLog(@"Component has version check: %@", className);
|
DLog(@"Component has version check: %@", className);
|
||||||
if (![bundleClass shouldLoadForOSVersion:[[NSProcessInfo processInfo] operatingSystemVersion]])
|
if(![bundleClass shouldLoadForOSVersion:[[NSProcessInfo processInfo] operatingSystemVersion]]) {
|
||||||
{
|
|
||||||
DLog(@"Plugin fails OS version check, ignoring");
|
DLog(@"Plugin fails OS version check, ignoring");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (NSString *className in classNames)
|
for(NSString *className in classNames) {
|
||||||
{
|
|
||||||
DLog(@"Class loaded: %@", className);
|
DLog(@"Class loaded: %@", className);
|
||||||
Class bundleClass = NSClassFromString(className);
|
Class bundleClass = NSClassFromString(className);
|
||||||
if ([bundleClass conformsToProtocol:@protocol(CogContainer)]) {
|
if([bundleClass conformsToProtocol:@protocol(CogContainer)]) {
|
||||||
[self setupContainer:className];
|
[self setupContainer:className];
|
||||||
}
|
}
|
||||||
if ([bundleClass conformsToProtocol:@protocol(CogDecoder)]) {
|
if([bundleClass conformsToProtocol:@protocol(CogDecoder)]) {
|
||||||
[self setupDecoder:className];
|
[self setupDecoder:className];
|
||||||
}
|
}
|
||||||
if ([bundleClass conformsToProtocol:@protocol(CogMetadataReader)]) {
|
if([bundleClass conformsToProtocol:@protocol(CogMetadataReader)]) {
|
||||||
[self setupMetadataReader:className];
|
[self setupMetadataReader:className];
|
||||||
}
|
}
|
||||||
if ([bundleClass conformsToProtocol:@protocol(CogPropertiesReader)]) {
|
if([bundleClass conformsToProtocol:@protocol(CogPropertiesReader)]) {
|
||||||
[self setupPropertiesReader:className];
|
[self setupPropertiesReader:className];
|
||||||
}
|
}
|
||||||
if ([bundleClass conformsToProtocol:@protocol(CogSource)]) {
|
if([bundleClass conformsToProtocol:@protocol(CogSource)]) {
|
||||||
[self setupSource:className];
|
[self setupSource:className];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)loadPluginsAtPath:(NSString *)path
|
- (void)loadPluginsAtPath:(NSString *)path {
|
||||||
{
|
|
||||||
|
|
||||||
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];
|
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];
|
||||||
|
|
||||||
for (NSString *pname in dirContents)
|
for(NSString *pname in dirContents) {
|
||||||
{
|
|
||||||
NSString *ppath;
|
NSString *ppath;
|
||||||
ppath = [NSString pathWithComponents:@[path,pname]];
|
ppath = [NSString pathWithComponents:@[path, pname]];
|
||||||
|
|
||||||
if ([[pname pathExtension] isEqualToString:@"bundle"])
|
if([[pname pathExtension] isEqualToString:@"bundle"]) {
|
||||||
{
|
|
||||||
NSBundle *b = [NSBundle bundleWithPath:ppath];
|
NSBundle *b = [NSBundle bundleWithPath:ppath];
|
||||||
[b load];
|
[b load];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)loadPlugins
|
- (void)loadPlugins {
|
||||||
{
|
|
||||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
||||||
NSString *basePath = [[paths firstObject] stringByAppendingPathComponent:@"Cog"];
|
NSString *basePath = [[paths firstObject] stringByAppendingPathComponent:@"Cog"];
|
||||||
|
|
||||||
|
@ -130,131 +118,106 @@ static PluginController *sharedPluginController = nil;
|
||||||
[self loadPluginsAtPath:[basePath stringByAppendingPathComponent:@"Plugins"]];
|
[self loadPluginsAtPath:[basePath stringByAppendingPathComponent:@"Plugins"]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setupContainer:(NSString *)className
|
- (void)setupContainer:(NSString *)className {
|
||||||
{
|
|
||||||
Class container = NSClassFromString(className);
|
Class container = NSClassFromString(className);
|
||||||
if (container && [container respondsToSelector:@selector(fileTypes)]) {
|
if(container && [container respondsToSelector:@selector(fileTypes)]) {
|
||||||
for (id fileType in [container fileTypes])
|
for(id fileType in [container fileTypes]) {
|
||||||
{
|
|
||||||
NSString *ext = [fileType lowercaseString];
|
NSString *ext = [fileType lowercaseString];
|
||||||
NSMutableArray *containerSet;
|
NSMutableArray *containerSet;
|
||||||
if (![containers objectForKey:ext])
|
if(![containers objectForKey:ext]) {
|
||||||
{
|
|
||||||
containerSet = [[NSMutableArray alloc] init];
|
containerSet = [[NSMutableArray alloc] init];
|
||||||
[containers setObject:containerSet forKey:ext];
|
[containers setObject:containerSet forKey:ext];
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
containerSet = [containers objectForKey:ext];
|
containerSet = [containers objectForKey:ext];
|
||||||
[containerSet addObject:className];
|
[containerSet addObject:className];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setupDecoder:(NSString *)className
|
- (void)setupDecoder:(NSString *)className {
|
||||||
{
|
|
||||||
Class decoder = NSClassFromString(className);
|
Class decoder = NSClassFromString(className);
|
||||||
if (decoder && [decoder respondsToSelector:@selector(fileTypes)]) {
|
if(decoder && [decoder respondsToSelector:@selector(fileTypes)]) {
|
||||||
for (id fileType in [decoder fileTypes])
|
for(id fileType in [decoder fileTypes]) {
|
||||||
{
|
|
||||||
NSString *ext = [fileType lowercaseString];
|
NSString *ext = [fileType lowercaseString];
|
||||||
NSMutableArray *decoders;
|
NSMutableArray *decoders;
|
||||||
if (![decodersByExtension objectForKey:ext])
|
if(![decodersByExtension objectForKey:ext]) {
|
||||||
{
|
|
||||||
decoders = [[NSMutableArray alloc] init];
|
decoders = [[NSMutableArray alloc] init];
|
||||||
[decodersByExtension setObject:decoders forKey:ext];
|
[decodersByExtension setObject:decoders forKey:ext];
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
decoders = [decodersByExtension objectForKey:ext];
|
decoders = [decodersByExtension objectForKey:ext];
|
||||||
[decoders addObject:className];
|
[decoders addObject:className];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decoder && [decoder respondsToSelector:@selector(mimeTypes)]) {
|
if(decoder && [decoder respondsToSelector:@selector(mimeTypes)]) {
|
||||||
for (id mimeType in [decoder mimeTypes])
|
for(id mimeType in [decoder mimeTypes]) {
|
||||||
{
|
|
||||||
NSString *mimetype = [mimeType lowercaseString];
|
NSString *mimetype = [mimeType lowercaseString];
|
||||||
NSMutableArray *decoders;
|
NSMutableArray *decoders;
|
||||||
if (![decodersByMimeType objectForKey:mimetype])
|
if(![decodersByMimeType objectForKey:mimetype]) {
|
||||||
{
|
|
||||||
decoders = [[NSMutableArray alloc] init];
|
decoders = [[NSMutableArray alloc] init];
|
||||||
[decodersByMimeType setObject:decoders forKey:mimetype];
|
[decodersByMimeType setObject:decoders forKey:mimetype];
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
decoders = [decodersByMimeType objectForKey:mimetype];
|
decoders = [decodersByMimeType objectForKey:mimetype];
|
||||||
[decoders addObject:className];
|
[decoders addObject:className];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setupMetadataReader:(NSString *)className
|
- (void)setupMetadataReader:(NSString *)className {
|
||||||
{
|
|
||||||
Class metadataReader = NSClassFromString(className);
|
Class metadataReader = NSClassFromString(className);
|
||||||
if (metadataReader && [metadataReader respondsToSelector:@selector(fileTypes)]) {
|
if(metadataReader && [metadataReader respondsToSelector:@selector(fileTypes)]) {
|
||||||
for (id fileType in [metadataReader fileTypes])
|
for(id fileType in [metadataReader fileTypes]) {
|
||||||
{
|
|
||||||
NSString *ext = [fileType lowercaseString];
|
NSString *ext = [fileType lowercaseString];
|
||||||
NSMutableArray *readers;
|
NSMutableArray *readers;
|
||||||
if (![metadataReaders objectForKey:ext])
|
if(![metadataReaders objectForKey:ext]) {
|
||||||
{
|
|
||||||
readers = [[NSMutableArray alloc] init];
|
readers = [[NSMutableArray alloc] init];
|
||||||
[metadataReaders setObject:readers forKey:ext];
|
[metadataReaders setObject:readers forKey:ext];
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
readers = [metadataReaders objectForKey:ext];
|
readers = [metadataReaders objectForKey:ext];
|
||||||
[readers addObject:className];
|
[readers addObject:className];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setupPropertiesReader:(NSString *)className
|
- (void)setupPropertiesReader:(NSString *)className {
|
||||||
{
|
|
||||||
Class propertiesReader = NSClassFromString(className);
|
Class propertiesReader = NSClassFromString(className);
|
||||||
if (propertiesReader && [propertiesReader respondsToSelector:@selector(fileTypes)]) {
|
if(propertiesReader && [propertiesReader respondsToSelector:@selector(fileTypes)]) {
|
||||||
for (id fileType in [propertiesReader fileTypes])
|
for(id fileType in [propertiesReader fileTypes]) {
|
||||||
{
|
|
||||||
NSString *ext = [fileType lowercaseString];
|
NSString *ext = [fileType lowercaseString];
|
||||||
NSMutableArray *readers;
|
NSMutableArray *readers;
|
||||||
if (![propertiesReadersByExtension objectForKey:ext])
|
if(![propertiesReadersByExtension objectForKey:ext]) {
|
||||||
{
|
|
||||||
readers = [[NSMutableArray alloc] init];
|
readers = [[NSMutableArray alloc] init];
|
||||||
[propertiesReadersByExtension setObject:readers forKey:ext];
|
[propertiesReadersByExtension setObject:readers forKey:ext];
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
readers = [propertiesReadersByExtension objectForKey:ext];
|
readers = [propertiesReadersByExtension objectForKey:ext];
|
||||||
[readers addObject:className];
|
[readers addObject:className];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (propertiesReader && [propertiesReader respondsToSelector:@selector(mimeTypes)]) {
|
if(propertiesReader && [propertiesReader respondsToSelector:@selector(mimeTypes)]) {
|
||||||
for (id mimeType in [propertiesReader mimeTypes])
|
for(id mimeType in [propertiesReader mimeTypes]) {
|
||||||
{
|
|
||||||
NSString *mimetype = [mimeType lowercaseString];
|
NSString *mimetype = [mimeType lowercaseString];
|
||||||
NSMutableArray *readers;
|
NSMutableArray *readers;
|
||||||
if (![propertiesReadersByMimeType objectForKey:mimetype])
|
if(![propertiesReadersByMimeType objectForKey:mimetype]) {
|
||||||
{
|
|
||||||
readers = [[NSMutableArray alloc] init];
|
readers = [[NSMutableArray alloc] init];
|
||||||
[propertiesReadersByMimeType setObject:readers forKey:mimetype];
|
[propertiesReadersByMimeType setObject:readers forKey:mimetype];
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
readers = [propertiesReadersByMimeType objectForKey:mimetype];
|
readers = [propertiesReadersByMimeType objectForKey:mimetype];
|
||||||
[readers addObject:className];
|
[readers addObject:className];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setupSource:(NSString *)className
|
- (void)setupSource:(NSString *)className {
|
||||||
{
|
|
||||||
Class source = NSClassFromString(className);
|
Class source = NSClassFromString(className);
|
||||||
if (source && [source respondsToSelector:@selector(schemes)]) {
|
if(source && [source respondsToSelector:@selector(schemes)]) {
|
||||||
for (id scheme in [source schemes])
|
for(id scheme in [source schemes]) {
|
||||||
{
|
|
||||||
[sources setObject:className forKey:scheme];
|
[sources setObject:className forKey:scheme];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)printPluginInfo
|
- (void)printPluginInfo {
|
||||||
{
|
|
||||||
ALog(@"Sources: %@", self.sources);
|
ALog(@"Sources: %@", self.sources);
|
||||||
ALog(@"Containers: %@", self.containers);
|
ALog(@"Containers: %@", self.containers);
|
||||||
ALog(@"Metadata Readers: %@", self.metadataReaders);
|
ALog(@"Metadata Readers: %@", self.metadataReaders);
|
||||||
|
@ -420,8 +383,7 @@ static PluginController *sharedPluginController = nil;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id<CogSource>) audioSourceForURL:(NSURL *)url
|
- (id<CogSource>)audioSourceForURL:(NSURL *)url {
|
||||||
{
|
|
||||||
NSString *scheme = [url scheme];
|
NSString *scheme = [url scheme];
|
||||||
|
|
||||||
Class source = NSClassFromString([sources objectForKey:scheme]);
|
Class source = NSClassFromString([sources objectForKey:scheme]);
|
||||||
|
@ -429,20 +391,17 @@ static PluginController *sharedPluginController = nil;
|
||||||
return [[source alloc] init];
|
return [[source alloc] init];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray *) urlsForContainerURL:(NSURL *)url
|
- (NSArray *)urlsForContainerURL:(NSURL *)url {
|
||||||
{
|
|
||||||
NSString *ext = [url pathExtension];
|
NSString *ext = [url pathExtension];
|
||||||
NSArray *containerSet = [containers objectForKey:[ext lowercaseString]];
|
NSArray *containerSet = [containers objectForKey:[ext lowercaseString]];
|
||||||
NSString *classString;
|
NSString *classString;
|
||||||
if (containerSet) {
|
if(containerSet) {
|
||||||
if ( [containerSet count] > 1 ) {
|
if([containerSet count] > 1) {
|
||||||
return [CogContainerMulti urlsForContainerURL:url containers:containerSet];
|
return [CogContainerMulti urlsForContainerURL:url containers:containerSet];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
classString = [containerSet objectAtIndex:0];
|
classString = [containerSet objectAtIndex:0];
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,20 +410,17 @@ static PluginController *sharedPluginController = nil;
|
||||||
return [container urlsForContainerURL:url];
|
return [container urlsForContainerURL:url];
|
||||||
}
|
}
|
||||||
|
|
||||||
//Note: Source is assumed to already be opened.
|
// Note: Source is assumed to already be opened.
|
||||||
- (id<CogDecoder>) audioDecoderForSource:(id <CogSource>)source skipCue:(BOOL)skip
|
- (id<CogDecoder>)audioDecoderForSource:(id<CogSource>)source skipCue:(BOOL)skip {
|
||||||
{
|
|
||||||
NSString *ext = [[source url] pathExtension];
|
NSString *ext = [[source url] pathExtension];
|
||||||
NSArray *decoders = [decodersByExtension objectForKey:[ext lowercaseString]];
|
NSArray *decoders = [decodersByExtension objectForKey:[ext lowercaseString]];
|
||||||
NSString *classString;
|
NSString *classString;
|
||||||
if (decoders) {
|
if(decoders) {
|
||||||
if ( [decoders count] > 1 ) {
|
if([decoders count] > 1) {
|
||||||
if (skip)
|
if(skip) {
|
||||||
{
|
NSMutableArray *_decoders = [decoders mutableCopy];
|
||||||
NSMutableArray * _decoders = [decoders mutableCopy];
|
for(int i = 0; i < [_decoders count];) {
|
||||||
for (int i = 0; i < [_decoders count];)
|
if([[_decoders objectAtIndex:i] isEqualToString:@"CueSheetDecoder"])
|
||||||
{
|
|
||||||
if ([[_decoders objectAtIndex:i] isEqualToString:@"CueSheetDecoder"])
|
|
||||||
[_decoders removeObjectAtIndex:i];
|
[_decoders removeObjectAtIndex:i];
|
||||||
else
|
else
|
||||||
++i;
|
++i;
|
||||||
|
@ -472,22 +428,18 @@ static PluginController *sharedPluginController = nil;
|
||||||
return [[CogDecoderMulti alloc] initWithDecoders:_decoders];
|
return [[CogDecoderMulti alloc] initWithDecoders:_decoders];
|
||||||
}
|
}
|
||||||
return [[CogDecoderMulti alloc] initWithDecoders:decoders];
|
return [[CogDecoderMulti alloc] initWithDecoders:decoders];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
classString = [decoders objectAtIndex:0];
|
classString = [decoders objectAtIndex:0];
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
decoders = [decodersByMimeType objectForKey:[[source mimeType] lowercaseString]];
|
decoders = [decodersByMimeType objectForKey:[[source mimeType] lowercaseString]];
|
||||||
if (decoders) {
|
if(decoders) {
|
||||||
if ( [decoders count] > 1 ) {
|
if([decoders count] > 1) {
|
||||||
return [[CogDecoderMulti alloc] initWithDecoders:decoders];
|
return [[CogDecoderMulti alloc] initWithDecoders:decoders];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
classString = [decoders objectAtIndex:0];
|
classString = [decoders objectAtIndex:0];
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
classString = @"SilenceDecoder";
|
classString = @"SilenceDecoder";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -497,24 +449,21 @@ static PluginController *sharedPluginController = nil;
|
||||||
return [[decoder alloc] init];
|
return [[decoder alloc] init];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDictionary *)metadataForURL:(NSURL *)url skipCue:(BOOL)skip
|
- (NSDictionary *)metadataForURL:(NSURL *)url skipCue:(BOOL)skip {
|
||||||
{
|
NSString *urlScheme = [url scheme];
|
||||||
NSString * urlScheme = [url scheme];
|
if([urlScheme isEqualToString:@"http"] ||
|
||||||
if ([urlScheme isEqualToString:@"http"] ||
|
|
||||||
[urlScheme isEqualToString:@"https"])
|
[urlScheme isEqualToString:@"https"])
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
NSString *ext = [url pathExtension];
|
NSString *ext = [url pathExtension];
|
||||||
NSArray *readers = [metadataReaders objectForKey:[ext lowercaseString]];
|
NSArray *readers = [metadataReaders objectForKey:[ext lowercaseString]];
|
||||||
NSString *classString;
|
NSString *classString;
|
||||||
if (readers) {
|
if(readers) {
|
||||||
if ( [readers count] > 1 ) {
|
if([readers count] > 1) {
|
||||||
if (skip)
|
if(skip) {
|
||||||
{
|
|
||||||
NSMutableArray *_readers = [readers mutableCopy];
|
NSMutableArray *_readers = [readers mutableCopy];
|
||||||
for (int i = 0; i < [_readers count];)
|
for(int i = 0; i < [_readers count];) {
|
||||||
{
|
if([[_readers objectAtIndex:i] isEqualToString:@"CueSheetMetadataReader"])
|
||||||
if ([[_readers objectAtIndex:i] isEqualToString:@"CueSheetMetadataReader"])
|
|
||||||
[_readers removeObjectAtIndex:i];
|
[_readers removeObjectAtIndex:i];
|
||||||
else
|
else
|
||||||
++i;
|
++i;
|
||||||
|
@ -522,12 +471,10 @@ static PluginController *sharedPluginController = nil;
|
||||||
return [CogMetadataReaderMulti metadataForURL:url readers:_readers];
|
return [CogMetadataReaderMulti metadataForURL:url readers:_readers];
|
||||||
}
|
}
|
||||||
return [CogMetadataReaderMulti metadataForURL:url readers:readers];
|
return [CogMetadataReaderMulti metadataForURL:url readers:readers];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
classString = [readers objectAtIndex:0];
|
classString = [readers objectAtIndex:0];
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,12 +483,10 @@ static PluginController *sharedPluginController = nil;
|
||||||
return [metadataReader metadataForURL:url];
|
return [metadataReader metadataForURL:url];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If no properties reader is defined, use the decoder's properties.
|
||||||
//If no properties reader is defined, use the decoder's properties.
|
- (NSDictionary *)propertiesForURL:(NSURL *)url {
|
||||||
- (NSDictionary *)propertiesForURL:(NSURL *)url
|
NSString *urlScheme = [url scheme];
|
||||||
{
|
if([urlScheme isEqualToString:@"http"] ||
|
||||||
NSString * urlScheme = [url scheme];
|
|
||||||
if ([urlScheme isEqualToString:@"http"] ||
|
|
||||||
[urlScheme isEqualToString:@"https"])
|
[urlScheme isEqualToString:@"https"])
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
|
@ -549,50 +494,43 @@ static PluginController *sharedPluginController = nil;
|
||||||
NSString *ext = [url pathExtension];
|
NSString *ext = [url pathExtension];
|
||||||
|
|
||||||
id<CogSource> source = [self audioSourceForURL:url];
|
id<CogSource> source = [self audioSourceForURL:url];
|
||||||
if (![source open:url])
|
if(![source open:url])
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
NSArray *readers = [propertiesReadersByExtension objectForKey:[ext lowercaseString]];
|
NSArray *readers = [propertiesReadersByExtension objectForKey:[ext lowercaseString]];
|
||||||
NSString *classString = nil;
|
NSString *classString = nil;
|
||||||
if (readers)
|
if(readers) {
|
||||||
{
|
if([readers count] > 1) {
|
||||||
if ( [readers count] > 1 ) {
|
|
||||||
properties = [CogPropertiesReaderMulti propertiesForSource:source readers:readers];
|
properties = [CogPropertiesReaderMulti propertiesForSource:source readers:readers];
|
||||||
if (properties != nil && [properties count])
|
if(properties != nil && [properties count])
|
||||||
return properties;
|
return properties;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
classString = [readers objectAtIndex:0];
|
classString = [readers objectAtIndex:0];
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
readers = [propertiesReadersByMimeType objectForKey:[[source mimeType] lowercaseString]];
|
readers = [propertiesReadersByMimeType objectForKey:[[source mimeType] lowercaseString]];
|
||||||
if (readers)
|
if(readers) {
|
||||||
{
|
if([readers count] > 1) {
|
||||||
if ( [readers count] > 1 ) {
|
|
||||||
properties = [CogPropertiesReaderMulti propertiesForSource:source readers:readers];
|
properties = [CogPropertiesReaderMulti propertiesForSource:source readers:readers];
|
||||||
if (properties != nil && [properties count])
|
if(properties != nil && [properties count])
|
||||||
return properties;
|
return properties;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
classString = [readers objectAtIndex:0];
|
classString = [readers objectAtIndex:0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (classString)
|
if(classString) {
|
||||||
{
|
|
||||||
Class propertiesReader = NSClassFromString(classString);
|
Class propertiesReader = NSClassFromString(classString);
|
||||||
|
|
||||||
properties = [propertiesReader propertiesForSource:source];
|
properties = [propertiesReader propertiesForSource:source];
|
||||||
if (properties != nil && [properties count])
|
if(properties != nil && [properties count])
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
id<CogDecoder> decoder = [self audioDecoderForSource:source skipCue:NO];
|
id<CogDecoder> decoder = [self audioDecoderForSource:source skipCue:NO];
|
||||||
if (![decoder open:source])
|
if(![decoder open:source]) {
|
||||||
{
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,10 +542,8 @@ static PluginController *sharedPluginController = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)putMetadataInURL:(NSURL *)url
|
- (int)putMetadataInURL:(NSURL *)url {
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
semaphore_t semaphore;
|
semaphore_t semaphore;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(id)init;
|
- (id)init;
|
||||||
-(void)signal;
|
- (void)signal;
|
||||||
-(void)timedWait:(int)microseconds;
|
- (void)timedWait:(int)microseconds;
|
||||||
-(void)wait;
|
- (void)wait;
|
||||||
-(void)waitIndefinitely;
|
- (void)waitIndefinitely;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -8,40 +8,33 @@
|
||||||
|
|
||||||
#import "Semaphore.h"
|
#import "Semaphore.h"
|
||||||
|
|
||||||
|
|
||||||
@implementation Semaphore
|
@implementation Semaphore
|
||||||
|
|
||||||
-(id)init
|
- (id)init {
|
||||||
{
|
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self)
|
if(self) {
|
||||||
{
|
|
||||||
semaphore_create(mach_task_self(), &semaphore, SYNC_POLICY_FIFO, 0);
|
semaphore_create(mach_task_self(), &semaphore, SYNC_POLICY_FIFO, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)signal
|
- (void)signal {
|
||||||
{
|
|
||||||
semaphore_signal_all(semaphore);
|
semaphore_signal_all(semaphore);
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)timedWait:(int)microseconds
|
- (void)timedWait:(int)microseconds {
|
||||||
{
|
mach_timespec_t timeout = { 0, microseconds * 1000UL };
|
||||||
mach_timespec_t timeout = {0, microseconds * 1000UL};
|
|
||||||
|
|
||||||
semaphore_timedwait(semaphore, timeout);
|
semaphore_timedwait(semaphore, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)wait
|
- (void)wait {
|
||||||
{
|
mach_timespec_t t = { 2.0, 0.0 }; // 2 second timeout
|
||||||
mach_timespec_t t = {2.0, 0.0}; //2 second timeout
|
|
||||||
semaphore_timedwait(semaphore, t);
|
semaphore_timedwait(semaphore, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)waitIndefinitely
|
- (void)waitIndefinitely {
|
||||||
{
|
|
||||||
semaphore_wait(semaphore);
|
semaphore_wait(semaphore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,7 @@
|
||||||
|
|
||||||
@class PlaylistEntry;
|
@class PlaylistEntry;
|
||||||
|
|
||||||
@interface AudioScrobbler : NSObject
|
@interface AudioScrobbler : NSObject {
|
||||||
{
|
|
||||||
NSString *_pluginID;
|
NSString *_pluginID;
|
||||||
NSMutableArray *_queue;
|
NSMutableArray *_queue;
|
||||||
|
|
||||||
|
@ -34,13 +33,13 @@
|
||||||
semaphore_t _semaphore;
|
semaphore_t _semaphore;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (BOOL) isRunning;
|
+ (BOOL)isRunning;
|
||||||
|
|
||||||
- (void) start:(PlaylistEntry *)pe;
|
- (void)start:(PlaylistEntry *)pe;
|
||||||
- (void) stop;
|
- (void)stop;
|
||||||
- (void) pause;
|
- (void)pause;
|
||||||
- (void) resume;
|
- (void)resume;
|
||||||
|
|
||||||
- (void) shutdown;
|
- (void)shutdown;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -28,14 +28,13 @@
|
||||||
// ========================================
|
// ========================================
|
||||||
// Symbolic Constants
|
// Symbolic Constants
|
||||||
// ========================================
|
// ========================================
|
||||||
NSString * const AudioScrobblerRunLoopMode = @"org.cogx.Cog.AudioScrobbler.RunLoopMode";
|
NSString *const AudioScrobblerRunLoopMode = @"org.cogx.Cog.AudioScrobbler.RunLoopMode";
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
// Helpers
|
// Helpers
|
||||||
// ========================================
|
// ========================================
|
||||||
static NSString *
|
static NSString *
|
||||||
escapeForLastFM(NSString *string)
|
escapeForLastFM(NSString *string) {
|
||||||
{
|
|
||||||
NSMutableString *result = [string mutableCopy];
|
NSMutableString *result = [string mutableCopy];
|
||||||
|
|
||||||
[result replaceOccurrencesOfString:@"&"
|
[result replaceOccurrencesOfString:@"&"
|
||||||
|
@ -48,27 +47,26 @@ escapeForLastFM(NSString *string)
|
||||||
|
|
||||||
@interface AudioScrobbler (Private)
|
@interface AudioScrobbler (Private)
|
||||||
|
|
||||||
- (NSMutableArray *) queue;
|
- (NSMutableArray *)queue;
|
||||||
- (NSString *) pluginID;
|
- (NSString *)pluginID;
|
||||||
|
|
||||||
- (void) sendCommand:(NSString *)command;
|
- (void)sendCommand:(NSString *)command;
|
||||||
|
|
||||||
- (BOOL) keepProcessingAudioScrobblerCommands;
|
- (BOOL)keepProcessingAudioScrobblerCommands;
|
||||||
- (void) setKeepProcessingAudioScrobblerCommands:(BOOL)keepProcessingAudioScrobblerCommands;
|
- (void)setKeepProcessingAudioScrobblerCommands:(BOOL)keepProcessingAudioScrobblerCommands;
|
||||||
|
|
||||||
- (BOOL) audioScrobblerThreadCompleted;
|
- (BOOL)audioScrobblerThreadCompleted;
|
||||||
- (void) setAudioScrobblerThreadCompleted:(BOOL)audioScrobblerThreadCompleted;
|
- (void)setAudioScrobblerThreadCompleted:(BOOL)audioScrobblerThreadCompleted;
|
||||||
|
|
||||||
- (semaphore_t) semaphore;
|
- (semaphore_t)semaphore;
|
||||||
|
|
||||||
- (void) processAudioScrobblerCommands:(id)unused;
|
- (void)processAudioScrobblerCommands:(id)unused;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation AudioScrobbler
|
@implementation AudioScrobbler
|
||||||
|
|
||||||
+ (BOOL) isRunning
|
+ (BOOL)isRunning {
|
||||||
{
|
|
||||||
NSArray *launchedApps = [[NSWorkspace sharedWorkspace] runningApplications];
|
NSArray *launchedApps = [[NSWorkspace sharedWorkspace] runningApplications];
|
||||||
BOOL running = NO;
|
BOOL running = NO;
|
||||||
for(NSRunningApplication *app in launchedApps) {
|
for(NSRunningApplication *app in launchedApps) {
|
||||||
|
@ -81,14 +79,11 @@ escapeForLastFM(NSString *string)
|
||||||
return running;
|
return running;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) init
|
- (id)init {
|
||||||
{
|
|
||||||
if((self = [super init])) {
|
if((self = [super init])) {
|
||||||
|
|
||||||
_pluginID = @"cog";
|
_pluginID = @"cog";
|
||||||
|
|
||||||
if([[NSUserDefaults standardUserDefaults] boolForKey:@"automaticallyLaunchLastFM"]) {
|
if([[NSUserDefaults standardUserDefaults] boolForKey:@"automaticallyLaunchLastFM"]) {
|
||||||
|
|
||||||
if(![AudioScrobbler isRunning]) {
|
if(![AudioScrobbler isRunning]) {
|
||||||
[[NSWorkspace sharedWorkspace] launchApplication:@"Last.fm.app"];
|
[[NSWorkspace sharedWorkspace] launchApplication:@"Last.fm.app"];
|
||||||
}
|
}
|
||||||
|
@ -110,18 +105,17 @@ escapeForLastFM(NSString *string)
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) dealloc
|
- (void)dealloc {
|
||||||
{
|
|
||||||
if([self keepProcessingAudioScrobblerCommands] || NO == [self audioScrobblerThreadCompleted])
|
if([self keepProcessingAudioScrobblerCommands] || NO == [self audioScrobblerThreadCompleted])
|
||||||
[self shutdown];
|
[self shutdown];
|
||||||
|
|
||||||
_queue = nil;
|
_queue = nil;
|
||||||
|
|
||||||
semaphore_destroy(mach_task_self(), _semaphore); _semaphore = 0;
|
semaphore_destroy(mach_task_self(), _semaphore);
|
||||||
|
_semaphore = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) start:(PlaylistEntry *)pe
|
- (void)start:(PlaylistEntry *)pe {
|
||||||
{
|
|
||||||
[self sendCommand:[NSString stringWithFormat:@"START c=%@&a=%@&t=%@&b=%@&m=%@&l=%i&p=%@\n",
|
[self sendCommand:[NSString stringWithFormat:@"START c=%@&a=%@&t=%@&b=%@&m=%@&l=%i&p=%@\n",
|
||||||
[self pluginID],
|
[self pluginID],
|
||||||
escapeForLastFM([pe artist]),
|
escapeForLastFM([pe artist]),
|
||||||
|
@ -129,27 +123,22 @@ escapeForLastFM(NSString *string)
|
||||||
escapeForLastFM([pe album]),
|
escapeForLastFM([pe album]),
|
||||||
@"", // TODO: MusicBrainz support
|
@"", // TODO: MusicBrainz support
|
||||||
[[pe length] intValue],
|
[[pe length] intValue],
|
||||||
escapeForLastFM([[pe URL] path])
|
escapeForLastFM([[pe URL] path])]];
|
||||||
]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) stop
|
- (void)stop {
|
||||||
{
|
|
||||||
[self sendCommand:[NSString stringWithFormat:@"STOP c=%@\n", [self pluginID]]];
|
[self sendCommand:[NSString stringWithFormat:@"STOP c=%@\n", [self pluginID]]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) pause
|
- (void)pause {
|
||||||
{
|
|
||||||
[self sendCommand:[NSString stringWithFormat:@"PAUSE c=%@\n", [self pluginID]]];
|
[self sendCommand:[NSString stringWithFormat:@"PAUSE c=%@\n", [self pluginID]]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) resume
|
- (void)resume {
|
||||||
{
|
|
||||||
[self sendCommand:[NSString stringWithFormat:@"RESUME c=%@\n", [self pluginID]]];
|
[self sendCommand:[NSString stringWithFormat:@"RESUME c=%@\n", [self pluginID]]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) shutdown
|
- (void)shutdown {
|
||||||
{
|
|
||||||
[self setKeepProcessingAudioScrobblerCommands:NO];
|
[self setKeepProcessingAudioScrobblerCommands:NO];
|
||||||
semaphore_signal([self semaphore]);
|
semaphore_signal([self semaphore]);
|
||||||
|
|
||||||
|
@ -162,54 +151,45 @@ escapeForLastFM(NSString *string)
|
||||||
|
|
||||||
@implementation AudioScrobbler (Private)
|
@implementation AudioScrobbler (Private)
|
||||||
|
|
||||||
- (NSMutableArray *) queue
|
- (NSMutableArray *)queue {
|
||||||
{
|
|
||||||
if(nil == _queue)
|
if(nil == _queue)
|
||||||
_queue = [[NSMutableArray alloc] init];
|
_queue = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
return _queue;
|
return _queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *) pluginID
|
- (NSString *)pluginID {
|
||||||
{
|
|
||||||
return _pluginID;
|
return _pluginID;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) sendCommand:(NSString *)command
|
- (void)sendCommand:(NSString *)command {
|
||||||
{
|
|
||||||
@synchronized([self queue]) {
|
@synchronized([self queue]) {
|
||||||
[[self queue] addObject:command];
|
[[self queue] addObject:command];
|
||||||
}
|
}
|
||||||
semaphore_signal([self semaphore]);
|
semaphore_signal([self semaphore]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) keepProcessingAudioScrobblerCommands
|
- (BOOL)keepProcessingAudioScrobblerCommands {
|
||||||
{
|
|
||||||
return _keepProcessingAudioScrobblerCommands;
|
return _keepProcessingAudioScrobblerCommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setKeepProcessingAudioScrobblerCommands:(BOOL)keepProcessingAudioScrobblerCommands
|
- (void)setKeepProcessingAudioScrobblerCommands:(BOOL)keepProcessingAudioScrobblerCommands {
|
||||||
{
|
|
||||||
_keepProcessingAudioScrobblerCommands = keepProcessingAudioScrobblerCommands;
|
_keepProcessingAudioScrobblerCommands = keepProcessingAudioScrobblerCommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) audioScrobblerThreadCompleted
|
- (BOOL)audioScrobblerThreadCompleted {
|
||||||
{
|
|
||||||
return _audioScrobblerThreadCompleted;
|
return _audioScrobblerThreadCompleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setAudioScrobblerThreadCompleted:(BOOL)audioScrobblerThreadCompleted
|
- (void)setAudioScrobblerThreadCompleted:(BOOL)audioScrobblerThreadCompleted {
|
||||||
{
|
|
||||||
_audioScrobblerThreadCompleted = audioScrobblerThreadCompleted;
|
_audioScrobblerThreadCompleted = audioScrobblerThreadCompleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (semaphore_t) semaphore
|
- (semaphore_t)semaphore {
|
||||||
{
|
|
||||||
return _semaphore;
|
return _semaphore;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) processAudioScrobblerCommands:(id)unused
|
- (void)processAudioScrobblerCommands:(id)unused {
|
||||||
{
|
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
AudioScrobblerClient *client = [[AudioScrobblerClient alloc] init];
|
AudioScrobblerClient *client = [[AudioScrobblerClient alloc] init];
|
||||||
mach_timespec_t timeout = { 5, 0 };
|
mach_timespec_t timeout = { 5, 0 };
|
||||||
|
@ -219,10 +199,9 @@ escapeForLastFM(NSString *string)
|
||||||
|
|
||||||
while([self keepProcessingAudioScrobblerCommands]) {
|
while([self keepProcessingAudioScrobblerCommands]) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
|
|
||||||
// Get the first command to be sent
|
// Get the first command to be sent
|
||||||
@synchronized([self queue]) {
|
@synchronized([self queue]) {
|
||||||
if ([[self queue] count]) {
|
if([[self queue] count]) {
|
||||||
command = [[self queue] objectAtIndex:0];
|
command = [[self queue] objectAtIndex:0];
|
||||||
[[self queue] removeObjectAtIndex:0];
|
[[self queue] removeObjectAtIndex:0];
|
||||||
}
|
}
|
||||||
|
@ -236,7 +215,7 @@ escapeForLastFM(NSString *string)
|
||||||
command = nil;
|
command = nil;
|
||||||
|
|
||||||
response = [client receive];
|
response = [client receive];
|
||||||
if(2 > [response length] || NSOrderedSame != [response compare:@"OK" options:NSLiteralSearch range:NSMakeRange(0,2)])
|
if(2 > [response length] || NSOrderedSame != [response compare:@"OK" options:NSLiteralSearch range:NSMakeRange(0, 2)])
|
||||||
ALog(@"AudioScrobbler error: %@", response);
|
ALog(@"AudioScrobbler error: %@", response);
|
||||||
|
|
||||||
[client shutdown];
|
[client shutdown];
|
||||||
|
@ -247,7 +226,7 @@ escapeForLastFM(NSString *string)
|
||||||
command = nil;
|
command = nil;
|
||||||
|
|
||||||
[client shutdown];
|
[client shutdown];
|
||||||
// ALog(@"Exception: %@",exception);
|
// ALog(@"Exception: %@",exception);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -262,7 +241,7 @@ escapeForLastFM(NSString *string)
|
||||||
[client send:[NSString stringWithFormat:@"STOP c=%@\n", [self pluginID]]];
|
[client send:[NSString stringWithFormat:@"STOP c=%@\n", [self pluginID]]];
|
||||||
|
|
||||||
response = [client receive];
|
response = [client receive];
|
||||||
if(2 > [response length] || NSOrderedSame != [response compare:@"OK" options:NSLiteralSearch range:NSMakeRange(0,2)])
|
if(2 > [response length] || NSOrderedSame != [response compare:@"OK" options:NSLiteralSearch range:NSMakeRange(0, 2)])
|
||||||
ALog(@"AudioScrobbler error: %@", response);
|
ALog(@"AudioScrobbler error: %@", response);
|
||||||
|
|
||||||
[client shutdown];
|
[client shutdown];
|
||||||
|
|
|
@ -22,21 +22,20 @@
|
||||||
|
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
|
||||||
@interface AudioScrobblerClient : NSObject
|
@interface AudioScrobblerClient : NSObject {
|
||||||
{
|
|
||||||
int _socket;
|
int _socket;
|
||||||
BOOL _doPortStepping;
|
BOOL _doPortStepping;
|
||||||
in_port_t _port;
|
in_port_t _port;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) connectToHost:(NSString *)hostname port:(in_port_t)port;
|
- (BOOL)connectToHost:(NSString *)hostname port:(in_port_t)port;
|
||||||
|
|
||||||
- (BOOL) isConnected;
|
- (BOOL)isConnected;
|
||||||
- (in_port_t) connectedPort;
|
- (in_port_t)connectedPort;
|
||||||
|
|
||||||
- (void) send:(NSString *)data;
|
- (void)send:(NSString *)data;
|
||||||
- (NSString *) receive;
|
- (NSString *)receive;
|
||||||
|
|
||||||
- (void) shutdown;
|
- (void)shutdown;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -33,8 +33,7 @@
|
||||||
#define kPortsToStep 5
|
#define kPortsToStep 5
|
||||||
|
|
||||||
static in_addr_t
|
static in_addr_t
|
||||||
addressForHost(NSString *hostname)
|
addressForHost(NSString *hostname) {
|
||||||
{
|
|
||||||
NSCParameterAssert(nil != hostname);
|
NSCParameterAssert(nil != hostname);
|
||||||
|
|
||||||
in_addr_t address;
|
in_addr_t address;
|
||||||
|
@ -56,13 +55,12 @@ addressForHost(NSString *hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
@interface AudioScrobblerClient (Private)
|
@interface AudioScrobblerClient (Private)
|
||||||
- (BOOL) connectToSocket:(in_addr_t)remoteAddress port:(in_port_t)port;
|
- (BOOL)connectToSocket:(in_addr_t)remoteAddress port:(in_port_t)port;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation AudioScrobblerClient
|
@implementation AudioScrobblerClient
|
||||||
|
|
||||||
- (id) init
|
- (id)init {
|
||||||
{
|
|
||||||
if((self = [super init])) {
|
if((self = [super init])) {
|
||||||
_socket = -1;
|
_socket = -1;
|
||||||
_doPortStepping = YES;
|
_doPortStepping = YES;
|
||||||
|
@ -70,8 +68,7 @@ addressForHost(NSString *hostname)
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) connectToHost:(NSString *)hostname port:(in_port_t)port
|
- (BOOL)connectToHost:(NSString *)hostname port:(in_port_t)port {
|
||||||
{
|
|
||||||
NSParameterAssert(nil != hostname);
|
NSParameterAssert(nil != hostname);
|
||||||
|
|
||||||
in_addr_t remoteAddress = addressForHost(hostname);
|
in_addr_t remoteAddress = addressForHost(hostname);
|
||||||
|
@ -82,20 +79,17 @@ addressForHost(NSString *hostname)
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) isConnected
|
- (BOOL)isConnected {
|
||||||
{
|
|
||||||
return (-1 != _socket);
|
return (-1 != _socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (in_port_t) connectedPort
|
- (in_port_t)connectedPort {
|
||||||
{
|
|
||||||
return _port;
|
return _port;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) send:(NSString *)data
|
- (void)send:(NSString *)data {
|
||||||
{
|
|
||||||
const char *utf8data = [data UTF8String];
|
const char *utf8data = [data UTF8String];
|
||||||
unsigned len = (unsigned int) strlen(utf8data);
|
unsigned len = (unsigned int)strlen(utf8data);
|
||||||
unsigned bytesToSend = len;
|
unsigned bytesToSend = len;
|
||||||
unsigned totalBytesSent = 0;
|
unsigned totalBytesSent = 0;
|
||||||
ssize_t bytesSent = 0;
|
ssize_t bytesSent = 0;
|
||||||
|
@ -115,9 +109,8 @@ addressForHost(NSString *hostname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *) receive
|
- (NSString *)receive {
|
||||||
{
|
char buffer[kBufferSize];
|
||||||
char buffer [ kBufferSize ];
|
|
||||||
int readSize = kBufferSize - 1;
|
int readSize = kBufferSize - 1;
|
||||||
ssize_t bytesRead = 0;
|
ssize_t bytesRead = 0;
|
||||||
BOOL keepGoing = YES;
|
BOOL keepGoing = YES;
|
||||||
|
@ -148,10 +141,9 @@ addressForHost(NSString *hostname)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) shutdown
|
- (void)shutdown {
|
||||||
{
|
|
||||||
int result;
|
int result;
|
||||||
char buffer [ kBufferSize ];
|
char buffer[kBufferSize];
|
||||||
ssize_t bytesRead;
|
ssize_t bytesRead;
|
||||||
|
|
||||||
if(NO == [self isConnected]) {
|
if(NO == [self isConnected]) {
|
||||||
|
@ -170,8 +162,7 @@ addressForHost(NSString *hostname)
|
||||||
if(0 != bytesRead) {
|
if(0 != bytesRead) {
|
||||||
NSString *received = [[NSString alloc] initWithBytes:buffer length:bytesRead encoding:NSUTF8StringEncoding];
|
NSString *received = [[NSString alloc] initWithBytes:buffer length:bytesRead encoding:NSUTF8StringEncoding];
|
||||||
ALog(@"Received unexpected bytes during shutdown: %@", received);
|
ALog(@"Received unexpected bytes during shutdown: %@", received);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,8 +178,7 @@ addressForHost(NSString *hostname)
|
||||||
|
|
||||||
@implementation AudioScrobblerClient (Private)
|
@implementation AudioScrobblerClient (Private)
|
||||||
|
|
||||||
- (BOOL) connectToSocket:(in_addr_t)remoteAddress port:(in_port_t)port
|
- (BOOL)connectToSocket:(in_addr_t)remoteAddress port:(in_port_t)port {
|
||||||
{
|
|
||||||
NSParameterAssert(INADDR_NONE != remoteAddress);
|
NSParameterAssert(INADDR_NONE != remoteAddress);
|
||||||
|
|
||||||
_port = port;
|
_port = port;
|
||||||
|
@ -214,7 +204,7 @@ addressForHost(NSString *hostname)
|
||||||
|
|
||||||
_port++;
|
_port++;
|
||||||
}
|
}
|
||||||
} while (YES == _doPortStepping && -1 == result && _port < (port + kPortsToStep));
|
} while(YES == _doPortStepping && -1 == result && _port < (port + kPortsToStep));
|
||||||
|
|
||||||
return (-1 != result);
|
return (-1 != result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,16 +6,16 @@
|
||||||
// Copyright 2005 Vincent Spader All rights reserved.
|
// Copyright 2005 Vincent Spader All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
|
||||||
#import "FeedbackSocket.h"
|
#import "FeedbackSocket.h"
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
@interface FeedbackController : NSWindowController<FeedbackSocketDelegate> {
|
@interface FeedbackController : NSWindowController <FeedbackSocketDelegate> {
|
||||||
IBOutlet NSTextField* fromView;
|
IBOutlet NSTextField* fromView;
|
||||||
IBOutlet NSTextField* subjectView;
|
IBOutlet NSTextField* subjectView;
|
||||||
IBOutlet NSTextView* messageView;
|
IBOutlet NSTextView* messageView;
|
||||||
IBOutlet NSProgressIndicator *sendingIndicator;
|
IBOutlet NSProgressIndicator* sendingIndicator;
|
||||||
|
|
||||||
FeedbackSocket *feedbackSocket;
|
FeedbackSocket* feedbackSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)sendFeedback:(id)sender;
|
- (IBAction)sendFeedback:(id)sender;
|
||||||
|
|
|
@ -12,13 +12,11 @@
|
||||||
|
|
||||||
@implementation FeedbackController
|
@implementation FeedbackController
|
||||||
|
|
||||||
- (id)init
|
- (id)init {
|
||||||
{
|
|
||||||
return [super initWithWindowNibName:@"Feedback"];
|
return [super initWithWindowNibName:@"Feedback"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)showWindow:(id)sender
|
- (IBAction)showWindow:(id)sender {
|
||||||
{
|
|
||||||
[fromView setStringValue:@""];
|
[fromView setStringValue:@""];
|
||||||
[subjectView setStringValue:@""];
|
[subjectView setStringValue:@""];
|
||||||
[messageView setString:@""];
|
[messageView setString:@""];
|
||||||
|
@ -26,16 +24,13 @@
|
||||||
[super showWindow:sender];
|
[super showWindow:sender];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)alertDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo
|
- (void)alertDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo {
|
||||||
{
|
if([(NSNumber *)CFBridgingRelease(contextInfo) boolValue] == YES) {
|
||||||
if ([(NSNumber *)CFBridgingRelease(contextInfo) boolValue]== YES)
|
|
||||||
{
|
|
||||||
[[self window] close];
|
[[self window] close];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)feedbackDidNotSend:(FeedbackSocket *)feedback
|
- (void)feedbackDidNotSend:(FeedbackSocket *)feedback {
|
||||||
{
|
|
||||||
ALog(@"Error sending feedback");
|
ALog(@"Error sending feedback");
|
||||||
|
|
||||||
[sendingIndicator stopAnimation:self];
|
[sendingIndicator stopAnimation:self];
|
||||||
|
@ -47,8 +42,7 @@
|
||||||
[alert beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:(void *)CFBridgingRetain([NSNumber numberWithBool:NO])];
|
[alert beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:(void *)CFBridgingRetain([NSNumber numberWithBool:NO])];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)feedbackDidSend:(FeedbackSocket *)feedback
|
- (void)feedbackDidSend:(FeedbackSocket *)feedback {
|
||||||
{
|
|
||||||
[sendingIndicator stopAnimation:self];
|
[sendingIndicator stopAnimation:self];
|
||||||
|
|
||||||
NSAlert *alert = [[NSAlert alloc] init];
|
NSAlert *alert = [[NSAlert alloc] init];
|
||||||
|
@ -58,12 +52,10 @@
|
||||||
[alert beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:(void *)CFBridgingRetain([NSNumber numberWithBool:YES])];
|
[alert beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:(void *)CFBridgingRetain([NSNumber numberWithBool:YES])];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (IBAction)sendFeedback:(id)sender {
|
||||||
- (IBAction)sendFeedback:(id)sender
|
|
||||||
{
|
|
||||||
[sendingIndicator startAnimation:self];
|
[sendingIndicator startAnimation:self];
|
||||||
|
|
||||||
//Using this so that if its a bad connection, it doesnt sit there looking stupid..or should it
|
// Using this so that if its a bad connection, it doesnt sit there looking stupid..or should it
|
||||||
feedbackSocket = [[FeedbackSocket alloc] init];
|
feedbackSocket = [[FeedbackSocket alloc] init];
|
||||||
[feedbackSocket setDelegate:self];
|
[feedbackSocket setDelegate:self];
|
||||||
|
|
||||||
|
@ -72,8 +64,7 @@
|
||||||
[feedbackSocket sendFeedback:[fromView stringValue] subject:[subjectView stringValue] message:[messageView string] version:version];
|
[feedbackSocket sendFeedback:[fromView stringValue] subject:[subjectView stringValue] message:[messageView string] version:version];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)cancel:(id)sender
|
- (IBAction)cancel:(id)sender {
|
||||||
{
|
|
||||||
[[self window] close];
|
[[self window] close];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setDelegate:(id<FeedbackSocketDelegate>)d;
|
- (void)setDelegate:(id<FeedbackSocketDelegate>)d;
|
||||||
- (void)sendFeedback: (NSString *)f subject:(NSString *)s message:(NSString *)m version:(NSString *)v;
|
- (void)sendFeedback:(NSString *)f subject:(NSString *)s message:(NSString *)m version:(NSString *)v;
|
||||||
|
|
||||||
- (void)setFrom:(NSString *)f;
|
- (void)setFrom:(NSString *)f;
|
||||||
- (void)setSubject:(NSString *)s;
|
- (void)setSubject:(NSString *)s;
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@protocol FeedbackSocketDelegate<NSObject>
|
@protocol FeedbackSocketDelegate <NSObject>
|
||||||
|
|
||||||
- (void)feedbackDidSend:(FeedbackSocket *)feedback;
|
- (void)feedbackDidSend:(FeedbackSocket *)feedback;
|
||||||
- (void)feedbackDidNotSend:(FeedbackSocket *)feedback;
|
- (void)feedbackDidNotSend:(FeedbackSocket *)feedback;
|
||||||
|
|
|
@ -12,13 +12,11 @@
|
||||||
|
|
||||||
@implementation FeedbackSocket
|
@implementation FeedbackSocket
|
||||||
|
|
||||||
NSString *encodeForURL(NSString *s)
|
NSString *encodeForURL(NSString *s) {
|
||||||
{
|
return (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)s, NULL, NULL, kCFStringEncodingUTF8));
|
||||||
return (NSString*) CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)s, NULL, NULL, kCFStringEncodingUTF8));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sendFeedbackThread:(id)sender
|
- (void)sendFeedbackThread:(id)sender {
|
||||||
{
|
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSString *f = encodeForURL(from);
|
NSString *f = encodeForURL(from);
|
||||||
NSString *s = encodeForURL(subject);
|
NSString *s = encodeForURL(subject);
|
||||||
|
@ -36,26 +34,21 @@ NSString *encodeForURL(NSString *s)
|
||||||
[post setHTTPMethod:@"POST"];
|
[post setHTTPMethod:@"POST"];
|
||||||
[post setHTTPBody:postData];
|
[post setHTTPBody:postData];
|
||||||
|
|
||||||
NSError* error;
|
NSError *error;
|
||||||
NSURLResponse* response;
|
NSURLResponse *response;
|
||||||
NSData* resultData = [NSURLConnection sendSynchronousRequest:post returningResponse:&response error:&error];
|
NSData *resultData = [NSURLConnection sendSynchronousRequest:post returningResponse:&response error:&error];
|
||||||
NSString *resultString = [[NSString alloc] initWithData:resultData encoding:NSASCIIStringEncoding];
|
NSString *resultString = [[NSString alloc] initWithData:resultData encoding:NSASCIIStringEncoding];
|
||||||
//DLog(@"RESULT: %@", resultString);
|
// DLog(@"RESULT: %@", resultString);
|
||||||
if ([resultString caseInsensitiveCompare:@"SUCCESS"] == NSOrderedSame)
|
if([resultString caseInsensitiveCompare:@"SUCCESS"] == NSOrderedSame) {
|
||||||
{
|
|
||||||
[self performSelectorOnMainThread:@selector(returnSuccess:) withObject:nil waitUntilDone:NO];
|
[self performSelectorOnMainThread:@selector(returnSuccess:) withObject:nil waitUntilDone:NO];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
[self performSelectorOnMainThread:@selector(returnFailure:) withObject:nil waitUntilDone:NO];
|
[self performSelectorOnMainThread:@selector(returnFailure:) withObject:nil waitUntilDone:NO];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sendFeedback: (NSString *)f subject:(NSString *)s message:(NSString *)m version:(NSString *)v
|
- (void)sendFeedback:(NSString *)f subject:(NSString *)s message:(NSString *)m version:(NSString *)v {
|
||||||
{
|
if([f isEqualToString:@""]) {
|
||||||
if ([f isEqualToString:@""])
|
|
||||||
{
|
|
||||||
f = @"Anonymous";
|
f = @"Anonymous";
|
||||||
}
|
}
|
||||||
[self setFrom:f];
|
[self setFrom:f];
|
||||||
|
@ -66,43 +59,35 @@ NSString *encodeForURL(NSString *s)
|
||||||
[NSThread detachNewThreadSelector:@selector(sendFeedbackThread:) toTarget:self withObject:nil];
|
[NSThread detachNewThreadSelector:@selector(sendFeedbackThread:) toTarget:self withObject:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)returnSuccess:(id)userInfo
|
- (void)returnSuccess:(id)userInfo {
|
||||||
{
|
if([delegate respondsToSelector:@selector(feedbackDidSend:)]) {
|
||||||
if ([delegate respondsToSelector:@selector(feedbackDidSend:)]) {
|
|
||||||
[delegate feedbackDidSend:self];
|
[delegate feedbackDidSend:self];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)returnFailure:(id)userInfo
|
- (void)returnFailure:(id)userInfo {
|
||||||
{
|
if([delegate respondsToSelector:@selector(feedbackDidNotSend:)]) {
|
||||||
if ([delegate respondsToSelector:@selector(feedbackDidNotSend:)]) {
|
|
||||||
[delegate feedbackDidNotSend:self];
|
[delegate feedbackDidNotSend:self];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)setDelegate:(id<FeedbackSocketDelegate>)d
|
- (void)setDelegate:(id<FeedbackSocketDelegate>)d {
|
||||||
{
|
|
||||||
delegate = d;
|
delegate = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)setFrom:(NSString *)f {
|
||||||
- (void)setFrom:(NSString *)f
|
|
||||||
{
|
|
||||||
from = f;
|
from = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setSubject:(NSString *)s
|
- (void)setSubject:(NSString *)s {
|
||||||
{
|
|
||||||
subject = s;
|
subject = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setMessage:(NSString *)m
|
- (void)setMessage:(NSString *)m {
|
||||||
{
|
|
||||||
message = m;
|
message = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setVersion:(NSString *)v
|
- (void)setVersion:(NSString *)v {
|
||||||
{
|
|
||||||
version = v;
|
version = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,6 @@
|
||||||
#import "PathNode.h"
|
#import "PathNode.h"
|
||||||
|
|
||||||
@interface ContainedNode : PathNode {
|
@interface ContainedNode : PathNode {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -9,36 +9,31 @@
|
||||||
#import "ContainedNode.h"
|
#import "ContainedNode.h"
|
||||||
#import "CogAudio/AudioMetadataReader.h"
|
#import "CogAudio/AudioMetadataReader.h"
|
||||||
|
|
||||||
|
|
||||||
@implementation ContainedNode
|
@implementation ContainedNode
|
||||||
|
|
||||||
- (BOOL)isLeaf
|
- (BOOL)isLeaf {
|
||||||
{
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setURL:(NSURL *)u
|
- (void)setURL:(NSURL *)u {
|
||||||
{
|
|
||||||
[super setURL:u];
|
[super setURL:u];
|
||||||
|
|
||||||
if ([u fragment])
|
if([u fragment]) {
|
||||||
{
|
|
||||||
NSDictionary *metadata = [AudioMetadataReader metadataForURL:u];
|
NSDictionary *metadata = [AudioMetadataReader metadataForURL:u];
|
||||||
NSString *title = nil;
|
NSString *title = nil;
|
||||||
NSString *artist = nil;
|
NSString *artist = nil;
|
||||||
if (metadata)
|
if(metadata) {
|
||||||
{
|
|
||||||
title = [metadata valueForKey:@"title"];
|
title = [metadata valueForKey:@"title"];
|
||||||
artist = [metadata valueForKey:@"artist"];
|
artist = [metadata valueForKey:@"artist"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (title && [title length])
|
if(title && [title length]) {
|
||||||
{
|
if(artist && [artist length]) {
|
||||||
if (artist && [artist length]) { display = [[u fragment] stringByAppendingFormat:@": %@ - %@", artist, title];}
|
display = [[u fragment] stringByAppendingFormat:@": %@ - %@", artist, title];
|
||||||
else { display = [[u fragment] stringByAppendingFormat:@": %@", title]; }
|
} else {
|
||||||
|
display = [[u fragment] stringByAppendingFormat:@": %@", title];
|
||||||
}
|
}
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
display = [u fragment];
|
display = [u fragment];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#import "PathNode.h"
|
#import "PathNode.h"
|
||||||
|
|
||||||
@interface ContainerNode : PathNode {
|
@interface ContainerNode : PathNode {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -15,18 +15,15 @@
|
||||||
|
|
||||||
@implementation ContainerNode
|
@implementation ContainerNode
|
||||||
|
|
||||||
- (BOOL)isLeaf
|
- (BOOL)isLeaf {
|
||||||
{
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)updatePath
|
- (void)updatePath {
|
||||||
{
|
|
||||||
NSArray *urls = [AudioContainer urlsForContainerURL:url];
|
NSArray *urls = [AudioContainer urlsForContainerURL:url];
|
||||||
|
|
||||||
NSMutableArray *paths = [[NSMutableArray alloc] init];
|
NSMutableArray *paths = [[NSMutableArray alloc] init];
|
||||||
for (NSURL *u in urls)
|
for(NSURL *u in urls) {
|
||||||
{
|
|
||||||
ContainedNode *node = [[ContainedNode alloc] initWithDataSource:dataSource url:u];
|
ContainedNode *node = [[ContainedNode alloc] initWithDataSource:dataSource url:u];
|
||||||
DLog(@"Node: %@", u);
|
DLog(@"Node: %@", u);
|
||||||
[paths addObject:node];
|
[paths addObject:node];
|
||||||
|
|
|
@ -6,11 +6,10 @@
|
||||||
// Copyright 2006 Vincent Spader. All rights reserved.
|
// Copyright 2006 Vincent Spader. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
|
||||||
#import "PathNode.h"
|
#import "PathNode.h"
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
@interface DirectoryNode : PathNode
|
@interface DirectoryNode : PathNode {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -15,24 +15,24 @@
|
||||||
|
|
||||||
@implementation DirectoryNode
|
@implementation DirectoryNode
|
||||||
|
|
||||||
- (BOOL)isLeaf
|
- (BOOL)isLeaf {
|
||||||
{
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)updatePath
|
- (void)updatePath {
|
||||||
{
|
NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtURL:url
|
||||||
NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtURL:url includingPropertiesForKeys:@[NSURLNameKey, NSURLIsDirectoryKey] options:(NSDirectoryEnumerationSkipsSubdirectoryDescendants | NSDirectoryEnumerationSkipsPackageDescendants | NSDirectoryEnumerationSkipsHiddenFiles) errorHandler:^BOOL(NSURL *url, NSError *error) {
|
includingPropertiesForKeys:@[NSURLNameKey, NSURLIsDirectoryKey]
|
||||||
|
options:(NSDirectoryEnumerationSkipsSubdirectoryDescendants | NSDirectoryEnumerationSkipsPackageDescendants | NSDirectoryEnumerationSkipsHiddenFiles)
|
||||||
|
errorHandler:^BOOL(NSURL *url, NSError *error) {
|
||||||
return NO;
|
return NO;
|
||||||
}];
|
}];
|
||||||
NSMutableArray *fullPaths = [[NSMutableArray alloc] init];
|
NSMutableArray *fullPaths = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
for (NSURL * theUrl in enumerator)
|
for(NSURL *theUrl in enumerator) {
|
||||||
{
|
|
||||||
[fullPaths addObject:[theUrl path]];
|
[fullPaths addObject:[theUrl path]];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self processPaths: [fullPaths sortedArrayUsingSelector:@selector(finderCompare:)]];
|
[self processPaths:[fullPaths sortedArrayUsingSelector:@selector(finderCompare:)]];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -6,11 +6,10 @@
|
||||||
// Copyright 2006 Vincent Spader. All rights reserved.
|
// Copyright 2006 Vincent Spader. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
|
||||||
#import "ImageTextCell.h"
|
#import "ImageTextCell.h"
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
@interface FileIconCell : ImageTextCell {
|
@interface FileIconCell : ImageTextCell {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -11,13 +11,11 @@
|
||||||
|
|
||||||
@implementation FileIconCell
|
@implementation FileIconCell
|
||||||
|
|
||||||
- (void)setObjectValue:(PathNode *)o
|
- (void)setObjectValue:(PathNode *)o {
|
||||||
{
|
if([o respondsToSelector:@selector(icon)] && [o respondsToSelector:@selector(display)]) {
|
||||||
if ([o respondsToSelector:@selector(icon)] && [o respondsToSelector:@selector(display)]) {
|
|
||||||
[super setObjectValue:[o display]];
|
[super setObjectValue:[o display]];
|
||||||
[super setImage: [o icon]];
|
[super setImage:[o icon]];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
[super setObjectValue:(id)o];
|
[super setObjectValue:(id)o];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,10 @@
|
||||||
// Copyright 2006 Vincent Spader. All rights reserved.
|
// Copyright 2006 Vincent Spader. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
|
||||||
#import "PathNode.h"
|
#import "PathNode.h"
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
@interface FileNode : PathNode
|
@interface FileNode : PathNode {
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -10,8 +10,7 @@
|
||||||
|
|
||||||
@implementation FileNode
|
@implementation FileNode
|
||||||
|
|
||||||
- (BOOL)isLeaf
|
- (BOOL)isLeaf {
|
||||||
{
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
|
||||||
#import "FileTreeDataSource.h"
|
#import "FileTreeDataSource.h"
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
@class SideViewController;
|
@class SideViewController;
|
||||||
@interface FileTreeController : NSObject {
|
@interface FileTreeController : NSObject {
|
||||||
|
|
|
@ -6,86 +6,73 @@
|
||||||
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "PlaylistController.h"
|
|
||||||
#import "FileTreeController.h"
|
#import "FileTreeController.h"
|
||||||
|
#import "PlaylistController.h"
|
||||||
#import "SideViewController.h"
|
#import "SideViewController.h"
|
||||||
|
|
||||||
|
|
||||||
@implementation FileTreeController
|
@implementation FileTreeController
|
||||||
|
|
||||||
- (IBAction)addToPlaylist:(id)sender
|
- (IBAction)addToPlaylist:(id)sender {
|
||||||
{
|
|
||||||
[self doAddToPlaylist:sender origin:URLOriginInternal];
|
[self doAddToPlaylist:sender origin:URLOriginInternal];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)doAddToPlaylist:(id)sender origin:(URLOrigin)origin
|
- (void)doAddToPlaylist:(id)sender origin:(URLOrigin)origin {
|
||||||
{
|
|
||||||
NSUInteger index;
|
NSUInteger index;
|
||||||
NSIndexSet *selectedIndexes = [outlineView selectedRowIndexes];
|
NSIndexSet *selectedIndexes = [outlineView selectedRowIndexes];
|
||||||
NSMutableArray *urls = [[NSMutableArray alloc] init];
|
NSMutableArray *urls = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
for (index = [selectedIndexes firstIndex];
|
for(index = [selectedIndexes firstIndex];
|
||||||
index != NSNotFound; index = [selectedIndexes indexGreaterThanIndex: index])
|
index != NSNotFound; index = [selectedIndexes indexGreaterThanIndex:index]) {
|
||||||
{
|
|
||||||
[urls addObject:[[outlineView itemAtRow:index] URL]];
|
[urls addObject:[[outlineView itemAtRow:index] URL]];
|
||||||
}
|
}
|
||||||
|
|
||||||
[controller doAddToPlaylist:urls origin:origin];
|
[controller doAddToPlaylist:urls origin:origin];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)addToPlaylistExternal:(id)sender
|
- (void)addToPlaylistExternal:(id)sender {
|
||||||
{
|
|
||||||
[self doAddToPlaylist:sender origin:URLOriginExternal];
|
[self doAddToPlaylist:sender origin:URLOriginExternal];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)setAsPlaylist:(id)sender
|
- (IBAction)setAsPlaylist:(id)sender {
|
||||||
{
|
|
||||||
[controller clear:sender];
|
[controller clear:sender];
|
||||||
[self addToPlaylist:sender];
|
[self addToPlaylist:sender];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)playPauseResume:(NSObject *)id
|
- (IBAction)playPauseResume:(NSObject *)id {
|
||||||
{
|
|
||||||
[controller playPauseResume:id];
|
[controller playPauseResume:id];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)showEntryInFinder:(id)sender
|
- (IBAction)showEntryInFinder:(id)sender {
|
||||||
{
|
|
||||||
NSUInteger index;
|
NSUInteger index;
|
||||||
NSWorkspace* ws = [NSWorkspace sharedWorkspace];
|
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
|
||||||
NSIndexSet *selectedIndexes = [outlineView selectedRowIndexes];
|
NSIndexSet *selectedIndexes = [outlineView selectedRowIndexes];
|
||||||
|
|
||||||
for (index = [selectedIndexes firstIndex];
|
for(index = [selectedIndexes firstIndex];
|
||||||
index != NSNotFound; index = [selectedIndexes indexGreaterThanIndex: index])
|
index != NSNotFound; index = [selectedIndexes indexGreaterThanIndex:index]) {
|
||||||
{
|
|
||||||
NSURL *url = [[outlineView itemAtRow:index] URL];
|
NSURL *url = [[outlineView itemAtRow:index] URL];
|
||||||
[ws selectFile:[url path] inFileViewerRootedAtPath:[url path]];
|
[ws selectFile:[url path] inFileViewerRootedAtPath:[url path]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)setAsRoot:(id)sender
|
- (IBAction)setAsRoot:(id)sender {
|
||||||
{
|
|
||||||
NSUInteger index = [[outlineView selectedRowIndexes] firstIndex];
|
NSUInteger index = [[outlineView selectedRowIndexes] firstIndex];
|
||||||
|
|
||||||
if (index != NSNotFound)
|
if(index != NSNotFound) {
|
||||||
{
|
|
||||||
[dataSource changeURL:[[outlineView itemAtRow:index] URL]];
|
[dataSource changeURL:[[outlineView itemAtRow:index] URL]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
-(BOOL)validateMenuItem:(NSMenuItem*)menuItem
|
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
|
||||||
{
|
|
||||||
SEL action = [menuItem action];
|
SEL action = [menuItem action];
|
||||||
|
|
||||||
if ([outlineView numberOfSelectedRows] == 0)
|
if([outlineView numberOfSelectedRows] == 0)
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
if (action == @selector(setAsRoot:))
|
if(action == @selector(setAsRoot:)) {
|
||||||
{
|
|
||||||
BOOL isDir;
|
BOOL isDir;
|
||||||
NSInteger row = [outlineView selectedRow];
|
NSInteger row = [outlineView selectedRow];
|
||||||
|
|
||||||
if ([outlineView numberOfSelectedRows] > 1)
|
if([outlineView numberOfSelectedRows] > 1)
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
// Only let directories be Set as Root
|
// Only let directories be Set as Root
|
||||||
|
|
|
@ -21,7 +21,7 @@ static NSURL *defaultMusicDirectory(void) {
|
||||||
error:nil];
|
error:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
@interface FileTreeDataSource()
|
@interface FileTreeDataSource ()
|
||||||
|
|
||||||
@property NSURL *rootURL;
|
@property NSURL *rootURL;
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ static NSURL *defaultMusicDirectory(void) {
|
||||||
|
|
||||||
+ (void)initialize {
|
+ (void)initialize {
|
||||||
NSString *path = [defaultMusicDirectory() absoluteString];
|
NSString *path = [defaultMusicDirectory() absoluteString];
|
||||||
NSDictionary *userDefaultsValuesDict = @{@"fileTreeRootURL": path};
|
NSDictionary *userDefaultsValuesDict = @{ @"fileTreeRootURL": path };
|
||||||
[[NSUserDefaults standardUserDefaults] registerDefaults:userDefaultsValuesDict];
|
[[NSUserDefaults standardUserDefaults] registerDefaults:userDefaultsValuesDict];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ static NSURL *defaultMusicDirectory(void) {
|
||||||
ofObject:(id)object
|
ofObject:(id)object
|
||||||
change:(NSDictionary *)change
|
change:(NSDictionary *)change
|
||||||
context:(void *)context {
|
context:(void *)context {
|
||||||
if ([keyPath isEqualToString:@"values.fileTreeRootURL"]) {
|
if([keyPath isEqualToString:@"values.fileTreeRootURL"]) {
|
||||||
NSString *url =
|
NSString *url =
|
||||||
[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"fileTreeRootURL"];
|
[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"fileTreeRootURL"];
|
||||||
DLog(@"File tree root URL: %@\n", url);
|
DLog(@"File tree root URL: %@\n", url);
|
||||||
|
@ -60,7 +60,7 @@ static NSURL *defaultMusicDirectory(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)changeURL:(NSURL *)url {
|
- (void)changeURL:(NSURL *)url {
|
||||||
if (url != nil) {
|
if(url != nil) {
|
||||||
[[[NSUserDefaultsController sharedUserDefaultsController] defaults] setObject:[url absoluteString]
|
[[[NSUserDefaultsController sharedUserDefaultsController] defaults] setObject:[url absoluteString]
|
||||||
forKey:@"fileTreeRootURL"];
|
forKey:@"fileTreeRootURL"];
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ static NSURL *defaultMusicDirectory(void) {
|
||||||
|
|
||||||
- (void)pathControlAction:(id)sender {
|
- (void)pathControlAction:(id)sender {
|
||||||
NSPathControlItem *item = [self.pathControl clickedPathItem];
|
NSPathControlItem *item = [self.pathControl clickedPathItem];
|
||||||
if (item != nil && item.URL != nil) {
|
if(item != nil && item.URL != nil) {
|
||||||
[self changeURL:item.URL];
|
[self changeURL:item.URL];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ static NSURL *defaultMusicDirectory(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setRootURL:(NSURL *)rootURL {
|
- (void)setRootURL:(NSURL *)rootURL {
|
||||||
if (![[NSFileManager defaultManager] fileExistsAtPath:[rootURL path]]) {
|
if(![[NSFileManager defaultManager] fileExistsAtPath:[rootURL path]]) {
|
||||||
rootURL = defaultMusicDirectory();
|
rootURL = defaultMusicDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,21 +93,20 @@ static NSURL *defaultMusicDirectory(void) {
|
||||||
NSString *relativePath = [[path stringByReplacingOccurrencesOfString:[[[self rootURL] path] stringByAppendingString:@"/"]
|
NSString *relativePath = [[path stringByReplacingOccurrencesOfString:[[[self rootURL] path] stringByAppendingString:@"/"]
|
||||||
withString:@""
|
withString:@""
|
||||||
options:NSAnchoredSearch
|
options:NSAnchoredSearch
|
||||||
range:NSMakeRange(0, [path length])
|
range:NSMakeRange(0, [path length])] stringByStandardizingPath];
|
||||||
] stringByStandardizingPath];
|
|
||||||
PathNode *node = rootNode;
|
PathNode *node = rootNode;
|
||||||
DLog(@"Root | Relative | Path: %@ | %@ | %@", [[self rootURL] path], relativePath, path);
|
DLog(@"Root | Relative | Path: %@ | %@ | %@", [[self rootURL] path], relativePath, path);
|
||||||
for (NSString *c in [relativePath pathComponents]) {
|
for(NSString *c in [relativePath pathComponents]) {
|
||||||
DLog(@"COMPONENT: %@", c);
|
DLog(@"COMPONENT: %@", c);
|
||||||
BOOL found = NO;
|
BOOL found = NO;
|
||||||
for (PathNode *subnode in [node subpaths]) {
|
for(PathNode *subnode in [node subpaths]) {
|
||||||
if ([[[[subnode URL] path] lastPathComponent] isEqualToString:c]) {
|
if([[[[subnode URL] path] lastPathComponent] isEqualToString:c]) {
|
||||||
node = subnode;
|
node = subnode;
|
||||||
found = YES;
|
found = YES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if(!found) {
|
||||||
DLog(@"Not found!");
|
DLog(@"Not found!");
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
@ -118,7 +117,7 @@ static NSURL *defaultMusicDirectory(void) {
|
||||||
|
|
||||||
- (void)pathDidChange:(NSString *)path {
|
- (void)pathDidChange:(NSString *)path {
|
||||||
DLog(@"PATH DID CHANGE: %@", path);
|
DLog(@"PATH DID CHANGE: %@", path);
|
||||||
//Need to find the corresponding node...and call [node reloadPath], then [self reloadPathNode:node]
|
// Need to find the corresponding node...and call [node reloadPath], then [self reloadPathNode:node]
|
||||||
PathNode *node = [self nodeForPath:path];
|
PathNode *node = [self nodeForPath:path];
|
||||||
DLog(@"NODE IS: %@", node);
|
DLog(@"NODE IS: %@", node);
|
||||||
[node updatePath];
|
[node updatePath];
|
||||||
|
@ -128,7 +127,7 @@ static NSURL *defaultMusicDirectory(void) {
|
||||||
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
|
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
|
||||||
PathNode *n = (item == nil ? rootNode : item);
|
PathNode *n = (item == nil ? rootNode : item);
|
||||||
|
|
||||||
return (int) [[n subpaths] count];
|
return (int)[[n subpaths] count];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
|
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
|
||||||
|
@ -140,7 +139,7 @@ static NSURL *defaultMusicDirectory(void) {
|
||||||
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
|
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
|
||||||
PathNode *n = (item == nil ? rootNode : item);
|
PathNode *n = (item == nil ? rootNode : item);
|
||||||
|
|
||||||
return [n subpaths][(NSUInteger) index];
|
return [n subpaths][(NSUInteger)index];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
|
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
|
||||||
|
@ -149,19 +148,18 @@ static NSURL *defaultMusicDirectory(void) {
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id <NSPasteboardWriting>)outlineView:(NSOutlineView *)outlineView pasteboardWriterForItem:(id)item {
|
- (id<NSPasteboardWriting>)outlineView:(NSOutlineView *)outlineView pasteboardWriterForItem:(id)item {
|
||||||
NSPasteboardItem *paste = [[NSPasteboardItem alloc] init];
|
NSPasteboardItem *paste = [[NSPasteboardItem alloc] init];
|
||||||
if (@available(macOS 10.13, *)) {
|
if(@available(macOS 10.13, *)) {
|
||||||
[paste setData:[[item URL] dataRepresentation] forType:NSPasteboardTypeFileURL];
|
[paste setData:[[item URL] dataRepresentation] forType:NSPasteboardTypeFileURL];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
[paste setPropertyList:@[[item URL]] forType:NSFilenamesPboardType];
|
[paste setPropertyList:@[[item URL]] forType:NSFilenamesPboardType];
|
||||||
}
|
}
|
||||||
return paste;
|
return paste;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)reloadPathNode:(PathNode *)item {
|
- (void)reloadPathNode:(PathNode *)item {
|
||||||
if (item == rootNode) {
|
if(item == rootNode) {
|
||||||
[self.outlineView reloadData];
|
[self.outlineView reloadData];
|
||||||
} else {
|
} else {
|
||||||
[self.outlineView reloadItem:item reloadChildren:YES];
|
[self.outlineView reloadItem:item reloadChildren:YES];
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
|
||||||
@interface FileTreeOutlineView : NSOutlineView {
|
@interface FileTreeOutlineView : NSOutlineView {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,37 +6,31 @@
|
||||||
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "FileTreeController.h"
|
|
||||||
#import "FileTreeOutlineView.h"
|
#import "FileTreeOutlineView.h"
|
||||||
|
#import "FileTreeController.h"
|
||||||
#import "FileTreeViewController.h"
|
#import "FileTreeViewController.h"
|
||||||
#import "PlaybackController.h"
|
#import "PlaybackController.h"
|
||||||
|
|
||||||
@implementation FileTreeOutlineView
|
@implementation FileTreeOutlineView
|
||||||
|
|
||||||
- (void)awakeFromNib
|
- (void)awakeFromNib {
|
||||||
{
|
|
||||||
[self setDoubleAction:@selector(addToPlaylistExternal:)];
|
[self setDoubleAction:@selector(addToPlaylistExternal:)];
|
||||||
[self setTarget:[self delegate]];
|
[self setTarget:[self delegate]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)keyDown:(NSEvent *)e
|
- (void)keyDown:(NSEvent *)e {
|
||||||
{
|
|
||||||
unsigned int modifiers = [e modifierFlags] & (NSEventModifierFlagCommand | NSEventModifierFlagShift | NSEventModifierFlagControl | NSEventModifierFlagOption);
|
unsigned int modifiers = [e modifierFlags] & (NSEventModifierFlagCommand | NSEventModifierFlagShift | NSEventModifierFlagControl | NSEventModifierFlagOption);
|
||||||
NSString *characters = [e characters];
|
NSString *characters = [e characters];
|
||||||
unichar c;
|
unichar c;
|
||||||
|
|
||||||
if ([characters length] == 1)
|
if([characters length] == 1) {
|
||||||
{
|
|
||||||
c = [characters characterAtIndex:0];
|
c = [characters characterAtIndex:0];
|
||||||
|
|
||||||
if (modifiers == 0 && (c == NSEnterCharacter || c == NSCarriageReturnCharacter))
|
if(modifiers == 0 && (c == NSEnterCharacter || c == NSCarriageReturnCharacter)) {
|
||||||
{
|
|
||||||
[(FileTreeController *)[self delegate] addToPlaylistExternal:self];
|
[(FileTreeController *)[self delegate] addToPlaylistExternal:self];
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
} else if(modifiers == 0 && c == ' ') {
|
||||||
else if (modifiers == 0 && c == ' ')
|
|
||||||
{
|
|
||||||
[(FileTreeController *)[self delegate] playPauseResume:self];
|
[(FileTreeController *)[self delegate] playPauseResume:self];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -48,25 +42,21 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// enables right-click selection for "Show in Finder" contextual menu
|
// enables right-click selection for "Show in Finder" contextual menu
|
||||||
-(NSMenu*)menuForEvent:(NSEvent*)event
|
- (NSMenu *)menuForEvent:(NSEvent *)event {
|
||||||
{
|
// Find which row is under the cursor
|
||||||
//Find which row is under the cursor
|
|
||||||
[[self window] makeFirstResponder:self];
|
[[self window] makeFirstResponder:self];
|
||||||
NSPoint menuPoint = [self convertPoint:[event locationInWindow] fromView:nil];
|
NSPoint menuPoint = [self convertPoint:[event locationInWindow] fromView:nil];
|
||||||
NSInteger iRow = [self rowAtPoint:menuPoint];
|
NSInteger iRow = [self rowAtPoint:menuPoint];
|
||||||
NSMenu* contextMenu = [self menu];
|
NSMenu *contextMenu = [self menu];
|
||||||
|
|
||||||
/* Update the file tree selection before showing menu
|
/* Update the file tree selection before showing menu
|
||||||
Preserves the selection if the row under the mouse is selected (to allow for
|
Preserves the selection if the row under the mouse is selected (to allow for
|
||||||
multiple items to be selected), otherwise selects the row under the mouse */
|
multiple items to be selected), otherwise selects the row under the mouse */
|
||||||
BOOL currentRowIsSelected = [[self selectedRowIndexes] containsIndex:iRow];
|
BOOL currentRowIsSelected = [[self selectedRowIndexes] containsIndex:iRow];
|
||||||
|
|
||||||
if (iRow == -1)
|
if(iRow == -1) {
|
||||||
{
|
|
||||||
[self deselectAll:self];
|
[self deselectAll:self];
|
||||||
}
|
} else if(!currentRowIsSelected) {
|
||||||
else if (!currentRowIsSelected)
|
|
||||||
{
|
|
||||||
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:iRow] byExtendingSelection:NO];
|
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:iRow] byExtendingSelection:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
|
||||||
#import "SideViewController.h"
|
#import "SideViewController.h"
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
@class PlaylistLoader;
|
@class PlaylistLoader;
|
||||||
@class PlaybackController;
|
@class PlaybackController;
|
||||||
|
@ -18,6 +18,6 @@
|
||||||
IBOutlet FileTreeOutlineView *fileTreeOutlineView;
|
IBOutlet FileTreeOutlineView *fileTreeOutlineView;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (FileTreeOutlineView*)outlineView;
|
- (FileTreeOutlineView *)outlineView;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -7,44 +7,37 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "FileTreeViewController.h"
|
#import "FileTreeViewController.h"
|
||||||
#import "PlaylistLoader.h"
|
|
||||||
#import "PlaybackController.h"
|
#import "PlaybackController.h"
|
||||||
|
#import "PlaylistLoader.h"
|
||||||
|
|
||||||
@implementation FileTreeViewController
|
@implementation FileTreeViewController
|
||||||
|
|
||||||
- (id)init
|
- (id)init {
|
||||||
{
|
|
||||||
return [super initWithNibName:@"FileTree" bundle:[NSBundle mainBundle]];
|
return [super initWithNibName:@"FileTree" bundle:[NSBundle mainBundle]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)addToPlaylistInternal:(NSArray *)urls
|
- (void)addToPlaylistInternal:(NSArray *)urls {
|
||||||
{
|
|
||||||
[self doAddToPlaylist:urls origin:URLOriginInternal];
|
[self doAddToPlaylist:urls origin:URLOriginInternal];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)addToPlaylistExternal:(NSArray *)urls
|
- (void)addToPlaylistExternal:(NSArray *)urls {
|
||||||
{
|
|
||||||
[self doAddToPlaylist:urls origin:URLOriginExternal];
|
[self doAddToPlaylist:urls origin:URLOriginExternal];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)doAddToPlaylist:(NSArray *)urls origin:(URLOrigin)origin
|
- (void)doAddToPlaylist:(NSArray *)urls origin:(URLOrigin)origin {
|
||||||
{
|
|
||||||
[playlistLoader willInsertURLs:urls origin:origin];
|
[playlistLoader willInsertURLs:urls origin:origin];
|
||||||
[playlistLoader didInsertURLs:[playlistLoader addURLs:urls sort:YES] origin:origin];
|
[playlistLoader didInsertURLs:[playlistLoader addURLs:urls sort:YES] origin:origin];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)clear:(id)sender
|
- (void)clear:(id)sender {
|
||||||
{
|
|
||||||
[playlistLoader clear:sender];
|
[playlistLoader clear:sender];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)playPauseResume:(NSObject *)id
|
- (void)playPauseResume:(NSObject *)id {
|
||||||
{
|
|
||||||
[playbackController playPauseResume:id];
|
[playbackController playPauseResume:id];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (FileTreeOutlineView*)outlineView
|
- (FileTreeOutlineView *)outlineView {
|
||||||
{
|
|
||||||
return fileTreeOutlineView;
|
return fileTreeOutlineView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,11 @@
|
||||||
|
|
||||||
@class FileTreeDataSource;
|
@class FileTreeDataSource;
|
||||||
|
|
||||||
@interface PathNode : NSObject
|
@interface PathNode : NSObject {
|
||||||
{
|
|
||||||
FileTreeDataSource *dataSource;
|
FileTreeDataSource *dataSource;
|
||||||
|
|
||||||
NSURL *url;
|
NSURL *url;
|
||||||
NSString *display; //The pretty path to display.
|
NSString *display; // The pretty path to display.
|
||||||
|
|
||||||
NSImage *icon;
|
NSImage *icon;
|
||||||
|
|
||||||
|
@ -27,7 +26,7 @@
|
||||||
- (NSURL *)URL;
|
- (NSURL *)URL;
|
||||||
- (void)setURL:(NSURL *)url;
|
- (void)setURL:(NSURL *)url;
|
||||||
|
|
||||||
- (void)processPaths: (NSArray *)contents;
|
- (void)processPaths:(NSArray *)contents;
|
||||||
|
|
||||||
- (NSArray *)subpaths;
|
- (NSArray *)subpaths;
|
||||||
- (void)setSubpaths:(NSArray *)s;
|
- (void)setSubpaths:(NSArray *)s;
|
||||||
|
@ -41,5 +40,4 @@
|
||||||
|
|
||||||
- (void)updatePath;
|
- (void)updatePath;
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -12,78 +12,67 @@
|
||||||
|
|
||||||
#import "FileTreeDataSource.h"
|
#import "FileTreeDataSource.h"
|
||||||
|
|
||||||
#import "FileNode.h"
|
|
||||||
#import "DirectoryNode.h"
|
|
||||||
#import "SmartFolderNode.h"
|
|
||||||
#import "ContainerNode.h"
|
#import "ContainerNode.h"
|
||||||
|
#import "DirectoryNode.h"
|
||||||
|
#import "FileNode.h"
|
||||||
|
#import "SmartFolderNode.h"
|
||||||
|
|
||||||
#import "Logging.h"
|
#import "Logging.h"
|
||||||
|
|
||||||
@implementation PathNode
|
@implementation PathNode
|
||||||
|
|
||||||
//From http://developer.apple.com/documentation/Cocoa/Conceptual/LowLevelFileMgmt/Tasks/ResolvingAliases.html
|
// From http://developer.apple.com/documentation/Cocoa/Conceptual/LowLevelFileMgmt/Tasks/ResolvingAliases.html
|
||||||
//Updated 2018-06-28
|
// Updated 2018-06-28
|
||||||
NSURL *resolveAliases(NSURL *url)
|
NSURL *resolveAliases(NSURL *url) {
|
||||||
{
|
|
||||||
CFErrorRef error;
|
CFErrorRef error;
|
||||||
CFDataRef bookmarkRef = CFURLCreateBookmarkDataFromFile(kCFAllocatorDefault, (__bridge CFURLRef)url, &error);
|
CFDataRef bookmarkRef = CFURLCreateBookmarkDataFromFile(kCFAllocatorDefault, (__bridge CFURLRef)url, &error);
|
||||||
if (bookmarkRef)
|
if(bookmarkRef) {
|
||||||
{
|
|
||||||
Boolean isStale;
|
Boolean isStale;
|
||||||
CFURLRef urlRef = CFURLCreateByResolvingBookmarkData(kCFAllocatorDefault, bookmarkRef, kCFURLBookmarkResolutionWithSecurityScope, NULL, NULL, &isStale, &error);
|
CFURLRef urlRef = CFURLCreateByResolvingBookmarkData(kCFAllocatorDefault, bookmarkRef, kCFURLBookmarkResolutionWithSecurityScope, NULL, NULL, &isStale, &error);
|
||||||
|
|
||||||
if (urlRef && !isStale)
|
if(urlRef && !isStale) {
|
||||||
{
|
|
||||||
return (NSURL *)CFBridgingRelease(urlRef);
|
return (NSURL *)CFBridgingRelease(urlRef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//DLog(@"Not resolved");
|
// DLog(@"Not resolved");
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithDataSource:(FileTreeDataSource *)ds url:(NSURL *)u
|
- (id)initWithDataSource:(FileTreeDataSource *)ds url:(NSURL *)u {
|
||||||
{
|
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
if (self)
|
if(self) {
|
||||||
{
|
|
||||||
dataSource = ds;
|
dataSource = ds;
|
||||||
[self setURL: u];
|
[self setURL:u];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setURL:(NSURL *)u
|
- (void)setURL:(NSURL *)u {
|
||||||
{
|
|
||||||
url = u;
|
url = u;
|
||||||
|
|
||||||
display = [[NSFileManager defaultManager] displayNameAtPath:[u path]];
|
display = [[NSFileManager defaultManager] displayNameAtPath:[u path]];
|
||||||
|
|
||||||
icon = [[NSWorkspace sharedWorkspace] iconForFile:[url path]];
|
icon = [[NSWorkspace sharedWorkspace] iconForFile:[url path]];
|
||||||
|
|
||||||
[icon setSize: NSMakeSize(16.0, 16.0)];
|
[icon setSize:NSMakeSize(16.0, 16.0)];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURL *)URL
|
- (NSURL *)URL {
|
||||||
{
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)updatePath
|
- (void)updatePath {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)processPaths: (NSArray *)contents
|
- (void)processPaths:(NSArray *)contents {
|
||||||
{
|
|
||||||
NSMutableArray *newSubpathsDirs = [[NSMutableArray alloc] init];
|
NSMutableArray *newSubpathsDirs = [[NSMutableArray alloc] init];
|
||||||
NSMutableArray *newSubpaths = [[NSMutableArray alloc] init];
|
NSMutableArray *newSubpaths = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
for (NSString *s in contents)
|
for(NSString *s in contents) {
|
||||||
{
|
if([s characterAtIndex:0] == '.') {
|
||||||
if ([s characterAtIndex:0] == '.')
|
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,44 +81,35 @@ NSURL *resolveAliases(NSURL *url)
|
||||||
|
|
||||||
PathNode *newNode;
|
PathNode *newNode;
|
||||||
|
|
||||||
//DLog(@"Before: %@", u);
|
// DLog(@"Before: %@", u);
|
||||||
u = resolveAliases(u);
|
u = resolveAliases(u);
|
||||||
//DLog(@"After: %@", u);
|
// DLog(@"After: %@", u);
|
||||||
|
|
||||||
BOOL isDir;
|
BOOL isDir;
|
||||||
|
|
||||||
if ([[s pathExtension] caseInsensitiveCompare:@"savedSearch"] == NSOrderedSame)
|
if([[s pathExtension] caseInsensitiveCompare:@"savedSearch"] == NSOrderedSame) {
|
||||||
{
|
|
||||||
DLog(@"Smart folder!");
|
DLog(@"Smart folder!");
|
||||||
newNode = [[SmartFolderNode alloc] initWithDataSource:dataSource url:u];
|
newNode = [[SmartFolderNode alloc] initWithDataSource:dataSource url:u];
|
||||||
isDir = NO;
|
isDir = NO;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
[[NSFileManager defaultManager] fileExistsAtPath:[u path] isDirectory:&isDir];
|
[[NSFileManager defaultManager] fileExistsAtPath:[u path] isDirectory:&isDir];
|
||||||
|
|
||||||
if (!isDir && ![[AudioPlayer fileTypes] containsObject:[[u pathExtension] lowercaseString]])
|
if(!isDir && ![[AudioPlayer fileTypes] containsObject:[[u pathExtension] lowercaseString]]) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDir)
|
if(isDir) {
|
||||||
{
|
|
||||||
newNode = [[DirectoryNode alloc] initWithDataSource:dataSource url:u];
|
newNode = [[DirectoryNode alloc] initWithDataSource:dataSource url:u];
|
||||||
}
|
} else if([[AudioPlayer containerTypes] containsObject:[[u pathExtension] lowercaseString]]) {
|
||||||
else if ([[AudioPlayer containerTypes] containsObject:[[u pathExtension] lowercaseString]])
|
|
||||||
{
|
|
||||||
newNode = [[ContainerNode alloc] initWithDataSource:dataSource url:u];
|
newNode = [[ContainerNode alloc] initWithDataSource:dataSource url:u];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
newNode = [[FileNode alloc] initWithDataSource:dataSource url:u];
|
newNode = [[FileNode alloc] initWithDataSource:dataSource url:u];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[newNode setDisplay:displayName];
|
[newNode setDisplay:displayName];
|
||||||
|
|
||||||
if (isDir)
|
if(isDir)
|
||||||
[newSubpathsDirs addObject:newNode];
|
[newSubpathsDirs addObject:newNode];
|
||||||
else
|
else
|
||||||
[newSubpaths addObject:newNode];
|
[newSubpaths addObject:newNode];
|
||||||
|
@ -139,39 +119,31 @@ NSURL *resolveAliases(NSURL *url)
|
||||||
[self setSubpaths:newSubpathsDirs];
|
[self setSubpaths:newSubpathsDirs];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray *)subpaths
|
- (NSArray *)subpaths {
|
||||||
{
|
if(subpaths == nil) {
|
||||||
if (subpaths == nil)
|
|
||||||
{
|
|
||||||
[self updatePath];
|
[self updatePath];
|
||||||
}
|
}
|
||||||
|
|
||||||
return subpaths;
|
return subpaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setSubpaths:(NSArray *)s
|
- (void)setSubpaths:(NSArray *)s {
|
||||||
{
|
|
||||||
subpaths = s;
|
subpaths = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)isLeaf {
|
||||||
- (BOOL)isLeaf
|
|
||||||
{
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setDisplay:(NSString *)s
|
- (void)setDisplay:(NSString *)s {
|
||||||
{
|
|
||||||
display = s;
|
display = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)display
|
- (NSString *)display {
|
||||||
{
|
|
||||||
return display;
|
return display;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSImage *)icon
|
- (NSImage *)icon {
|
||||||
{
|
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
#include <CoreServices/CoreServices.h>
|
#include <CoreServices/CoreServices.h>
|
||||||
|
|
||||||
|
|
||||||
@interface PathWatcher : NSObject {
|
@interface PathWatcher : NSObject {
|
||||||
FSEventStreamRef stream;
|
FSEventStreamRef stream;
|
||||||
FSEventStreamContext *context;
|
FSEventStreamContext *context;
|
||||||
|
@ -20,7 +19,7 @@
|
||||||
- (void)setDelegate:(id)d;
|
- (void)setDelegate:(id)d;
|
||||||
- (id)delegate;
|
- (id)delegate;
|
||||||
|
|
||||||
- (void)setPath:(NSString *)path; //Set the path to watch
|
- (void)setPath:(NSString *)path; // Set the path to watch
|
||||||
- (void)cleanUp;
|
- (void)cleanUp;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -9,19 +9,18 @@
|
||||||
#import "PathWatcher.h"
|
#import "PathWatcher.h"
|
||||||
|
|
||||||
static void myFSEventCallback(
|
static void myFSEventCallback(
|
||||||
ConstFSEventStreamRef streamRef,
|
ConstFSEventStreamRef streamRef,
|
||||||
void *clientCallBackInfo,
|
void *clientCallBackInfo,
|
||||||
size_t numEvents,
|
size_t numEvents,
|
||||||
void *eventPaths,
|
void *eventPaths,
|
||||||
const FSEventStreamEventFlags eventFlags[],
|
const FSEventStreamEventFlags eventFlags[],
|
||||||
const FSEventStreamEventId eventIds[])
|
const FSEventStreamEventId eventIds[]) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
char **paths = eventPaths;
|
char **paths = eventPaths;
|
||||||
PathWatcher *pathWatcher = (__bridge PathWatcher *)clientCallBackInfo;
|
PathWatcher *pathWatcher = (__bridge PathWatcher *)clientCallBackInfo;
|
||||||
|
|
||||||
printf("Callback called\n");
|
printf("Callback called\n");
|
||||||
for (i=0; i<numEvents; i++) {
|
for(i = 0; i < numEvents; i++) {
|
||||||
NSString *pathString = [[NSString alloc] initWithUTF8String:paths[i]];
|
NSString *pathString = [[NSString alloc] initWithUTF8String:paths[i]];
|
||||||
[[pathWatcher delegate] pathDidChange:pathString];
|
[[pathWatcher delegate] pathDidChange:pathString];
|
||||||
}
|
}
|
||||||
|
@ -29,28 +28,26 @@ static void myFSEventCallback(
|
||||||
|
|
||||||
@implementation PathWatcher
|
@implementation PathWatcher
|
||||||
|
|
||||||
- (void)cleanUp
|
- (void)cleanUp {
|
||||||
{
|
if(stream) {
|
||||||
if (stream) {
|
|
||||||
FSEventStreamStop(stream);
|
FSEventStreamStop(stream);
|
||||||
FSEventStreamInvalidate(stream);
|
FSEventStreamInvalidate(stream);
|
||||||
FSEventStreamRelease(stream);
|
FSEventStreamRelease(stream);
|
||||||
stream = NULL;
|
stream = NULL;
|
||||||
}
|
}
|
||||||
if (context) {
|
if(context) {
|
||||||
free(context);
|
free(context);
|
||||||
context = NULL;
|
context = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setPath:(NSString *)path
|
- (void)setPath:(NSString *)path {
|
||||||
{
|
|
||||||
[self cleanUp];
|
[self cleanUp];
|
||||||
|
|
||||||
//Create FSEvent stream
|
// Create FSEvent stream
|
||||||
NSArray *pathsToWatch = @[path];
|
NSArray *pathsToWatch = @[path];
|
||||||
|
|
||||||
context = (FSEventStreamContext*)malloc(sizeof(FSEventStreamContext));
|
context = (FSEventStreamContext *)malloc(sizeof(FSEventStreamContext));
|
||||||
context->version = 0;
|
context->version = 0;
|
||||||
context->info = (__bridge void *)self;
|
context->info = (__bridge void *)self;
|
||||||
context->retain = NULL;
|
context->retain = NULL;
|
||||||
|
@ -62,7 +59,7 @@ static void myFSEventCallback(
|
||||||
context,
|
context,
|
||||||
(__bridge CFArrayRef)pathsToWatch,
|
(__bridge CFArrayRef)pathsToWatch,
|
||||||
kFSEventStreamEventIdSinceNow, // Or a previous event ID
|
kFSEventStreamEventIdSinceNow, // Or a previous event ID
|
||||||
1.0, //latency in seconds
|
1.0, // latency in seconds
|
||||||
kFSEventStreamCreateFlagNone // Watch this and all its subdirectories
|
kFSEventStreamCreateFlagNone // Watch this and all its subdirectories
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -71,19 +68,15 @@ static void myFSEventCallback(
|
||||||
FSEventStreamStart(stream);
|
FSEventStreamStart(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setDelegate:(id)d
|
- (void)setDelegate:(id)d {
|
||||||
{
|
|
||||||
delegate = d;
|
delegate = d;
|
||||||
}
|
}
|
||||||
- (id)delegate
|
- (id)delegate {
|
||||||
{
|
|
||||||
return delegate;
|
return delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) dealloc
|
- (void)dealloc {
|
||||||
{
|
|
||||||
[self cleanUp];
|
[self cleanUp];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -15,13 +15,11 @@
|
||||||
|
|
||||||
@implementation SmartFolderNode
|
@implementation SmartFolderNode
|
||||||
|
|
||||||
- (BOOL)isLeaf
|
- (BOOL)isLeaf {
|
||||||
{
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)updatePath
|
- (void)updatePath {
|
||||||
{
|
|
||||||
NSDictionary *doc = [NSDictionary dictionaryWithContentsOfFile:[url path]];
|
NSDictionary *doc = [NSDictionary dictionaryWithContentsOfFile:[url path]];
|
||||||
NSString *rawQuery = [doc objectForKey:@"RawQuery"];
|
NSString *rawQuery = [doc objectForKey:@"RawQuery"];
|
||||||
NSArray *searchPaths = [[doc objectForKey:@"SearchCriteria"] objectForKey:@"CurrentFolderPath"];
|
NSArray *searchPaths = [[doc objectForKey:@"SearchCriteria"] objectForKey:@"CurrentFolderPath"];
|
||||||
|
@ -32,46 +30,41 @@
|
||||||
|
|
||||||
MDQuerySetSearchScope(query, (CFArrayRef)searchPaths, 0);
|
MDQuerySetSearchScope(query, (CFArrayRef)searchPaths, 0);
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryFinished:) name:(NSString*)kMDQueryDidFinishNotification object:(__bridge id)query];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryFinished:) name:(NSString *)kMDQueryDidFinishNotification object:(__bridge id)query];
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryUpdate:) name:(NSString*)kMDQueryDidUpdateNotification object:(__bridge id)query];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryUpdate:) name:(NSString *)kMDQueryDidUpdateNotification object:(__bridge id)query];
|
||||||
|
|
||||||
DLog(@"Making query!");
|
DLog(@"Making query!");
|
||||||
MDQueryExecute(query, kMDQueryWantsUpdates);
|
MDQueryExecute(query, kMDQueryWantsUpdates);
|
||||||
|
|
||||||
//Note: This is asynchronous!
|
// Note: This is asynchronous!
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setSubpaths:(id)s
|
- (void)setSubpaths:(id)s {
|
||||||
{
|
|
||||||
subpaths = s;
|
subpaths = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (unsigned int)countOfSubpaths
|
- (unsigned int)countOfSubpaths {
|
||||||
{
|
return (unsigned int)[[self subpaths] count];
|
||||||
return (unsigned int) [[self subpaths] count];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (PathNode *)objectInSubpathsAtIndex:(unsigned int)index
|
- (PathNode *)objectInSubpathsAtIndex:(unsigned int)index {
|
||||||
{
|
|
||||||
return [[self subpaths] objectAtIndex:index];
|
return [[self subpaths] objectAtIndex:index];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)queryFinished:(NSNotification *)notification
|
- (void)queryFinished:(NSNotification *)notification {
|
||||||
{
|
|
||||||
DLog(@"Query finished!");
|
DLog(@"Query finished!");
|
||||||
MDQueryRef query = (__bridge MDQueryRef)[notification object];
|
MDQueryRef query = (__bridge MDQueryRef)[notification object];
|
||||||
|
|
||||||
NSMutableArray *results = [NSMutableArray array];
|
NSMutableArray *results = [NSMutableArray array];
|
||||||
|
|
||||||
MDQueryDisableUpdates(query);
|
MDQueryDisableUpdates(query);
|
||||||
int c = (int) MDQueryGetResultCount(query);
|
int c = (int)MDQueryGetResultCount(query);
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < c; i++)
|
for(i = 0; i < c; i++) {
|
||||||
{
|
|
||||||
MDItemRef item = (MDItemRef)MDQueryGetResultAtIndex(query, i);
|
MDItemRef item = (MDItemRef)MDQueryGetResultAtIndex(query, i);
|
||||||
|
|
||||||
NSString *itemPath = (NSString *) CFBridgingRelease(MDItemCopyAttribute(item, kMDItemPath));
|
NSString *itemPath = (NSString *)CFBridgingRelease(MDItemCopyAttribute(item, kMDItemPath));
|
||||||
|
|
||||||
[results addObject:itemPath];
|
[results addObject:itemPath];
|
||||||
}
|
}
|
||||||
|
@ -85,17 +78,13 @@
|
||||||
[dataSource reloadPathNode:self];
|
[dataSource reloadPathNode:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)queryUpdate:(NSNotification *)notification
|
- (void)queryUpdate:(NSNotification *)notification {
|
||||||
{
|
|
||||||
DLog(@"Query update!");
|
DLog(@"Query update!");
|
||||||
[self queryFinished: notification];
|
[self queryFinished:notification];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc {
|
||||||
{
|
|
||||||
CFRelease(_query);
|
CFRelease(_query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,7 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
|
||||||
@interface BlankZeroFormatter : NSFormatter {
|
@interface BlankZeroFormatter : NSFormatter {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -8,11 +8,9 @@
|
||||||
|
|
||||||
#import "BlankZeroFormatter.h"
|
#import "BlankZeroFormatter.h"
|
||||||
|
|
||||||
|
|
||||||
@implementation BlankZeroFormatter
|
@implementation BlankZeroFormatter
|
||||||
|
|
||||||
- (NSString *) stringForObjectValue:(id)object
|
- (NSString *)stringForObjectValue:(id)object {
|
||||||
{
|
|
||||||
NSString *result = nil;
|
NSString *result = nil;
|
||||||
int value;
|
int value;
|
||||||
|
|
||||||
|
@ -22,7 +20,7 @@
|
||||||
|
|
||||||
value = [object intValue];
|
value = [object intValue];
|
||||||
|
|
||||||
if (value)
|
if(value)
|
||||||
result = [NSString stringWithFormat:@"%i", value];
|
result = [NSString stringWithFormat:@"%i", value];
|
||||||
else
|
else
|
||||||
result = [NSString string];
|
result = [NSString string];
|
||||||
|
@ -30,8 +28,7 @@
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) getObjectValue:(id *)object forString:(NSString *)string errorDescription:(NSString **)error
|
- (BOOL)getObjectValue:(id *)object forString:(NSString *)string errorDescription:(NSString **)error {
|
||||||
{
|
|
||||||
if(NULL != object) {
|
if(NULL != object) {
|
||||||
*object = [NSNumber numberWithInt:[string intValue]];
|
*object = [NSNumber numberWithInt:[string intValue]];
|
||||||
|
|
||||||
|
@ -41,8 +38,7 @@
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSAttributedString *) attributedStringForObjectValue:(id)object withDefaultAttributes:(NSDictionary *)attributes
|
- (NSAttributedString *)attributedStringForObjectValue:(id)object withDefaultAttributes:(NSDictionary *)attributes {
|
||||||
{
|
|
||||||
NSAttributedString *result = nil;
|
NSAttributedString *result = nil;
|
||||||
|
|
||||||
result = [[NSAttributedString alloc] initWithString:[self stringForObjectValue:object] attributes:attributes];
|
result = [[NSAttributedString alloc] initWithString:[self stringForObjectValue:object] attributes:attributes];
|
||||||
|
|
|
@ -8,9 +8,7 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
|
||||||
@interface IndexFormatter : NSFormatter {
|
@interface IndexFormatter : NSFormatter {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -8,11 +8,9 @@
|
||||||
|
|
||||||
#import "IndexFormatter.h"
|
#import "IndexFormatter.h"
|
||||||
|
|
||||||
|
|
||||||
@implementation IndexFormatter
|
@implementation IndexFormatter
|
||||||
|
|
||||||
- (NSString *) stringForObjectValue:(id)object
|
- (NSString *)stringForObjectValue:(id)object {
|
||||||
{
|
|
||||||
NSString *result = nil;
|
NSString *result = nil;
|
||||||
int value;
|
int value;
|
||||||
|
|
||||||
|
@ -27,8 +25,7 @@
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) getObjectValue:(id *)object forString:(NSString *)string errorDescription:(NSString **)error
|
- (BOOL)getObjectValue:(id *)object forString:(NSString *)string errorDescription:(NSString **)error {
|
||||||
{
|
|
||||||
if(NULL != object) {
|
if(NULL != object) {
|
||||||
*object = [NSNumber numberWithInt:[string intValue]];
|
*object = [NSNumber numberWithInt:[string intValue]];
|
||||||
|
|
||||||
|
@ -38,8 +35,7 @@
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSAttributedString *) attributedStringForObjectValue:(id)object withDefaultAttributes:(NSDictionary *)attributes
|
- (NSAttributedString *)attributedStringForObjectValue:(id)object withDefaultAttributes:(NSDictionary *)attributes {
|
||||||
{
|
|
||||||
NSAttributedString *result = nil;
|
NSAttributedString *result = nil;
|
||||||
|
|
||||||
result = [[NSAttributedString alloc] initWithString:[self stringForObjectValue:object] attributes:attributes];
|
result = [[NSAttributedString alloc] initWithString:[self stringForObjectValue:object] attributes:attributes];
|
||||||
|
|
|
@ -20,8 +20,7 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
@interface SecondsFormatter : NSFormatter
|
@interface SecondsFormatter : NSFormatter {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -22,8 +22,7 @@
|
||||||
|
|
||||||
@implementation SecondsFormatter
|
@implementation SecondsFormatter
|
||||||
|
|
||||||
- (NSString *) stringForObjectValue:(id)object
|
- (NSString *)stringForObjectValue:(id)object {
|
||||||
{
|
|
||||||
NSString *result = nil;
|
NSString *result = nil;
|
||||||
unsigned value;
|
unsigned value;
|
||||||
unsigned days = 0;
|
unsigned days = 0;
|
||||||
|
@ -52,22 +51,18 @@
|
||||||
|
|
||||||
if(0 < days) {
|
if(0 < days) {
|
||||||
result = [NSString stringWithFormat:@"%u:%.2u:%.2u:%.2u", days, hours, minutes, seconds];
|
result = [NSString stringWithFormat:@"%u:%.2u:%.2u:%.2u", days, hours, minutes, seconds];
|
||||||
}
|
} else if(0 < hours) {
|
||||||
else if(0 < hours) {
|
|
||||||
result = [NSString stringWithFormat:@"%u:%.2u:%.2u", hours, minutes, seconds];
|
result = [NSString stringWithFormat:@"%u:%.2u:%.2u", hours, minutes, seconds];
|
||||||
}
|
} else if(0 < minutes) {
|
||||||
else if(0 < minutes) {
|
|
||||||
result = [NSString stringWithFormat:@"%u:%.2u", minutes, seconds];
|
result = [NSString stringWithFormat:@"%u:%.2u", minutes, seconds];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
result = [NSString stringWithFormat:@"0:%.2u", seconds];
|
result = [NSString stringWithFormat:@"0:%.2u", seconds];
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) getObjectValue:(id *)object forString:(NSString *)string errorDescription:(NSString **)error
|
- (BOOL)getObjectValue:(id *)object forString:(NSString *)string errorDescription:(NSString **)error {
|
||||||
{
|
|
||||||
NSScanner *scanner = nil;
|
NSScanner *scanner = nil;
|
||||||
BOOL result = NO;
|
BOOL result = NO;
|
||||||
int value = 0;
|
int value = 0;
|
||||||
|
@ -76,7 +71,6 @@
|
||||||
scanner = [NSScanner scannerWithString:string];
|
scanner = [NSScanner scannerWithString:string];
|
||||||
|
|
||||||
while(NO == [scanner isAtEnd]) {
|
while(NO == [scanner isAtEnd]) {
|
||||||
|
|
||||||
// Grab a value
|
// Grab a value
|
||||||
if([scanner scanInt:&value]) {
|
if([scanner scanInt:&value]) {
|
||||||
seconds *= 60;
|
seconds *= 60;
|
||||||
|
@ -90,16 +84,14 @@
|
||||||
|
|
||||||
if(result && NULL != object) {
|
if(result && NULL != object) {
|
||||||
*object = [NSNumber numberWithUnsignedInt:seconds];
|
*object = [NSNumber numberWithUnsignedInt:seconds];
|
||||||
}
|
} else if(NULL != error) {
|
||||||
else if(NULL != error) {
|
|
||||||
*error = @"Couldn't convert value to seconds";
|
*error = @"Couldn't convert value to seconds";
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSAttributedString *) attributedStringForObjectValue:(id)object withDefaultAttributes:(NSDictionary *)attributes
|
- (NSAttributedString *)attributedStringForObjectValue:(id)object withDefaultAttributes:(NSDictionary *)attributes {
|
||||||
{
|
|
||||||
NSAttributedString *result = nil;
|
NSAttributedString *result = nil;
|
||||||
|
|
||||||
result = [[NSAttributedString alloc] initWithString:[self stringForObjectValue:object] attributes:attributes];
|
result = [[NSAttributedString alloc] initWithString:[self stringForObjectValue:object] attributes:attributes];
|
||||||
|
|
|
@ -6,12 +6,10 @@
|
||||||
// Copyright 2009 __MyCompanyName__. All rights reserved.
|
// Copyright 2009 __MyCompanyName__. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
|
||||||
#import "AppController.h"
|
#import "AppController.h"
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
@interface InfoWindowController : NSWindowController {
|
||||||
@interface InfoWindowController : NSWindowController
|
|
||||||
{
|
|
||||||
IBOutlet id playlistSelectionController;
|
IBOutlet id playlistSelectionController;
|
||||||
IBOutlet id currentEntryController;
|
IBOutlet id currentEntryController;
|
||||||
IBOutlet AppController *appController;
|
IBOutlet AppController *appController;
|
||||||
|
|
|
@ -7,51 +7,46 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "InfoWindowController.h"
|
#import "InfoWindowController.h"
|
||||||
|
#import "AppController.h"
|
||||||
|
#import "Logging.h"
|
||||||
#import "MissingAlbumArtTransformer.h"
|
#import "MissingAlbumArtTransformer.h"
|
||||||
#import "PlaylistEntry.h"
|
#import "PlaylistEntry.h"
|
||||||
#import "Logging.h"
|
|
||||||
#import "AppController.h"
|
|
||||||
|
|
||||||
@implementation InfoWindowController
|
@implementation InfoWindowController
|
||||||
|
|
||||||
@synthesize valueToDisplay;
|
@synthesize valueToDisplay;
|
||||||
|
|
||||||
+ (void)initialize
|
+ (void)initialize {
|
||||||
{
|
|
||||||
NSValueTransformer *missingAlbumArtTransformer = [[MissingAlbumArtTransformer alloc] init];
|
NSValueTransformer *missingAlbumArtTransformer = [[MissingAlbumArtTransformer alloc] init];
|
||||||
[NSValueTransformer setValueTransformer:missingAlbumArtTransformer
|
[NSValueTransformer setValueTransformer:missingAlbumArtTransformer
|
||||||
forName:@"MissingAlbumArtTransformer"];
|
forName:@"MissingAlbumArtTransformer"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)init
|
- (id)init {
|
||||||
{
|
|
||||||
return [super initWithWindowNibName:@"InfoInspector"];
|
return [super initWithWindowNibName:@"InfoInspector"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)awakeFromNib
|
- (void)awakeFromNib {
|
||||||
{
|
|
||||||
[playlistSelectionController addObserver:self forKeyPath:@"selection" options:NSKeyValueObservingOptionNew context:nil];
|
[playlistSelectionController addObserver:self forKeyPath:@"selection" options:NSKeyValueObservingOptionNew context:nil];
|
||||||
[currentEntryController addObserver:self forKeyPath:@"content" options:NSKeyValueObservingOptionNew context:nil];
|
[currentEntryController addObserver:self forKeyPath:@"content" options:NSKeyValueObservingOptionNew context:nil];
|
||||||
[appController addObserver:self forKeyPath:@"miniMode" options:NSKeyValueObservingOptionNew context:nil];
|
[appController addObserver:self forKeyPath:@"miniMode" options:NSKeyValueObservingOptionNew context:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
|
||||||
{
|
|
||||||
// Avoid "selection" because it creates a proxy that's hard to reason with when we don't need to write.
|
// Avoid "selection" because it creates a proxy that's hard to reason with when we don't need to write.
|
||||||
PlaylistEntry* currentSelection = [[playlistSelectionController selectedObjects] firstObject];
|
PlaylistEntry *currentSelection = [[playlistSelectionController selectedObjects] firstObject];
|
||||||
if (currentSelection != NULL) {
|
if(currentSelection != NULL) {
|
||||||
[self setValueToDisplay: currentSelection];
|
[self setValueToDisplay:currentSelection];
|
||||||
} else {
|
} else {
|
||||||
[self setValueToDisplay:[currentEntryController content]];
|
[self setValueToDisplay:[currentEntryController content]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)toggleWindow:(id)sender
|
- (IBAction)toggleWindow:(id)sender {
|
||||||
{
|
if([[self window] isVisible])
|
||||||
if ([[self window] isVisible])
|
|
||||||
[[self window] orderOut:self];
|
[[self window] orderOut:self];
|
||||||
else {
|
else {
|
||||||
if ([NSApp mainWindow]) {
|
if([NSApp mainWindow]) {
|
||||||
NSRect rect = [[NSApp mainWindow] frame];
|
NSRect rect = [[NSApp mainWindow] frame];
|
||||||
// Align Info Inspector HUD Panel to the right of Main Window.
|
// Align Info Inspector HUD Panel to the right of Main Window.
|
||||||
NSPoint point = NSMakePoint(NSMaxX(rect), NSMaxY(rect));
|
NSPoint point = NSMakePoint(NSMaxX(rect), NSMaxY(rect));
|
||||||
|
|
|
@ -8,9 +8,7 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
|
||||||
@interface MissingAlbumArtTransformer : NSValueTransformer {
|
@interface MissingAlbumArtTransformer : NSValueTransformer {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -8,15 +8,18 @@
|
||||||
|
|
||||||
#import "MissingAlbumArtTransformer.h"
|
#import "MissingAlbumArtTransformer.h"
|
||||||
|
|
||||||
|
|
||||||
@implementation MissingAlbumArtTransformer
|
@implementation MissingAlbumArtTransformer
|
||||||
|
|
||||||
+ (Class)transformedValueClass { return [NSImage class]; }
|
+ (Class)transformedValueClass {
|
||||||
+ (BOOL)allowsReverseTransformation { return NO; }
|
return [NSImage class];
|
||||||
|
}
|
||||||
|
+ (BOOL)allowsReverseTransformation {
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
// Convert from NSImage to NSImage
|
// Convert from NSImage to NSImage
|
||||||
- (id)transformedValue:(id)value {
|
- (id)transformedValue:(id)value {
|
||||||
if (value == nil) {
|
if(value == nil) {
|
||||||
return [NSImage imageNamed:@"missingArt"];
|
return [NSImage imageNamed:@"missingArt"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
Playlist/DNDArrayController.h
Executable file → Normal file
8
Playlist/DNDArrayController.h
Executable file → Normal file
|
@ -10,23 +10,23 @@ extern NSString *iTunesDropType;
|
||||||
@property IBOutlet NSTableView *tableView;
|
@property IBOutlet NSTableView *tableView;
|
||||||
|
|
||||||
// table view drag and drop support
|
// table view drag and drop support
|
||||||
- (id <NSPasteboardWriting>)tableView:(NSTableView *)tableView
|
- (id<NSPasteboardWriting>)tableView:(NSTableView *)tableView
|
||||||
pasteboardWriterForRow:(NSInteger)row;
|
pasteboardWriterForRow:(NSInteger)row;
|
||||||
- (void)tableView:(NSTableView *)tableView
|
- (void)tableView:(NSTableView *)tableView
|
||||||
draggingSession:(NSDraggingSession *)session
|
draggingSession:(NSDraggingSession *)session
|
||||||
willBeginAtPoint:(NSPoint)screenPoint
|
willBeginAtPoint:(NSPoint)screenPoint
|
||||||
forRowIndexes:(NSIndexSet *)rowIndexes;
|
forRowIndexes:(NSIndexSet *)rowIndexes;
|
||||||
- (NSDragOperation)tableView:(NSTableView *)tableView
|
- (NSDragOperation)tableView:(NSTableView *)tableView
|
||||||
validateDrop:(id <NSDraggingInfo>)info
|
validateDrop:(id<NSDraggingInfo>)info
|
||||||
proposedRow:(NSInteger)row
|
proposedRow:(NSInteger)row
|
||||||
proposedDropOperation:(NSTableViewDropOperation)dropOperation;
|
proposedDropOperation:(NSTableViewDropOperation)dropOperation;
|
||||||
- (BOOL)tableView:(NSTableView *)tableView
|
- (BOOL)tableView:(NSTableView *)tableView
|
||||||
acceptDrop:(id <NSDraggingInfo>)info
|
acceptDrop:(id<NSDraggingInfo>)info
|
||||||
row:(NSInteger)row
|
row:(NSInteger)row
|
||||||
dropOperation:(NSTableViewDropOperation)dropOperation;
|
dropOperation:(NSTableViewDropOperation)dropOperation;
|
||||||
|
|
||||||
// utility methods
|
// utility methods
|
||||||
-(void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet *)indexSet
|
- (void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet *)indexSet
|
||||||
toIndex:(NSUInteger)insertIndex;
|
toIndex:(NSUInteger)insertIndex;
|
||||||
// This is needed to undo the above
|
// This is needed to undo the above
|
||||||
- (void)moveObjectsFromIndex:(NSUInteger)fromIndex
|
- (void)moveObjectsFromIndex:(NSUInteger)fromIndex
|
||||||
|
|
55
Playlist/DNDArrayController.m
Executable file → Normal file
55
Playlist/DNDArrayController.m
Executable file → Normal file
|
@ -13,10 +13,9 @@ NSString *iTunesDropType = @"com.apple.tv.metadata";
|
||||||
[super awakeFromNib];
|
[super awakeFromNib];
|
||||||
// register for drag and drop
|
// register for drag and drop
|
||||||
NSPasteboardType fileType;
|
NSPasteboardType fileType;
|
||||||
if (@available(macOS 10.13, *)) {
|
if(@available(macOS 10.13, *)) {
|
||||||
fileType = NSPasteboardTypeFileURL;
|
fileType = NSPasteboardTypeFileURL;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
fileType = NSFilenamesPboardType;
|
fileType = NSFilenamesPboardType;
|
||||||
}
|
}
|
||||||
[self.tableView registerForDraggedTypes:@[CogDNDIndexType,
|
[self.tableView registerForDraggedTypes:@[CogDNDIndexType,
|
||||||
|
@ -25,8 +24,7 @@ NSString *iTunesDropType = @"com.apple.tv.metadata";
|
||||||
iTunesDropType]];
|
iTunesDropType]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id<NSPasteboardWriting>)tableView:(NSTableView *)tableView
|
||||||
- (id <NSPasteboardWriting>)tableView:(NSTableView *)tableView
|
|
||||||
pasteboardWriterForRow:(NSInteger)row {
|
pasteboardWriterForRow:(NSInteger)row {
|
||||||
NSPasteboardItem *item = [[NSPasteboardItem alloc] init];
|
NSPasteboardItem *item = [[NSPasteboardItem alloc] init];
|
||||||
[item setString:[@(row) stringValue] forType:CogDNDIndexType];
|
[item setString:[@(row) stringValue] forType:CogDNDIndexType];
|
||||||
|
@ -34,7 +32,6 @@ NSString *iTunesDropType = @"com.apple.tv.metadata";
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)tableView:(NSTableView *)tableView
|
- (void)tableView:(NSTableView *)tableView
|
||||||
draggingSession:(NSDraggingSession *)session
|
draggingSession:(NSDraggingSession *)session
|
||||||
willBeginAtPoint:(NSPoint)screenPoint
|
willBeginAtPoint:(NSPoint)screenPoint
|
||||||
|
@ -42,14 +39,13 @@ NSString *iTunesDropType = @"com.apple.tv.metadata";
|
||||||
DLog(@"Drag session started with indexes: %@", rowIndexes);
|
DLog(@"Drag session started with indexes: %@", rowIndexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (NSDragOperation)tableView:(NSTableView *)tableView
|
- (NSDragOperation)tableView:(NSTableView *)tableView
|
||||||
validateDrop:(id <NSDraggingInfo>)info
|
validateDrop:(id<NSDraggingInfo>)info
|
||||||
proposedRow:(NSInteger)row
|
proposedRow:(NSInteger)row
|
||||||
proposedDropOperation:(NSTableViewDropOperation)dropOperation {
|
proposedDropOperation:(NSTableViewDropOperation)dropOperation {
|
||||||
NSDragOperation dragOp = NSDragOperationCopy;
|
NSDragOperation dragOp = NSDragOperationCopy;
|
||||||
|
|
||||||
if ([info draggingSource] == tableView)
|
if([info draggingSource] == tableView)
|
||||||
dragOp = NSDragOperationMove;
|
dragOp = NSDragOperationMove;
|
||||||
|
|
||||||
DLog(@"VALIDATING DROP!");
|
DLog(@"VALIDATING DROP!");
|
||||||
|
@ -60,26 +56,25 @@ NSString *iTunesDropType = @"com.apple.tv.metadata";
|
||||||
return dragOp;
|
return dragOp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)tableView:(NSTableView *)tableView
|
- (BOOL)tableView:(NSTableView *)tableView
|
||||||
acceptDrop:(id <NSDraggingInfo>)info
|
acceptDrop:(id<NSDraggingInfo>)info
|
||||||
row:(NSInteger)row
|
row:(NSInteger)row
|
||||||
dropOperation:(NSTableViewDropOperation)dropOperation {
|
dropOperation:(NSTableViewDropOperation)dropOperation {
|
||||||
if (row < 0) {
|
if(row < 0) {
|
||||||
row = 0;
|
row = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSArray<NSPasteboardItem *> *items = info.draggingPasteboard.pasteboardItems;
|
NSArray<NSPasteboardItem *> *items = info.draggingPasteboard.pasteboardItems;
|
||||||
// if drag source is self, it's a move
|
// if drag source is self, it's a move
|
||||||
if ([info draggingSource] == tableView || items == nil) {
|
if([info draggingSource] == tableView || items == nil) {
|
||||||
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
|
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
|
||||||
for (NSPasteboardItem *item in items) {
|
for(NSPasteboardItem *item in items) {
|
||||||
[indexSet addIndex:(NSUInteger) [[item stringForType:CogDNDIndexType] intValue]];
|
[indexSet addIndex:(NSUInteger)[[item stringForType:CogDNDIndexType] intValue]];
|
||||||
}
|
}
|
||||||
if ([indexSet count] > 0) {
|
if([indexSet count] > 0) {
|
||||||
DLog(@"INDEX SET ON DROP: %@", indexSet);
|
DLog(@"INDEX SET ON DROP: %@", indexSet);
|
||||||
NSArray *selected = [[self arrangedObjects] objectsAtIndexes:indexSet];
|
NSArray *selected = [[self arrangedObjects] objectsAtIndexes:indexSet];
|
||||||
[self moveObjectsInArrangedObjectsFromIndexes:indexSet toIndex:(unsigned int) row];
|
[self moveObjectsInArrangedObjectsFromIndexes:indexSet toIndex:(unsigned int)row];
|
||||||
|
|
||||||
[self setSelectedObjects:selected];
|
[self setSelectedObjects:selected];
|
||||||
|
|
||||||
|
@ -91,17 +86,16 @@ NSString *iTunesDropType = @"com.apple.tv.metadata";
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet *)indexSet
|
- (void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet *)indexSet
|
||||||
toIndex:(NSUInteger)insertIndex {
|
toIndex:(NSUInteger)insertIndex {
|
||||||
__block NSUInteger rangeCount = 0;
|
__block NSUInteger rangeCount = 0;
|
||||||
__block NSUInteger firstIndex = 0;
|
__block NSUInteger firstIndex = 0;
|
||||||
[indexSet enumerateRangesUsingBlock:^(NSRange range, BOOL * _Nonnull stop) {
|
[indexSet enumerateRangesUsingBlock:^(NSRange range, BOOL *_Nonnull stop) {
|
||||||
if (++rangeCount == 1)
|
if(++rangeCount == 1)
|
||||||
firstIndex = range.location;
|
firstIndex = range.location;
|
||||||
}];
|
}];
|
||||||
|
|
||||||
if (rangeCount == 1 &&
|
if(rangeCount == 1 &&
|
||||||
(insertIndex >= firstIndex &&
|
(insertIndex >= firstIndex &&
|
||||||
insertIndex < firstIndex + [indexSet count])) // Null operation
|
insertIndex < firstIndex + [indexSet count])) // Null operation
|
||||||
return;
|
return;
|
||||||
|
@ -113,8 +107,8 @@ NSString *iTunesDropType = @"com.apple.tv.metadata";
|
||||||
id object;
|
id object;
|
||||||
NSUInteger removeIndex;
|
NSUInteger removeIndex;
|
||||||
|
|
||||||
while (NSNotFound != index) {
|
while(NSNotFound != index) {
|
||||||
if (index >= insertIndex) {
|
if(index >= insertIndex) {
|
||||||
removeIndex = index + aboveInsertIndexCount;
|
removeIndex = index + aboveInsertIndexCount;
|
||||||
aboveInsertIndexCount += 1;
|
aboveInsertIndexCount += 1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -136,18 +130,18 @@ NSString *iTunesDropType = @"com.apple.tv.metadata";
|
||||||
__block NSUInteger rangeCount = 0;
|
__block NSUInteger rangeCount = 0;
|
||||||
__block NSUInteger firstIndex = 0;
|
__block NSUInteger firstIndex = 0;
|
||||||
__block NSUInteger _fromIndex = fromIndex;
|
__block NSUInteger _fromIndex = fromIndex;
|
||||||
[indexSet enumerateRangesUsingBlock:^(NSRange range, BOOL * _Nonnull stop) {
|
[indexSet enumerateRangesUsingBlock:^(NSRange range, BOOL *_Nonnull stop) {
|
||||||
if (++rangeCount == 1)
|
if(++rangeCount == 1)
|
||||||
firstIndex = range.location;
|
firstIndex = range.location;
|
||||||
if (_fromIndex >= range.location) {
|
if(_fromIndex >= range.location) {
|
||||||
if (_fromIndex < range.location + range.length)
|
if(_fromIndex < range.location + range.length)
|
||||||
_fromIndex = range.location;
|
_fromIndex = range.location;
|
||||||
else
|
else
|
||||||
_fromIndex -= range.length;
|
_fromIndex -= range.length;
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
if (rangeCount == 1 &&
|
if(rangeCount == 1 &&
|
||||||
(fromIndex >= firstIndex &&
|
(fromIndex >= firstIndex &&
|
||||||
fromIndex < firstIndex + [indexSet count])) // Null operation
|
fromIndex < firstIndex + [indexSet count])) // Null operation
|
||||||
return;
|
return;
|
||||||
|
@ -161,11 +155,11 @@ NSString *iTunesDropType = @"com.apple.tv.metadata";
|
||||||
id object;
|
id object;
|
||||||
|
|
||||||
fromIndex += [objects count];
|
fromIndex += [objects count];
|
||||||
for (NSUInteger i = 0; i < [objects count]; i++) {
|
for(NSUInteger i = 0; i < [objects count]; i++) {
|
||||||
[self removeObjectAtArrangedObjectIndex:--fromIndex];
|
[self removeObjectAtArrangedObjectIndex:--fromIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
while (NSNotFound != index) {
|
while(NSNotFound != index) {
|
||||||
object = objects[itemIndex++];
|
object = objects[itemIndex++];
|
||||||
|
|
||||||
[self insertObject:object atArrangedObjectIndex:index];
|
[self insertObject:object atArrangedObjectIndex:index];
|
||||||
|
@ -174,5 +168,4 @@ NSString *iTunesDropType = @"com.apple.tv.metadata";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
// Copyright 2005 Vincent Spader All rights reserved.
|
// Copyright 2005 Vincent Spader All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#import "DNDArrayController.h"
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
#import <Foundation/NSUndoManager.h>
|
#import <Foundation/NSUndoManager.h>
|
||||||
#import "DNDArrayController.h"
|
|
||||||
|
|
||||||
@class PlaylistLoader;
|
@class PlaylistLoader;
|
||||||
@class PlaylistEntry;
|
@class PlaylistEntry;
|
||||||
|
@ -26,7 +26,9 @@ static inline BOOL IsRepeatOneSet() {
|
||||||
return [[NSUserDefaults standardUserDefaults] integerForKey:@"repeat"] == RepeatModeRepeatOne;
|
return [[NSUserDefaults standardUserDefaults] integerForKey:@"repeat"] == RepeatModeRepeatOne;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef enum { ShuffleOff = 0, ShuffleAlbums, ShuffleAll } ShuffleMode;
|
typedef enum { ShuffleOff = 0,
|
||||||
|
ShuffleAlbums,
|
||||||
|
ShuffleAll } ShuffleMode;
|
||||||
|
|
||||||
typedef NS_ENUM(NSInteger, URLOrigin) {
|
typedef NS_ENUM(NSInteger, URLOrigin) {
|
||||||
URLOriginInternal = 0,
|
URLOriginInternal = 0,
|
||||||
|
@ -38,7 +40,7 @@ typedef NS_ENUM(NSInteger, URLOrigin) {
|
||||||
IBOutlet SpotlightWindowController *spotlightWindowController;
|
IBOutlet SpotlightWindowController *spotlightWindowController;
|
||||||
IBOutlet PlaybackController *playbackController;
|
IBOutlet PlaybackController *playbackController;
|
||||||
|
|
||||||
NSValueTransformer * statusImageTransformer;
|
NSValueTransformer *statusImageTransformer;
|
||||||
|
|
||||||
NSMutableArray *shuffleList;
|
NSMutableArray *shuffleList;
|
||||||
NSMutableArray *queueList;
|
NSMutableArray *queueList;
|
||||||
|
@ -50,26 +52,26 @@ typedef NS_ENUM(NSInteger, URLOrigin) {
|
||||||
NSUndoManager *undoManager;
|
NSUndoManager *undoManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property(nonatomic, retain) PlaylistEntry * _Nullable currentEntry;
|
@property(nonatomic, retain) PlaylistEntry *_Nullable currentEntry;
|
||||||
@property(retain) NSString * _Nullable totalTime;
|
@property(retain) NSString *_Nullable totalTime;
|
||||||
|
|
||||||
// Private Methods
|
// Private Methods
|
||||||
- (void)updateTotalTime;
|
- (void)updateTotalTime;
|
||||||
- (void)updatePlaylistIndexes;
|
- (void)updatePlaylistIndexes;
|
||||||
- (IBAction)stopAfterCurrent:(id _Nullable )sender;
|
- (IBAction)stopAfterCurrent:(id _Nullable)sender;
|
||||||
|
|
||||||
// PUBLIC METHODS
|
// PUBLIC METHODS
|
||||||
- (void)setShuffle:(ShuffleMode)s;
|
- (void)setShuffle:(ShuffleMode)s;
|
||||||
- (ShuffleMode)shuffle;
|
- (ShuffleMode)shuffle;
|
||||||
- (void)setRepeat:(RepeatMode)r;
|
- (void)setRepeat:(RepeatMode)r;
|
||||||
- (RepeatMode)repeat;
|
- (RepeatMode)repeat;
|
||||||
- (NSArray * _Nullable)filterPlaylistOnAlbum:(NSString * _Nullable)album;
|
- (NSArray *_Nullable)filterPlaylistOnAlbum:(NSString *_Nullable)album;
|
||||||
|
|
||||||
- (PlaylistEntry * _Nullable)getNextEntry:(PlaylistEntry * _Nullable)pe;
|
- (PlaylistEntry *_Nullable)getNextEntry:(PlaylistEntry *_Nullable)pe;
|
||||||
- (PlaylistEntry * _Nullable)getPrevEntry:(PlaylistEntry * _Nullable)pe;
|
- (PlaylistEntry *_Nullable)getPrevEntry:(PlaylistEntry *_Nullable)pe;
|
||||||
|
|
||||||
/* Methods for undoing various actions */
|
/* Methods for undoing various actions */
|
||||||
- (NSUndoManager * _Nullable)undoManager;
|
- (NSUndoManager *_Nullable)undoManager;
|
||||||
|
|
||||||
- (IBAction)toggleShuffle:(id _Nullable)sender;
|
- (IBAction)toggleShuffle:(id _Nullable)sender;
|
||||||
|
|
||||||
|
@ -98,25 +100,25 @@ typedef NS_ENUM(NSInteger, URLOrigin) {
|
||||||
- (void)addShuffledListToFront;
|
- (void)addShuffledListToFront;
|
||||||
- (void)resetShuffleList;
|
- (void)resetShuffleList;
|
||||||
|
|
||||||
- (PlaylistEntry * _Nullable)shuffledEntryAtIndex:(NSInteger)i;
|
- (PlaylistEntry *_Nullable)shuffledEntryAtIndex:(NSInteger)i;
|
||||||
- (PlaylistEntry * _Nullable)entryAtIndex:(NSInteger)i;
|
- (PlaylistEntry *_Nullable)entryAtIndex:(NSInteger)i;
|
||||||
|
|
||||||
// Event inlets:
|
// Event inlets:
|
||||||
- (void)willInsertURLs:(NSArray * _Nullable)urls origin:(URLOrigin)origin;
|
- (void)willInsertURLs:(NSArray *_Nullable)urls origin:(URLOrigin)origin;
|
||||||
- (void)didInsertURLs:(NSArray * _Nullable)urls origin:(URLOrigin)origin;
|
- (void)didInsertURLs:(NSArray *_Nullable)urls origin:(URLOrigin)origin;
|
||||||
|
|
||||||
// queue methods
|
// queue methods
|
||||||
- (IBAction)toggleQueued:(id _Nullable)sender;
|
- (IBAction)toggleQueued:(id _Nullable)sender;
|
||||||
- (IBAction)emptyQueueList:(id _Nullable)sender;
|
- (IBAction)emptyQueueList:(id _Nullable)sender;
|
||||||
- (void)emptyQueueListUnsynced;
|
- (void)emptyQueueListUnsynced;
|
||||||
- (NSMutableArray * _Nullable)queueList;
|
- (NSMutableArray *_Nullable)queueList;
|
||||||
|
|
||||||
// reload metadata of selection
|
// reload metadata of selection
|
||||||
- (IBAction)reloadTags:(id _Nullable)sender;
|
- (IBAction)reloadTags:(id _Nullable)sender;
|
||||||
|
|
||||||
- (void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet * _Nullable)indexSet
|
- (void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet *_Nullable)indexSet
|
||||||
toIndex:(NSUInteger)insertIndex;
|
toIndex:(NSUInteger)insertIndex;
|
||||||
|
|
||||||
- (void)insertObjectsUnsynced:(NSArray * _Nullable)objects atArrangedObjectIndexes:(NSIndexSet * _Nullable)indexes;
|
- (void)insertObjectsUnsynced:(NSArray *_Nullable)objects atArrangedObjectIndexes:(NSIndexSet *_Nullable)indexes;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
@interface PlaylistEntry : NSObject<NSCopying> {
|
@interface PlaylistEntry : NSObject <NSCopying> {
|
||||||
NSInteger index;
|
NSInteger index;
|
||||||
NSInteger shuffleIndex;
|
NSInteger shuffleIndex;
|
||||||
NSInteger dbIndex;
|
NSInteger dbIndex;
|
||||||
|
|
|
@ -67,89 +67,72 @@
|
||||||
|
|
||||||
// The following read-only keys depend on the values of other properties
|
// The following read-only keys depend on the values of other properties
|
||||||
|
|
||||||
+ (NSSet *)keyPathsForValuesAffectingDisplay
|
+ (NSSet *)keyPathsForValuesAffectingDisplay {
|
||||||
{
|
return [NSSet setWithObjects:@"artist", @"title", nil];
|
||||||
return [NSSet setWithObjects:@"artist",@"title",nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSSet *)keyPathsForValuesAffectingLength
|
+ (NSSet *)keyPathsForValuesAffectingLength {
|
||||||
{
|
|
||||||
return [NSSet setWithObject:@"totalFrames"];
|
return [NSSet setWithObject:@"totalFrames"];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSSet *)keyPathsForValuesAffectingPath
|
+ (NSSet *)keyPathsForValuesAffectingPath {
|
||||||
{
|
|
||||||
return [NSSet setWithObject:@"URL"];
|
return [NSSet setWithObject:@"URL"];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSSet *)keyPathsForValuesAffectingFilename
|
+ (NSSet *)keyPathsForValuesAffectingFilename {
|
||||||
{
|
|
||||||
return [NSSet setWithObject:@"URL"];
|
return [NSSet setWithObject:@"URL"];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSSet *)keyPathsForValuesAffectingStatus
|
+ (NSSet *)keyPathsForValuesAffectingStatus {
|
||||||
{
|
return [NSSet setWithObjects:@"current", @"queued", @"error", @"stopAfter", nil];
|
||||||
return [NSSet setWithObjects:@"current",@"queued", @"error", @"stopAfter", nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSSet *)keyPathsForValuesAffectingStatusMessage
|
+ (NSSet *)keyPathsForValuesAffectingStatusMessage {
|
||||||
{
|
|
||||||
return [NSSet setWithObjects:@"current", @"queued", @"queuePosition", @"error", @"errorMessage", @"stopAfter", nil];
|
return [NSSet setWithObjects:@"current", @"queued", @"queuePosition", @"error", @"errorMessage", @"stopAfter", nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSSet *)keyPathsForValuesAffectingSpam
|
+ (NSSet *)keyPathsForValuesAffectingSpam {
|
||||||
{
|
|
||||||
return [NSSet setWithObjects:@"albumartist", @"artist", @"title", @"album", @"track", @"disc", @"totalFrames", @"currentPosition", @"bitrate", nil];
|
return [NSSet setWithObjects:@"albumartist", @"artist", @"title", @"album", @"track", @"disc", @"totalFrames", @"currentPosition", @"bitrate", nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSSet *)keyPathsForValuesAffectingTrackText
|
+ (NSSet *)keyPathsForValuesAffectingTrackText {
|
||||||
{
|
|
||||||
return [NSSet setWithObjects:@"track", @"disc", nil];
|
return [NSSet setWithObjects:@"track", @"disc", nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSSet *)keyPathsForValuesAffectingYearText
|
+ (NSSet *)keyPathsForValuesAffectingYearText {
|
||||||
{
|
|
||||||
return [NSSet setWithObject:@"year"];
|
return [NSSet setWithObject:@"year"];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSSet *)keyPathsForValuesAffectingCuesheetPresent
|
+ (NSSet *)keyPathsForValuesAffectingCuesheetPresent {
|
||||||
{
|
|
||||||
return [NSSet setWithObject:@"cuesheet"];
|
return [NSSet setWithObject:@"cuesheet"];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSSet *)keyPathsForValuesAffectingPositionText
|
+ (NSSet *)keyPathsForValuesAffectingPositionText {
|
||||||
{
|
|
||||||
return [NSSet setWithObject:@"currentPosition"];
|
return [NSSet setWithObject:@"currentPosition"];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSSet *)keyPathsForValuesAffectingLengthText
|
+ (NSSet *)keyPathsForValuesAffectingLengthText {
|
||||||
{
|
|
||||||
return [NSSet setWithObject:@"length"];
|
return [NSSet setWithObject:@"length"];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSSet *)keyPathsForValuesAffectingAlbumArt
|
+ (NSSet *)keyPathsForValuesAffectingAlbumArt {
|
||||||
{
|
|
||||||
return [NSSet setWithObject:@"albumArtInternal"];
|
return [NSSet setWithObject:@"albumArtInternal"];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSSet *)keyPathsForValuesAffectingGainCorrection
|
+ (NSSet *)keyPathsForValuesAffectingGainCorrection {
|
||||||
{
|
|
||||||
return [NSSet setWithObjects:@"replayGainAlbumGain", @"replayGainAlbumPeak", @"replayGainTrackGain", @"replayGainTrackPeak", @"volume", nil];
|
return [NSSet setWithObjects:@"replayGainAlbumGain", @"replayGainAlbumPeak", @"replayGainTrackGain", @"replayGainTrackPeak", @"volume", nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSSet *)keyPathsForValuesAffectingGainInfo
|
+ (NSSet *)keyPathsForValuesAffectingGainInfo {
|
||||||
{
|
|
||||||
return [NSSet setWithObjects:@"replayGainAlbumGain", @"replayGainAlbumPeak", @"replayGainTrackGain", @"replayGainTrackPeak", @"volume", nil];
|
return [NSSet setWithObjects:@"replayGainAlbumGain", @"replayGainAlbumPeak", @"replayGainTrackGain", @"replayGainTrackPeak", @"volume", nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)description
|
- (NSString *)description {
|
||||||
{
|
|
||||||
return [NSString stringWithFormat:@"PlaylistEntry %li:(%@)", self.index, self.URL];
|
return [NSString stringWithFormat:@"PlaylistEntry %li:(%@)", self.index, self.URL];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)init
|
- (id)init {
|
||||||
{
|
if(self = [super init]) {
|
||||||
if (self = [super init]) {
|
|
||||||
self.replayGainAlbumGain = 0;
|
self.replayGainAlbumGain = 0;
|
||||||
self.replayGainAlbumPeak = 0;
|
self.replayGainAlbumPeak = 0;
|
||||||
self.replayGainTrackGain = 0;
|
self.replayGainTrackGain = 0;
|
||||||
|
@ -159,8 +142,7 @@
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc {
|
||||||
{
|
|
||||||
self.errorMessage = nil;
|
self.errorMessage = nil;
|
||||||
|
|
||||||
self.URL = nil;
|
self.URL = nil;
|
||||||
|
@ -183,25 +165,21 @@
|
||||||
|
|
||||||
// Get the URL if the title is blank
|
// Get the URL if the title is blank
|
||||||
@synthesize title;
|
@synthesize title;
|
||||||
- (NSString *)title
|
- (NSString *)title {
|
||||||
{
|
if((title == nil || [title isEqualToString:@""]) && self.URL) {
|
||||||
if((title == nil || [title isEqualToString:@""]) && self.URL)
|
|
||||||
{
|
|
||||||
return [[self.URL path] lastPathComponent];
|
return [[self.URL path] lastPathComponent];
|
||||||
}
|
}
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
@synthesize rawTitle;
|
@synthesize rawTitle;
|
||||||
- (NSString *)rawTitle
|
- (NSString *)rawTitle {
|
||||||
{
|
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
@dynamic display;
|
@dynamic display;
|
||||||
- (NSString *)display
|
- (NSString *)display {
|
||||||
{
|
if((self.artist == NULL) || ([self.artist isEqualToString:@""]))
|
||||||
if ((self.artist == NULL) || ([self.artist isEqualToString:@""]))
|
|
||||||
return self.title;
|
return self.title;
|
||||||
else {
|
else {
|
||||||
return [NSString stringWithFormat:@"%@ - %@", self.artist, self.title];
|
return [NSString stringWithFormat:@"%@ - %@", self.artist, self.title];
|
||||||
|
@ -209,8 +187,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@dynamic spam;
|
@dynamic spam;
|
||||||
- (NSString *)spam
|
- (NSString *)spam {
|
||||||
{
|
|
||||||
BOOL hasBitrate = (self.bitrate != 0);
|
BOOL hasBitrate = (self.bitrate != 0);
|
||||||
BOOL hasArtist = (self.artist != nil) && (![self.artist isEqualToString:@""]);
|
BOOL hasArtist = (self.artist != nil) && (![self.artist isEqualToString:@""]);
|
||||||
BOOL hasAlbumArtist = (self.albumartist != nil) && (![self.albumartist isEqualToString:@""]);
|
BOOL hasAlbumArtist = (self.albumartist != nil) && (![self.albumartist isEqualToString:@""]);
|
||||||
|
@ -222,11 +199,11 @@
|
||||||
BOOL hasTitle = (title != nil) && (![title isEqualToString:@""]);
|
BOOL hasTitle = (title != nil) && (![title isEqualToString:@""]);
|
||||||
BOOL hasCodec = (self.codec != nil) && (![self.codec isEqualToString:@""]);
|
BOOL hasCodec = (self.codec != nil) && (![self.codec isEqualToString:@""]);
|
||||||
|
|
||||||
NSMutableString * filename = [NSMutableString stringWithString:[self filename]];
|
NSMutableString *filename = [NSMutableString stringWithString:[self filename]];
|
||||||
NSRange dotPosition = [filename rangeOfString:@"." options:NSBackwardsSearch];
|
NSRange dotPosition = [filename rangeOfString:@"." options:NSBackwardsSearch];
|
||||||
NSString * extension = nil;
|
NSString *extension = nil;
|
||||||
|
|
||||||
if (dotPosition.length > 0) {
|
if(dotPosition.length > 0) {
|
||||||
dotPosition.location++;
|
dotPosition.location++;
|
||||||
dotPosition.length = [filename length] - dotPosition.location;
|
dotPosition.length = [filename length] - dotPosition.location;
|
||||||
extension = [filename substringWithRange:dotPosition];
|
extension = [filename substringWithRange:dotPosition];
|
||||||
|
@ -236,17 +213,16 @@
|
||||||
hasExtension = YES;
|
hasExtension = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSMutableArray * elements = [NSMutableArray array];
|
NSMutableArray *elements = [NSMutableArray array];
|
||||||
|
|
||||||
if (hasExtension) {
|
if(hasExtension) {
|
||||||
[elements addObject:@"["];
|
[elements addObject:@"["];
|
||||||
if (hasCodec) {
|
if(hasCodec) {
|
||||||
[elements addObject:self.codec];
|
[elements addObject:self.codec];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
[elements addObject:[extension uppercaseString]];
|
[elements addObject:[extension uppercaseString]];
|
||||||
}
|
}
|
||||||
if (hasBitrate) {
|
if(hasBitrate) {
|
||||||
[elements addObject:@"@"];
|
[elements addObject:@"@"];
|
||||||
[elements addObject:[NSString stringWithFormat:@"%u", self.bitrate]];
|
[elements addObject:[NSString stringWithFormat:@"%u", self.bitrate]];
|
||||||
[elements addObject:@"kbps"];
|
[elements addObject:@"kbps"];
|
||||||
|
@ -254,46 +230,44 @@
|
||||||
[elements addObject:@"] "];
|
[elements addObject:@"] "];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasArtist) {
|
if(hasArtist) {
|
||||||
if (hasAlbumArtist) {
|
if(hasAlbumArtist) {
|
||||||
[elements addObject:self.albumartist];
|
[elements addObject:self.albumartist];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
[elements addObject:self.artist];
|
[elements addObject:self.artist];
|
||||||
}
|
}
|
||||||
[elements addObject:@" - "];
|
[elements addObject:@" - "];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasAlbum) {
|
if(hasAlbum) {
|
||||||
[elements addObject:@"["];
|
[elements addObject:@"["];
|
||||||
[elements addObject:self.album];
|
[elements addObject:self.album];
|
||||||
if (hasTrack) {
|
if(hasTrack) {
|
||||||
[elements addObject:@" #"];
|
[elements addObject:@" #"];
|
||||||
[elements addObject:self.trackText];
|
[elements addObject:self.trackText];
|
||||||
}
|
}
|
||||||
[elements addObject:@"] "];
|
[elements addObject:@"] "];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasTitle) {
|
if(hasTitle) {
|
||||||
[elements addObject:title];
|
[elements addObject:title];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
[elements addObject:filename];
|
[elements addObject:filename];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasAlbumArtist && hasArtist) {
|
if(hasAlbumArtist && hasArtist) {
|
||||||
[elements addObject:@" // "];
|
[elements addObject:@" // "];
|
||||||
[elements addObject:self.artist];
|
[elements addObject:self.artist];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasCurrentPosition || hasLength) {
|
if(hasCurrentPosition || hasLength) {
|
||||||
SecondsFormatter *secondsFormatter = [[SecondsFormatter alloc] init];
|
SecondsFormatter *secondsFormatter = [[SecondsFormatter alloc] init];
|
||||||
[elements addObject:@" ("];
|
[elements addObject:@" ("];
|
||||||
if (hasCurrentPosition) {
|
if(hasCurrentPosition) {
|
||||||
[elements addObject:[secondsFormatter stringForObjectValue:[NSNumber numberWithFloat:currentPosition]]];
|
[elements addObject:[secondsFormatter stringForObjectValue:[NSNumber numberWithFloat:currentPosition]]];
|
||||||
}
|
}
|
||||||
if (hasLength) {
|
if(hasLength) {
|
||||||
if (hasCurrentPosition) {
|
if(hasCurrentPosition) {
|
||||||
[elements addObject:@" / "];
|
[elements addObject:@" / "];
|
||||||
}
|
}
|
||||||
[elements addObject:[secondsFormatter stringForObjectValue:[self length]]];
|
[elements addObject:[secondsFormatter stringForObjectValue:[self length]]];
|
||||||
|
@ -305,116 +279,85 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@dynamic trackText;
|
@dynamic trackText;
|
||||||
-(NSString *)trackText
|
- (NSString *)trackText {
|
||||||
{
|
if([self.track intValue]) {
|
||||||
if ([self.track intValue])
|
if([self.disc intValue]) {
|
||||||
{
|
|
||||||
if ([self.disc intValue])
|
|
||||||
{
|
|
||||||
return [NSString stringWithFormat:@"%@.%02u", self.disc, [self.track intValue]];
|
return [NSString stringWithFormat:@"%@.%02u", self.disc, [self.track intValue]];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return [NSString stringWithFormat:@"%02u", [self.track intValue]];
|
return [NSString stringWithFormat:@"%02u", [self.track intValue]];
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return @"";
|
return @"";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@dynamic yearText;
|
@dynamic yearText;
|
||||||
-(NSString *)yearText
|
- (NSString *)yearText {
|
||||||
{
|
if([self.year intValue]) {
|
||||||
if ([self.year intValue])
|
|
||||||
{
|
|
||||||
return [NSString stringWithFormat:@"%@", self.year];
|
return [NSString stringWithFormat:@"%@", self.year];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return @"";
|
return @"";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@dynamic cuesheetPresent;
|
@dynamic cuesheetPresent;
|
||||||
-(NSString *)cuesheetPresent
|
- (NSString *)cuesheetPresent {
|
||||||
{
|
if(cuesheet && [cuesheet length]) {
|
||||||
if (cuesheet && [cuesheet length])
|
|
||||||
{
|
|
||||||
return @"yes";
|
return @"yes";
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return @"no";
|
return @"no";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@dynamic gainCorrection;
|
@dynamic gainCorrection;
|
||||||
- (NSString *)gainCorrection
|
- (NSString *)gainCorrection {
|
||||||
{
|
if(replayGainAlbumGain) {
|
||||||
if (replayGainAlbumGain)
|
if(replayGainAlbumPeak)
|
||||||
{
|
|
||||||
if (replayGainAlbumPeak)
|
|
||||||
return @"Album Gain plus Peak";
|
return @"Album Gain plus Peak";
|
||||||
else
|
else
|
||||||
return @"Album Gain";
|
return @"Album Gain";
|
||||||
}
|
} else if(replayGainTrackGain) {
|
||||||
else if (replayGainTrackGain)
|
if(replayGainTrackPeak)
|
||||||
{
|
|
||||||
if (replayGainTrackPeak)
|
|
||||||
return @"Track Gain plus Peak";
|
return @"Track Gain plus Peak";
|
||||||
else
|
else
|
||||||
return @"Track Gain";
|
return @"Track Gain";
|
||||||
}
|
} else if(volume && volume != 1) {
|
||||||
else if (volume && volume != 1)
|
|
||||||
{
|
|
||||||
return @"Volume scale";
|
return @"Volume scale";
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return @"None";
|
return @"None";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@dynamic gainInfo;
|
@dynamic gainInfo;
|
||||||
- (NSString *)gainInfo
|
- (NSString *)gainInfo {
|
||||||
{
|
NSMutableArray *gainItems = [[NSMutableArray alloc] init];
|
||||||
NSMutableArray * gainItems = [[NSMutableArray alloc] init];
|
if(replayGainAlbumGain) {
|
||||||
if (replayGainAlbumGain)
|
|
||||||
{
|
|
||||||
[gainItems addObject:[NSString stringWithFormat:@"Album Gain: %+.2f dB", replayGainAlbumGain]];
|
[gainItems addObject:[NSString stringWithFormat:@"Album Gain: %+.2f dB", replayGainAlbumGain]];
|
||||||
}
|
}
|
||||||
if (replayGainAlbumPeak)
|
if(replayGainAlbumPeak) {
|
||||||
{
|
|
||||||
[gainItems addObject:[NSString stringWithFormat:@"Album Peak: %.6f", replayGainAlbumPeak]];
|
[gainItems addObject:[NSString stringWithFormat:@"Album Peak: %.6f", replayGainAlbumPeak]];
|
||||||
}
|
}
|
||||||
if (replayGainTrackGain)
|
if(replayGainTrackGain) {
|
||||||
{
|
|
||||||
[gainItems addObject:[NSString stringWithFormat:@"Track Gain: %+.2f dB", replayGainTrackGain]];
|
[gainItems addObject:[NSString stringWithFormat:@"Track Gain: %+.2f dB", replayGainTrackGain]];
|
||||||
}
|
}
|
||||||
if (replayGainTrackPeak)
|
if(replayGainTrackPeak) {
|
||||||
{
|
|
||||||
[gainItems addObject:[NSString stringWithFormat:@"Track Peak: %.6f", replayGainTrackPeak]];
|
[gainItems addObject:[NSString stringWithFormat:@"Track Peak: %.6f", replayGainTrackPeak]];
|
||||||
}
|
}
|
||||||
if (volume && volume != 1)
|
if(volume && volume != 1) {
|
||||||
{
|
|
||||||
[gainItems addObject:[NSString stringWithFormat:@"Volume Scale: %.2f%C", volume, (unichar)0x00D7]];
|
[gainItems addObject:[NSString stringWithFormat:@"Volume Scale: %.2f%C", volume, (unichar)0x00D7]];
|
||||||
}
|
}
|
||||||
return [gainItems componentsJoinedByString:@"\n"];
|
return [gainItems componentsJoinedByString:@"\n"];
|
||||||
}
|
}
|
||||||
|
|
||||||
@dynamic positionText;
|
@dynamic positionText;
|
||||||
- (NSString *)positionText
|
- (NSString *)positionText {
|
||||||
{
|
|
||||||
SecondsFormatter *secondsFormatter = [[SecondsFormatter alloc] init];
|
SecondsFormatter *secondsFormatter = [[SecondsFormatter alloc] init];
|
||||||
NSString *time = [secondsFormatter stringForObjectValue:[NSNumber numberWithFloat:currentPosition]];
|
NSString *time = [secondsFormatter stringForObjectValue:[NSNumber numberWithFloat:currentPosition]];
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
@dynamic lengthText;
|
@dynamic lengthText;
|
||||||
- (NSString *)lengthText
|
- (NSString *)lengthText {
|
||||||
{
|
|
||||||
SecondsFormatter *secondsFormatter = [[SecondsFormatter alloc] init];
|
SecondsFormatter *secondsFormatter = [[SecondsFormatter alloc] init];
|
||||||
NSString *time = [secondsFormatter stringForObjectValue:[self length]];
|
NSString *time = [secondsFormatter stringForObjectValue:[self length]];
|
||||||
return time;
|
return time;
|
||||||
|
@ -423,15 +366,13 @@
|
||||||
@synthesize albumArtInternal;
|
@synthesize albumArtInternal;
|
||||||
|
|
||||||
@dynamic albumArt;
|
@dynamic albumArt;
|
||||||
- (NSImage *)albumArt
|
- (NSImage *)albumArt {
|
||||||
{
|
if(!albumArtInternal) return nil;
|
||||||
if (!albumArtInternal) return nil;
|
|
||||||
|
|
||||||
NSString *imageCacheTag = [NSString stringWithFormat:@"%@-%@-%@-%@", album, artist, genre, year];
|
NSString *imageCacheTag = [NSString stringWithFormat:@"%@-%@-%@-%@", album, artist, genre, year];
|
||||||
NSImage *image = [NSImage imageNamed:imageCacheTag];
|
NSImage *image = [NSImage imageNamed:imageCacheTag];
|
||||||
|
|
||||||
if (image == nil)
|
if(image == nil) {
|
||||||
{
|
|
||||||
image = [[NSImage alloc] initWithData:albumArtInternal];
|
image = [[NSImage alloc] initWithData:albumArtInternal];
|
||||||
[image setName:imageCacheTag];
|
[image setName:imageCacheTag];
|
||||||
}
|
}
|
||||||
|
@ -439,52 +380,39 @@
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setAlbumArt:(id)data
|
- (void)setAlbumArt:(id)data {
|
||||||
{
|
if([data isKindOfClass:[NSData class]]) {
|
||||||
if ([data isKindOfClass:[NSData class]])
|
|
||||||
{
|
|
||||||
[self setAlbumArtInternal:data];
|
[self setAlbumArtInternal:data];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@dynamic length;
|
@dynamic length;
|
||||||
- (NSNumber *)length
|
- (NSNumber *)length {
|
||||||
{
|
return [NSNumber numberWithDouble:(self.metadataLoaded) ? ((double)self.totalFrames / self.sampleRate) : 0.0];
|
||||||
return [NSNumber numberWithDouble:(self.metadataLoaded)?((double)self.totalFrames / self.sampleRate):0.0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@dynamic path;
|
@dynamic path;
|
||||||
- (NSString *)path
|
- (NSString *)path {
|
||||||
{
|
if([self.URL isFileURL])
|
||||||
if ([self.URL isFileURL])
|
|
||||||
return [[self.URL path] stringByAbbreviatingWithTildeInPath];
|
return [[self.URL path] stringByAbbreviatingWithTildeInPath];
|
||||||
else
|
else
|
||||||
return [self.URL absoluteString];
|
return [self.URL absoluteString];
|
||||||
}
|
}
|
||||||
|
|
||||||
@dynamic filename;
|
@dynamic filename;
|
||||||
- (NSString *)filename
|
- (NSString *)filename {
|
||||||
{
|
|
||||||
return [[self.URL path] lastPathComponent];
|
return [[self.URL path] lastPathComponent];
|
||||||
}
|
}
|
||||||
|
|
||||||
@dynamic status;
|
@dynamic status;
|
||||||
- (NSString *)status
|
- (NSString *)status {
|
||||||
{
|
if(self.stopAfter) {
|
||||||
if (self.stopAfter)
|
|
||||||
{
|
|
||||||
return @"stopAfter";
|
return @"stopAfter";
|
||||||
}
|
} else if(self.current) {
|
||||||
else if (self.current)
|
|
||||||
{
|
|
||||||
return @"playing";
|
return @"playing";
|
||||||
}
|
} else if(self.queued) {
|
||||||
else if (self.queued)
|
|
||||||
{
|
|
||||||
return @"queued";
|
return @"queued";
|
||||||
}
|
} else if(self.error) {
|
||||||
else if (self.error)
|
|
||||||
{
|
|
||||||
return @"error";
|
return @"error";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,37 +420,25 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@dynamic statusMessage;
|
@dynamic statusMessage;
|
||||||
- (NSString *)statusMessage
|
- (NSString *)statusMessage {
|
||||||
{
|
if(self.stopAfter) {
|
||||||
if (self.stopAfter)
|
|
||||||
{
|
|
||||||
return @"Stopping once finished...";
|
return @"Stopping once finished...";
|
||||||
}
|
} else if(self.current) {
|
||||||
else if (self.current)
|
|
||||||
{
|
|
||||||
return @"Playing...";
|
return @"Playing...";
|
||||||
}
|
} else if(self.queued) {
|
||||||
else if (self.queued)
|
|
||||||
{
|
|
||||||
return [NSString stringWithFormat:@"Queued: %li", self.queuePosition + 1];
|
return [NSString stringWithFormat:@"Queued: %li", self.queuePosition + 1];
|
||||||
}
|
} else if(self.error) {
|
||||||
else if (self.error)
|
|
||||||
{
|
|
||||||
return errorMessage;
|
return errorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setMetadata:(NSDictionary *)metadata
|
- (void)setMetadata:(NSDictionary *)metadata {
|
||||||
{
|
if(metadata == nil) {
|
||||||
if (metadata == nil)
|
|
||||||
{
|
|
||||||
self.error = YES;
|
self.error = YES;
|
||||||
self.errorMessage = @"Unable to retrieve metadata.";
|
self.errorMessage = @"Unable to retrieve metadata.";
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
[self setValuesForKeysWithDictionary:metadata];
|
[self setValuesForKeysWithDictionary:metadata];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,7 +448,7 @@
|
||||||
- (id)copyWithZone:(NSZone *)zone {
|
- (id)copyWithZone:(NSZone *)zone {
|
||||||
PlaylistEntry *pe = [[[self class] allocWithZone:zone] init];
|
PlaylistEntry *pe = [[[self class] allocWithZone:zone] init];
|
||||||
|
|
||||||
if (pe) {
|
if(pe) {
|
||||||
pe->index = index;
|
pe->index = index;
|
||||||
pe->shuffleIndex = shuffleIndex;
|
pe->shuffleIndex = shuffleIndex;
|
||||||
pe->dbIndex = dbIndex;
|
pe->dbIndex = dbIndex;
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue