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,59 +9,56 @@
|
||||||
@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;
|
||||||
|
|
||||||
IBOutlet PlaylistController *playlistController;
|
IBOutlet PlaylistController *playlistController;
|
||||||
IBOutlet PlaylistLoader *playlistLoader;
|
IBOutlet PlaylistLoader *playlistLoader;
|
||||||
|
|
||||||
IBOutlet NSWindow *mainWindow;
|
IBOutlet NSWindow *mainWindow;
|
||||||
IBOutlet NSWindow *miniWindow;
|
IBOutlet NSWindow *miniWindow;
|
||||||
IBOutlet NSSplitView *mainView;
|
IBOutlet NSSplitView *mainView;
|
||||||
|
|
||||||
IBOutlet NSSegmentedControl *playbackButtons;
|
IBOutlet NSSegmentedControl *playbackButtons;
|
||||||
IBOutlet NSButton *fileButton;
|
IBOutlet NSButton *fileButton;
|
||||||
IBOutlet NSButton *shuffleButton;
|
IBOutlet NSButton *shuffleButton;
|
||||||
IBOutlet NSButton *repeatButton;
|
IBOutlet NSButton *repeatButton;
|
||||||
IBOutlet NSButton *randomizeButton;
|
IBOutlet NSButton *randomizeButton;
|
||||||
|
|
||||||
IBOutlet NSTextField *totalTimeField;
|
IBOutlet NSTextField *totalTimeField;
|
||||||
|
|
||||||
IBOutlet PlaylistView *playlistView;
|
IBOutlet PlaylistView *playlistView;
|
||||||
|
|
||||||
IBOutlet NSMenuItem *showIndexColumn;
|
IBOutlet NSMenuItem *showIndexColumn;
|
||||||
IBOutlet NSMenuItem *showTitleColumn;
|
IBOutlet NSMenuItem *showTitleColumn;
|
||||||
IBOutlet NSMenuItem *showAlbumArtistColumn;
|
IBOutlet NSMenuItem *showAlbumArtistColumn;
|
||||||
IBOutlet NSMenuItem *showArtistColumn;
|
IBOutlet NSMenuItem *showArtistColumn;
|
||||||
IBOutlet NSMenuItem *showAlbumColumn;
|
IBOutlet NSMenuItem *showAlbumColumn;
|
||||||
IBOutlet NSMenuItem *showGenreColumn;
|
IBOutlet NSMenuItem *showGenreColumn;
|
||||||
IBOutlet NSMenuItem *showLengthColumn;
|
IBOutlet NSMenuItem *showLengthColumn;
|
||||||
IBOutlet NSMenuItem *showTrackColumn;
|
IBOutlet NSMenuItem *showTrackColumn;
|
||||||
IBOutlet NSMenuItem *showYearColumn;
|
IBOutlet NSMenuItem *showYearColumn;
|
||||||
|
|
||||||
IBOutlet NSMenu *dockMenu;
|
|
||||||
IBOutlet NSMenuItem *currentArtistItem;
|
|
||||||
|
|
||||||
IBOutlet NSWindowController *spotlightWindowController;
|
|
||||||
|
|
||||||
IBOutlet FileTreeViewController *fileTreeViewController;
|
|
||||||
|
|
||||||
IBOutlet SUUpdater *updater;
|
|
||||||
|
|
||||||
NSOperationQueue *queue; // Since we are the app delegate, we take care of the op queue
|
IBOutlet NSMenu *dockMenu;
|
||||||
|
IBOutlet NSMenuItem *currentArtistItem;
|
||||||
NSMutableSet* expandedNodes;
|
|
||||||
|
IBOutlet NSWindowController *spotlightWindowController;
|
||||||
BOOL miniMode;
|
|
||||||
|
IBOutlet FileTreeViewController *fileTreeViewController;
|
||||||
|
|
||||||
|
IBOutlet SUUpdater *updater;
|
||||||
|
|
||||||
|
NSOperationQueue *queue; // Since we are the app delegate, we take care of the op queue
|
||||||
|
|
||||||
|
NSMutableSet *expandedNodes;
|
||||||
|
|
||||||
|
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
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -12,15 +12,15 @@
|
||||||
|
|
||||||
@interface DockIconController : NSObject {
|
@interface DockIconController : NSObject {
|
||||||
NSImage *dockImage;
|
NSImage *dockImage;
|
||||||
|
|
||||||
IBOutlet PlaybackController *playbackController;
|
IBOutlet PlaybackController *playbackController;
|
||||||
|
|
||||||
NSInteger lastPlaybackStatus;
|
NSInteger lastPlaybackStatus;
|
||||||
NSInteger lastColorfulStatus;
|
NSInteger lastColorfulStatus;
|
||||||
NSNumber *lastProgressStatus;
|
NSNumber *lastProgressStatus;
|
||||||
|
|
||||||
NSImageView *imageView;
|
NSImageView *imageView;
|
||||||
NSProgressIndicator *progressIndicator;
|
NSProgressIndicator *progressIndicator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -7,197 +7,172 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#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"];
|
||||||
{
|
} else {
|
||||||
return [baseName stringByAppendingString:@"Colorful"];
|
return baseName;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return baseName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)refreshDockIcon:(NSInteger)playbackStatus withProgress:(double)progressStatus
|
|
||||||
{
|
|
||||||
BOOL displayChanged = NO;
|
|
||||||
BOOL drawIcon = NO;
|
|
||||||
BOOL removeProgress = NO;
|
|
||||||
|
|
||||||
if ( playbackStatus < 0 )
|
|
||||||
playbackStatus = lastPlaybackStatus;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lastPlaybackStatus = playbackStatus;
|
|
||||||
drawIcon = YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( progressStatus < -2 )
|
|
||||||
progressStatus = [lastProgressStatus doubleValue];
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (progressStatus < 0 && [lastProgressStatus doubleValue] >= 0)
|
|
||||||
removeProgress = YES;
|
|
||||||
lastProgressStatus = [NSNumber numberWithDouble:progressStatus];
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL displayProgress = (progressStatus >= 0.0);
|
|
||||||
|
|
||||||
NSImage *badgeImage = nil;
|
|
||||||
|
|
||||||
BOOL colorfulIcons = [[NSUserDefaults standardUserDefaults] boolForKey:@"colorfulDockIcons"];
|
|
||||||
|
|
||||||
if ((colorfulIcons && lastColorfulStatus < 1) ||
|
|
||||||
(!colorfulIcons && lastColorfulStatus != 0))
|
|
||||||
{
|
|
||||||
lastColorfulStatus = colorfulIcons ? 1 : 0;
|
|
||||||
drawIcon = YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSDockTile *dockTile = [NSApp dockTile];
|
|
||||||
|
|
||||||
if (drawIcon)
|
|
||||||
{
|
|
||||||
switch (playbackStatus) {
|
|
||||||
case CogStatusPlaying:
|
|
||||||
badgeImage = [NSImage imageNamed:getBadgeName(@"playDockBadge", colorfulIcons)];
|
|
||||||
break;
|
|
||||||
case CogStatusPaused:
|
|
||||||
badgeImage = [NSImage imageNamed:getBadgeName(@"pauseDockBadge", colorfulIcons)];
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
badgeImage = [NSImage imageNamed:getBadgeName(@"stopDockBadge", colorfulIcons)];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSSize badgeSize = [badgeImage size];
|
|
||||||
|
|
||||||
NSImage *newDockImage = [dockImage copy];
|
|
||||||
[newDockImage lockFocus];
|
|
||||||
|
|
||||||
[badgeImage drawInRect:NSMakeRect(0, 0, 128, 128)
|
|
||||||
fromRect:NSMakeRect(0, 0, badgeSize.width, badgeSize.height)
|
|
||||||
operation:NSCompositingOperationSourceOver fraction:1.0];
|
|
||||||
|
|
||||||
[newDockImage unlockFocus];
|
|
||||||
|
|
||||||
imageView = [[NSImageView alloc] init];
|
|
||||||
[imageView setImage:newDockImage];
|
|
||||||
[dockTile setContentView:imageView];
|
|
||||||
|
|
||||||
progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0.0, 0.0, dockTile.size.width, 10.0)];
|
|
||||||
[progressIndicator setStyle:NSProgressIndicatorBarStyle];
|
|
||||||
[progressIndicator setIndeterminate:NO];
|
|
||||||
[progressIndicator setBezeled:YES];
|
|
||||||
[progressIndicator setMinValue:0];
|
|
||||||
[progressIndicator setMaxValue:100];
|
|
||||||
[progressIndicator setHidden:YES];
|
|
||||||
|
|
||||||
[imageView addSubview:progressIndicator];
|
|
||||||
|
|
||||||
displayChanged = YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (displayProgress)
|
|
||||||
{
|
|
||||||
if (!imageView)
|
|
||||||
{
|
|
||||||
imageView = [[NSImageView alloc] init];
|
|
||||||
[imageView setImage:[NSApp applicationIconImage]];
|
|
||||||
[dockTile setContentView:imageView];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!progressIndicator)
|
|
||||||
{
|
|
||||||
progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0.0, 0.0, dockTile.size.width, 10.0)];
|
|
||||||
[progressIndicator setIndeterminate:NO];
|
|
||||||
[progressIndicator setBezeled:YES];
|
|
||||||
[progressIndicator setMinValue:0];
|
|
||||||
[progressIndicator setMaxValue:100];
|
|
||||||
|
|
||||||
[imageView addSubview:progressIndicator];
|
|
||||||
}
|
|
||||||
|
|
||||||
[progressIndicator setDoubleValue:progressStatus];
|
|
||||||
[progressIndicator setHidden:NO];
|
|
||||||
|
|
||||||
displayChanged = YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (removeProgress)
|
|
||||||
{
|
|
||||||
if (progressIndicator)
|
|
||||||
[progressIndicator setHidden:YES];
|
|
||||||
|
|
||||||
displayChanged = YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (displayChanged)
|
|
||||||
[dockTile display];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
|
||||||
{
|
|
||||||
if ([DockIconPlaybackStatusObservationContext isEqual:(__bridge id)(context)])
|
|
||||||
{
|
|
||||||
if ([keyPath isEqualToString:@"playbackStatus"])
|
|
||||||
{
|
|
||||||
NSInteger playbackStatus = [[change objectForKey:NSKeyValueChangeNewKey] integerValue];
|
|
||||||
|
|
||||||
[self refreshDockIcon:playbackStatus withProgress:-10];
|
|
||||||
}
|
|
||||||
else if ([keyPath isEqualToString:@"progressBarStatus"])
|
|
||||||
{
|
|
||||||
double progressStatus = [[change objectForKey:NSKeyValueChangeNewKey] doubleValue];
|
|
||||||
|
|
||||||
[self refreshDockIcon:-1 withProgress:progressStatus];
|
|
||||||
}
|
|
||||||
else if ([keyPath isEqualToString:@"values.colorfulDockIcons"])
|
|
||||||
{
|
|
||||||
[self refreshDockIcon:-1 withProgress:-10];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
|
||||||
|
- (void)refreshDockIcon:(NSInteger)playbackStatus withProgress:(double)progressStatus {
|
||||||
|
BOOL displayChanged = NO;
|
||||||
|
BOOL drawIcon = NO;
|
||||||
|
BOOL removeProgress = NO;
|
||||||
|
|
||||||
|
if(playbackStatus < 0)
|
||||||
|
playbackStatus = lastPlaybackStatus;
|
||||||
|
else {
|
||||||
|
lastPlaybackStatus = playbackStatus;
|
||||||
|
drawIcon = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(progressStatus < -2)
|
||||||
|
progressStatus = [lastProgressStatus doubleValue];
|
||||||
|
else {
|
||||||
|
if(progressStatus < 0 && [lastProgressStatus doubleValue] >= 0)
|
||||||
|
removeProgress = YES;
|
||||||
|
lastProgressStatus = [NSNumber numberWithDouble:progressStatus];
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL displayProgress = (progressStatus >= 0.0);
|
||||||
|
|
||||||
|
NSImage *badgeImage = nil;
|
||||||
|
|
||||||
|
BOOL colorfulIcons = [[NSUserDefaults standardUserDefaults] boolForKey:@"colorfulDockIcons"];
|
||||||
|
|
||||||
|
if((colorfulIcons && lastColorfulStatus < 1) ||
|
||||||
|
(!colorfulIcons && lastColorfulStatus != 0)) {
|
||||||
|
lastColorfulStatus = colorfulIcons ? 1 : 0;
|
||||||
|
drawIcon = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSDockTile *dockTile = [NSApp dockTile];
|
||||||
|
|
||||||
|
if(drawIcon) {
|
||||||
|
switch(playbackStatus) {
|
||||||
|
case CogStatusPlaying:
|
||||||
|
badgeImage = [NSImage imageNamed:getBadgeName(@"playDockBadge", colorfulIcons)];
|
||||||
|
break;
|
||||||
|
case CogStatusPaused:
|
||||||
|
badgeImage = [NSImage imageNamed:getBadgeName(@"pauseDockBadge", colorfulIcons)];
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
badgeImage = [NSImage imageNamed:getBadgeName(@"stopDockBadge", colorfulIcons)];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSSize badgeSize = [badgeImage size];
|
||||||
|
|
||||||
|
NSImage *newDockImage = [dockImage copy];
|
||||||
|
[newDockImage lockFocus];
|
||||||
|
|
||||||
|
[badgeImage drawInRect:NSMakeRect(0, 0, 128, 128)
|
||||||
|
fromRect:NSMakeRect(0, 0, badgeSize.width, badgeSize.height)
|
||||||
|
operation:NSCompositingOperationSourceOver
|
||||||
|
fraction:1.0];
|
||||||
|
|
||||||
|
[newDockImage unlockFocus];
|
||||||
|
|
||||||
|
imageView = [[NSImageView alloc] init];
|
||||||
|
[imageView setImage:newDockImage];
|
||||||
|
[dockTile setContentView:imageView];
|
||||||
|
|
||||||
|
progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0.0, 0.0, dockTile.size.width, 10.0)];
|
||||||
|
[progressIndicator setStyle:NSProgressIndicatorBarStyle];
|
||||||
|
[progressIndicator setIndeterminate:NO];
|
||||||
|
[progressIndicator setBezeled:YES];
|
||||||
|
[progressIndicator setMinValue:0];
|
||||||
|
[progressIndicator setMaxValue:100];
|
||||||
|
[progressIndicator setHidden:YES];
|
||||||
|
|
||||||
|
[imageView addSubview:progressIndicator];
|
||||||
|
|
||||||
|
displayChanged = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(displayProgress) {
|
||||||
|
if(!imageView) {
|
||||||
|
imageView = [[NSImageView alloc] init];
|
||||||
|
[imageView setImage:[NSApp applicationIconImage]];
|
||||||
|
[dockTile setContentView:imageView];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!progressIndicator) {
|
||||||
|
progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0.0, 0.0, dockTile.size.width, 10.0)];
|
||||||
|
[progressIndicator setIndeterminate:NO];
|
||||||
|
[progressIndicator setBezeled:YES];
|
||||||
|
[progressIndicator setMinValue:0];
|
||||||
|
[progressIndicator setMaxValue:100];
|
||||||
|
|
||||||
|
[imageView addSubview:progressIndicator];
|
||||||
|
}
|
||||||
|
|
||||||
|
[progressIndicator setDoubleValue:progressStatus];
|
||||||
|
[progressIndicator setHidden:NO];
|
||||||
|
|
||||||
|
displayChanged = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(removeProgress) {
|
||||||
|
if(progressIndicator)
|
||||||
|
[progressIndicator setHidden:YES];
|
||||||
|
|
||||||
|
displayChanged = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(displayChanged)
|
||||||
|
[dockTile display];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
|
||||||
|
if([DockIconPlaybackStatusObservationContext isEqual:(__bridge id)(context)]) {
|
||||||
|
if([keyPath isEqualToString:@"playbackStatus"]) {
|
||||||
|
NSInteger playbackStatus = [[change objectForKey:NSKeyValueChangeNewKey] integerValue];
|
||||||
|
|
||||||
|
[self refreshDockIcon:playbackStatus withProgress:-10];
|
||||||
|
} else if([keyPath isEqualToString:@"progressBarStatus"]) {
|
||||||
|
double progressStatus = [[change objectForKey:NSKeyValueChangeNewKey] doubleValue];
|
||||||
|
|
||||||
|
[self refreshDockIcon:-1 withProgress:progressStatus];
|
||||||
|
} else if([keyPath isEqualToString:@"values.colorfulDockIcons"]) {
|
||||||
|
[self refreshDockIcon:-1 withProgress:-10];
|
||||||
|
}
|
||||||
|
} 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];
|
||||||
imageView = nil;
|
imageView = nil;
|
||||||
progressIndicator = nil;
|
progressIndicator = nil;
|
||||||
[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,68 +10,67 @@
|
||||||
#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 {
|
||||||
AppController *_appController;
|
AppController *_appController;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)finishLaunching {
|
- (void)finishLaunching {
|
||||||
[super finishLaunching];
|
[super finishLaunching];
|
||||||
_appController = (AppController *)[self delegate];
|
_appController = (AppController *)[self delegate];
|
||||||
|
|
||||||
MPRemoteCommandCenter *remoteCommandCenter = [MPRemoteCommandCenter sharedCommandCenter];
|
MPRemoteCommandCenter *remoteCommandCenter = [MPRemoteCommandCenter sharedCommandCenter];
|
||||||
|
|
||||||
[remoteCommandCenter.playCommand setEnabled:YES];
|
[remoteCommandCenter.playCommand setEnabled:YES];
|
||||||
[remoteCommandCenter.pauseCommand setEnabled:YES];
|
[remoteCommandCenter.pauseCommand setEnabled:YES];
|
||||||
[remoteCommandCenter.togglePlayPauseCommand setEnabled:YES];
|
[remoteCommandCenter.togglePlayPauseCommand setEnabled:YES];
|
||||||
[remoteCommandCenter.stopCommand setEnabled:YES];
|
[remoteCommandCenter.stopCommand setEnabled:YES];
|
||||||
[remoteCommandCenter.changePlaybackPositionCommand setEnabled:YES];
|
[remoteCommandCenter.changePlaybackPositionCommand setEnabled:YES];
|
||||||
[remoteCommandCenter.nextTrackCommand setEnabled:YES];
|
[remoteCommandCenter.nextTrackCommand setEnabled:YES];
|
||||||
[remoteCommandCenter.previousTrackCommand setEnabled:YES];
|
[remoteCommandCenter.previousTrackCommand setEnabled:YES];
|
||||||
|
|
||||||
[[remoteCommandCenter playCommand] addTarget:self action:@selector(clickPlay)];
|
[[remoteCommandCenter playCommand] addTarget:self action:@selector(clickPlay)];
|
||||||
[[remoteCommandCenter pauseCommand] addTarget:self action:@selector(clickPause)];
|
[[remoteCommandCenter pauseCommand] addTarget:self action:@selector(clickPause)];
|
||||||
[[remoteCommandCenter togglePlayPauseCommand] addTarget:self action:@selector(clickPlay)];
|
[[remoteCommandCenter togglePlayPauseCommand] addTarget:self action:@selector(clickPlay)];
|
||||||
[[remoteCommandCenter stopCommand] addTarget:self action:@selector(clickStop)];
|
[[remoteCommandCenter stopCommand] addTarget:self action:@selector(clickStop)];
|
||||||
[[remoteCommandCenter changePlaybackPositionCommand] addTarget:self action:@selector(clickSeek:)];
|
[[remoteCommandCenter changePlaybackPositionCommand] addTarget:self action:@selector(clickSeek:)];
|
||||||
[[remoteCommandCenter nextTrackCommand] addTarget:self action:@selector(clickNext)];
|
[[remoteCommandCenter nextTrackCommand] addTarget:self action:@selector(clickNext)];
|
||||||
[[remoteCommandCenter previousTrackCommand] addTarget:self action:@selector(clickPrev)];
|
[[remoteCommandCenter previousTrackCommand] addTarget:self action:@selector(clickPrev)];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (MPRemoteCommandHandlerStatus)clickPlay {
|
- (MPRemoteCommandHandlerStatus)clickPlay {
|
||||||
[_appController clickPlay];
|
[_appController clickPlay];
|
||||||
return MPRemoteCommandHandlerStatusSuccess;
|
return MPRemoteCommandHandlerStatusSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (MPRemoteCommandHandlerStatus)clickPause {
|
- (MPRemoteCommandHandlerStatus)clickPause {
|
||||||
[_appController clickPause];
|
[_appController clickPause];
|
||||||
return MPRemoteCommandHandlerStatusSuccess;
|
return MPRemoteCommandHandlerStatusSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (MPRemoteCommandHandlerStatus)clickStop {
|
- (MPRemoteCommandHandlerStatus)clickStop {
|
||||||
[_appController clickStop];
|
[_appController clickStop];
|
||||||
return MPRemoteCommandHandlerStatusSuccess;
|
return MPRemoteCommandHandlerStatusSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (MPRemoteCommandHandlerStatus)clickNext {
|
- (MPRemoteCommandHandlerStatus)clickNext {
|
||||||
[_appController clickNext];
|
[_appController clickNext];
|
||||||
return MPRemoteCommandHandlerStatusSuccess;
|
return MPRemoteCommandHandlerStatusSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (MPRemoteCommandHandlerStatus)clickPrev {
|
- (MPRemoteCommandHandlerStatus)clickPrev {
|
||||||
[_appController clickPrev];
|
[_appController clickPrev];
|
||||||
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,42 +23,41 @@ 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;
|
|
||||||
IBOutlet PlaylistView *playlistView;
|
IBOutlet PlaylistView *playlistView;
|
||||||
IBOutlet PlaylistLoader *playlistLoader;
|
IBOutlet PlaylistLoader *playlistLoader;
|
||||||
|
|
||||||
IBOutlet NSSlider *volumeSlider;
|
IBOutlet NSSlider *volumeSlider;
|
||||||
|
|
||||||
IBOutlet NSArrayController *outputDevices;
|
IBOutlet NSArrayController *outputDevices;
|
||||||
|
|
||||||
NSTimer *positionTimer;
|
NSTimer *positionTimer;
|
||||||
|
|
||||||
AudioPlayer *audioPlayer;
|
AudioPlayer *audioPlayer;
|
||||||
|
|
||||||
CogStatus playbackStatus;
|
CogStatus playbackStatus;
|
||||||
double position;
|
double position;
|
||||||
double lastPosition;
|
double lastPosition;
|
||||||
BOOL seekable;
|
BOOL seekable;
|
||||||
BOOL fading;
|
BOOL fading;
|
||||||
|
|
||||||
// progress bar display
|
// progress bar display
|
||||||
double progressBarStatus;
|
double progressBarStatus;
|
||||||
|
|
||||||
BOOL _eqWasOpen;
|
BOOL _eqWasOpen;
|
||||||
BOOL _eqStubbed;
|
BOOL _eqStubbed;
|
||||||
AudioUnit _eq;
|
AudioUnit _eq;
|
||||||
AUPluginUI *_equi;
|
AUPluginUI *_equi;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property CogStatus playbackStatus;
|
@property CogStatus playbackStatus;
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -15,11 +15,11 @@
|
||||||
@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;
|
||||||
IBOutlet NSWindow *miniWindow;
|
IBOutlet NSWindow *miniWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -20,372 +20,372 @@ 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;
|
||||||
|
|
||||||
NSOperationQueue *queue;
|
NSOperationQueue *queue;
|
||||||
|
|
||||||
PlaylistEntry *entry;
|
PlaylistEntry *entry;
|
||||||
|
|
||||||
Boolean didGainUN API_AVAILABLE(macosx(10.14));
|
Boolean didGainUN API_AVAILABLE(macosx(10.14));
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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"
|
||||||
options:UNNotificationActionOptionNone];
|
options:UNNotificationActionOptionNone];
|
||||||
|
|
||||||
UNNotificationCategory *playCategory = [UNNotificationCategory
|
UNNotificationCategory *playCategory = [UNNotificationCategory
|
||||||
categoryWithIdentifier:@"play"
|
categoryWithIdentifier:@"play"
|
||||||
actions:@[ skipAction ]
|
actions:@[skipAction]
|
||||||
intentIdentifiers:@[]
|
intentIdentifiers:@[]
|
||||||
options:UNNotificationCategoryOptionNone];
|
options:UNNotificationCategoryOptionNone];
|
||||||
|
|
||||||
[center setNotificationCategories:
|
[center setNotificationCategories:
|
||||||
[NSSet setWithObject:playCategory]];
|
[NSSet setWithObject:playCategory]];
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[center setDelegate:self];
|
[center setDelegate:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
queue = [[NSOperationQueue alloc] init];
|
queue = [[NSOperationQueue alloc] init];
|
||||||
[queue setMaxConcurrentOperationCount:1];
|
[queue setMaxConcurrentOperationCount:1];
|
||||||
|
|
||||||
scrobbler = [[AudioScrobbler alloc] init];
|
scrobbler = [[AudioScrobbler alloc] init];
|
||||||
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
|
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
|
||||||
|
|
||||||
entry = nil;
|
entry = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
||||||
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;
|
||||||
case TrackPaused:
|
case TrackPaused:
|
||||||
state = @"Paused";
|
state = @"Paused";
|
||||||
break;
|
break;
|
||||||
case TrackStopped:
|
case TrackStopped:
|
||||||
state = @"Stopped";
|
state = @"Stopped";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
[dict setObject:state forKey:TrackState];
|
[dict setObject:state forKey:TrackState];
|
||||||
|
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)performPlaybackDidBeginActions:(PlaylistEntry *)pe {
|
- (void)performPlaybackDidBeginActions:(PlaylistEntry *)pe {
|
||||||
if (NO == [pe error]) {
|
if(NO == [pe error]) {
|
||||||
entry = pe;
|
entry = pe;
|
||||||
|
|
||||||
[[NSDistributedNotificationCenter defaultCenter]
|
[[NSDistributedNotificationCenter defaultCenter]
|
||||||
postNotificationName:TrackNotification
|
postNotificationName:TrackNotification
|
||||||
object:nil
|
object:nil
|
||||||
userInfo:[self fillNotificationDictionary:pe status:TrackPlaying]
|
userInfo:[self fillNotificationDictionary:pe status:TrackPlaying]
|
||||||
deliverImmediately:YES];
|
deliverImmediately:YES];
|
||||||
|
|
||||||
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];
|
||||||
|
|
||||||
UNMutableNotificationContent *content =
|
UNMutableNotificationContent *content =
|
||||||
[[UNMutableNotificationContent alloc] init];
|
[[UNMutableNotificationContent alloc] init];
|
||||||
|
|
||||||
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 = @"";
|
||||||
}
|
}
|
||||||
|
|
||||||
NSString *body = [NSString stringWithFormat:@"%@\n%@", [pe title], subtitle];
|
NSString *body = [NSString stringWithFormat:@"%@\n%@", [pe title], subtitle];
|
||||||
content.body = body;
|
content.body = body;
|
||||||
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]) {
|
||||||
NSString *tmpFileName =
|
NSString *tmpFileName =
|
||||||
[[NSProcessInfo.processInfo globallyUniqueString]
|
[[NSProcessInfo.processInfo globallyUniqueString]
|
||||||
stringByAppendingString:@".jpg"];
|
stringByAppendingString:@".jpg"];
|
||||||
NSURL *fileURL =
|
NSURL *fileURL =
|
||||||
[tmpSubFolderURL URLByAppendingPathComponent:tmpFileName];
|
[tmpSubFolderURL URLByAppendingPathComponent:tmpFileName];
|
||||||
NSImage *image = [pe albumArt];
|
NSImage *image = [pe albumArt];
|
||||||
CGImageRef cgRef = [image CGImageForProposedRect:NULL
|
CGImageRef cgRef = [image CGImageForProposedRect:NULL
|
||||||
context:nil
|
context:nil
|
||||||
hints:nil];
|
hints:nil];
|
||||||
|
|
||||||
if (cgRef) {
|
|
||||||
NSBitmapImageRep *newRep =
|
|
||||||
[[NSBitmapImageRep alloc] initWithCGImage:cgRef];
|
|
||||||
NSData *jpgData = [newRep
|
|
||||||
representationUsingType:NSBitmapImageFileTypeJPEG
|
|
||||||
properties:@{NSImageCompressionFactor : @0.5f}];
|
|
||||||
[jpgData writeToURL:fileURL atomically:YES];
|
|
||||||
|
|
||||||
UNNotificationAttachment *icon =
|
if(cgRef) {
|
||||||
[UNNotificationAttachment attachmentWithIdentifier:@"art"
|
NSBitmapImageRep *newRep =
|
||||||
URL:fileURL
|
[[NSBitmapImageRep alloc] initWithCGImage:cgRef];
|
||||||
options:nil
|
NSData *jpgData = [newRep
|
||||||
error:&error];
|
representationUsingType:NSBitmapImageFileTypeJPEG
|
||||||
if (error) {
|
properties:@{ NSImageCompressionFactor: @0.5f }];
|
||||||
// We have size limit of 10MB per image attachment.
|
[jpgData writeToURL:fileURL atomically:YES];
|
||||||
NSLog(@"%@", error.localizedDescription);
|
|
||||||
} else {
|
|
||||||
content.attachments = @[ icon ];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UNNotificationRequest *request =
|
UNNotificationAttachment *icon =
|
||||||
[UNNotificationRequest requestWithIdentifier:@"PlayTrack"
|
[UNNotificationAttachment attachmentWithIdentifier:@"art"
|
||||||
content:content
|
URL:fileURL
|
||||||
trigger:nil];
|
options:nil
|
||||||
|
error:&error];
|
||||||
|
if(error) {
|
||||||
|
// We have size limit of 10MB per image attachment.
|
||||||
|
NSLog(@"%@", error.localizedDescription);
|
||||||
|
} else {
|
||||||
|
content.attachments = @[icon];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[center addNotificationRequest:request
|
UNNotificationRequest *request =
|
||||||
withCompletionHandler:^(NSError *_Nullable error) {
|
[UNNotificationRequest requestWithIdentifier:@"PlayTrack"
|
||||||
NSLog(@"%@", error.localizedDescription);
|
content:content
|
||||||
}];
|
trigger:nil];
|
||||||
}
|
|
||||||
} else {
|
|
||||||
NSUserNotification *notif = [[NSUserNotification alloc] init];
|
|
||||||
notif.title = [pe title];
|
|
||||||
|
|
||||||
NSString *subtitle;
|
[center addNotificationRequest:request
|
||||||
if ([pe artist] && [pe album]) {
|
withCompletionHandler:^(NSError *_Nullable error) {
|
||||||
subtitle = [NSString stringWithFormat:@"%@ - %@", [pe artist], [pe album]];
|
NSLog(@"%@", error.localizedDescription);
|
||||||
} else if ([pe artist]) {
|
}];
|
||||||
subtitle = [pe artist];
|
}
|
||||||
} else if ([pe album]) {
|
} else {
|
||||||
subtitle = [pe album];
|
NSUserNotification *notif = [[NSUserNotification alloc] init];
|
||||||
} else {
|
notif.title = [pe title];
|
||||||
subtitle = @"";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ([defaults boolForKey:@"notifications.itunes-style"]) {
|
NSString *subtitle;
|
||||||
notif.subtitle = subtitle;
|
if([pe artist] && [pe album]) {
|
||||||
[notif setValue:@YES forKey:@"_showsButtons"];
|
subtitle = [NSString stringWithFormat:@"%@ - %@", [pe artist], [pe album]];
|
||||||
} else {
|
} else if([pe artist]) {
|
||||||
notif.informativeText = subtitle;
|
subtitle = [pe artist];
|
||||||
}
|
} else if([pe album]) {
|
||||||
|
subtitle = [pe album];
|
||||||
|
} else {
|
||||||
|
subtitle = @"";
|
||||||
|
}
|
||||||
|
|
||||||
if ([notif respondsToSelector:@selector(setContentImage:)]) {
|
if([defaults boolForKey:@"notifications.itunes-style"]) {
|
||||||
if ([defaults boolForKey:@"notifications.show-album-art"] &&
|
notif.subtitle = subtitle;
|
||||||
[pe albumArtInternal]) {
|
[notif setValue:@YES forKey:@"_showsButtons"];
|
||||||
NSImage *image = [pe albumArt];
|
} else {
|
||||||
|
notif.informativeText = subtitle;
|
||||||
|
}
|
||||||
|
|
||||||
if ([defaults boolForKey:@"notifications.itunes-style"]) {
|
if([notif respondsToSelector:@selector(setContentImage:)]) {
|
||||||
[notif setValue:image forKey:@"_identityImage"];
|
if([defaults boolForKey:@"notifications.show-album-art"] &&
|
||||||
} else {
|
[pe albumArtInternal]) {
|
||||||
notif.contentImage = image;
|
NSImage *image = [pe albumArt];
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
notif.actionButtonTitle = @"Skip";
|
if([defaults boolForKey:@"notifications.itunes-style"]) {
|
||||||
|
[notif setValue:image forKey:@"_identityImage"];
|
||||||
|
} else {
|
||||||
|
notif.contentImage = image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[[NSUserNotificationCenter defaultUserNotificationCenter]
|
notif.actionButtonTitle = @"Skip";
|
||||||
scheduleNotification:notif];
|
|
||||||
}
|
[[NSUserNotificationCenter defaultUserNotificationCenter]
|
||||||
}
|
scheduleNotification:notif];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)performPlaybackDidPauseActions {
|
- (void)performPlaybackDidPauseActions {
|
||||||
[[NSDistributedNotificationCenter defaultCenter]
|
[[NSDistributedNotificationCenter defaultCenter]
|
||||||
postNotificationName:TrackNotification
|
postNotificationName:TrackNotification
|
||||||
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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)performPlaybackDidResumeActions {
|
- (void)performPlaybackDidResumeActions {
|
||||||
[[NSDistributedNotificationCenter defaultCenter]
|
[[NSDistributedNotificationCenter defaultCenter]
|
||||||
postNotificationName:TrackNotification
|
postNotificationName:TrackNotification
|
||||||
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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)performPlaybackDidStopActions {
|
- (void)performPlaybackDidStopActions {
|
||||||
[[NSDistributedNotificationCenter defaultCenter]
|
[[NSDistributedNotificationCenter defaultCenter]
|
||||||
postNotificationName:TrackNotification
|
postNotificationName:TrackNotification
|
||||||
object:nil
|
object:nil
|
||||||
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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)awakeFromNib {
|
- (void)awakeFromNib {
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(playbackDidBegin:)
|
selector:@selector(playbackDidBegin:)
|
||||||
name:CogPlaybackDidBeginNotficiation
|
name:CogPlaybackDidBeginNotficiation
|
||||||
object:nil];
|
object:nil];
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(playbackDidPause:)
|
selector:@selector(playbackDidPause:)
|
||||||
name:CogPlaybackDidPauseNotficiation
|
name:CogPlaybackDidPauseNotficiation
|
||||||
object:nil];
|
object:nil];
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(playbackDidResume:)
|
selector:@selector(playbackDidResume:)
|
||||||
name:CogPlaybackDidResumeNotficiation
|
name:CogPlaybackDidResumeNotficiation
|
||||||
object:nil];
|
object:nil];
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(playbackDidStop:)
|
selector:@selector(playbackDidStop:)
|
||||||
name:CogPlaybackDidStopNotficiation
|
name:CogPlaybackDidStopNotficiation
|
||||||
object:nil];
|
object:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)playbackDidBegin:(NSNotification *)notification {
|
- (void)playbackDidBegin:(NSNotification *)notification {
|
||||||
NSOperation *op = [NSBlockOperation blockOperationWithBlock:^{
|
NSOperation *op = [NSBlockOperation blockOperationWithBlock:^{
|
||||||
[self performPlaybackDidBeginActions:(PlaylistEntry *)[notification object]];
|
[self performPlaybackDidBeginActions:(PlaylistEntry *)[notification object]];
|
||||||
}];
|
}];
|
||||||
[queue addOperation:op];
|
[queue addOperation:op];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)playbackDidPause:(NSNotification *)notification {
|
- (void)playbackDidPause:(NSNotification *)notification {
|
||||||
NSOperation *op = [NSBlockOperation blockOperationWithBlock:^{
|
NSOperation *op = [NSBlockOperation blockOperationWithBlock:^{
|
||||||
[self performPlaybackDidPauseActions];
|
[self performPlaybackDidPauseActions];
|
||||||
}];
|
}];
|
||||||
[queue addOperation:op];
|
[queue addOperation:op];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)playbackDidResume:(NSNotification *)notification {
|
- (void)playbackDidResume:(NSNotification *)notification {
|
||||||
NSOperation *op = [NSBlockOperation blockOperationWithBlock:^{
|
NSOperation *op = [NSBlockOperation blockOperationWithBlock:^{
|
||||||
[self performPlaybackDidResumeActions];
|
[self performPlaybackDidResumeActions];
|
||||||
}];
|
}];
|
||||||
[queue addOperation:op];
|
[queue addOperation:op];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)playbackDidStop:(NSNotification *)notification {
|
- (void)playbackDidStop:(NSNotification *)notification {
|
||||||
NSOperation *op = [NSBlockOperation blockOperationWithBlock:^{
|
NSOperation *op = [NSBlockOperation blockOperationWithBlock:^{
|
||||||
[self performPlaybackDidStopActions];
|
[self performPlaybackDidStopActions];
|
||||||
}];
|
}];
|
||||||
[queue addOperation:op];
|
[queue addOperation:op];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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];
|
||||||
}; break;
|
}; break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -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,11 +12,10 @@
|
||||||
|
|
||||||
@implementation AudioContainer
|
@implementation AudioContainer
|
||||||
|
|
||||||
+ (NSArray *) urlsForContainerURL:(NSURL *)url
|
+ (NSArray *)urlsForContainerURL:(NSURL *)url {
|
||||||
{
|
@autoreleasepool {
|
||||||
@autoreleasepool {
|
return [[PluginController sharedPluginController] urlsForContainerURL:url];
|
||||||
return [[PluginController sharedPluginController] urlsForContainerURL:url];
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -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,14 +12,12 @@
|
||||||
|
|
||||||
@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];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -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,18 +11,16 @@
|
||||||
|
|
||||||
@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];
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -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,34 +21,33 @@
|
||||||
@class BufferChain;
|
@class BufferChain;
|
||||||
@class OutputNode;
|
@class OutputNode;
|
||||||
|
|
||||||
@interface AudioPlayer : NSObject
|
@interface AudioPlayer : NSObject {
|
||||||
{
|
|
||||||
BufferChain *bufferChain;
|
BufferChain *bufferChain;
|
||||||
OutputNode *output;
|
OutputNode *output;
|
||||||
|
|
||||||
double volume;
|
double volume;
|
||||||
|
|
||||||
NSMutableArray *chainQueue;
|
NSMutableArray *chainQueue;
|
||||||
|
|
||||||
NSURL *nextStream;
|
NSURL *nextStream;
|
||||||
id nextStreamUserInfo;
|
id nextStreamUserInfo;
|
||||||
NSDictionary *nextStreamRGInfo;
|
NSDictionary *nextStreamRGInfo;
|
||||||
|
|
||||||
id delegate;
|
id delegate;
|
||||||
|
|
||||||
BOOL outputLaunched;
|
BOOL outputLaunched;
|
||||||
BOOL endOfInputReached;
|
BOOL endOfInputReached;
|
||||||
BOOL startedPaused;
|
BOOL startedPaused;
|
||||||
BOOL initialBufferFilled;
|
BOOL initialBufferFilled;
|
||||||
|
|
||||||
Semaphore *semaphore;
|
Semaphore *semaphore;
|
||||||
|
|
||||||
atomic_bool resettingNow;
|
atomic_bool resettingNow;
|
||||||
atomic_int refCount;
|
atomic_int refCount;
|
||||||
|
|
||||||
int currentPlaybackStatus;
|
int currentPlaybackStatus;
|
||||||
|
|
||||||
BOOL shouldContinue;
|
BOOL shouldContinue;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)init;
|
- (id)init;
|
||||||
|
@ -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,39 +8,35 @@
|
||||||
|
|
||||||
#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;
|
||||||
endOfInputReached = NO;
|
endOfInputReached = NO;
|
||||||
|
|
||||||
chainQueue = [[NSMutableArray alloc] init];
|
chainQueue = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
semaphore = [[Semaphore alloc] init];
|
semaphore = [[Semaphore alloc] init];
|
||||||
|
|
||||||
atomic_init(&resettingNow, false);
|
atomic_init(&resettingNow, false);
|
||||||
atomic_init(&refCount, 0);
|
atomic_init(&refCount, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setDelegate:(id)d
|
- (void)setDelegate:(id)d {
|
||||||
{
|
|
||||||
delegate = d;
|
delegate = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,597 +44,531 @@
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
userInfo = nextStreamUserInfo;
|
userInfo = nextStreamUserInfo;
|
||||||
rgi = nextStreamRGInfo;
|
rgi = nextStreamRGInfo;
|
||||||
|
|
||||||
[self notifyStreamChanged:userInfo];
|
[self notifyStreamChanged:userInfo];
|
||||||
|
|
||||||
bufferChain = [[BufferChain alloc] initWithController:self];
|
bufferChain = [[BufferChain alloc] initWithController:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
[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];
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[self setShouldContinue:YES];
|
[self setShouldContinue:YES];
|
||||||
|
|
||||||
outputLaunched = NO;
|
outputLaunched = NO;
|
||||||
startedPaused = paused;
|
startedPaused = paused;
|
||||||
initialBufferFilled = NO;
|
initialBufferFilled = NO;
|
||||||
|
|
||||||
[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;
|
||||||
{
|
if(initialBufferFilled)
|
||||||
startedPaused = NO;
|
[self launchOutputThread];
|
||||||
if (initialBufferFilled)
|
}
|
||||||
[self launchOutputThread];
|
|
||||||
}
|
|
||||||
|
|
||||||
[output resume];
|
[output resume];
|
||||||
|
|
||||||
[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
|
||||||
{
|
// that the user thinks they're seeking into
|
||||||
// This is a dirty hack in case the playback has finished with the track
|
CogStatus status = (CogStatus)currentPlaybackStatus;
|
||||||
// that the user thinks they're seeking into
|
NSURL *url;
|
||||||
CogStatus status = (CogStatus) currentPlaybackStatus;
|
id userInfo;
|
||||||
NSURL *url;
|
NSDictionary *rgi;
|
||||||
id userInfo;
|
|
||||||
NSDictionary *rgi;
|
@synchronized(chainQueue) {
|
||||||
|
url = [bufferChain streamURL];
|
||||||
@synchronized (chainQueue) {
|
userInfo = [bufferChain userInfo];
|
||||||
url = [bufferChain streamURL];
|
rgi = [bufferChain rgInfo];
|
||||||
userInfo = [bufferChain userInfo];
|
}
|
||||||
rgi = [bufferChain rgInfo];
|
|
||||||
}
|
[self stop];
|
||||||
|
|
||||||
[self stop];
|
[self play:url withUserInfo:userInfo withRGInfo:rgi startPaused:(status == CogStatusPaused) andSeekTo:time];
|
||||||
|
} else {
|
||||||
[self play:url withUserInfo:userInfo withRGInfo:rgi startPaused:(status == CogStatusPaused) andSeekTo:time];
|
// Still decoding the current file, safe to seek within it
|
||||||
}
|
[output seek:time];
|
||||||
else
|
[bufferChain seek:time];
|
||||||
{
|
}
|
||||||
// Still decoding the current file, safe to seek within it
|
|
||||||
[output 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;
|
||||||
|
|
||||||
nextStreamRGInfo = rgi;
|
nextStreamRGInfo = rgi;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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];
|
||||||
|
|
||||||
[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))
|
|
||||||
return YES;
|
|
||||||
|
|
||||||
atomic_fetch_add(&refCount, 1);
|
|
||||||
|
|
||||||
@synchronized (chainQueue) {
|
if(atomic_load_explicit(&resettingNow, memory_order_relaxed))
|
||||||
// No point in constructing new chain for the next playlist entry
|
return YES;
|
||||||
// if there's already one at the head of chainQueue... r-r-right?
|
|
||||||
for (BufferChain *chain in chainQueue)
|
|
||||||
{
|
|
||||||
if ([chain isRunning])
|
|
||||||
{
|
|
||||||
atomic_fetch_sub(&refCount, 1);
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We don't want to do this, it may happen with a lot of short files
|
atomic_fetch_add(&refCount, 1);
|
||||||
//if ([chainQueue count] >= 5)
|
|
||||||
//{
|
|
||||||
// return YES;
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
double duration = 0.0;
|
@synchronized(chainQueue) {
|
||||||
|
// No point in constructing new chain for the next playlist entry
|
||||||
|
// if there's already one at the head of chainQueue... r-r-right?
|
||||||
|
for(BufferChain *chain in chainQueue) {
|
||||||
|
if([chain isRunning]) {
|
||||||
|
atomic_fetch_sub(&refCount, 1);
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@synchronized (chainQueue) {
|
// We don't want to do this, it may happen with a lot of short files
|
||||||
for (BufferChain *chain in chainQueue) {
|
// if ([chainQueue count] >= 5)
|
||||||
duration += [chain secondsBuffered];
|
//{
|
||||||
}
|
// return YES;
|
||||||
}
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
while (duration >= 30.0 && shouldContinue)
|
double duration = 0.0;
|
||||||
{
|
|
||||||
[semaphore wait];
|
|
||||||
if (atomic_load_explicit(&resettingNow, memory_order_relaxed)) {
|
|
||||||
atomic_fetch_sub(&refCount, 1);
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
@synchronized (chainQueue) {
|
|
||||||
duration = 0.0;
|
|
||||||
for (BufferChain *chain in chainQueue) {
|
|
||||||
duration += [chain secondsBuffered];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nextStreamUserInfo = [sender userInfo];
|
|
||||||
|
|
||||||
nextStreamRGInfo = [sender rgInfo];
|
|
||||||
|
|
||||||
// This call can sometimes lead to invoking a chainQueue block on another thread
|
|
||||||
[self requestNextStream: nextStreamUserInfo];
|
|
||||||
|
|
||||||
if (!nextStream) {
|
|
||||||
atomic_fetch_sub(&refCount, 1);
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
@synchronized (chainQueue) {
|
@synchronized(chainQueue) {
|
||||||
|
for(BufferChain *chain in chainQueue) {
|
||||||
|
duration += [chain secondsBuffered];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while(duration >= 30.0 && shouldContinue) {
|
||||||
|
[semaphore wait];
|
||||||
|
if(atomic_load_explicit(&resettingNow, memory_order_relaxed)) {
|
||||||
|
atomic_fetch_sub(&refCount, 1);
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
@synchronized(chainQueue) {
|
||||||
|
duration = 0.0;
|
||||||
|
for(BufferChain *chain in chainQueue) {
|
||||||
|
duration += [chain secondsBuffered];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nextStreamUserInfo = [sender userInfo];
|
||||||
|
|
||||||
|
nextStreamRGInfo = [sender rgInfo];
|
||||||
|
|
||||||
|
// This call can sometimes lead to invoking a chainQueue block on another thread
|
||||||
|
[self requestNextStream:nextStreamUserInfo];
|
||||||
|
|
||||||
|
if(!nextStream) {
|
||||||
|
atomic_fetch_sub(&refCount, 1);
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
|
||||||
|
|
||||||
if ([nextStream isFileURL] && [[lastChain streamURL] isFileURL])
|
|
||||||
{
|
|
||||||
NSMutableString *unixPathNext = [[nextStream path] mutableCopy];
|
|
||||||
NSMutableString *unixPathPrev = [[[lastChain streamURL] path] mutableCopy];
|
|
||||||
|
|
||||||
if ([unixPathNext isEqualToString:unixPathPrev])
|
|
||||||
pathsEqual = YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pathsEqual || ([[nextStream scheme] isEqualToString:[[lastChain streamURL] scheme]]
|
BOOL pathsEqual = NO;
|
||||||
&& (([nextStream host] == nil &&
|
|
||||||
[[lastChain streamURL] host] == nil)
|
if([nextStream isFileURL] && [[lastChain streamURL] isFileURL]) {
|
||||||
|| [[nextStream host] isEqualToString:[[lastChain streamURL] host]])
|
NSMutableString *unixPathNext = [[nextStream path] mutableCopy];
|
||||||
&& [[nextStream path] isEqualToString:[[lastChain streamURL] path]]))
|
NSMutableString *unixPathPrev = [[[lastChain streamURL] path] mutableCopy];
|
||||||
{
|
|
||||||
if ([lastChain setTrack:nextStream]
|
if([unixPathNext isEqualToString:unixPathPrev])
|
||||||
&& [newChain openWithInput:[lastChain inputNode] withOutputFormat:[output format] withRGInfo:nextStreamRGInfo])
|
pathsEqual = YES;
|
||||||
{
|
}
|
||||||
|
|
||||||
|
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]])) {
|
||||||
|
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);
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
{
|
atomic_fetch_sub(&refCount, 1);
|
||||||
newChain = nil;
|
|
||||||
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];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self addChainToQueue:newChain];
|
|
||||||
|
|
||||||
newChain = nil;
|
|
||||||
|
|
||||||
// I'm stupid and can't hold too much stuff in my head all at once, so writing it here.
|
[self addChainToQueue:newChain];
|
||||||
//
|
|
||||||
// Once we get here:
|
newChain = nil;
|
||||||
// - buffer chain for previous stream finished reading
|
|
||||||
// - there are (probably) some bytes of the previous stream in the output buffer which haven't been played
|
// I'm stupid and can't hold too much stuff in my head all at once, so writing it here.
|
||||||
// (by output node) yet
|
//
|
||||||
// - self.bufferChain == previous playlist entry's buffer chain
|
// Once we get here:
|
||||||
// - self.nextStream == next playlist entry's URL
|
// - buffer chain for previous stream finished reading
|
||||||
// - self.nextStreamUserInfo == next playlist entry
|
// - there are (probably) some bytes of the previous stream in the output buffer which haven't been played
|
||||||
// - head of chainQueue is the buffer chain for the next entry (which has launched its threads already)
|
// (by output node) yet
|
||||||
|
// - self.bufferChain == previous playlist entry's buffer chain
|
||||||
|
// - self.nextStream == next playlist entry's URL
|
||||||
|
// - self.nextStreamUserInfo == next playlist entry
|
||||||
|
// - head of chainQueue is the buffer chain for the next entry (which has launched its threads already)
|
||||||
}
|
}
|
||||||
|
|
||||||
atomic_fetch_sub(&refCount, 1);
|
atomic_fetch_sub(&refCount, 1);
|
||||||
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
|
// - the buffer chain for the next entry is the first item in chainQueue
|
||||||
// - the buffer chain for the next entry is the first item in chainQueue
|
|
||||||
|
|
||||||
@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;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bufferChain = nil;
|
|
||||||
bufferChain = [chainQueue objectAtIndex:0];
|
|
||||||
|
|
||||||
[chainQueue removeObjectAtIndex:0];
|
bufferChain = nil;
|
||||||
|
bufferChain = [chainQueue objectAtIndex:0];
|
||||||
|
|
||||||
|
[chainQueue removeObjectAtIndex:0];
|
||||||
DLog(@"New!!! %@ %@", bufferChain, [[bufferChain inputNode] decoder]);
|
DLog(@"New!!! %@ %@", bufferChain, [[bufferChain inputNode] decoder]);
|
||||||
|
|
||||||
[semaphore signal];
|
[semaphore signal];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self notifyStreamChanged:[bufferChain userInfo]];
|
[self notifyStreamChanged:[bufferChain userInfo]];
|
||||||
[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]];
|
|
||||||
[invocation setTarget:delegate];
|
|
||||||
[invocation setSelector:selector];
|
|
||||||
[invocation setArgument:(void*)&self atIndex:2];
|
|
||||||
[invocation setArgument:&obj atIndex:3];
|
|
||||||
[invocation retainArguments];
|
|
||||||
|
|
||||||
[invocation performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone: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 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 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 {
|
||||||
|
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[delegate methodSignatureForSelector:selector]];
|
||||||
|
[invocation setTarget:delegate];
|
||||||
|
[invocation setSelector:selector];
|
||||||
|
[invocation setArgument:(void *)&self atIndex:2];
|
||||||
|
[invocation setArgument:&obj atIndex:3];
|
||||||
|
[invocation setArgument:&obj2 atIndex:4];
|
||||||
|
[invocation retainArguments];
|
||||||
|
|
||||||
|
[invocation performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:wait];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setPlaybackStatus:(int)status waitUntilDone:(BOOL)wait {
|
||||||
|
currentPlaybackStatus = status;
|
||||||
|
|
||||||
- (void)setPlaybackStatus:(int)status waitUntilDone:(BOOL)wait
|
|
||||||
{
|
|
||||||
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];
|
||||||
NSArray *decoderTypes = [[pluginController decodersByExtension] allKeys];
|
NSArray *decoderTypes = [[pluginController decodersByExtension] allKeys];
|
||||||
NSArray *metdataReaderTypes = [[pluginController metadataReaders] allKeys];
|
NSArray *metdataReaderTypes = [[pluginController metadataReaders] allKeys];
|
||||||
NSArray *propertiesReaderTypes = [[pluginController propertiesReadersByExtension] allKeys];
|
NSArray *propertiesReaderTypes = [[pluginController propertiesReadersByExtension] allKeys];
|
||||||
|
|
||||||
NSMutableSet *types = [NSMutableSet set];
|
NSMutableSet *types = [NSMutableSet set];
|
||||||
|
|
||||||
[types addObjectsFromArray:containerTypes];
|
[types addObjectsFromArray:containerTypes];
|
||||||
[types addObjectsFromArray:decoderTypes];
|
[types addObjectsFromArray:decoderTypes];
|
||||||
[types addObjectsFromArray:metdataReaderTypes];
|
[types addObjectsFromArray:metdataReaderTypes];
|
||||||
[types addObjectsFromArray:propertiesReaderTypes];
|
[types addObjectsFromArray:propertiesReaderTypes];
|
||||||
|
|
||||||
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];
|
||||||
|
|
||||||
// the playbackController needs to know the new volume, so it can update the
|
// the playbackController needs to know the new volume, so it can update the
|
||||||
// volumeSlider accordingly.
|
// volumeSlider accordingly.
|
||||||
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);
|
||||||
|
|
||||||
[self setVolume:newVolume];
|
[self setVolume:newVolume];
|
||||||
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);
|
}
|
||||||
}
|
atomic_store(&resettingNow, false);
|
||||||
atomic_store(&resettingNow, false);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@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,11 +13,10 @@
|
||||||
|
|
||||||
@implementation AudioPropertiesReader
|
@implementation AudioPropertiesReader
|
||||||
|
|
||||||
+ (NSDictionary *)propertiesForURL:(NSURL *)url
|
+ (NSDictionary *)propertiesForURL:(NSURL *)url {
|
||||||
{
|
@autoreleasepool {
|
||||||
@autoreleasepool {
|
return [[PluginController sharedPluginController] propertiesForURL:url];
|
||||||
return [[PluginController sharedPluginController] propertiesForURL:url];
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -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,32 +8,32 @@
|
||||||
#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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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,66 +9,66 @@
|
||||||
|
|
||||||
@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;
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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;
|
||||||
}
|
}
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -8,37 +8,37 @@
|
||||||
|
|
||||||
#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;
|
||||||
ConverterNode *converterNode;
|
ConverterNode *converterNode;
|
||||||
|
|
||||||
AudioStreamBasicDescription inputFormat;
|
AudioStreamBasicDescription inputFormat;
|
||||||
|
|
||||||
NSURL *streamURL;
|
NSURL *streamURL;
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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,271 +7,241 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#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;
|
||||||
rgInfo = nil;
|
rgInfo = nil;
|
||||||
|
|
||||||
inputNode = nil;
|
inputNode = nil;
|
||||||
converterNode = nil;
|
converterNode = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)buildChain
|
- (void)buildChain {
|
||||||
{
|
inputNode = nil;
|
||||||
inputNode = nil;
|
converterNode = nil;
|
||||||
converterNode = nil;
|
|
||||||
|
|
||||||
inputNode = [[InputNode alloc] initWithController:self previous:nil];
|
inputNode = [[InputNode alloc] initWithController:self previous:nil];
|
||||||
converterNode = [[ConverterNode alloc] initWithController:self previous:inputNode];
|
converterNode = [[ConverterNode alloc] initWithController:self previous:inputNode];
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
NSDictionary * properties = [inputNode properties];
|
|
||||||
|
|
||||||
inputFormat = [inputNode nodeFormat];
|
|
||||||
|
|
||||||
outputFormat.mChannelsPerFrame = inputFormat.mChannelsPerFrame;
|
|
||||||
outputFormat.mBytesPerFrame = ((outputFormat.mBitsPerChannel + 7) / 8) * outputFormat.mChannelsPerFrame;
|
|
||||||
outputFormat.mBytesPerPacket = outputFormat.mBytesPerFrame * outputFormat.mFramesPerPacket;
|
|
||||||
|
|
||||||
if (![converterNode setupWithInputFormat:inputFormat outputFormat:outputFormat isLossless:[[properties valueForKey:@"encoding"] isEqualToString:@"lossless"]])
|
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
[self setRGInfo:rgi];
|
NSDictionary *properties = [inputNode properties];
|
||||||
|
|
||||||
// return NO;
|
inputFormat = [inputNode nodeFormat];
|
||||||
|
|
||||||
|
outputFormat.mChannelsPerFrame = inputFormat.mChannelsPerFrame;
|
||||||
|
outputFormat.mBytesPerFrame = ((outputFormat.mBitsPerChannel + 7) / 8) * outputFormat.mChannelsPerFrame;
|
||||||
|
outputFormat.mBytesPerPacket = outputFormat.mBytesPerFrame * outputFormat.mFramesPerPacket;
|
||||||
|
|
||||||
|
if(![converterNode setupWithInputFormat:inputFormat outputFormat:outputFormat isLossless:[[properties valueForKey:@"encoding"] isEqualToString:@"lossless"]])
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
[self setRGInfo:rgi];
|
||||||
|
|
||||||
|
// 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;
|
|
||||||
|
|
||||||
NSDictionary * properties = [inputNode properties];
|
|
||||||
|
|
||||||
inputFormat = [inputNode nodeFormat];
|
|
||||||
|
|
||||||
outputFormat.mChannelsPerFrame = inputFormat.mChannelsPerFrame;
|
|
||||||
outputFormat.mBytesPerFrame = ((outputFormat.mBitsPerChannel + 7) / 8) * outputFormat.mChannelsPerFrame;
|
|
||||||
outputFormat.mBytesPerPacket = outputFormat.mBytesPerFrame * outputFormat.mFramesPerPacket;
|
|
||||||
|
|
||||||
DLog(@"Input Properties: %@", properties);
|
|
||||||
if (![converterNode setupWithInputFormat:inputFormat outputFormat:outputFormat isLossless:[[properties objectForKey:@"encoding"] isEqualToString:@"lossless"]])
|
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
[self setRGInfo:rgi];
|
NSDictionary *properties = [inputNode properties];
|
||||||
|
|
||||||
|
inputFormat = [inputNode nodeFormat];
|
||||||
|
|
||||||
|
outputFormat.mChannelsPerFrame = inputFormat.mChannelsPerFrame;
|
||||||
|
outputFormat.mBytesPerFrame = ((outputFormat.mBitsPerChannel + 7) / 8) * outputFormat.mChannelsPerFrame;
|
||||||
|
outputFormat.mBytesPerPacket = outputFormat.mBytesPerFrame * outputFormat.mFramesPerPacket;
|
||||||
|
|
||||||
|
DLog(@"Input Properties: %@", properties);
|
||||||
|
if(![converterNode setupWithInputFormat:inputFormat outputFormat:outputFormat isLossless:[[properties objectForKey:@"encoding"] isEqualToString:@"lossless"]])
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
[self setRGInfo:rgi];
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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])
|
|
||||||
return NO;
|
|
||||||
|
|
||||||
NSDictionary * properties = [inputNode properties];
|
|
||||||
|
|
||||||
DLog(@"Input Properties: %@", properties);
|
|
||||||
|
|
||||||
inputFormat = [inputNode nodeFormat];
|
|
||||||
|
|
||||||
outputFormat.mChannelsPerFrame = inputFormat.mChannelsPerFrame;
|
if(![inputNode openWithDecoder:decoder])
|
||||||
outputFormat.mBytesPerFrame = ((outputFormat.mBitsPerChannel + 7) / 8) * outputFormat.mChannelsPerFrame;
|
return NO;
|
||||||
outputFormat.mBytesPerPacket = outputFormat.mBytesPerFrame * outputFormat.mFramesPerPacket;
|
|
||||||
|
|
||||||
if (![converterNode setupWithInputFormat:inputFormat outputFormat:outputFormat isLossless:[[properties objectForKey:@"encoding"] isEqualToString:@"lossless"]])
|
NSDictionary *properties = [inputNode properties];
|
||||||
return NO;
|
|
||||||
|
DLog(@"Input Properties: %@", properties);
|
||||||
[self setRGInfo:rgi];
|
|
||||||
|
inputFormat = [inputNode nodeFormat];
|
||||||
return YES;
|
|
||||||
|
outputFormat.mChannelsPerFrame = inputFormat.mChannelsPerFrame;
|
||||||
|
outputFormat.mBytesPerFrame = ((outputFormat.mBitsPerChannel + 7) / 8) * outputFormat.mChannelsPerFrame;
|
||||||
|
outputFormat.mBytesPerPacket = outputFormat.mBytesPerFrame * outputFormat.mFramesPerPacket;
|
||||||
|
|
||||||
|
if(![converterNode setupWithInputFormat:inputFormat outputFormat:outputFormat isLossless:[[properties objectForKey:@"encoding"] isEqualToString:@"lossless"]])
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
[self setRGInfo:rgi];
|
||||||
|
|
||||||
|
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];
|
[[inputNode exitAtTheEndOfTheStream] wait]; // wait for decoder to be closed (see InputNode's -(void)process )
|
||||||
[[inputNode exitAtTheEndOfTheStream] wait]; // wait for decoder to be closed (see InputNode's -(void)process )
|
|
||||||
|
|
||||||
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];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -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,27 +15,27 @@
|
||||||
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;
|
||||||
|
|
||||||
BOOL inAdder;
|
BOOL inAdder;
|
||||||
BOOL inRemover;
|
BOOL inRemover;
|
||||||
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,85 +12,85 @@
|
||||||
@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;
|
||||||
|
|
||||||
inAdder = NO;
|
inAdder = NO;
|
||||||
inRemover = NO;
|
inRemover = NO;
|
||||||
stopping = NO;
|
stopping = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
const double chunkDuration = [chunk duration];
|
const double chunkDuration = [chunk duration];
|
||||||
|
|
||||||
@synchronized(chunkList) {
|
@synchronized(chunkList) {
|
||||||
[chunkList addObject:chunk];
|
[chunkList addObject:chunk];
|
||||||
listDuration += chunkDuration;
|
listDuration += chunkDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
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];
|
||||||
inRemover = NO;
|
inRemover = NO;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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 <soxr.h>
|
#import <soxr.h>
|
||||||
|
|
||||||
|
@ -20,62 +20,62 @@
|
||||||
#import "HeadphoneFilter.h"
|
#import "HeadphoneFilter.h"
|
||||||
|
|
||||||
@interface ConverterNode : Node {
|
@interface ConverterNode : Node {
|
||||||
NSDictionary * rgInfo;
|
NSDictionary *rgInfo;
|
||||||
|
|
||||||
soxr_t soxr;
|
|
||||||
|
|
||||||
void *inputBuffer;
|
soxr_t soxr;
|
||||||
size_t inputBufferSize;
|
|
||||||
size_t inpSize, inpOffset;
|
void *inputBuffer;
|
||||||
|
size_t inputBufferSize;
|
||||||
BOOL stopping;
|
size_t inpSize, inpOffset;
|
||||||
BOOL convertEntered;
|
|
||||||
BOOL paused;
|
BOOL stopping;
|
||||||
BOOL outputFormatChanged;
|
BOOL convertEntered;
|
||||||
|
BOOL paused;
|
||||||
BOOL skipResampler;
|
BOOL outputFormatChanged;
|
||||||
|
|
||||||
unsigned int PRIME_LEN_;
|
BOOL skipResampler;
|
||||||
unsigned int N_samples_to_add_;
|
|
||||||
unsigned int N_samples_to_drop_;
|
unsigned int PRIME_LEN_;
|
||||||
|
unsigned int N_samples_to_add_;
|
||||||
unsigned int is_preextrapolated_;
|
unsigned int N_samples_to_drop_;
|
||||||
unsigned int is_postextrapolated_;
|
|
||||||
|
unsigned int is_preextrapolated_;
|
||||||
|
unsigned int is_postextrapolated_;
|
||||||
|
|
||||||
|
int latencyEaten;
|
||||||
|
int latencyEatenPost;
|
||||||
|
|
||||||
|
double sampleRatio;
|
||||||
|
|
||||||
|
float volumeScale;
|
||||||
|
|
||||||
|
void *floatBuffer;
|
||||||
|
size_t floatBufferSize;
|
||||||
|
size_t floatSize, floatOffset;
|
||||||
|
|
||||||
|
void *extrapolateBuffer;
|
||||||
|
size_t extrapolateBufferSize;
|
||||||
|
|
||||||
|
void **dsd2pcm;
|
||||||
|
size_t dsd2pcmCount;
|
||||||
|
int dsd2pcmLatency;
|
||||||
|
int dsdLatencyEaten;
|
||||||
|
|
||||||
|
BOOL rememberedLossless;
|
||||||
|
|
||||||
int latencyEaten;
|
|
||||||
int latencyEatenPost;
|
|
||||||
|
|
||||||
double sampleRatio;
|
|
||||||
|
|
||||||
float volumeScale;
|
|
||||||
|
|
||||||
void *floatBuffer;
|
|
||||||
size_t floatBufferSize;
|
|
||||||
size_t floatSize, floatOffset;
|
|
||||||
|
|
||||||
void *extrapolateBuffer;
|
|
||||||
size_t extrapolateBufferSize;
|
|
||||||
|
|
||||||
void **dsd2pcm;
|
|
||||||
size_t dsd2pcmCount;
|
|
||||||
int dsd2pcmLatency;
|
|
||||||
int dsdLatencyEaten;
|
|
||||||
|
|
||||||
BOOL rememberedLossless;
|
|
||||||
|
|
||||||
AudioStreamBasicDescription inputFormat;
|
AudioStreamBasicDescription inputFormat;
|
||||||
AudioStreamBasicDescription floatFormat;
|
AudioStreamBasicDescription floatFormat;
|
||||||
AudioStreamBasicDescription dmFloatFormat; // downmixed/upmixed float format
|
AudioStreamBasicDescription dmFloatFormat; // downmixed/upmixed float format
|
||||||
AudioStreamBasicDescription outputFormat;
|
AudioStreamBasicDescription outputFormat;
|
||||||
|
|
||||||
AudioStreamBasicDescription previousOutputFormat;
|
AudioStreamBasicDescription previousOutputFormat;
|
||||||
AudioStreamBasicDescription rememberedInputFormat;
|
AudioStreamBasicDescription rememberedInputFormat;
|
||||||
RefillNode *refillNode;
|
RefillNode *refillNode;
|
||||||
id __weak originalPreviousNode;
|
id __weak originalPreviousNode;
|
||||||
|
|
||||||
void *hdcd_decoder;
|
void *hdcd_decoder;
|
||||||
|
|
||||||
HeadphoneFilter *hFilter;
|
HeadphoneFilter *hFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property AudioStreamBasicDescription inputFormat;
|
@property AudioStreamBasicDescription inputFormat;
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -6,21 +6,20 @@
|
||||||
// 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"
|
||||||
|
|
||||||
@interface DownmixProcessor : NSObject {
|
@interface DownmixProcessor : NSObject {
|
||||||
HeadphoneFilter *hFilter;
|
HeadphoneFilter *hFilter;
|
||||||
|
|
||||||
AudioStreamBasicDescription inputFormat;
|
AudioStreamBasicDescription inputFormat;
|
||||||
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,294 +10,272 @@
|
||||||
|
|
||||||
#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 },
|
||||||
/*quadrophonic*/
|
{ 0.4142F, 0.4142F } },
|
||||||
{
|
/*quadrophonic*/
|
||||||
{0.4226F,0.0F},{0.0F,0.4226F},{0.366F,0.2114F},{0.2114F,0.336F}
|
{
|
||||||
},
|
{ 0.4226F, 0.0F },
|
||||||
/*5.0*/
|
{ 0.0F, 0.4226F },
|
||||||
{
|
{ 0.366F, 0.2114F },
|
||||||
{0.651F,0.0F},{0.0F,0.651F},{0.46F,0.46F},{0.5636F,0.3254F},
|
{ 0.2114F, 0.336F } },
|
||||||
{0.3254F,0.5636F}
|
/*5.0*/
|
||||||
},
|
{
|
||||||
/*5.1*/
|
{ 0.651F, 0.0F },
|
||||||
{
|
{ 0.0F, 0.651F },
|
||||||
{0.529F,0.0F},{0.0F,0.529F},{0.3741F,0.3741F},{0.3741F,0.3741F},{0.4582F,0.2645F},
|
{ 0.46F, 0.46F },
|
||||||
{0.2645F,0.4582F}
|
{ 0.5636F, 0.3254F },
|
||||||
},
|
{ 0.3254F, 0.5636F } },
|
||||||
/*6.1*/
|
/*5.1*/
|
||||||
{
|
{
|
||||||
{0.4553F,0.0F},{0.0F,0.4553F},{0.322F,0.322F},{0.322F,0.322F},{0.2788F,0.2788F},
|
{ 0.529F, 0.0F },
|
||||||
{0.3943F,0.2277F},{0.2277F,0.3943F}
|
{ 0.0F, 0.529F },
|
||||||
},
|
{ 0.3741F, 0.3741F },
|
||||||
/*7.1*/
|
{ 0.3741F, 0.3741F },
|
||||||
{
|
{ 0.4582F, 0.2645F },
|
||||||
{0.3886F,0.0F},{0.0F,0.3886F},{0.2748F,0.2748F},{0.2748F,0.2748F},{0.3366F,0.1943F},
|
{ 0.2645F, 0.4582F } },
|
||||||
{0.1943F,0.3366F},{0.3366F,0.1943F},{0.1943F,0.3366F}
|
/*6.1*/
|
||||||
}
|
{
|
||||||
|
{ 0.4553F, 0.0F },
|
||||||
|
{ 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*/
|
||||||
|
{
|
||||||
|
{ 0.3886F, 0.0F },
|
||||||
|
{ 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;
|
||||||
{
|
for(int j = 0; j < channels; ++j) {
|
||||||
float left = 0, right = 0;
|
left += inBuffer[i * channels + j] * STEREO_DOWNMIX[channels - 3][j][0];
|
||||||
for (int j = 0; j < channels; ++j)
|
right += inBuffer[i * channels + j] * STEREO_DOWNMIX[channels - 3][j][1];
|
||||||
{
|
}
|
||||||
left += inBuffer[i * channels + j] * STEREO_DOWNMIX[channels - 3][j][0];
|
outBuffer[i * 2 + 0] = left;
|
||||||
right += inBuffer[i * channels + j] * STEREO_DOWNMIX[channels - 3][j][1];
|
outBuffer[i * 2 + 1] = right;
|
||||||
}
|
}
|
||||||
outBuffer[i * 2 + 0] = left;
|
|
||||||
outBuffer[i * 2 + 1] = right;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
{
|
inBuffer = tempBuffer;
|
||||||
downmix_to_stereo(inBuffer, channels, tempBuffer, count);
|
channels = 2;
|
||||||
inBuffer = tempBuffer;
|
}
|
||||||
channels = 2;
|
float invchannels = 1.0 / (float)channels;
|
||||||
}
|
for(size_t i = 0; i < count; ++i) {
|
||||||
float invchannels = 1.0 / (float)channels;
|
float sample = 0;
|
||||||
for (size_t i = 0; i < count; ++i)
|
for(int j = 0; j < channels; ++j) {
|
||||||
{
|
sample += inBuffer[i * channels + j];
|
||||||
float sample = 0;
|
}
|
||||||
for (int j = 0; j < channels; ++j)
|
outBuffer[i] = sample * invchannels;
|
||||||
{
|
}
|
||||||
sample += inBuffer[i * channels + j];
|
|
||||||
}
|
|
||||||
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) {
|
||||||
{
|
// upmix mono to stereo
|
||||||
if (inchannels == 1 && outchannels == 2)
|
float sample = inBuffer[i];
|
||||||
{
|
outBuffer[i * 2 + 0] = sample;
|
||||||
// upmix mono to stereo
|
outBuffer[i * 2 + 1] = sample;
|
||||||
float sample = inBuffer[i];
|
} else if(inchannels == 1 && outchannels == 4) {
|
||||||
outBuffer[i * 2 + 0] = sample;
|
// upmix mono to quad
|
||||||
outBuffer[i * 2 + 1] = sample;
|
float sample = inBuffer[i];
|
||||||
}
|
outBuffer[i * 4 + 0] = sample;
|
||||||
else if (inchannels == 1 && outchannels == 4)
|
outBuffer[i * 4 + 1] = sample;
|
||||||
{
|
outBuffer[i * 4 + 2] = 0;
|
||||||
// upmix mono to quad
|
outBuffer[i * 4 + 3] = 0;
|
||||||
float sample = inBuffer[i];
|
} else if(inchannels == 1 && (outchannels == 3 || outchannels >= 5)) {
|
||||||
outBuffer[i * 4 + 0] = sample;
|
// upmix mono to center channel
|
||||||
outBuffer[i * 4 + 1] = sample;
|
float sample = inBuffer[i];
|
||||||
outBuffer[i * 4 + 2] = 0;
|
outBuffer[i * outchannels + 2] = sample;
|
||||||
outBuffer[i * 4 + 3] = 0;
|
for(int j = 0; j < 2; ++j) {
|
||||||
}
|
outBuffer[i * outchannels + j] = 0;
|
||||||
else if (inchannels == 1 && (outchannels == 3 || outchannels >= 5))
|
}
|
||||||
{
|
for(int j = 3; j < outchannels; ++j) {
|
||||||
// upmix mono to center channel
|
outBuffer[i * outchannels + j] = 0;
|
||||||
float sample = inBuffer[i];
|
}
|
||||||
outBuffer[i * outchannels + 2] = sample;
|
} else if(inchannels == 4 && outchannels >= 5) {
|
||||||
for (int j = 0; j < 2; ++j)
|
float fl = inBuffer[i * 4 + 0];
|
||||||
{
|
float fr = inBuffer[i * 4 + 1];
|
||||||
outBuffer[i * outchannels + j] = 0;
|
float bl = inBuffer[i * 4 + 2];
|
||||||
}
|
float br = inBuffer[i * 4 + 3];
|
||||||
for (int j = 3; j < outchannels; ++j)
|
const int skipclfe = (outchannels == 5) ? 1 : 2;
|
||||||
{
|
outBuffer[i * outchannels + 0] = fl;
|
||||||
outBuffer[i * outchannels + j] = 0;
|
outBuffer[i * outchannels + 1] = fr;
|
||||||
}
|
outBuffer[i * outchannels + skipclfe + 2] = bl;
|
||||||
}
|
outBuffer[i * outchannels + skipclfe + 3] = br;
|
||||||
else if (inchannels == 4 && outchannels >= 5)
|
for(int j = 0; j < skipclfe; ++j) {
|
||||||
{
|
outBuffer[i * outchannels + 2 + j] = 0;
|
||||||
float fl = inBuffer[i * 4 + 0];
|
}
|
||||||
float fr = inBuffer[i * 4 + 1];
|
for(int j = 4 + skipclfe; j < outchannels; ++j) {
|
||||||
float bl = inBuffer[i * 4 + 2];
|
outBuffer[i * outchannels + j] = 0;
|
||||||
float br = inBuffer[i * 4 + 3];
|
}
|
||||||
const int skipclfe = (outchannels == 5) ? 1 : 2;
|
} else if(inchannels == 5 && outchannels >= 6) {
|
||||||
outBuffer[i * outchannels + 0] = fl;
|
float fl = inBuffer[i * 5 + 0];
|
||||||
outBuffer[i * outchannels + 1] = fr;
|
float fr = inBuffer[i * 5 + 1];
|
||||||
outBuffer[i * outchannels + skipclfe + 2] = bl;
|
float c = inBuffer[i * 5 + 2];
|
||||||
outBuffer[i * outchannels + skipclfe + 3] = br;
|
float bl = inBuffer[i * 5 + 3];
|
||||||
for (int j = 0; j < skipclfe; ++j)
|
float br = inBuffer[i * 5 + 4];
|
||||||
{
|
outBuffer[i * outchannels + 0] = fl;
|
||||||
outBuffer[i * outchannels + 2 + j] = 0;
|
outBuffer[i * outchannels + 1] = fr;
|
||||||
}
|
outBuffer[i * outchannels + 2] = c;
|
||||||
for (int j = 4 + skipclfe; j < outchannels; ++j)
|
outBuffer[i * outchannels + 3] = 0;
|
||||||
{
|
outBuffer[i * outchannels + 4] = bl;
|
||||||
outBuffer[i * outchannels + j] = 0;
|
outBuffer[i * outchannels + 5] = br;
|
||||||
}
|
for(int j = 6; j < outchannels; ++j) {
|
||||||
}
|
outBuffer[i * outchannels + j] = 0;
|
||||||
else if (inchannels == 5 && outchannels >= 6)
|
}
|
||||||
{
|
} else if(inchannels == 7 && outchannels == 8) {
|
||||||
float fl = inBuffer[i * 5 + 0];
|
float fl = inBuffer[i * 7 + 0];
|
||||||
float fr = inBuffer[i * 5 + 1];
|
float fr = inBuffer[i * 7 + 1];
|
||||||
float c = inBuffer[i * 5 + 2];
|
float c = inBuffer[i * 7 + 2];
|
||||||
float bl = inBuffer[i * 5 + 3];
|
float lfe = inBuffer[i * 7 + 3];
|
||||||
float br = inBuffer[i * 5 + 4];
|
float sl = inBuffer[i * 7 + 4];
|
||||||
outBuffer[i * outchannels + 0] = fl;
|
float sr = inBuffer[i * 7 + 5];
|
||||||
outBuffer[i * outchannels + 1] = fr;
|
float bc = inBuffer[i * 7 + 6];
|
||||||
outBuffer[i * outchannels + 2] = c;
|
outBuffer[i * 8 + 0] = fl;
|
||||||
outBuffer[i * outchannels + 3] = 0;
|
outBuffer[i * 8 + 1] = fr;
|
||||||
outBuffer[i * outchannels + 4] = bl;
|
outBuffer[i * 8 + 2] = c;
|
||||||
outBuffer[i * outchannels + 5] = br;
|
outBuffer[i * 8 + 3] = lfe;
|
||||||
for (int j = 6; j < outchannels; ++j)
|
outBuffer[i * 8 + 4] = bc;
|
||||||
{
|
outBuffer[i * 8 + 5] = bc;
|
||||||
outBuffer[i * outchannels + j] = 0;
|
outBuffer[i * 8 + 6] = sl;
|
||||||
}
|
outBuffer[i * 8 + 7] = sr;
|
||||||
}
|
} else {
|
||||||
else if (inchannels == 7 && outchannels == 8)
|
// upmix N channels to N channels plus silence the empty channels
|
||||||
{
|
float samples[inchannels];
|
||||||
float fl = inBuffer[i * 7 + 0];
|
for(int j = 0; j < inchannels; ++j) {
|
||||||
float fr = inBuffer[i * 7 + 1];
|
samples[j] = inBuffer[i * inchannels + j];
|
||||||
float c = inBuffer[i * 7 + 2];
|
}
|
||||||
float lfe = inBuffer[i * 7 + 3];
|
for(int j = 0; j < inchannels; ++j) {
|
||||||
float sl = inBuffer[i * 7 + 4];
|
outBuffer[i * outchannels + j] = samples[j];
|
||||||
float sr = inBuffer[i * 7 + 5];
|
}
|
||||||
float bc = inBuffer[i * 7 + 6];
|
for(int j = inchannels; j < outchannels; ++j) {
|
||||||
outBuffer[i * 8 + 0] = fl;
|
outBuffer[i * outchannels + j] = 0;
|
||||||
outBuffer[i * 8 + 1] = fr;
|
}
|
||||||
outBuffer[i * 8 + 2] = c;
|
}
|
||||||
outBuffer[i * 8 + 3] = lfe;
|
}
|
||||||
outBuffer[i * 8 + 4] = bc;
|
|
||||||
outBuffer[i * 8 + 5] = bc;
|
|
||||||
outBuffer[i * 8 + 6] = sl;
|
|
||||||
outBuffer[i * 8 + 7] = sr;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// upmix N channels to N channels plus silence the empty channels
|
|
||||||
float samples[inchannels];
|
|
||||||
for (int j = 0; j < inchannels; ++j)
|
|
||||||
{
|
|
||||||
samples[j] = inBuffer[i * inchannels + j];
|
|
||||||
}
|
|
||||||
for (int j = 0; j < inchannels; ++j)
|
|
||||||
{
|
|
||||||
outBuffer[i * outchannels + j] = samples[j];
|
|
||||||
}
|
|
||||||
for (int j = inchannels; j < outchannels; ++j)
|
|
||||||
{
|
|
||||||
outBuffer[i * outchannels + j] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@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 (inf.mFormatID != kAudioFormatLinearPCM ||
|
|
||||||
(inf.mFormatFlags & kAudioFormatFlagsNativeFloatPacked) != kAudioFormatFlagsNativeFloatPacked ||
|
|
||||||
inf.mBitsPerChannel != 32 ||
|
|
||||||
inf.mBytesPerFrame != (4 * inf.mChannelsPerFrame) ||
|
|
||||||
inf.mBytesPerPacket != inf.mFramesPerPacket * inf.mBytesPerFrame)
|
|
||||||
return nil;
|
|
||||||
|
|
||||||
if (outf.mFormatID != kAudioFormatLinearPCM ||
|
|
||||||
(outf.mFormatFlags & kAudioFormatFlagsNativeFloatPacked) != kAudioFormatFlagsNativeFloatPacked ||
|
|
||||||
outf.mBitsPerChannel != 32 ||
|
|
||||||
outf.mBytesPerFrame != (4 * outf.mChannelsPerFrame) ||
|
|
||||||
outf.mBytesPerPacket != outf.mFramesPerPacket * outf.mBytesPerFrame)
|
|
||||||
return nil;
|
|
||||||
|
|
||||||
inputFormat = inf;
|
|
||||||
outputFormat = outf;
|
|
||||||
|
|
||||||
[self setupVirt];
|
if(self) {
|
||||||
|
if(inf.mFormatID != kAudioFormatLinearPCM ||
|
||||||
|
(inf.mFormatFlags & kAudioFormatFlagsNativeFloatPacked) != kAudioFormatFlagsNativeFloatPacked ||
|
||||||
|
inf.mBitsPerChannel != 32 ||
|
||||||
|
inf.mBytesPerFrame != (4 * inf.mChannelsPerFrame) ||
|
||||||
|
inf.mBytesPerPacket != inf.mFramesPerPacket * inf.mBytesPerFrame)
|
||||||
|
return nil;
|
||||||
|
|
||||||
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.headphoneVirtualization" options:0 context:nil];
|
if(outf.mFormatID != kAudioFormatLinearPCM ||
|
||||||
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.hrirPath" options:0 context:nil];
|
(outf.mFormatFlags & kAudioFormatFlagsNativeFloatPacked) != kAudioFormatFlagsNativeFloatPacked ||
|
||||||
}
|
outf.mBitsPerChannel != 32 ||
|
||||||
|
outf.mBytesPerFrame != (4 * outf.mChannelsPerFrame) ||
|
||||||
return self;
|
outf.mBytesPerPacket != outf.mFramesPerPacket * outf.mBytesPerFrame)
|
||||||
|
return nil;
|
||||||
|
|
||||||
|
inputFormat = inf;
|
||||||
|
outputFormat = outf;
|
||||||
|
|
||||||
|
[self setupVirt];
|
||||||
|
|
||||||
|
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.headphoneVirtualization" options:0 context:nil];
|
||||||
|
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.hrirPath" options:0 context:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
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"];
|
|
||||||
|
|
||||||
if (hVirt &&
|
|
||||||
outputFormat.mChannelsPerFrame == 2 &&
|
|
||||||
inputFormat.mChannelsPerFrame >= 1 &&
|
|
||||||
inputFormat.mChannelsPerFrame <= 8) {
|
|
||||||
NSString * userPreset = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] stringForKey:@"hrirPath"];
|
|
||||||
|
|
||||||
NSURL * presetUrl = nil;
|
|
||||||
|
|
||||||
if (userPreset && ![userPreset isEqualToString:@""]) {
|
|
||||||
presetUrl = [NSURL fileURLWithPath:userPreset];
|
|
||||||
if (![HeadphoneFilter validateImpulseFile:presetUrl])
|
|
||||||
presetUrl = nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!presetUrl) {
|
|
||||||
presetUrl = [[NSBundle mainBundle] URLForResource:@"gsx" withExtension:@"wv"];
|
|
||||||
if (![HeadphoneFilter validateImpulseFile:presetUrl])
|
|
||||||
presetUrl = nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (presetUrl) {
|
BOOL hVirt = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"headphoneVirtualization"];
|
||||||
@synchronized(hFilter) {
|
|
||||||
hFilter = [[HeadphoneFilter alloc] initWithImpulseFile:presetUrl forSampleRate:outputFormat.mSampleRate withInputChannels:inputFormat.mChannelsPerFrame];
|
if(hVirt &&
|
||||||
}
|
outputFormat.mChannelsPerFrame == 2 &&
|
||||||
}
|
inputFormat.mChannelsPerFrame >= 1 &&
|
||||||
}
|
inputFormat.mChannelsPerFrame <= 8) {
|
||||||
|
NSString *userPreset = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] stringForKey:@"hrirPath"];
|
||||||
|
|
||||||
|
NSURL *presetUrl = nil;
|
||||||
|
|
||||||
|
if(userPreset && ![userPreset isEqualToString:@""]) {
|
||||||
|
presetUrl = [NSURL fileURLWithPath:userPreset];
|
||||||
|
if(![HeadphoneFilter validateImpulseFile:presetUrl])
|
||||||
|
presetUrl = nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!presetUrl) {
|
||||||
|
presetUrl = [[NSBundle mainBundle] URLForResource:@"gsx" withExtension:@"wv"];
|
||||||
|
if(![HeadphoneFilter validateImpulseFile:presetUrl])
|
||||||
|
presetUrl = nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(presetUrl) {
|
||||||
|
@synchronized(hFilter) {
|
||||||
|
hFilter = [[HeadphoneFilter alloc] initWithImpulseFile:presetUrl forSampleRate:outputFormat.mSampleRate withInputChannels:inputFormat.mChannelsPerFrame];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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) {
|
||||||
}
|
memcpy(outBuffer, inBuffer, frames * outputFormat.mBytesPerPacket);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -8,43 +8,43 @@
|
||||||
#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;
|
||||||
|
|
||||||
size_t fftSize;
|
size_t fftSize;
|
||||||
size_t fftSizeOver2;
|
size_t fftSizeOver2;
|
||||||
size_t log2n;
|
size_t log2n;
|
||||||
size_t log2nhalf;
|
size_t log2nhalf;
|
||||||
size_t bufferSize;
|
size_t bufferSize;
|
||||||
size_t paddedBufferSize;
|
size_t paddedBufferSize;
|
||||||
size_t channelCount;
|
size_t channelCount;
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (BOOL)validateImpulseFile:(NSURL *)url;
|
+ (BOOL)validateImpulseFile:(NSURL *)url;
|
||||||
|
|
||||||
- (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"
|
||||||
|
@ -19,486 +19,484 @@
|
||||||
|
|
||||||
// Symmetrical / no-reverb sets
|
// Symmetrical / no-reverb sets
|
||||||
static const int8_t speakers_to_hesuvi_7[8][2][8] = {
|
static const int8_t speakers_to_hesuvi_7[8][2][8] = {
|
||||||
// mono/center
|
// mono/center
|
||||||
{ { 6 }, { 6 } },
|
{ { 6 }, { 6 } },
|
||||||
// left/right
|
// left/right
|
||||||
{ { 0, 1 }, { 1, 0 } },
|
{ { 0, 1 }, { 1, 0 } },
|
||||||
// left/right/center
|
// left/right/center
|
||||||
{ { 0, 1, 6 }, { 1, 0, 6 } },
|
{ { 0, 1, 6 }, { 1, 0, 6 } },
|
||||||
// left/right/back lef/back right
|
// left/right/back lef/back right
|
||||||
{ { 0, 1, 4, 5 }, { 1, 0, 5, 4 } },
|
{ { 0, 1, 4, 5 }, { 1, 0, 5, 4 } },
|
||||||
// left/right/center/back left/back right
|
// left/right/center/back left/back right
|
||||||
{ { 0, 1, 6, 4, 5 }, { 1, 0, 6, 5, 4 } },
|
{ { 0, 1, 6, 4, 5 }, { 1, 0, 6, 5, 4 } },
|
||||||
// left/right/center/lfe(center)/back left/back right
|
// left/right/center/lfe(center)/back left/back right
|
||||||
{ { 0, 1, 6, 6, 4, 5 }, { 1, 0, 6, 6, 5, 4 } },
|
{ { 0, 1, 6, 6, 4, 5 }, { 1, 0, 6, 6, 5, 4 } },
|
||||||
// left/right/center/lfe(center)/back center(special)/side left/side right
|
// left/right/center/lfe(center)/back center(special)/side left/side right
|
||||||
{ { 0, 1, 6, 6, -1, 2, 3 }, { 1, 0, 6, 6, -1, 3, 2 } },
|
{ { 0, 1, 6, 6, -1, 2, 3 }, { 1, 0, 6, 6, -1, 3, 2 } },
|
||||||
// left/right/center/lfe(center)/back left/back right/side left/side right
|
// left/right/center/lfe(center)/back left/back right/side left/side right
|
||||||
{ { 0, 1, 6, 6, 4, 5, 2, 3 }, { 1, 0, 6, 6, 5, 4, 3, 2 } }
|
{ { 0, 1, 6, 6, 4, 5, 2, 3 }, { 1, 0, 6, 6, 5, 4, 3, 2 } }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Asymmetrical / reverb sets
|
// Asymmetrical / reverb sets
|
||||||
static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
static const int8_t speakers_to_hesuvi_14[8][2][8] = {
|
||||||
// mono/center
|
// mono/center
|
||||||
{ { 6 }, { 13 } },
|
{ { 6 }, { 13 } },
|
||||||
// left/right
|
// left/right
|
||||||
{ { 0, 8 }, { 1, 7 } },
|
{ { 0, 8 }, { 1, 7 } },
|
||||||
// left/right/center
|
// left/right/center
|
||||||
{ { 0, 8, 6 }, { 1, 7, 13 } },
|
{ { 0, 8, 6 }, { 1, 7, 13 } },
|
||||||
// left/right/back left/back right
|
// left/right/back left/back right
|
||||||
{ { 0, 8, 4, 12 }, { 1, 7, 5, 11 } },
|
{ { 0, 8, 4, 12 }, { 1, 7, 5, 11 } },
|
||||||
// left/right/center/back left/back right
|
// left/right/center/back left/back right
|
||||||
{ { 0, 8, 6, 4, 12 }, { 1, 7, 13, 5, 11 } },
|
{ { 0, 8, 6, 4, 12 }, { 1, 7, 13, 5, 11 } },
|
||||||
// left/right/center/lfe(center)/back left/back right
|
// left/right/center/lfe(center)/back left/back right
|
||||||
{ { 0, 8, 6, 6, 4, 12 }, { 1, 7, 13, 13, 5, 11 } },
|
{ { 0, 8, 6, 6, 4, 12 }, { 1, 7, 13, 13, 5, 11 } },
|
||||||
// left/right/center/lfe(center)/back center(special)/side left/side right
|
// left/right/center/lfe(center)/back center(special)/side left/side right
|
||||||
{ { 0, 8, 6, 6, -1, 2, 10 }, { 1, 7, 13, 13, -1, 3, 9 } },
|
{ { 0, 8, 6, 6, -1, 2, 10 }, { 1, 7, 13, 13, -1, 3, 9 } },
|
||||||
// left/right/center/lfe(center)/back left/back right/side left/side right
|
// left/right/center/lfe(center)/back left/back right/side left/side right
|
||||||
{ { 0, 8, 6, 6, 4, 12, 2, 10 }, { 1, 7, 13, 13, 5, 11, 3, 9 } }
|
{ { 0, 8, 6, 6, 4, 12, 2, 10 }, { 1, 7, 13, 13, 5, 11, 3, 9 } }
|
||||||
};
|
};
|
||||||
|
|
||||||
+ (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];
|
|
||||||
|
|
||||||
if (decoder == nil) {
|
id<CogDecoder> decoder = [AudioDecoder audioDecoderForSource:source];
|
||||||
[source close];
|
|
||||||
source = nil;
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (![decoder open:source])
|
if(decoder == nil) {
|
||||||
{
|
[source close];
|
||||||
decoder = nil;
|
source = nil;
|
||||||
[source close];
|
return NO;
|
||||||
source = nil;
|
}
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSDictionary *properties = [decoder properties];
|
|
||||||
|
|
||||||
[decoder close];
|
|
||||||
decoder = nil;
|
|
||||||
[source close];
|
|
||||||
source = nil;
|
|
||||||
|
|
||||||
int impulseChannels = [[properties objectForKey:@"channels"] intValue];
|
|
||||||
|
|
||||||
if ([[properties objectForKey:@"floatingPoint"] boolValue] != YES ||
|
|
||||||
[[properties objectForKey:@"bitsPerSample"] intValue] != 32 ||
|
|
||||||
!([[properties objectForKey:@"endian"] isEqualToString:@"host"] ||
|
|
||||||
[[properties objectForKey:@"endian"] isEqualToString:@"little"]) ||
|
|
||||||
(impulseChannels != 14 && impulseChannels != 7))
|
|
||||||
return NO;
|
|
||||||
|
|
||||||
return YES;
|
if(![decoder open:source]) {
|
||||||
|
decoder = nil;
|
||||||
|
[source close];
|
||||||
|
source = nil;
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSDictionary *properties = [decoder properties];
|
||||||
|
|
||||||
|
[decoder close];
|
||||||
|
decoder = nil;
|
||||||
|
[source close];
|
||||||
|
source = nil;
|
||||||
|
|
||||||
|
int impulseChannels = [[properties objectForKey:@"channels"] intValue];
|
||||||
|
|
||||||
|
if([[properties objectForKey:@"floatingPoint"] boolValue] != YES ||
|
||||||
|
[[properties objectForKey:@"bitsPerSample"] intValue] != 32 ||
|
||||||
|
!([[properties objectForKey:@"endian"] isEqualToString:@"host"] ||
|
||||||
|
[[properties objectForKey:@"endian"] isEqualToString:@"little"]) ||
|
||||||
|
(impulseChannels != 14 && impulseChannels != 7))
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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) {
|
|
||||||
id<CogSource> source = [AudioSource audioSourceForURL:url];
|
|
||||||
if (!source)
|
|
||||||
return nil;
|
|
||||||
|
|
||||||
if (![source open:url])
|
if(self) {
|
||||||
return nil;
|
id<CogSource> source = [AudioSource audioSourceForURL:url];
|
||||||
|
if(!source)
|
||||||
id<CogDecoder> decoder = [AudioDecoder audioDecoderForSource:source];
|
return nil;
|
||||||
|
|
||||||
if (decoder == nil) {
|
if(![source open:url])
|
||||||
[source close];
|
return nil;
|
||||||
source = nil;
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (![decoder open:source])
|
id<CogDecoder> decoder = [AudioDecoder audioDecoderForSource:source];
|
||||||
{
|
|
||||||
decoder = nil;
|
|
||||||
[source close];
|
|
||||||
source = nil;
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSDictionary *properties = [decoder properties];
|
|
||||||
|
|
||||||
double sampleRateOfSource = [[properties objectForKey:@"sampleRate"] floatValue];
|
|
||||||
|
|
||||||
int sampleCount = [[properties objectForKey:@"totalFrames"] intValue];
|
|
||||||
int impulseChannels = [[properties objectForKey:@"channels"] intValue];
|
|
||||||
|
|
||||||
if ([[properties objectForKey:@"floatingPoint"] boolValue] != YES ||
|
|
||||||
[[properties objectForKey:@"bitsPerSample"] intValue] != 32 ||
|
|
||||||
!([[properties objectForKey:@"endian"] isEqualToString:@"host"] ||
|
|
||||||
[[properties objectForKey:@"endian"] isEqualToString:@"little"]) ||
|
|
||||||
(impulseChannels != 14 && impulseChannels != 7)) {
|
|
||||||
[decoder close];
|
|
||||||
decoder = nil;
|
|
||||||
[source close];
|
|
||||||
source = nil;
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
float * impulseBuffer = (float *) malloc(sampleCount * sizeof(float) * impulseChannels);
|
if(decoder == nil) {
|
||||||
if (!impulseBuffer) {
|
[source close];
|
||||||
[decoder close];
|
source = nil;
|
||||||
decoder = nil;
|
return nil;
|
||||||
[source close];
|
}
|
||||||
source = nil;
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ([decoder readAudio:impulseBuffer frames:sampleCount] != sampleCount) {
|
|
||||||
[decoder close];
|
|
||||||
decoder = nil;
|
|
||||||
[source close];
|
|
||||||
source = nil;
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
[decoder close];
|
if(![decoder open:source]) {
|
||||||
decoder = nil;
|
decoder = nil;
|
||||||
[source close];
|
[source close];
|
||||||
source = nil;
|
source = nil;
|
||||||
|
return nil;
|
||||||
if (sampleRateOfSource != sampleRate) {
|
}
|
||||||
double sampleRatio = sampleRate / sampleRateOfSource;
|
|
||||||
int resampledCount = (int)ceil((double)sampleCount * sampleRatio);
|
|
||||||
|
|
||||||
soxr_quality_spec_t q_spec = soxr_quality_spec(SOXR_HQ, 0);
|
NSDictionary *properties = [decoder properties];
|
||||||
soxr_io_spec_t io_spec = soxr_io_spec(SOXR_FLOAT32_I, SOXR_FLOAT32_I);
|
|
||||||
soxr_runtime_spec_t runtime_spec = soxr_runtime_spec(0);
|
|
||||||
|
|
||||||
soxr_error_t error;
|
|
||||||
|
|
||||||
unsigned long PRIME_LEN_ = MAX(sampleRateOfSource/20, 1024u);
|
|
||||||
PRIME_LEN_ = MIN(PRIME_LEN_, 16384u);
|
|
||||||
PRIME_LEN_ = MAX(PRIME_LEN_, 2*LPC_ORDER + 1);
|
|
||||||
|
|
||||||
unsigned int N_samples_to_add_ = sampleRateOfSource;
|
|
||||||
unsigned int N_samples_to_drop_ = sampleRate;
|
|
||||||
|
|
||||||
samples_len(&N_samples_to_add_, &N_samples_to_drop_, 20, 8192u);
|
|
||||||
|
|
||||||
int resamplerLatencyIn = (int) N_samples_to_add_;
|
double sampleRateOfSource = [[properties objectForKey:@"sampleRate"] floatValue];
|
||||||
int resamplerLatencyOut = (int) N_samples_to_drop_;
|
|
||||||
|
|
||||||
float * tempImpulse = (float *) realloc(impulseBuffer, (sampleCount + resamplerLatencyIn * 2 + 1024) * sizeof(float) * impulseChannels);
|
|
||||||
if (!tempImpulse) {
|
|
||||||
free(impulseBuffer);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
impulseBuffer = tempImpulse;
|
|
||||||
|
|
||||||
resampledCount += resamplerLatencyOut * 2 + 1024;
|
|
||||||
|
|
||||||
float * resampledImpulse = (float *) malloc(resampledCount * sizeof(float) * impulseChannels);
|
|
||||||
if (!resampledImpulse) {
|
|
||||||
free(impulseBuffer);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t prime = MIN(sampleCount, PRIME_LEN_);
|
|
||||||
|
|
||||||
void * extrapolate_buffer = NULL;
|
|
||||||
size_t extrapolate_buffer_size = 0;
|
|
||||||
|
|
||||||
memmove(impulseBuffer + resamplerLatencyIn * impulseChannels, impulseBuffer, sampleCount * sizeof(float) * impulseChannels);
|
int sampleCount = [[properties objectForKey:@"totalFrames"] intValue];
|
||||||
lpc_extrapolate_bkwd(impulseBuffer + N_samples_to_add_ * impulseChannels, sampleCount, prime, impulseChannels, LPC_ORDER, N_samples_to_add_, &extrapolate_buffer, &extrapolate_buffer_size);
|
int impulseChannels = [[properties objectForKey:@"channels"] intValue];
|
||||||
lpc_extrapolate_fwd(impulseBuffer + N_samples_to_add_ * impulseChannels, sampleCount, prime, impulseChannels, LPC_ORDER, N_samples_to_add_, &extrapolate_buffer, &extrapolate_buffer_size);
|
|
||||||
free(extrapolate_buffer);
|
|
||||||
|
|
||||||
size_t inputDone = 0;
|
if([[properties objectForKey:@"floatingPoint"] boolValue] != YES ||
|
||||||
size_t outputDone = 0;
|
[[properties objectForKey:@"bitsPerSample"] intValue] != 32 ||
|
||||||
|
!([[properties objectForKey:@"endian"] isEqualToString:@"host"] ||
|
||||||
|
[[properties objectForKey:@"endian"] isEqualToString:@"little"]) ||
|
||||||
|
(impulseChannels != 14 && impulseChannels != 7)) {
|
||||||
|
[decoder close];
|
||||||
|
decoder = nil;
|
||||||
|
[source close];
|
||||||
|
source = nil;
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
error = soxr_oneshot(sampleRateOfSource, sampleRate, impulseChannels, impulseBuffer, sampleCount + N_samples_to_add_ * 2, &inputDone, resampledImpulse, resampledCount, &outputDone, &io_spec, &q_spec, &runtime_spec);
|
float *impulseBuffer = (float *)malloc(sampleCount * sizeof(float) * impulseChannels);
|
||||||
|
if(!impulseBuffer) {
|
||||||
if (error) {
|
[decoder close];
|
||||||
free(resampledImpulse);
|
decoder = nil;
|
||||||
free(impulseBuffer);
|
[source close];
|
||||||
return nil;
|
source = nil;
|
||||||
}
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
outputDone -= N_samples_to_drop_ * 2;
|
if([decoder readAudio:impulseBuffer frames:sampleCount] != sampleCount) {
|
||||||
|
[decoder close];
|
||||||
|
decoder = nil;
|
||||||
|
[source close];
|
||||||
|
source = nil;
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
memmove(resampledImpulse, resampledImpulse + N_samples_to_drop_ * impulseChannels, outputDone * sizeof(float) * impulseChannels);
|
[decoder close];
|
||||||
|
decoder = nil;
|
||||||
|
[source close];
|
||||||
|
source = nil;
|
||||||
|
|
||||||
free(impulseBuffer);
|
if(sampleRateOfSource != sampleRate) {
|
||||||
impulseBuffer = resampledImpulse;
|
double sampleRatio = sampleRate / sampleRateOfSource;
|
||||||
sampleCount = (int) outputDone;
|
int resampledCount = (int)ceil((double)sampleCount * sampleRatio);
|
||||||
}
|
|
||||||
|
|
||||||
channelCount = channels;
|
soxr_quality_spec_t q_spec = soxr_quality_spec(SOXR_HQ, 0);
|
||||||
|
soxr_io_spec_t io_spec = soxr_io_spec(SOXR_FLOAT32_I, SOXR_FLOAT32_I);
|
||||||
|
soxr_runtime_spec_t runtime_spec = soxr_runtime_spec(0);
|
||||||
|
|
||||||
bufferSize = 512;
|
soxr_error_t error;
|
||||||
fftSize = sampleCount + bufferSize;
|
|
||||||
|
|
||||||
int pow = 1;
|
unsigned long PRIME_LEN_ = MAX(sampleRateOfSource / 20, 1024u);
|
||||||
while (fftSize > 2) { pow++; fftSize /= 2; }
|
PRIME_LEN_ = MIN(PRIME_LEN_, 16384u);
|
||||||
fftSize = 2 << pow;
|
PRIME_LEN_ = MAX(PRIME_LEN_, 2 * LPC_ORDER + 1);
|
||||||
|
|
||||||
float * deinterleavedImpulseBuffer = (float *) _mm_malloc(fftSize * sizeof(float) * impulseChannels, 16);
|
unsigned int N_samples_to_add_ = sampleRateOfSource;
|
||||||
if (!deinterleavedImpulseBuffer) {
|
unsigned int N_samples_to_drop_ = sampleRate;
|
||||||
free(impulseBuffer);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < impulseChannels; ++i) {
|
|
||||||
cblas_scopy(sampleCount, impulseBuffer + i, impulseChannels, deinterleavedImpulseBuffer + i * fftSize, 1);
|
|
||||||
vDSP_vclr(deinterleavedImpulseBuffer + i * fftSize + sampleCount, 1, fftSize - sampleCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(impulseBuffer);
|
samples_len(&N_samples_to_add_, &N_samples_to_drop_, 20, 8192u);
|
||||||
|
|
||||||
paddedBufferSize = fftSize;
|
int resamplerLatencyIn = (int)N_samples_to_add_;
|
||||||
fftSizeOver2 = (fftSize + 1) / 2;
|
int resamplerLatencyOut = (int)N_samples_to_drop_;
|
||||||
log2n = log2f(fftSize);
|
|
||||||
log2nhalf = log2n / 2;
|
|
||||||
|
|
||||||
fftSetup = vDSP_create_fftsetup(log2n, FFT_RADIX2);
|
float *tempImpulse = (float *)realloc(impulseBuffer, (sampleCount + resamplerLatencyIn * 2 + 1024) * sizeof(float) * impulseChannels);
|
||||||
if (!fftSetup) {
|
if(!tempImpulse) {
|
||||||
_mm_free(deinterleavedImpulseBuffer);
|
free(impulseBuffer);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
paddedSignal = (float *) _mm_malloc(sizeof(float) * paddedBufferSize, 16);
|
impulseBuffer = tempImpulse;
|
||||||
if (!paddedSignal) {
|
|
||||||
_mm_free(deinterleavedImpulseBuffer);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
signal_fft.realp = (float *) _mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
|
||||||
signal_fft.imagp = (float *) _mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
|
||||||
if (!signal_fft.realp || !signal_fft.imagp) {
|
|
||||||
_mm_free(deinterleavedImpulseBuffer);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
if (!input_filtered_signal_per_channel[0].realp ||
|
|
||||||
!input_filtered_signal_per_channel[0].imagp) {
|
|
||||||
_mm_free(deinterleavedImpulseBuffer);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
if (!input_filtered_signal_per_channel[1].realp ||
|
|
||||||
!input_filtered_signal_per_channel[1].imagp) {
|
|
||||||
_mm_free(deinterleavedImpulseBuffer);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
impulse_responses = (COMPLEX_SPLIT *) calloc(sizeof(COMPLEX_SPLIT), channels * 2);
|
resampledCount += resamplerLatencyOut * 2 + 1024;
|
||||||
if (!impulse_responses) {
|
|
||||||
_mm_free(deinterleavedImpulseBuffer);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < channels; ++i) {
|
float *resampledImpulse = (float *)malloc(resampledCount * sizeof(float) * impulseChannels);
|
||||||
impulse_responses[i * 2 + 0].realp = (float *) _mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
if(!resampledImpulse) {
|
||||||
impulse_responses[i * 2 + 0].imagp = (float *) _mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
free(impulseBuffer);
|
||||||
impulse_responses[i * 2 + 1].realp = (float *) _mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
return nil;
|
||||||
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 ||
|
|
||||||
!impulse_responses[i * 2 + 1].realp || !impulse_responses[i * 2 + 1].imagp) {
|
|
||||||
_mm_free(deinterleavedImpulseBuffer);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
int leftInChannel;
|
|
||||||
int rightInChannel;
|
|
||||||
|
|
||||||
if (impulseChannels == 7) {
|
|
||||||
leftInChannel = speakers_to_hesuvi_7[channels-1][0][i];
|
|
||||||
rightInChannel = speakers_to_hesuvi_7[channels-1][1][i];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
leftInChannel = speakers_to_hesuvi_14[channels-1][0][i];
|
|
||||||
rightInChannel = speakers_to_hesuvi_14[channels-1][1][i];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (leftInChannel == -1 || rightInChannel == -1) {
|
|
||||||
float * temp;
|
|
||||||
if (impulseChannels == 7) {
|
|
||||||
temp = (float *) malloc(sizeof(float) * fftSize);
|
|
||||||
if (!temp) {
|
|
||||||
_mm_free(deinterleavedImpulseBuffer);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
cblas_scopy((int)fftSize, deinterleavedImpulseBuffer + 4 * fftSize, 1, temp, 1);
|
size_t prime = MIN(sampleCount, PRIME_LEN_);
|
||||||
vDSP_vadd(temp, 1, deinterleavedImpulseBuffer + 5 * fftSize, 1, temp, 1, fftSize);
|
|
||||||
|
|
||||||
vDSP_ctoz((DSPComplex *)temp, 2, &impulse_responses[i * 2 + 0], 1, fftSizeOver2);
|
|
||||||
vDSP_ctoz((DSPComplex *)temp, 2, &impulse_responses[i * 2 + 1], 1, fftSizeOver2);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
temp = (float *) malloc(sizeof(float) * fftSize * 2);
|
|
||||||
if (!temp) {
|
|
||||||
_mm_free(deinterleavedImpulseBuffer);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
cblas_scopy((int)fftSize, deinterleavedImpulseBuffer + 4 * fftSize, 1, temp, 1);
|
void *extrapolate_buffer = NULL;
|
||||||
vDSP_vadd(temp, 1, deinterleavedImpulseBuffer + 12 * fftSize, 1, temp, 1, fftSize);
|
size_t extrapolate_buffer_size = 0;
|
||||||
|
|
||||||
cblas_scopy((int)fftSize, deinterleavedImpulseBuffer + 5 * fftSize, 1, temp + fftSize, 1);
|
memmove(impulseBuffer + resamplerLatencyIn * impulseChannels, impulseBuffer, sampleCount * sizeof(float) * impulseChannels);
|
||||||
vDSP_vadd(temp + fftSize, 1, deinterleavedImpulseBuffer + 11 * fftSize, 1, temp + fftSize, 1, fftSize);
|
lpc_extrapolate_bkwd(impulseBuffer + N_samples_to_add_ * impulseChannels, sampleCount, prime, impulseChannels, LPC_ORDER, N_samples_to_add_, &extrapolate_buffer, &extrapolate_buffer_size);
|
||||||
|
lpc_extrapolate_fwd(impulseBuffer + N_samples_to_add_ * impulseChannels, sampleCount, prime, impulseChannels, LPC_ORDER, N_samples_to_add_, &extrapolate_buffer, &extrapolate_buffer_size);
|
||||||
|
free(extrapolate_buffer);
|
||||||
|
|
||||||
vDSP_ctoz((DSPComplex *)temp, 2, &impulse_responses[i * 2 + 0], 1, fftSizeOver2);
|
size_t inputDone = 0;
|
||||||
vDSP_ctoz((DSPComplex *)(temp + fftSize), 2, &impulse_responses[i * 2 + 1], 1, fftSizeOver2);
|
size_t outputDone = 0;
|
||||||
}
|
|
||||||
|
|
||||||
free(temp);
|
error = soxr_oneshot(sampleRateOfSource, sampleRate, impulseChannels, impulseBuffer, sampleCount + N_samples_to_add_ * 2, &inputDone, resampledImpulse, resampledCount, &outputDone, &io_spec, &q_spec, &runtime_spec);
|
||||||
}
|
|
||||||
else {
|
|
||||||
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_fft_zrip(fftSetup, &impulse_responses[i * 2 + 0], 1, log2n, FFT_FORWARD);
|
|
||||||
vDSP_fft_zrip(fftSetup, &impulse_responses[i * 2 + 1], 1, log2n, FFT_FORWARD);
|
|
||||||
}
|
|
||||||
|
|
||||||
_mm_free(deinterleavedImpulseBuffer);
|
|
||||||
|
|
||||||
left_result = (float *) _mm_malloc(sizeof(float) * fftSize, 16);
|
|
||||||
right_result = (float *) _mm_malloc(sizeof(float) * fftSize, 16);
|
|
||||||
if (!left_result || !right_result)
|
|
||||||
return nil;
|
|
||||||
|
|
||||||
prevOverlapLeft = (float *) _mm_malloc(sizeof(float) * fftSize, 16);
|
|
||||||
prevOverlapRight = (float *) _mm_malloc(sizeof(float) * fftSize, 16);
|
|
||||||
if (!prevOverlapLeft || !prevOverlapRight)
|
|
||||||
return nil;
|
|
||||||
|
|
||||||
left_mix_result = (float *) _mm_malloc(sizeof(float) * fftSize, 16);
|
if(error) {
|
||||||
right_mix_result = (float *) _mm_malloc(sizeof(float) * fftSize, 16);
|
free(resampledImpulse);
|
||||||
if (!left_mix_result || !right_mix_result)
|
free(impulseBuffer);
|
||||||
return nil;
|
return nil;
|
||||||
|
}
|
||||||
prevOverlapLength = 0;
|
|
||||||
}
|
outputDone -= N_samples_to_drop_ * 2;
|
||||||
|
|
||||||
return self;
|
memmove(resampledImpulse, resampledImpulse + N_samples_to_drop_ * impulseChannels, outputDone * sizeof(float) * impulseChannels);
|
||||||
|
|
||||||
|
free(impulseBuffer);
|
||||||
|
impulseBuffer = resampledImpulse;
|
||||||
|
sampleCount = (int)outputDone;
|
||||||
|
}
|
||||||
|
|
||||||
|
channelCount = channels;
|
||||||
|
|
||||||
|
bufferSize = 512;
|
||||||
|
fftSize = sampleCount + bufferSize;
|
||||||
|
|
||||||
|
int pow = 1;
|
||||||
|
while(fftSize > 2) {
|
||||||
|
pow++;
|
||||||
|
fftSize /= 2;
|
||||||
|
}
|
||||||
|
fftSize = 2 << pow;
|
||||||
|
|
||||||
|
float *deinterleavedImpulseBuffer = (float *)_mm_malloc(fftSize * sizeof(float) * impulseChannels, 16);
|
||||||
|
if(!deinterleavedImpulseBuffer) {
|
||||||
|
free(impulseBuffer);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(size_t i = 0; i < impulseChannels; ++i) {
|
||||||
|
cblas_scopy(sampleCount, impulseBuffer + i, impulseChannels, deinterleavedImpulseBuffer + i * fftSize, 1);
|
||||||
|
vDSP_vclr(deinterleavedImpulseBuffer + i * fftSize + sampleCount, 1, fftSize - sampleCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(impulseBuffer);
|
||||||
|
|
||||||
|
paddedBufferSize = fftSize;
|
||||||
|
fftSizeOver2 = (fftSize + 1) / 2;
|
||||||
|
log2n = log2f(fftSize);
|
||||||
|
log2nhalf = log2n / 2;
|
||||||
|
|
||||||
|
fftSetup = vDSP_create_fftsetup(log2n, FFT_RADIX2);
|
||||||
|
if(!fftSetup) {
|
||||||
|
_mm_free(deinterleavedImpulseBuffer);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
paddedSignal = (float *)_mm_malloc(sizeof(float) * paddedBufferSize, 16);
|
||||||
|
if(!paddedSignal) {
|
||||||
|
_mm_free(deinterleavedImpulseBuffer);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
signal_fft.realp = (float *)_mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
||||||
|
signal_fft.imagp = (float *)_mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
||||||
|
if(!signal_fft.realp || !signal_fft.imagp) {
|
||||||
|
_mm_free(deinterleavedImpulseBuffer);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
if(!input_filtered_signal_per_channel[0].realp ||
|
||||||
|
!input_filtered_signal_per_channel[0].imagp) {
|
||||||
|
_mm_free(deinterleavedImpulseBuffer);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
if(!input_filtered_signal_per_channel[1].realp ||
|
||||||
|
!input_filtered_signal_per_channel[1].imagp) {
|
||||||
|
_mm_free(deinterleavedImpulseBuffer);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
impulse_responses = (COMPLEX_SPLIT *)calloc(sizeof(COMPLEX_SPLIT), channels * 2);
|
||||||
|
if(!impulse_responses) {
|
||||||
|
_mm_free(deinterleavedImpulseBuffer);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
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].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].imagp = (float *)_mm_malloc(sizeof(float) * fftSizeOver2, 16);
|
||||||
|
|
||||||
|
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) {
|
||||||
|
_mm_free(deinterleavedImpulseBuffer);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
int leftInChannel;
|
||||||
|
int rightInChannel;
|
||||||
|
|
||||||
|
if(impulseChannels == 7) {
|
||||||
|
leftInChannel = speakers_to_hesuvi_7[channels - 1][0][i];
|
||||||
|
rightInChannel = speakers_to_hesuvi_7[channels - 1][1][i];
|
||||||
|
} else {
|
||||||
|
leftInChannel = speakers_to_hesuvi_14[channels - 1][0][i];
|
||||||
|
rightInChannel = speakers_to_hesuvi_14[channels - 1][1][i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(leftInChannel == -1 || rightInChannel == -1) {
|
||||||
|
float *temp;
|
||||||
|
if(impulseChannels == 7) {
|
||||||
|
temp = (float *)malloc(sizeof(float) * fftSize);
|
||||||
|
if(!temp) {
|
||||||
|
_mm_free(deinterleavedImpulseBuffer);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
cblas_scopy((int)fftSize, deinterleavedImpulseBuffer + 4 * fftSize, 1, temp, 1);
|
||||||
|
vDSP_vadd(temp, 1, deinterleavedImpulseBuffer + 5 * fftSize, 1, temp, 1, fftSize);
|
||||||
|
|
||||||
|
vDSP_ctoz((DSPComplex *)temp, 2, &impulse_responses[i * 2 + 0], 1, fftSizeOver2);
|
||||||
|
vDSP_ctoz((DSPComplex *)temp, 2, &impulse_responses[i * 2 + 1], 1, fftSizeOver2);
|
||||||
|
} else {
|
||||||
|
temp = (float *)malloc(sizeof(float) * fftSize * 2);
|
||||||
|
if(!temp) {
|
||||||
|
_mm_free(deinterleavedImpulseBuffer);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
cblas_scopy((int)fftSize, deinterleavedImpulseBuffer + 4 * fftSize, 1, temp, 1);
|
||||||
|
vDSP_vadd(temp, 1, deinterleavedImpulseBuffer + 12 * fftSize, 1, temp, 1, fftSize);
|
||||||
|
|
||||||
|
cblas_scopy((int)fftSize, deinterleavedImpulseBuffer + 5 * fftSize, 1, temp + fftSize, 1);
|
||||||
|
vDSP_vadd(temp + fftSize, 1, deinterleavedImpulseBuffer + 11 * fftSize, 1, temp + fftSize, 1, fftSize);
|
||||||
|
|
||||||
|
vDSP_ctoz((DSPComplex *)temp, 2, &impulse_responses[i * 2 + 0], 1, fftSizeOver2);
|
||||||
|
vDSP_ctoz((DSPComplex *)(temp + fftSize), 2, &impulse_responses[i * 2 + 1], 1, fftSizeOver2);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(temp);
|
||||||
|
} else {
|
||||||
|
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_fft_zrip(fftSetup, &impulse_responses[i * 2 + 0], 1, log2n, FFT_FORWARD);
|
||||||
|
vDSP_fft_zrip(fftSetup, &impulse_responses[i * 2 + 1], 1, log2n, FFT_FORWARD);
|
||||||
|
}
|
||||||
|
|
||||||
|
_mm_free(deinterleavedImpulseBuffer);
|
||||||
|
|
||||||
|
left_result = (float *)_mm_malloc(sizeof(float) * fftSize, 16);
|
||||||
|
right_result = (float *)_mm_malloc(sizeof(float) * fftSize, 16);
|
||||||
|
if(!left_result || !right_result)
|
||||||
|
return nil;
|
||||||
|
|
||||||
|
prevOverlapLeft = (float *)_mm_malloc(sizeof(float) * fftSize, 16);
|
||||||
|
prevOverlapRight = (float *)_mm_malloc(sizeof(float) * fftSize, 16);
|
||||||
|
if(!prevOverlapLeft || !prevOverlapRight)
|
||||||
|
return nil;
|
||||||
|
|
||||||
|
left_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)
|
||||||
|
return nil;
|
||||||
|
|
||||||
|
prevOverlapLength = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
if (fftSetup) vDSP_destroy_fftsetup(fftSetup);
|
if(fftSetup) vDSP_destroy_fftsetup(fftSetup);
|
||||||
|
|
||||||
_mm_free(paddedSignal);
|
|
||||||
|
|
||||||
_mm_free(signal_fft.realp);
|
|
||||||
_mm_free(signal_fft.imagp);
|
|
||||||
|
|
||||||
_mm_free(input_filtered_signal_per_channel[0].realp);
|
_mm_free(paddedSignal);
|
||||||
_mm_free(input_filtered_signal_per_channel[0].imagp);
|
|
||||||
_mm_free(input_filtered_signal_per_channel[1].realp);
|
|
||||||
_mm_free(input_filtered_signal_per_channel[1].imagp);
|
|
||||||
|
|
||||||
if (impulse_responses) {
|
_mm_free(signal_fft.realp);
|
||||||
for (size_t i = 0; i < channelCount * 2; ++i) {
|
_mm_free(signal_fft.imagp);
|
||||||
_mm_free(impulse_responses[i].realp);
|
|
||||||
_mm_free(impulse_responses[i].imagp);
|
|
||||||
}
|
|
||||||
free(impulse_responses);
|
|
||||||
}
|
|
||||||
|
|
||||||
_mm_free(left_result);
|
_mm_free(input_filtered_signal_per_channel[0].realp);
|
||||||
_mm_free(right_result);
|
_mm_free(input_filtered_signal_per_channel[0].imagp);
|
||||||
|
_mm_free(input_filtered_signal_per_channel[1].realp);
|
||||||
_mm_free(prevOverlapLeft);
|
_mm_free(input_filtered_signal_per_channel[1].imagp);
|
||||||
_mm_free(prevOverlapRight);
|
|
||||||
|
|
||||||
_mm_free(left_mix_result);
|
if(impulse_responses) {
|
||||||
_mm_free(right_mix_result);
|
for(size_t i = 0; i < channelCount * 2; ++i) {
|
||||||
|
_mm_free(impulse_responses[i].realp);
|
||||||
|
_mm_free(impulse_responses[i].imagp);
|
||||||
|
}
|
||||||
|
free(impulse_responses);
|
||||||
|
}
|
||||||
|
|
||||||
|
_mm_free(left_result);
|
||||||
|
_mm_free(right_result);
|
||||||
|
|
||||||
|
_mm_free(prevOverlapLeft);
|
||||||
|
_mm_free(prevOverlapRight);
|
||||||
|
|
||||||
|
_mm_free(left_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);
|
||||||
|
|
||||||
vDSP_ctoz((DSPComplex *)paddedSignal, 2, &signal_fft, 1, fftSizeOver2);
|
vDSP_ctoz((DSPComplex *)paddedSignal, 2, &signal_fft, 1, fftSizeOver2);
|
||||||
|
|
||||||
vDSP_fft_zrip(fftSetup, &signal_fft, 1, log2n, FFT_FORWARD);
|
vDSP_fft_zrip(fftSetup, &signal_fft, 1, log2n, FFT_FORWARD);
|
||||||
|
|
||||||
// One channel forward, then multiply and back twice
|
// One channel forward, then multiply and back twice
|
||||||
|
|
||||||
float preserveIRNyq = impulse_responses[i * 2 + 0].imagp[0];
|
float preserveIRNyq = impulse_responses[i * 2 + 0].imagp[0];
|
||||||
float preserveSigNyq = signal_fft.imagp[0];
|
float preserveSigNyq = signal_fft.imagp[0];
|
||||||
impulse_responses[i * 2 + 0].imagp[0] = 0;
|
impulse_responses[i * 2 + 0].imagp[0] = 0;
|
||||||
signal_fft.imagp[0] = 0;
|
signal_fft.imagp[0] = 0;
|
||||||
|
|
||||||
vDSP_zvmul(&signal_fft, 1, &impulse_responses[i * 2 + 0], 1, &input_filtered_signal_per_channel[0], 1, fftSizeOver2, 1);
|
vDSP_zvmul(&signal_fft, 1, &impulse_responses[i * 2 + 0], 1, &input_filtered_signal_per_channel[0], 1, fftSizeOver2, 1);
|
||||||
|
|
||||||
input_filtered_signal_per_channel[0].imagp[0] = preserveIRNyq * preserveSigNyq;
|
input_filtered_signal_per_channel[0].imagp[0] = preserveIRNyq * preserveSigNyq;
|
||||||
impulse_responses[i * 2 + 0].imagp[0] = preserveIRNyq;
|
impulse_responses[i * 2 + 0].imagp[0] = preserveIRNyq;
|
||||||
|
|
||||||
preserveIRNyq = impulse_responses[i * 2 + 1].imagp[0];
|
preserveIRNyq = impulse_responses[i * 2 + 1].imagp[0];
|
||||||
impulse_responses[i * 2 + 1].imagp[0] = 0;
|
impulse_responses[i * 2 + 1].imagp[0] = 0;
|
||||||
|
|
||||||
vDSP_zvmul(&signal_fft, 1, &impulse_responses[i * 2 + 1], 1, &input_filtered_signal_per_channel[1], 1, fftSizeOver2, 1);
|
vDSP_zvmul(&signal_fft, 1, &impulse_responses[i * 2 + 1], 1, &input_filtered_signal_per_channel[1], 1, fftSizeOver2, 1);
|
||||||
|
|
||||||
input_filtered_signal_per_channel[1].imagp[0] = preserveIRNyq * preserveSigNyq;
|
input_filtered_signal_per_channel[1].imagp[0] = preserveIRNyq * preserveSigNyq;
|
||||||
impulse_responses[i * 2 + 1].imagp[0] = preserveIRNyq;
|
impulse_responses[i * 2 + 1].imagp[0] = preserveIRNyq;
|
||||||
|
|
||||||
vDSP_fft_zrip(fftSetup, &input_filtered_signal_per_channel[0], 1, log2n, FFT_INVERSE);
|
vDSP_fft_zrip(fftSetup, &input_filtered_signal_per_channel[0], 1, log2n, FFT_INVERSE);
|
||||||
vDSP_fft_zrip(fftSetup, &input_filtered_signal_per_channel[1], 1, log2n, FFT_INVERSE);
|
vDSP_fft_zrip(fftSetup, &input_filtered_signal_per_channel[1], 1, log2n, FFT_INVERSE);
|
||||||
|
|
||||||
vDSP_ztoc(&input_filtered_signal_per_channel[0], 1, (DSPComplex *)left_result, 2, fftSizeOver2);
|
vDSP_ztoc(&input_filtered_signal_per_channel[0], 1, (DSPComplex *)left_result, 2, fftSizeOver2);
|
||||||
vDSP_ztoc(&input_filtered_signal_per_channel[1], 1, (DSPComplex *)right_result, 2, fftSizeOver2);
|
vDSP_ztoc(&input_filtered_signal_per_channel[1], 1, (DSPComplex *)right_result, 2, fftSizeOver2);
|
||||||
|
|
||||||
vDSP_vadd(left_mix_result, 1, left_result, 1, left_mix_result, 1, fftSize);
|
vDSP_vadd(left_mix_result, 1, left_result, 1, left_mix_result, 1, fftSize);
|
||||||
vDSP_vadd(right_mix_result, 1, right_result, 1, right_mix_result, 1, fftSize);
|
vDSP_vadd(right_mix_result, 1, right_result, 1, right_mix_result, 1, fftSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
prevOverlapLength = (int)(fftSize - countToDo);
|
prevOverlapLength = (int)(fftSize - countToDo);
|
||||||
|
|
||||||
cblas_scopy(prevOverlapLength, left_mix_result + countToDo, 1, prevOverlapLeft, 1);
|
cblas_scopy(prevOverlapLength, left_mix_result + countToDo, 1, prevOverlapLeft, 1);
|
||||||
cblas_scopy(prevOverlapLength, right_mix_result + countToDo, 1, prevOverlapRight, 1);
|
cblas_scopy(prevOverlapLength, right_mix_result + countToDo, 1, prevOverlapRight, 1);
|
||||||
|
|
||||||
vDSP_vsmul(left_mix_result, 1, &scale, left_mix_result, 1, countToDo);
|
vDSP_vsmul(left_mix_result, 1, &scale, left_mix_result, 1, countToDo);
|
||||||
vDSP_vsmul(right_mix_result, 1, &scale, right_mix_result, 1, countToDo);
|
vDSP_vsmul(right_mix_result, 1, &scale, right_mix_result, 1, countToDo);
|
||||||
|
|
||||||
cblas_scopy((int)countToDo, left_mix_result, 1, outBuffer + 0, 2);
|
cblas_scopy((int)countToDo, left_mix_result, 1, outBuffer + 0, 2);
|
||||||
cblas_scopy((int)countToDo, right_mix_result, 1, outBuffer + 1, 2);
|
cblas_scopy((int)countToDo, right_mix_result, 1, outBuffer + 1, 2);
|
||||||
|
|
||||||
inBuffer += countToDo * channelCount;
|
inBuffer += countToDo * channelCount;
|
||||||
outBuffer += countToDo * 2;
|
outBuffer += countToDo * 2;
|
||||||
|
|
||||||
count -= countToDo;
|
count -= countToDo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)reset {
|
- (void)reset {
|
||||||
prevOverlapLength = 0;
|
prevOverlapLength = 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 "AudioDecoder.h"
|
#import "AudioDecoder.h"
|
||||||
#import "Node.h"
|
#import "Node.h"
|
||||||
|
@ -20,32 +20,32 @@
|
||||||
|
|
||||||
@interface InputNode : Node {
|
@interface InputNode : Node {
|
||||||
id<CogDecoder> decoder;
|
id<CogDecoder> decoder;
|
||||||
|
|
||||||
int bytesPerSample;
|
int bytesPerSample;
|
||||||
int bytesPerFrame;
|
int bytesPerFrame;
|
||||||
BOOL floatingPoint;
|
BOOL floatingPoint;
|
||||||
BOOL swapEndian;
|
BOOL swapEndian;
|
||||||
|
|
||||||
BOOL shouldSeek;
|
BOOL shouldSeek;
|
||||||
long seekFrame;
|
long seekFrame;
|
||||||
|
|
||||||
BOOL observersAdded;
|
|
||||||
|
|
||||||
Semaphore *exitAtTheEndOfTheStream;
|
BOOL observersAdded;
|
||||||
|
|
||||||
|
Semaphore *exitAtTheEndOfTheStream;
|
||||||
}
|
}
|
||||||
@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,258 +7,229 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#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;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSDictionary *properties = [decoder properties];
|
NSDictionary *properties = [decoder properties];
|
||||||
int bitsPerSample = [[properties objectForKey:@"bitsPerSample"] intValue];
|
int bitsPerSample = [[properties objectForKey:@"bitsPerSample"] intValue];
|
||||||
int channels = [[properties objectForKey:@"channels"] intValue];
|
int channels = [[properties objectForKey:@"channels"] intValue];
|
||||||
|
|
||||||
bytesPerFrame = ((bitsPerSample + 7) / 8) * channels;
|
bytesPerFrame = ((bitsPerSample + 7) / 8) * channels;
|
||||||
|
|
||||||
nodeFormat = propertiesToASBD(properties);
|
nodeFormat = propertiesToASBD(properties);
|
||||||
nodeLossless = [[properties valueForKey:@"encoding"] isEqualToString:@"lossless"];
|
nodeLossless = [[properties valueForKey:@"encoding"] isEqualToString:@"lossless"];
|
||||||
|
|
||||||
shouldContinue = YES;
|
shouldContinue = YES;
|
||||||
shouldSeek = NO;
|
shouldSeek = NO;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
NSDictionary *properties = [decoder properties];
|
NSDictionary *properties = [decoder properties];
|
||||||
int bitsPerSample = [[properties objectForKey:@"bitsPerSample"] intValue];
|
int bitsPerSample = [[properties objectForKey:@"bitsPerSample"] intValue];
|
||||||
int channels = [[properties objectForKey:@"channels"] intValue];
|
int channels = [[properties objectForKey:@"channels"] intValue];
|
||||||
|
|
||||||
bytesPerFrame = ((bitsPerSample + 7) / 8) * channels;
|
bytesPerFrame = ((bitsPerSample + 7) / 8) * channels;
|
||||||
|
|
||||||
nodeFormat = propertiesToASBD(properties);
|
nodeFormat = propertiesToASBD(properties);
|
||||||
nodeLossless = [[properties valueForKey:@"encoding"] isEqualToString:@"lossless"];
|
nodeLossless = [[properties valueForKey:@"encoding"] isEqualToString:@"lossless"];
|
||||||
|
|
||||||
[self registerObservers];
|
[self registerObservers];
|
||||||
|
|
||||||
shouldContinue = YES;
|
shouldContinue = YES;
|
||||||
shouldSeek = NO;
|
shouldSeek = NO;
|
||||||
|
|
||||||
DLog(@"DONES: %@", decoder);
|
DLog(@"DONES: %@", decoder);
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)registerObservers {
|
||||||
- (void)registerObservers
|
|
||||||
{
|
|
||||||
DLog(@"REGISTERING OBSERVERS");
|
DLog(@"REGISTERING OBSERVERS");
|
||||||
[decoder addObserver:self
|
[decoder addObserver:self
|
||||||
forKeyPath:@"properties"
|
forKeyPath:@"properties"
|
||||||
options:(NSKeyValueObservingOptionNew)
|
options:(NSKeyValueObservingOptionNew)
|
||||||
context:NULL];
|
context:NULL];
|
||||||
|
|
||||||
[decoder addObserver:self
|
[decoder addObserver:self
|
||||||
forKeyPath:@"metadata"
|
forKeyPath:@"metadata"
|
||||||
options:(NSKeyValueObservingOptionNew)
|
options:(NSKeyValueObservingOptionNew)
|
||||||
context:NULL];
|
context:NULL];
|
||||||
|
|
||||||
observersAdded = YES;
|
observersAdded = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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");
|
||||||
|
|
||||||
amountInBuffer = 0;
|
|
||||||
// This resets the converter's buffer
|
|
||||||
[self resetBuffer];
|
|
||||||
[converter resetBuffer];
|
|
||||||
[converter inputFormatDidChange:[[[controller controller] bufferChain] inputFormat]];
|
|
||||||
|
|
||||||
DLog(@"Reset buffer!");
|
amountInBuffer = 0;
|
||||||
|
// This resets the converter's buffer
|
||||||
|
[self resetBuffer];
|
||||||
|
[converter resetBuffer];
|
||||||
|
[converter inputFormatDidChange:[[[controller controller] bufferChain] inputFormat]];
|
||||||
|
|
||||||
|
DLog(@"Reset buffer!");
|
||||||
|
|
||||||
|
DLog(@"SEEKING!");
|
||||||
|
seekError = [decoder seek:seekFrame] < 0;
|
||||||
|
|
||||||
DLog(@"SEEKING!");
|
|
||||||
seekError = [decoder seek:seekFrame] < 0;
|
|
||||||
|
|
||||||
shouldSeek = NO;
|
shouldSeek = NO;
|
||||||
DLog(@"Seeked! Resetting Buffer");
|
DLog(@"Seeked! Resetting Buffer");
|
||||||
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 {
|
||||||
}
|
if(initialBufferFilled == NO) {
|
||||||
else
|
|
||||||
{
|
|
||||||
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;
|
||||||
{
|
shouldClose = NO;
|
||||||
endOfStream = NO;
|
continue;
|
||||||
shouldClose = NO;
|
}
|
||||||
continue;
|
else {
|
||||||
}
|
break;
|
||||||
else
|
}
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldClose)
|
if(shouldClose)
|
||||||
[decoder close];
|
[decoder close];
|
||||||
|
|
||||||
free(inputBuffer);
|
free(inputBuffer);
|
||||||
|
|
||||||
[exitAtTheEndOfTheStream signal];
|
[exitAtTheEndOfTheStream signal];
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeObservers
|
- (void)removeObservers {
|
||||||
{
|
if(observersAdded) {
|
||||||
if (observersAdded)
|
[decoder removeObserver:self forKeyPath:@"properties"];
|
||||||
{
|
[decoder removeObserver:self forKeyPath:@"metadata"];
|
||||||
[decoder removeObserver:self forKeyPath:@"properties"];
|
observersAdded = NO;
|
||||||
[decoder removeObserver:self forKeyPath:@"metadata"];
|
}
|
||||||
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];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -6,37 +6,37 @@
|
||||||
// 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
|
||||||
|
|
||||||
@interface Node : NSObject {
|
@interface Node : NSObject {
|
||||||
ChunkList *buffer;
|
ChunkList *buffer;
|
||||||
Semaphore *semaphore;
|
Semaphore *semaphore;
|
||||||
|
|
||||||
NSRecursiveLock *accessLock;
|
NSRecursiveLock *accessLock;
|
||||||
|
|
||||||
id __weak previousNode;
|
id __weak previousNode;
|
||||||
id __weak controller;
|
id __weak controller;
|
||||||
|
|
||||||
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;
|
||||||
BOOL nodeLossless;
|
BOOL nodeLossless;
|
||||||
}
|
}
|
||||||
- (id)initWithController:(id)c previous:(id)p;
|
- (id)initWithController:(id)c previous:(id)p;
|
||||||
|
|
||||||
- (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,194 +8,169 @@
|
||||||
|
|
||||||
#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];
|
|
||||||
|
accessLock = [[NSRecursiveLock alloc] init];
|
||||||
accessLock = [[NSRecursiveLock alloc] init];
|
|
||||||
|
|
||||||
initialBufferFilled = NO;
|
initialBufferFilled = NO;
|
||||||
|
|
||||||
controller = c;
|
controller = c;
|
||||||
endOfStream = NO;
|
endOfStream = NO;
|
||||||
shouldContinue = YES;
|
shouldContinue = YES;
|
||||||
|
|
||||||
nodeLossless = NO;
|
nodeLossless = NO;
|
||||||
|
|
||||||
[self setPreviousNode:p];
|
[self setPreviousNode:p];
|
||||||
}
|
}
|
||||||
|
|
||||||
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];
|
|
||||||
|
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(initialBufferFilled == NO) {
|
||||||
if (durationLeft < chunkDuration) {
|
initialBufferFilled = YES;
|
||||||
if (initialBufferFilled == NO) {
|
if([controller respondsToSelector:@selector(initialBufferFilled:)])
|
||||||
initialBufferFilled = YES;
|
[controller performSelector:@selector(initialBufferFilled:) withObject:self];
|
||||||
if ([controller respondsToSelector:@selector(initialBufferFilled:)])
|
}
|
||||||
[controller performSelector:@selector(initialBufferFilled:) withObject:self];
|
}
|
||||||
}
|
|
||||||
}
|
if(durationLeft < chunkDuration || shouldReset) {
|
||||||
|
[accessLock unlock];
|
||||||
if (durationLeft < chunkDuration || shouldReset) {
|
[semaphore wait];
|
||||||
[accessLock unlock];
|
[accessLock lock];
|
||||||
[semaphore wait];
|
}
|
||||||
[accessLock lock];
|
|
||||||
}
|
durationLeft = [buffer maxDuration] - [buffer listDuration];
|
||||||
|
}
|
||||||
durationLeft = [buffer maxDuration] - [buffer listDuration];
|
|
||||||
}
|
[buffer addChunk:chunk];
|
||||||
|
|
||||||
[buffer addChunk:chunk];
|
[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;
|
||||||
{
|
[accessLock unlock];
|
||||||
endOfStream = YES;
|
return [[AudioChunk alloc] init];
|
||||||
[accessLock unlock];
|
}
|
||||||
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])
|
|
||||||
{
|
|
||||||
[[previousNode semaphore] signal];
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
if([ret frameCount]) {
|
||||||
|
[[previousNode semaphore] signal];
|
||||||
|
}
|
||||||
|
|
||||||
|
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,22 +8,22 @@
|
||||||
|
|
||||||
#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"
|
||||||
|
|
||||||
@interface OutputNode : Node {
|
@interface OutputNode : Node {
|
||||||
AudioStreamBasicDescription format;
|
AudioStreamBasicDescription format;
|
||||||
|
|
||||||
double amountPlayed;
|
double amountPlayed;
|
||||||
double sampleRatio;
|
double sampleRatio;
|
||||||
OutputCoreAudio *output;
|
OutputCoreAudio *output;
|
||||||
|
|
||||||
BOOL paused;
|
BOOL paused;
|
||||||
BOOL started;
|
BOOL started;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)beginEqualizer:(AudioUnit)eq;
|
- (void)beginEqualizer:(AudioUnit)eq;
|
||||||
|
@ -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,118 +7,102 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#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;
|
||||||
|
|
||||||
paused = YES;
|
paused = YES;
|
||||||
started = NO;
|
started = NO;
|
||||||
|
|
||||||
output = [[OutputCoreAudio alloc] initWithController:self];
|
output = [[OutputCoreAudio alloc] initWithController:self];
|
||||||
|
|
||||||
[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
|
||||||
{
|
// We also have to jump the play position ahead accounting for
|
||||||
// This clears the resampler buffer, but not the input buffer
|
// the data we are flushing
|
||||||
// We also have to jump the play position ahead accounting for
|
|
||||||
// the data we are flushing
|
|
||||||
#if 0
|
#if 0
|
||||||
// We no longer need to do this, because outputchanged converter
|
// We no longer need to do this, because outputchanged converter
|
||||||
// now uses the RefillNode to slap the previous samples into
|
// now uses the RefillNode to slap the previous samples into
|
||||||
|
@ -126,54 +110,46 @@
|
||||||
if (oldSampleRatio)
|
if (oldSampleRatio)
|
||||||
amountPlayed += oldSampleRatio * [[converter buffer] bufferedLength];
|
amountPlayed += oldSampleRatio * [[converter buffer] bufferedLength];
|
||||||
#endif
|
#endif
|
||||||
[converter setOutputFormat:format];
|
[converter setOutputFormat:format];
|
||||||
[converter inputFormatDidChange:[bufferChain inputFormat]];
|
[converter inputFormatDidChange:[bufferChain inputFormat]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@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 "Plugin.h"
|
#import "Plugin.h"
|
||||||
|
@ -18,9 +18,9 @@
|
||||||
#define INPUT_NODE_SEEK
|
#define INPUT_NODE_SEEK
|
||||||
|
|
||||||
@interface RefillNode : Node {
|
@interface RefillNode : Node {
|
||||||
// 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,44 +6,40 @@
|
||||||
// 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
|
||||||
{
|
buffer = [[ChunkList alloc] initWithMaximumDuration:12.0];
|
||||||
// This special node should be able to handle up to four buffers
|
semaphore = [[Semaphore alloc] init];
|
||||||
buffer = [[ChunkList alloc] initWithMaximumDuration:12.0];
|
|
||||||
semaphore = [[Semaphore alloc] init];
|
|
||||||
|
|
||||||
initialBufferFilled = NO;
|
|
||||||
|
|
||||||
controller = c;
|
|
||||||
endOfStream = NO;
|
|
||||||
shouldContinue = YES;
|
|
||||||
|
|
||||||
nodeLossless = NO;
|
|
||||||
|
|
||||||
[self setPreviousNode:p];
|
initialBufferFilled = NO;
|
||||||
}
|
|
||||||
|
controller = c;
|
||||||
return self;
|
endOfStream = NO;
|
||||||
|
shouldContinue = YES;
|
||||||
|
|
||||||
|
nodeLossless = NO;
|
||||||
|
|
||||||
|
[self setPreviousNode:p];
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -6,16 +6,16 @@
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
#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;
|
||||||
id<CogDecoder> theDecoder;
|
id<CogDecoder> theDecoder;
|
||||||
NSMutableArray *cachedObservers;
|
NSMutableArray *cachedObservers;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(id)initWithDecoders:(NSArray *)decoders;
|
- (id)initWithDecoders:(NSArray *)decoders;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -8,200 +8,180 @@
|
||||||
|
|
||||||
#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 *classString2 = (NSString *)obj2;
|
||||||
NSString *classString1 = (NSString *)obj1;
|
|
||||||
NSString *classString2 = (NSString *)obj2;
|
Class class1 = NSClassFromString(classString1);
|
||||||
|
Class class2 = NSClassFromString(classString2);
|
||||||
Class class1 = NSClassFromString(classString1);
|
|
||||||
Class class2 = NSClassFromString(classString2);
|
float priority1 = [class1 priority];
|
||||||
|
float priority2 = [class2 priority];
|
||||||
float priority1 = [class1 priority];
|
|
||||||
float priority2 = [class2 priority];
|
if(priority1 == priority2)
|
||||||
|
return NSOrderedSame;
|
||||||
if (priority1 == priority2) return NSOrderedSame;
|
else if(priority1 > priority2)
|
||||||
else if (priority1 > priority2) return NSOrderedAscending;
|
return NSOrderedAscending;
|
||||||
else return NSOrderedDescending;
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSArray *)fileTypeAssociations {
|
+ (NSArray *)fileTypeAssociations {
|
||||||
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);
|
||||||
{
|
theDecoder = nil;
|
||||||
theDecoders = sortClassesByPriority(decoders);
|
cachedObservers = [[NSMutableArray alloc] init];
|
||||||
theDecoder = nil;
|
}
|
||||||
cachedObservers = [[NSMutableArray alloc] init];
|
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);
|
||||||
{
|
theDecoder = [[decoder alloc] init];
|
||||||
Class decoder = NSClassFromString(classString);
|
for(NSDictionary *obsItem in cachedObservers) {
|
||||||
theDecoder = [[decoder alloc] init];
|
[theDecoder addObserver:[obsItem objectForKey:@"observer"]
|
||||||
for (NSDictionary *obsItem in cachedObservers) {
|
forKeyPath:[obsItem objectForKey:@"keyPath"]
|
||||||
[theDecoder addObserver:[obsItem objectForKey:@"observer"]
|
options:[[obsItem objectForKey:@"options"] unsignedIntegerValue]
|
||||||
forKeyPath:[obsItem objectForKey:@"keyPath"]
|
context:(__bridge void *)([obsItem objectForKey:@"context"])];
|
||||||
options:[[obsItem objectForKey:@"options"] unsignedIntegerValue]
|
}
|
||||||
context:(__bridge void *)([obsItem objectForKey:@"context"])];
|
if([theDecoder open:source])
|
||||||
}
|
return YES;
|
||||||
if ([theDecoder open:source])
|
for(NSDictionary *obsItem in cachedObservers) {
|
||||||
return YES;
|
[theDecoder removeObserver:[obsItem objectForKey:@"observer"] forKeyPath:[obsItem objectForKey:@"keyPath"]];
|
||||||
for (NSDictionary *obsItem in cachedObservers) {
|
}
|
||||||
[theDecoder removeObserver:[obsItem objectForKey:@"observer"] forKeyPath:[obsItem objectForKey:@"keyPath"]];
|
if([source seekable])
|
||||||
}
|
[source seek:0 whence:SEEK_SET];
|
||||||
if ([source seekable])
|
}
|
||||||
[source seek:0 whence:SEEK_SET];
|
theDecoder = nil;
|
||||||
}
|
return NO;
|
||||||
theDecoder = nil;
|
|
||||||
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];
|
[theDecoder close];
|
||||||
[theDecoder close];
|
theDecoder = nil;
|
||||||
theDecoder = nil;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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);
|
||||||
{
|
NSArray *urls = [container urlsForContainerURL:url];
|
||||||
Class container = NSClassFromString(classString);
|
if([urls count])
|
||||||
NSArray * urls = [container urlsForContainerURL:url];
|
return urls;
|
||||||
if ([urls count])
|
}
|
||||||
return urls;
|
return nil;
|
||||||
}
|
|
||||||
return nil;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@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);
|
||||||
{
|
NSDictionary *data = [reader metadataForURL:url];
|
||||||
Class reader = NSClassFromString(classString);
|
if([data count])
|
||||||
NSDictionary * data = [reader metadataForURL:url];
|
return data;
|
||||||
if ([data count])
|
}
|
||||||
return data;
|
return nil;
|
||||||
}
|
|
||||||
return nil;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@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);
|
||||||
{
|
NSDictionary *data = [reader propertiesForSource:source];
|
||||||
Class reader = NSClassFromString(classString);
|
if([data count])
|
||||||
NSDictionary * data = [reader propertiesForSource:source];
|
return data;
|
||||||
if ([data count])
|
if([source seekable])
|
||||||
return data;
|
[source seek:0 whence:SEEK_SET];
|
||||||
if ([source seekable])
|
}
|
||||||
[source seek:0 whence:SEEK_SET];
|
return nil;
|
||||||
}
|
|
||||||
return nil;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -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,46 +29,46 @@
|
||||||
@class OutputNode;
|
@class OutputNode;
|
||||||
|
|
||||||
@interface OutputCoreAudio : NSObject {
|
@interface OutputCoreAudio : NSObject {
|
||||||
OutputNode * outputController;
|
OutputNode *outputController;
|
||||||
|
|
||||||
Semaphore * writeSemaphore;
|
|
||||||
Semaphore * readSemaphore;
|
|
||||||
|
|
||||||
BOOL stopInvoked;
|
|
||||||
BOOL running;
|
|
||||||
BOOL stopping;
|
|
||||||
BOOL stopped;
|
|
||||||
BOOL started;
|
|
||||||
BOOL paused;
|
|
||||||
BOOL stopNext;
|
|
||||||
|
|
||||||
BOOL eqEnabled;
|
|
||||||
|
|
||||||
BOOL streamFormatStarted;
|
|
||||||
|
|
||||||
atomic_long bytesRendered;
|
|
||||||
atomic_long bytesHdcdSustained;
|
|
||||||
|
|
||||||
BOOL listenerapplied;
|
|
||||||
BOOL observersapplied;
|
|
||||||
|
|
||||||
float volume;
|
|
||||||
|
|
||||||
AVAudioFormat *_deviceFormat;
|
|
||||||
|
|
||||||
AudioDeviceID outputDeviceID;
|
Semaphore *writeSemaphore;
|
||||||
AudioStreamBasicDescription deviceFormat; // info about the default device
|
Semaphore *readSemaphore;
|
||||||
AudioStreamBasicDescription streamFormat; // stream format last seen in render callback
|
|
||||||
|
BOOL stopInvoked;
|
||||||
|
BOOL running;
|
||||||
|
BOOL stopping;
|
||||||
|
BOOL stopped;
|
||||||
|
BOOL started;
|
||||||
|
BOOL paused;
|
||||||
|
BOOL stopNext;
|
||||||
|
|
||||||
|
BOOL eqEnabled;
|
||||||
|
|
||||||
|
BOOL streamFormatStarted;
|
||||||
|
|
||||||
|
atomic_long bytesRendered;
|
||||||
|
atomic_long bytesHdcdSustained;
|
||||||
|
|
||||||
|
BOOL listenerapplied;
|
||||||
|
BOOL observersapplied;
|
||||||
|
|
||||||
|
float volume;
|
||||||
|
|
||||||
|
AVAudioFormat *_deviceFormat;
|
||||||
|
|
||||||
|
AudioDeviceID outputDeviceID;
|
||||||
|
AudioStreamBasicDescription deviceFormat; // info about the default device
|
||||||
|
AudioStreamBasicDescription streamFormat; // stream format last seen in render callback
|
||||||
|
|
||||||
|
AUAudioUnit *_au;
|
||||||
|
size_t _bufferSize;
|
||||||
|
|
||||||
|
AudioUnit _eq;
|
||||||
|
|
||||||
|
DownmixProcessor *downmixer;
|
||||||
|
|
||||||
AUAudioUnit *_au;
|
|
||||||
size_t _bufferSize;
|
|
||||||
|
|
||||||
AudioUnit _eq;
|
|
||||||
|
|
||||||
DownmixProcessor * downmixer;
|
|
||||||
|
|
||||||
#ifdef OUTPUT_LOG
|
#ifdef OUTPUT_LOG
|
||||||
FILE *_logFile;
|
FILE *_logFile;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -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
|
||||||
|
@ -19,22 +19,22 @@
|
||||||
+ (BOOL)shouldLoadForOSVersion:(NSOperatingSystemVersion)version;
|
+ (BOOL)shouldLoadForOSVersion:(NSOperatingSystemVersion)version;
|
||||||
@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;
|
||||||
|
|
||||||
+ (NSArray *)urlsForContainerURL:(NSURL *)url;
|
+ (NSArray *)urlsForContainerURL:(NSURL *)url;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@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;
|
||||||
|
@ -16,7 +15,7 @@
|
||||||
|
|
||||||
NSMutableDictionary *decodersByExtension;
|
NSMutableDictionary *decodersByExtension;
|
||||||
NSMutableDictionary *decodersByMimeType;
|
NSMutableDictionary *decodersByMimeType;
|
||||||
|
|
||||||
BOOL configured;
|
BOOL configured;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +34,7 @@
|
||||||
- (void)setup;
|
- (void)setup;
|
||||||
- (void)printPluginInfo;
|
- (void)printPluginInfo;
|
||||||
|
|
||||||
- (void)loadPlugins;
|
- (void)loadPlugins;
|
||||||
- (void)loadPluginsAtPath:(NSString *)path;
|
- (void)loadPluginsAtPath:(NSString *)path;
|
||||||
|
|
||||||
- (void)setupSource:(NSString *)className;
|
- (void)setupSource:(NSString *)className;
|
||||||
|
|
|
@ -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,239 +22,202 @@
|
||||||
|
|
||||||
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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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];
|
||||||
|
|
||||||
self.metadataReaders = [[NSMutableDictionary alloc] init];
|
self.metadataReaders = [[NSMutableDictionary alloc] init];
|
||||||
|
|
||||||
self.propertiesReadersByExtension = [[NSMutableDictionary alloc] init];
|
self.propertiesReadersByExtension = [[NSMutableDictionary alloc] init];
|
||||||
self.propertiesReadersByMimeType = [[NSMutableDictionary alloc] init];
|
self.propertiesReadersByMimeType = [[NSMutableDictionary alloc] init];
|
||||||
|
|
||||||
self.decodersByExtension = [[NSMutableDictionary alloc] init];
|
self.decodersByExtension = [[NSMutableDictionary alloc] init];
|
||||||
self.decodersByMimeType = [[NSMutableDictionary alloc] init];
|
self.decodersByMimeType = [[NSMutableDictionary alloc] init];
|
||||||
|
|
||||||
[self setup];
|
[self setup];
|
||||||
}
|
}
|
||||||
|
|
||||||
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];
|
||||||
|
|
||||||
[self loadPlugins];
|
[self loadPlugins];
|
||||||
[self printPluginInfo];
|
[self printPluginInfo];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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");
|
||||||
{
|
return;
|
||||||
DLog(@"Plugin fails OS version check, ignoring");
|
}
|
||||||
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"];
|
|
||||||
|
|
||||||
[self loadPluginsAtPath:[[NSBundle mainBundle] builtInPlugInsPath]];
|
[self loadPluginsAtPath:[[NSBundle mainBundle] builtInPlugInsPath]];
|
||||||
[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];
|
||||||
{
|
[containers setObject:containerSet forKey:ext];
|
||||||
containerSet = [[NSMutableArray alloc] init];
|
} else
|
||||||
[containers setObject:containerSet forKey:ext];
|
containerSet = [containers objectForKey:ext];
|
||||||
}
|
[containerSet addObject:className];
|
||||||
else
|
|
||||||
containerSet = [containers objectForKey:ext];
|
|
||||||
[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];
|
||||||
{
|
[decodersByExtension setObject:decoders forKey:ext];
|
||||||
decoders = [[NSMutableArray alloc] init];
|
} else
|
||||||
[decodersByExtension setObject:decoders forKey:ext];
|
decoders = [decodersByExtension objectForKey:ext];
|
||||||
}
|
|
||||||
else
|
|
||||||
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];
|
||||||
{
|
[decodersByMimeType setObject:decoders forKey:mimetype];
|
||||||
decoders = [[NSMutableArray alloc] init];
|
} else
|
||||||
[decodersByMimeType setObject:decoders forKey:mimetype];
|
decoders = [decodersByMimeType objectForKey:mimetype];
|
||||||
}
|
[decoders addObject:className];
|
||||||
else
|
|
||||||
decoders = [decodersByMimeType objectForKey:mimetype];
|
|
||||||
[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];
|
||||||
{
|
[metadataReaders setObject:readers forKey:ext];
|
||||||
readers = [[NSMutableArray alloc] init];
|
} else
|
||||||
[metadataReaders setObject:readers forKey:ext];
|
readers = [metadataReaders objectForKey:ext];
|
||||||
}
|
[readers addObject:className];
|
||||||
else
|
|
||||||
readers = [metadataReaders objectForKey:ext];
|
|
||||||
[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];
|
||||||
{
|
[propertiesReadersByExtension setObject:readers forKey:ext];
|
||||||
readers = [[NSMutableArray alloc] init];
|
} else
|
||||||
[propertiesReadersByExtension setObject:readers forKey:ext];
|
readers = [propertiesReadersByExtension objectForKey:ext];
|
||||||
}
|
[readers addObject:className];
|
||||||
else
|
|
||||||
readers = [propertiesReadersByExtension objectForKey:ext];
|
|
||||||
[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];
|
||||||
{
|
[propertiesReadersByMimeType setObject:readers forKey:mimetype];
|
||||||
readers = [[NSMutableArray alloc] init];
|
} else
|
||||||
[propertiesReadersByMimeType setObject:readers forKey:mimetype];
|
readers = [propertiesReadersByMimeType objectForKey:mimetype];
|
||||||
}
|
[readers addObject:className];
|
||||||
else
|
|
||||||
readers = [propertiesReadersByMimeType objectForKey:mimetype];
|
|
||||||
[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);
|
||||||
|
@ -264,7 +227,7 @@ static PluginController *sharedPluginController = nil;
|
||||||
|
|
||||||
ALog(@"Decoders by Extension: %@", self.decodersByExtension);
|
ALog(@"Decoders by Extension: %@", self.decodersByExtension);
|
||||||
ALog(@"Decoders by Mime Type: %@", self.decodersByMimeType);
|
ALog(@"Decoders by Mime Type: %@", self.decodersByMimeType);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// XXX Keep in sync with Info.plist on disk!
|
// XXX Keep in sync with Info.plist on disk!
|
||||||
NSString * plistHeader = @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
|
NSString * plistHeader = @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
|
||||||
|
@ -420,194 +383,167 @@ 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]);
|
||||||
|
|
||||||
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 {
|
||||||
}
|
return nil;
|
||||||
else {
|
}
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
Class container = NSClassFromString(classString);
|
Class container = NSClassFromString(classString);
|
||||||
|
|
||||||
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"])
|
||||||
{
|
[_decoders removeObjectAtIndex:i];
|
||||||
if ([[_decoders objectAtIndex:i] isEqualToString:@"CueSheetDecoder"])
|
else
|
||||||
[_decoders removeObjectAtIndex:i];
|
++i;
|
||||||
else
|
}
|
||||||
++i;
|
return [[CogDecoderMulti alloc] initWithDecoders:_decoders];
|
||||||
}
|
}
|
||||||
return [[CogDecoderMulti alloc] initWithDecoders:_decoders];
|
return [[CogDecoderMulti alloc] initWithDecoders:decoders];
|
||||||
}
|
} else {
|
||||||
return [[CogDecoderMulti alloc] initWithDecoders:decoders];
|
classString = [decoders objectAtIndex:0];
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
classString = [decoders objectAtIndex:0];
|
decoders = [decodersByMimeType objectForKey:[[source mimeType] lowercaseString]];
|
||||||
}
|
if(decoders) {
|
||||||
}
|
if([decoders count] > 1) {
|
||||||
else {
|
return [[CogDecoderMulti alloc] initWithDecoders:decoders];
|
||||||
decoders = [decodersByMimeType objectForKey:[[source mimeType] lowercaseString]];
|
} else {
|
||||||
if (decoders) {
|
classString = [decoders objectAtIndex:0];
|
||||||
if ( [decoders count] > 1 ) {
|
}
|
||||||
return [[CogDecoderMulti alloc] initWithDecoders:decoders];
|
} else {
|
||||||
}
|
classString = @"SilenceDecoder";
|
||||||
else {
|
}
|
||||||
classString = [decoders objectAtIndex:0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
classString = @"SilenceDecoder";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Class decoder = NSClassFromString(classString);
|
Class decoder = NSClassFromString(classString);
|
||||||
|
|
||||||
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"])
|
||||||
{
|
[_readers removeObjectAtIndex:i];
|
||||||
if ([[_readers objectAtIndex:i] isEqualToString:@"CueSheetMetadataReader"])
|
else
|
||||||
[_readers removeObjectAtIndex:i];
|
++i;
|
||||||
else
|
}
|
||||||
++i;
|
return [CogMetadataReaderMulti metadataForURL:url readers:_readers];
|
||||||
}
|
}
|
||||||
return [CogMetadataReaderMulti metadataForURL:url readers:_readers];
|
return [CogMetadataReaderMulti metadataForURL:url readers:readers];
|
||||||
}
|
} else {
|
||||||
return [CogMetadataReaderMulti metadataForURL:url readers:readers];
|
classString = [readers objectAtIndex:0];
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
classString = [readers objectAtIndex:0];
|
return nil;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
Class metadataReader = NSClassFromString(classString);
|
Class metadataReader = NSClassFromString(classString);
|
||||||
|
|
||||||
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];
|
[urlScheme isEqualToString:@"https"])
|
||||||
if ([urlScheme isEqualToString:@"http"] ||
|
|
||||||
[urlScheme isEqualToString:@"https"])
|
|
||||||
return nil;
|
|
||||||
|
|
||||||
NSDictionary *properties = nil;
|
|
||||||
NSString *ext = [url pathExtension];
|
|
||||||
|
|
||||||
id<CogSource> source = [self audioSourceForURL:url];
|
|
||||||
if (![source open:url])
|
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
NSArray *readers = [propertiesReadersByExtension objectForKey:[ext lowercaseString]];
|
|
||||||
NSString *classString = nil;
|
|
||||||
if (readers)
|
|
||||||
{
|
|
||||||
if ( [readers count] > 1 ) {
|
|
||||||
properties = [CogPropertiesReaderMulti propertiesForSource:source readers:readers];
|
|
||||||
if (properties != nil && [properties count])
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
classString = [readers objectAtIndex:0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
readers = [propertiesReadersByMimeType objectForKey:[[source mimeType] lowercaseString]];
|
|
||||||
if (readers)
|
|
||||||
{
|
|
||||||
if ( [readers count] > 1 ) {
|
|
||||||
properties = [CogPropertiesReaderMulti propertiesForSource:source readers:readers];
|
|
||||||
if (properties != nil && [properties count])
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
classString = [readers objectAtIndex:0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (classString)
|
NSDictionary *properties = nil;
|
||||||
{
|
NSString *ext = [url pathExtension];
|
||||||
|
|
||||||
|
id<CogSource> source = [self audioSourceForURL:url];
|
||||||
|
if(![source open:url])
|
||||||
|
return nil;
|
||||||
|
|
||||||
|
NSArray *readers = [propertiesReadersByExtension objectForKey:[ext lowercaseString]];
|
||||||
|
NSString *classString = nil;
|
||||||
|
if(readers) {
|
||||||
|
if([readers count] > 1) {
|
||||||
|
properties = [CogPropertiesReaderMulti propertiesForSource:source readers:readers];
|
||||||
|
if(properties != nil && [properties count])
|
||||||
|
return properties;
|
||||||
|
} else {
|
||||||
|
classString = [readers objectAtIndex:0];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
readers = [propertiesReadersByMimeType objectForKey:[[source mimeType] lowercaseString]];
|
||||||
|
if(readers) {
|
||||||
|
if([readers count] > 1) {
|
||||||
|
properties = [CogPropertiesReaderMulti propertiesForSource:source readers:readers];
|
||||||
|
if(properties != nil && [properties count])
|
||||||
|
return properties;
|
||||||
|
} else {
|
||||||
|
classString = [readers objectAtIndex:0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSDictionary *properties = [decoder properties];
|
NSDictionary *properties = [decoder properties];
|
||||||
|
|
||||||
[decoder close];
|
[decoder close];
|
||||||
|
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)putMetadataInURL:(NSURL *)url
|
- (int)putMetadataInURL:(NSURL *)url {
|
||||||
{
|
return 0;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
typedef NS_ENUM(NSInteger, CogStatus) {
|
typedef NS_ENUM(NSInteger, CogStatus) {
|
||||||
CogStatusStopped = 0,
|
CogStatusStopped = 0,
|
||||||
CogStatusPaused,
|
CogStatusPaused,
|
||||||
CogStatusPlaying,
|
CogStatusPlaying,
|
||||||
CogStatusStopping,
|
CogStatusStopping,
|
||||||
};
|
};
|
||||||
|
|
|
@ -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,41 +8,34 @@
|
||||||
|
|
||||||
#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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -24,23 +24,22 @@
|
||||||
|
|
||||||
@class PlaylistEntry;
|
@class PlaylistEntry;
|
||||||
|
|
||||||
@interface AudioScrobbler : NSObject
|
@interface AudioScrobbler : NSObject {
|
||||||
{
|
NSString *_pluginID;
|
||||||
NSString *_pluginID;
|
NSMutableArray *_queue;
|
||||||
NSMutableArray *_queue;
|
|
||||||
|
|
||||||
BOOL _audioScrobblerThreadCompleted;
|
BOOL _audioScrobblerThreadCompleted;
|
||||||
BOOL _keepProcessingAudioScrobblerCommands;
|
BOOL _keepProcessingAudioScrobblerCommands;
|
||||||
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,128 +28,117 @@
|
||||||
// ========================================
|
// ========================================
|
||||||
// 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:@"&"
|
||||||
withString:@"&&"
|
withString:@"&&"
|
||||||
options:NSLiteralSearch
|
options:NSLiteralSearch
|
||||||
range:NSMakeRange(0, [result length])];
|
range:NSMakeRange(0, [result length])];
|
||||||
|
|
||||||
return (nil == result ? @"" : result);
|
return (nil == result ? @"" : result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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) {
|
if([[app bundleIdentifier] isEqualToString:@"fm.last.Last.fm"] ||
|
||||||
if([[app bundleIdentifier] isEqualToString:@"fm.last.Last.fm"] ||
|
[[app bundleIdentifier] isEqualToString:@"fm.last.Scrobbler"]) {
|
||||||
[[app bundleIdentifier] isEqualToString:@"fm.last.Scrobbler"]) {
|
running = YES;
|
||||||
running = YES;
|
break;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
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"];
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_keepProcessingAudioScrobblerCommands = YES;
|
_keepProcessingAudioScrobblerCommands = YES;
|
||||||
|
|
||||||
kern_return_t result = semaphore_create(mach_task_self(), &_semaphore, SYNC_POLICY_FIFO, 0);
|
kern_return_t result = semaphore_create(mach_task_self(), &_semaphore, SYNC_POLICY_FIFO, 0);
|
||||||
|
|
||||||
if(KERN_SUCCESS != result) {
|
if(KERN_SUCCESS != result) {
|
||||||
ALog(@"Couldn't create semaphore (%s).", mach_error_type(result));
|
ALog(@"Couldn't create semaphore (%s).", mach_error_type(result));
|
||||||
|
|
||||||
self = nil;
|
self = nil;
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
[NSThread detachNewThreadSelector:@selector(processAudioScrobblerCommands:) toTarget:self withObject:nil];
|
[NSThread detachNewThreadSelector:@selector(processAudioScrobblerCommands:) toTarget:self withObject:nil];
|
||||||
}
|
}
|
||||||
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]),
|
escapeForLastFM([pe title]),
|
||||||
escapeForLastFM([pe title]),
|
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,119 +151,109 @@ 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 };
|
NSString *command = nil;
|
||||||
NSString *command = nil;
|
NSString *response = nil;
|
||||||
NSString *response = nil;
|
in_port_t port = 33367;
|
||||||
in_port_t port = 33367;
|
|
||||||
|
|
||||||
while([self keepProcessingAudioScrobblerCommands]) {
|
|
||||||
@autoreleasepool {
|
|
||||||
|
|
||||||
// Get the first command to be sent
|
while([self keepProcessingAudioScrobblerCommands]) {
|
||||||
@synchronized([self queue]) {
|
@autoreleasepool {
|
||||||
if ([[self queue] count]) {
|
// Get the first command to be sent
|
||||||
command = [[self queue] objectAtIndex:0];
|
@synchronized([self queue]) {
|
||||||
[[self queue] removeObjectAtIndex:0];
|
if([[self queue] count]) {
|
||||||
}
|
command = [[self queue] objectAtIndex:0];
|
||||||
}
|
[[self queue] removeObjectAtIndex:0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(nil != command) {
|
if(nil != command) {
|
||||||
@try {
|
@try {
|
||||||
if([client connectToHost:@"localhost" port:port]) {
|
if([client connectToHost:@"localhost" port:port]) {
|
||||||
port = [client connectedPort];
|
port = [client connectedPort];
|
||||||
[client send:command];
|
[client send:command];
|
||||||
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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@catch(NSException *exception) {
|
@catch(NSException *exception) {
|
||||||
command = nil;
|
command = nil;
|
||||||
|
|
||||||
[client shutdown];
|
[client shutdown];
|
||||||
// ALog(@"Exception: %@",exception);
|
// ALog(@"Exception: %@",exception);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
semaphore_timedwait([self semaphore], timeout);
|
semaphore_timedwait([self semaphore], timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send a final stop command to cleanup
|
// Send a final stop command to cleanup
|
||||||
@try {
|
@try {
|
||||||
if([client connectToHost:@"localhost" port:port]) {
|
if([client connectToHost:@"localhost" port:port]) {
|
||||||
[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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@catch(NSException *exception) {
|
@catch(NSException *exception) {
|
||||||
[client shutdown];
|
[client shutdown];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self setAudioScrobblerThreadCompleted:YES];
|
[self setAudioScrobblerThreadCompleted:YES];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is a port of the BlockingClient client class from
|
* This is a port of the BlockingClient client class from
|
||||||
* the Last.fm ScrobSub library by sharevari
|
* the Last.fm ScrobSub library by sharevari
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -29,135 +29,127 @@
|
||||||
|
|
||||||
#import "Logging.h"
|
#import "Logging.h"
|
||||||
|
|
||||||
#define kBufferSize 1024
|
#define kBufferSize 1024
|
||||||
#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;
|
||||||
struct hostent *hostinfo;
|
struct hostent *hostinfo;
|
||||||
|
|
||||||
address = inet_addr([hostname cStringUsingEncoding:NSASCIIStringEncoding]);
|
address = inet_addr([hostname cStringUsingEncoding:NSASCIIStringEncoding]);
|
||||||
|
|
||||||
if(INADDR_NONE == address) {
|
if(INADDR_NONE == address) {
|
||||||
hostinfo = gethostbyname([hostname cStringUsingEncoding:NSASCIIStringEncoding]);
|
hostinfo = gethostbyname([hostname cStringUsingEncoding:NSASCIIStringEncoding]);
|
||||||
if(NULL == hostinfo) {
|
if(NULL == hostinfo) {
|
||||||
ALog(@"AudioScrobblerClient error: Unable to resolve address for \"%@\".", hostname);
|
ALog(@"AudioScrobblerClient error: Unable to resolve address for \"%@\".", hostname);
|
||||||
return INADDR_NONE;
|
return INADDR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
address = *((in_addr_t *)hostinfo->h_addr_list[0]);
|
address = *((in_addr_t *)hostinfo->h_addr_list[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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;
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
|
||||||
if(INADDR_NONE != remoteAddress)
|
if(INADDR_NONE != remoteAddress)
|
||||||
return [self connectToSocket:remoteAddress port:port];
|
return [self connectToSocket:remoteAddress port:port];
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
if(NO == [self isConnected]) {
|
if(NO == [self isConnected]) {
|
||||||
ALog(@"AudioScrobblerClient error: Can't send data, client not connected");
|
ALog(@"AudioScrobblerClient error: Can't send data, client not connected");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(totalBytesSent < bytesToSend && -1 != bytesSent) {
|
while(totalBytesSent < bytesToSend && -1 != bytesSent) {
|
||||||
bytesSent = send(_socket, utf8data + totalBytesSent, bytesToSend - totalBytesSent, 0);
|
bytesSent = send(_socket, utf8data + totalBytesSent, bytesToSend - totalBytesSent, 0);
|
||||||
|
|
||||||
if(-1 == bytesSent || 0 == bytesSent)
|
if(-1 == bytesSent || 0 == bytesSent)
|
||||||
ALog(@"AudioScrobblerClient error: Unable to send data through socket: %s", strerror(errno));
|
ALog(@"AudioScrobblerClient error: Unable to send data through socket: %s", strerror(errno));
|
||||||
|
|
||||||
totalBytesSent += bytesSent;
|
totalBytesSent += bytesSent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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;
|
NSString *result = nil;
|
||||||
NSString *result = nil;
|
|
||||||
|
|
||||||
if(NO == [self isConnected]) {
|
if(NO == [self isConnected]) {
|
||||||
ALog(@"AudioScrobblerClient error: Can't receive data, client not connected");
|
ALog(@"AudioScrobblerClient error: Can't receive data, client not connected");
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
bytesRead = recv(_socket, buffer, readSize, 0);
|
bytesRead = recv(_socket, buffer, readSize, 0);
|
||||||
if(-1 == bytesRead || 0 == bytesRead) {
|
if(-1 == bytesRead || 0 == bytesRead) {
|
||||||
ALog(@"AudioScrobblerClient error: Unable to receive data through socket: %s", strerror(errno));
|
ALog(@"AudioScrobblerClient error: Unable to receive data through socket: %s", strerror(errno));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if('\n' == buffer[bytesRead - 1]) {
|
if('\n' == buffer[bytesRead - 1]) {
|
||||||
--bytesRead;
|
--bytesRead;
|
||||||
keepGoing = NO;
|
keepGoing = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer[bytesRead] = '\0';
|
buffer[bytesRead] = '\0';
|
||||||
result = [[NSString alloc] initWithUTF8String:buffer];
|
result = [[NSString alloc] initWithUTF8String:buffer];
|
||||||
|
|
||||||
} while(keepGoing);
|
} while(keepGoing);
|
||||||
|
|
||||||
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]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = shutdown(_socket, SHUT_WR);
|
result = shutdown(_socket, SHUT_WR);
|
||||||
if(-1 == result)
|
if(-1 == result)
|
||||||
ALog(@"AudioScrobblerClient error: Socket shutdown failed: %s", strerror(errno));
|
ALog(@"AudioScrobblerClient error: Socket shutdown failed: %s", strerror(errno));
|
||||||
|
@ -166,36 +158,34 @@ addressForHost(NSString *hostname)
|
||||||
bytesRead = recv(_socket, buffer, kBufferSize, 0);
|
bytesRead = recv(_socket, buffer, kBufferSize, 0);
|
||||||
if(-1 == bytesRead)
|
if(-1 == bytesRead)
|
||||||
ALog(@"AudioScrobblerClient error: Waiting for shutdown confirmation failed: %s", strerror(errno));
|
ALog(@"AudioScrobblerClient error: Waiting for shutdown confirmation failed: %s", strerror(errno));
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = close(_socket);
|
result = close(_socket);
|
||||||
if(-1 == result)
|
if(-1 == result)
|
||||||
ALog(@"Couldn't close socket (%s)", strerror(errno));
|
ALog(@"Couldn't close socket (%s)", strerror(errno));
|
||||||
|
|
||||||
_socket = -1;
|
_socket = -1;
|
||||||
_port = 0;
|
_port = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@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;
|
||||||
|
|
||||||
int result;
|
int result;
|
||||||
do {
|
do {
|
||||||
struct sockaddr_in socketAddress;
|
struct sockaddr_in socketAddress;
|
||||||
|
|
||||||
_socket = socket(AF_INET, SOCK_STREAM, 0);
|
_socket = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if(-1 == _socket) {
|
if(-1 == _socket) {
|
||||||
|
@ -203,9 +193,9 @@ addressForHost(NSString *hostname)
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
socketAddress.sin_family = AF_INET;
|
socketAddress.sin_family = AF_INET;
|
||||||
socketAddress.sin_addr.s_addr = remoteAddress;
|
socketAddress.sin_addr.s_addr = remoteAddress;
|
||||||
socketAddress.sin_port = htons(_port);
|
socketAddress.sin_port = htons(_port);
|
||||||
|
|
||||||
result = connect(_socket, (const struct sockaddr *)&socketAddress, sizeof(struct sockaddr_in));
|
result = connect(_socket, (const struct sockaddr *)&socketAddress, sizeof(struct sockaddr_in));
|
||||||
if(-1 == result) {
|
if(-1 == result) {
|
||||||
|
@ -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,43 +12,37 @@
|
||||||
|
|
||||||
@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:@""];
|
||||||
|
|
||||||
[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];
|
||||||
|
|
||||||
NSAlert *alert = [[NSAlert alloc] init];
|
NSAlert *alert = [[NSAlert alloc] init];
|
||||||
[alert setMessageText:NSLocalizedString(@"FeedbackFailedMessageText", @"")];
|
[alert setMessageText:NSLocalizedString(@"FeedbackFailedMessageText", @"")];
|
||||||
[alert setInformativeText:NSLocalizedString(@"FeedbackFailedInformativeText", @"")];
|
[alert setInformativeText:NSLocalizedString(@"FeedbackFailedInformativeText", @"")];
|
||||||
|
|
||||||
[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,22 +52,19 @@
|
||||||
[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];
|
||||||
|
|
||||||
NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
|
NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
|
||||||
|
|
||||||
[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];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,12 +15,12 @@
|
||||||
NSString *subject;
|
NSString *subject;
|
||||||
NSString *message;
|
NSString *message;
|
||||||
NSString *version;
|
NSString *version;
|
||||||
|
|
||||||
id<FeedbackSocketDelegate> delegate;
|
id<FeedbackSocketDelegate> delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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,97 +12,82 @@
|
||||||
|
|
||||||
@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);
|
NSString *m = encodeForURL(message);
|
||||||
NSString *m = encodeForURL(message);
|
NSString *v = encodeForURL(version);
|
||||||
NSString *v = encodeForURL(version);
|
|
||||||
|
NSString *postString = [NSString stringWithFormat:@"from=%@&subject=%@&message=%@&version=%@", f, s, m, v];
|
||||||
NSString *postString = [NSString stringWithFormat:@"from=%@&subject=%@&message=%@&version=%@", f, s, m, v];
|
|
||||||
|
NSData *postData = [postString dataUsingEncoding:NSASCIIStringEncoding];
|
||||||
NSData *postData = [postString dataUsingEncoding:NSASCIIStringEncoding];
|
|
||||||
|
NSURL *url = [NSURL URLWithString:@"https://kode54.net/cog/feedback.php"];
|
||||||
NSURL *url = [NSURL URLWithString:@"https://kode54.net/cog/feedback.php"];
|
NSMutableURLRequest *post = [NSMutableURLRequest requestWithURL:url];
|
||||||
NSMutableURLRequest *post = [NSMutableURLRequest requestWithURL:url];
|
|
||||||
|
[post addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
|
||||||
[post addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
|
[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];
|
||||||
{
|
} else {
|
||||||
[self performSelectorOnMainThread:@selector(returnSuccess:) withObject:nil waitUntilDone:NO];
|
[self performSelectorOnMainThread:@selector(returnFailure:) withObject:nil waitUntilDone:NO];
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
|
||||||
[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];
|
||||||
[self setSubject:s];
|
[self setSubject:s];
|
||||||
[self setMessage:m];
|
[self setMessage:m];
|
||||||
[self setVersion:v];
|
[self setVersion:v];
|
||||||
|
|
||||||
[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,38 +9,33 @@
|
||||||
#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"];
|
||||||
{
|
artist = [metadata valueForKey:@"artist"];
|
||||||
title = [metadata valueForKey:@"title"];
|
}
|
||||||
artist = [metadata valueForKey:@"artist"];
|
|
||||||
}
|
if(title && [title length]) {
|
||||||
|
if(artist && [artist length]) {
|
||||||
if (title && [title length])
|
display = [[u fragment] stringByAppendingFormat:@": %@ - %@", artist, title];
|
||||||
{
|
} else {
|
||||||
if (artist && [artist length]) { display = [[u fragment] stringByAppendingFormat:@": %@ - %@", artist, title];}
|
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,23 +15,20 @@
|
||||||
|
|
||||||
@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];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self setSubpaths:paths];
|
[self setSubpaths:paths];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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]
|
||||||
return NO;
|
options:(NSDirectoryEnumerationSkipsSubdirectoryDescendants | NSDirectoryEnumerationSkipsPackageDescendants | NSDirectoryEnumerationSkipsHiddenFiles)
|
||||||
}];
|
errorHandler:^BOOL(NSURL *url, NSError *error) {
|
||||||
|
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
|
||||||
|
|
|
@ -14,158 +14,156 @@
|
||||||
#import "Logging.h"
|
#import "Logging.h"
|
||||||
|
|
||||||
static NSURL *defaultMusicDirectory(void) {
|
static NSURL *defaultMusicDirectory(void) {
|
||||||
return [[NSFileManager defaultManager] URLForDirectory:NSMusicDirectory
|
return [[NSFileManager defaultManager] URLForDirectory:NSMusicDirectory
|
||||||
inDomain:NSUserDomainMask
|
inDomain:NSUserDomainMask
|
||||||
appropriateForURL:nil
|
appropriateForURL:nil
|
||||||
create:NO
|
create:NO
|
||||||
error:nil];
|
error:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
@interface FileTreeDataSource()
|
@interface FileTreeDataSource ()
|
||||||
|
|
||||||
@property NSURL *rootURL;
|
@property NSURL *rootURL;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation FileTreeDataSource {
|
@implementation FileTreeDataSource {
|
||||||
PathNode *rootNode;
|
PathNode *rootNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (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];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)awakeFromNib {
|
- (void)awakeFromNib {
|
||||||
[self.pathControl setTarget:self];
|
[self.pathControl setTarget:self];
|
||||||
[self.pathControl setAction:@selector(pathControlAction:)];
|
[self.pathControl setAction:@selector(pathControlAction:)];
|
||||||
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self
|
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self
|
||||||
forKeyPath:@"values.fileTreeRootURL"
|
forKeyPath:@"values.fileTreeRootURL"
|
||||||
options:NSKeyValueObservingOptionNew |
|
options:NSKeyValueObservingOptionNew |
|
||||||
NSKeyValueObservingOptionInitial
|
NSKeyValueObservingOptionInitial
|
||||||
context:nil];
|
context:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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 {
|
||||||
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);
|
||||||
self.rootURL = [NSURL URLWithString:url];
|
self.rootURL = [NSURL URLWithString:url];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURL *)rootURL {
|
- (NSURL *)rootURL {
|
||||||
return [rootNode URL];
|
return [rootNode URL];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setRootURL:(NSURL *)rootURL {
|
- (void)setRootURL:(NSURL *)rootURL {
|
||||||
if (![[NSFileManager defaultManager] fileExistsAtPath:[rootURL path]]) {
|
if(![[NSFileManager defaultManager] fileExistsAtPath:[rootURL path]]) {
|
||||||
rootURL = defaultMusicDirectory();
|
rootURL = defaultMusicDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
rootNode = [[DirectoryNode alloc] initWithDataSource:self url:rootURL];
|
rootNode = [[DirectoryNode alloc] initWithDataSource:self url:rootURL];
|
||||||
|
|
||||||
[self.watcher setPath:[rootURL path]];
|
[self.watcher setPath:[rootURL path]];
|
||||||
|
|
||||||
[self reloadPathNode:rootNode];
|
[self reloadPathNode:rootNode];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (PathNode *)nodeForPath:(NSString *)path {
|
- (PathNode *)nodeForPath:(NSString *)path {
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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];
|
||||||
[self reloadPathNode:node];
|
[self reloadPathNode:node];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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 {
|
||||||
PathNode *n = (item == nil ? rootNode : item);
|
PathNode *n = (item == nil ? rootNode : item);
|
||||||
|
|
||||||
return ![n isLeaf];
|
return ![n isLeaf];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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 {
|
||||||
PathNode *n = (item == nil ? rootNode : item);
|
PathNode *n = (item == nil ? rootNode : item);
|
||||||
|
|
||||||
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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
|
||||||
@interface FileTreeOutlineView : NSOutlineView {
|
@interface FileTreeOutlineView : NSOutlineView {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,71 +6,61 @@
|
||||||
// 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)) {
|
||||||
|
[(FileTreeController *)[self delegate] addToPlaylistExternal:self];
|
||||||
if (modifiers == 0 && (c == NSEnterCharacter || c == NSCarriageReturnCharacter))
|
|
||||||
{
|
return;
|
||||||
[(FileTreeController *)[self delegate] addToPlaylistExternal:self];
|
} else if(modifiers == 0 && c == ' ') {
|
||||||
|
[(FileTreeController *)[self delegate] playPauseResume:self];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (modifiers == 0 && c == ' ')
|
}
|
||||||
{
|
|
||||||
[(FileTreeController *)[self delegate] playPauseResume:self];
|
[super keyDown:e];
|
||||||
return;
|
|
||||||
}
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
[super keyDown:e];
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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];
|
||||||
{
|
} else if(!currentRowIsSelected) {
|
||||||
[self deselectAll:self];
|
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:iRow] byExtendingSelection:NO];
|
||||||
}
|
}
|
||||||
else if (!currentRowIsSelected)
|
|
||||||
{
|
return contextMenu;
|
||||||
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:iRow] byExtendingSelection:NO];
|
|
||||||
}
|
|
||||||
|
|
||||||
return contextMenu;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -15,9 +15,9 @@
|
||||||
@interface FileTreeViewController : SideViewController {
|
@interface FileTreeViewController : SideViewController {
|
||||||
IBOutlet PlaylistLoader *playlistLoader;
|
IBOutlet PlaylistLoader *playlistLoader;
|
||||||
IBOutlet PlaybackController *playbackController;
|
IBOutlet PlaybackController *playbackController;
|
||||||
IBOutlet FileTreeOutlineView *fileTreeOutlineView;
|
IBOutlet FileTreeOutlineView *fileTreeOutlineView;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (FileTreeOutlineView*)outlineView;
|
- (FileTreeOutlineView *)outlineView;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -7,45 +7,38 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -10,13 +10,12 @@
|
||||||
|
|
||||||
@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;
|
||||||
|
|
||||||
NSArray *subpaths;
|
NSArray *subpaths;
|
||||||
|
@ -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,166 +12,138 @@
|
||||||
|
|
||||||
#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;
|
||||||
{
|
CFURLRef urlRef = CFURLCreateByResolvingBookmarkData(kCFAllocatorDefault, bookmarkRef, kCFURLBookmarkResolutionWithSecurityScope, NULL, NULL, &isStale, &error);
|
||||||
Boolean isStale;
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSURL *u = [NSURL fileURLWithPath:s];
|
NSURL *u = [NSURL fileURLWithPath:s];
|
||||||
NSString *displayName = [[NSFileManager defaultManager] displayNameAtPath:[u path]];
|
NSString *displayName = [[NSFileManager defaultManager] displayNameAtPath:[u path]];
|
||||||
|
|
||||||
PathNode *newNode;
|
|
||||||
|
|
||||||
//DLog(@"Before: %@", u);
|
|
||||||
u = resolveAliases(u);
|
|
||||||
//DLog(@"After: %@", u);
|
|
||||||
|
|
||||||
BOOL isDir;
|
PathNode *newNode;
|
||||||
|
|
||||||
if ([[s pathExtension] caseInsensitiveCompare:@"savedSearch"] == NSOrderedSame)
|
// DLog(@"Before: %@", u);
|
||||||
{
|
u = resolveAliases(u);
|
||||||
|
// DLog(@"After: %@", u);
|
||||||
|
|
||||||
|
BOOL isDir;
|
||||||
|
|
||||||
|
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];
|
||||||
}
|
}
|
||||||
|
|
||||||
[newSubpathsDirs addObjectsFromArray:newSubpaths];
|
[newSubpathsDirs addObjectsFromArray:newSubpaths];
|
||||||
[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,10 +9,9 @@
|
||||||
#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;
|
||||||
|
|
||||||
IBOutlet id delegate;
|
IBOutlet id delegate;
|
||||||
}
|
}
|
||||||
|
@ -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,81 +9,74 @@
|
||||||
#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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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
|
|
||||||
NSArray *pathsToWatch = @[path];
|
|
||||||
|
|
||||||
context = (FSEventStreamContext*)malloc(sizeof(FSEventStreamContext));
|
// Create FSEvent stream
|
||||||
context->version = 0;
|
NSArray *pathsToWatch = @[path];
|
||||||
context->info = (__bridge void *)self;
|
|
||||||
context->retain = NULL;
|
context = (FSEventStreamContext *)malloc(sizeof(FSEventStreamContext));
|
||||||
context->release = NULL;
|
context->version = 0;
|
||||||
|
context->info = (__bridge void *)self;
|
||||||
|
context->retain = NULL;
|
||||||
|
context->release = NULL;
|
||||||
|
|
||||||
|
// Create the stream, passing in a callback
|
||||||
|
stream = FSEventStreamCreate(NULL,
|
||||||
|
&myFSEventCallback,
|
||||||
|
context,
|
||||||
|
(__bridge CFArrayRef)pathsToWatch,
|
||||||
|
kFSEventStreamEventIdSinceNow, // Or a previous event ID
|
||||||
|
1.0, // latency in seconds
|
||||||
|
kFSEventStreamCreateFlagNone // Watch this and all its subdirectories
|
||||||
|
);
|
||||||
|
|
||||||
|
FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
|
||||||
|
|
||||||
// Create the stream, passing in a callback
|
|
||||||
stream = FSEventStreamCreate(NULL,
|
|
||||||
&myFSEventCallback,
|
|
||||||
context,
|
|
||||||
(__bridge CFArrayRef)pathsToWatch,
|
|
||||||
kFSEventStreamEventIdSinceNow, // Or a previous event ID
|
|
||||||
1.0, //latency in seconds
|
|
||||||
kFSEventStreamCreateFlagNone // Watch this and all its subdirectories
|
|
||||||
);
|
|
||||||
|
|
||||||
FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
|
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#import "PathNode.h"
|
#import "PathNode.h"
|
||||||
|
|
||||||
@interface SmartFolderNode : PathNode {
|
@interface SmartFolderNode : PathNode {
|
||||||
MDQueryRef _query;
|
MDQueryRef _query;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -15,87 +15,76 @@
|
||||||
|
|
||||||
@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"];
|
||||||
|
|
||||||
// Ugh, Carbon from now on...
|
// Ugh, Carbon from now on...
|
||||||
MDQueryRef query = MDQueryCreate(kCFAllocatorDefault, (CFStringRef)rawQuery, NULL, NULL);
|
MDQueryRef query = MDQueryCreate(kCFAllocatorDefault, (CFStringRef)rawQuery, NULL, NULL);
|
||||||
_query = query;
|
_query = query;
|
||||||
|
|
||||||
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];
|
||||||
}
|
}
|
||||||
|
|
||||||
MDQueryEnableUpdates(query);
|
MDQueryEnableUpdates(query);
|
||||||
|
|
||||||
DLog(@"Query update!");
|
DLog(@"Query update!");
|
||||||
|
|
||||||
[self processPaths:[results sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]];
|
[self processPaths:[results sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]];
|
||||||
|
|
||||||
[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,43 +8,39 @@
|
||||||
|
|
||||||
#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;
|
||||||
|
|
||||||
if(nil == object || NO == [object isKindOfClass:[NSNumber class]]) {
|
if(nil == object || NO == [object isKindOfClass:[NSNumber class]]) {
|
||||||
return [NSString string];
|
return [NSString string];
|
||||||
}
|
}
|
||||||
|
|
||||||
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];
|
||||||
|
|
||||||
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]];
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
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];
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,7 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
|
||||||
@interface IndexFormatter : NSFormatter {
|
@interface IndexFormatter : NSFormatter {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -8,40 +8,36 @@
|
||||||
|
|
||||||
#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;
|
||||||
|
|
||||||
if(nil == object || NO == [object isKindOfClass:[NSNumber class]]) {
|
if(nil == object || NO == [object isKindOfClass:[NSNumber class]]) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = ([object intValue] + 1);
|
value = ([object intValue] + 1);
|
||||||
|
|
||||||
result = [NSString stringWithFormat:@"%i", value];
|
result = [NSString stringWithFormat:@"%i", value];
|
||||||
|
|
||||||
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]];
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
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];
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,7 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
@interface SecondsFormatter : NSFormatter
|
@interface SecondsFormatter : NSFormatter {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -22,29 +22,28 @@
|
||||||
|
|
||||||
@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;
|
unsigned hours = 0;
|
||||||
unsigned hours = 0;
|
unsigned minutes = 0;
|
||||||
unsigned minutes = 0;
|
unsigned seconds = 0;
|
||||||
unsigned seconds = 0;
|
|
||||||
|
|
||||||
if(nil == object || NO == [object isKindOfClass:[NSNumber class]] || isnan([object doubleValue])) {
|
if(nil == object || NO == [object isKindOfClass:[NSNumber class]] || isnan([object doubleValue])) {
|
||||||
return @"";
|
return @"";
|
||||||
}
|
}
|
||||||
|
|
||||||
value = (unsigned)([object doubleValue]);
|
|
||||||
|
|
||||||
seconds = value % 60;
|
value = (unsigned)([object doubleValue]);
|
||||||
minutes = value / 60;
|
|
||||||
|
seconds = value % 60;
|
||||||
|
minutes = value / 60;
|
||||||
|
|
||||||
while(60 <= minutes) {
|
while(60 <= minutes) {
|
||||||
minutes -= 60;
|
minutes -= 60;
|
||||||
++hours;
|
++hours;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(24 <= hours) {
|
while(24 <= hours) {
|
||||||
hours -= 24;
|
hours -= 24;
|
||||||
++days;
|
++days;
|
||||||
|
@ -52,56 +51,49 @@
|
||||||
|
|
||||||
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;
|
unsigned seconds = 0;
|
||||||
unsigned seconds = 0;
|
|
||||||
|
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;
|
||||||
seconds += value;
|
seconds += value;
|
||||||
result = YES;
|
result = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grab the separator, if present
|
// Grab the separator, if present
|
||||||
[scanner scanString:@":" intoString:NULL];
|
[scanner scanString:@":" intoString:NULL];
|
||||||
}
|
}
|
||||||
|
|
||||||
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];
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,17 +6,15 @@
|
||||||
// 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;
|
||||||
|
|
||||||
id __unsafe_unretained valueToDisplay;
|
id __unsafe_unretained valueToDisplay;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property(assign) id valueToDisplay;
|
@property(assign) id valueToDisplay;
|
||||||
|
|
|
@ -7,58 +7,53 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#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));
|
||||||
[[self window] setFrameTopLeftPoint:point];
|
[[self window] setFrameTopLeftPoint:point];
|
||||||
}
|
}
|
||||||
[self showWindow:self];
|
[self showWindow:self];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -8,9 +8,7 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
|
||||||
@interface MissingAlbumArtTransformer : NSValueTransformer {
|
@interface MissingAlbumArtTransformer : NSValueTransformer {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -8,18 +8,21 @@
|
||||||
|
|
||||||
#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"];
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
Playlist/DNDArrayController.h
Executable file → Normal file
12
Playlist/DNDArrayController.h
Executable file → Normal file
|
@ -10,24 +10,24 @@ 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
|
||||||
toArrangedObjectIndexes:(NSIndexSet *)indexSet;
|
toArrangedObjectIndexes:(NSIndexSet *)indexSet;
|
||||||
|
|
233
Playlist/DNDArrayController.m
Executable file → Normal file
233
Playlist/DNDArrayController.m
Executable file → Normal file
|
@ -10,169 +10,162 @@ NSString *iTunesDropType = @"com.apple.tv.metadata";
|
||||||
@implementation DNDArrayController
|
@implementation DNDArrayController
|
||||||
|
|
||||||
- (void)awakeFromNib {
|
- (void)awakeFromNib {
|
||||||
[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,
|
CogUrlsPboardType,
|
||||||
CogUrlsPboardType,
|
fileType,
|
||||||
fileType,
|
iTunesDropType]];
|
||||||
iTunesDropType]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id<NSPasteboardWriting>)tableView:(NSTableView *)tableView
|
||||||
|
pasteboardWriterForRow:(NSInteger)row {
|
||||||
|
NSPasteboardItem *item = [[NSPasteboardItem alloc] init];
|
||||||
|
[item setString:[@(row) stringValue] forType:CogDNDIndexType];
|
||||||
|
|
||||||
- (id <NSPasteboardWriting>)tableView:(NSTableView *)tableView
|
return item;
|
||||||
pasteboardWriterForRow:(NSInteger)row {
|
|
||||||
NSPasteboardItem *item = [[NSPasteboardItem alloc] init];
|
|
||||||
[item setString:[@(row) stringValue] forType:CogDNDIndexType];
|
|
||||||
|
|
||||||
return item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (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 {
|
||||||
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!");
|
||||||
// we want to put the object at, not over,
|
// we want to put the object at, not over,
|
||||||
// the current row (contrast NSTableViewDropOn)
|
// the current row (contrast NSTableViewDropOn)
|
||||||
[tableView setDropRow:row dropOperation:NSTableViewDropAbove];
|
[tableView setDropRow:row dropOperation:NSTableViewDropAbove];
|
||||||
|
|
||||||
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];
|
||||||
|
|
||||||
DLog(@"ACCEPTING DROP!");
|
DLog(@"ACCEPTING DROP!");
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DLog(@"REJECTING DROP!");
|
DLog(@"REJECTING DROP!");
|
||||||
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 &&
|
|
||||||
(insertIndex >= firstIndex &&
|
|
||||||
insertIndex < firstIndex + [indexSet count])) // Null operation
|
|
||||||
return;
|
|
||||||
|
|
||||||
NSArray *objects = [self arrangedObjects];
|
|
||||||
NSUInteger index = [indexSet lastIndex];
|
|
||||||
|
|
||||||
NSUInteger aboveInsertIndexCount = 0;
|
if(rangeCount == 1 &&
|
||||||
id object;
|
(insertIndex >= firstIndex &&
|
||||||
NSUInteger removeIndex;
|
insertIndex < firstIndex + [indexSet count])) // Null operation
|
||||||
|
return;
|
||||||
|
|
||||||
while (NSNotFound != index) {
|
NSArray *objects = [self arrangedObjects];
|
||||||
if (index >= insertIndex) {
|
NSUInteger index = [indexSet lastIndex];
|
||||||
removeIndex = index + aboveInsertIndexCount;
|
|
||||||
aboveInsertIndexCount += 1;
|
|
||||||
} else {
|
|
||||||
removeIndex = index;
|
|
||||||
insertIndex -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
object = objects[removeIndex];
|
NSUInteger aboveInsertIndexCount = 0;
|
||||||
|
id object;
|
||||||
|
NSUInteger removeIndex;
|
||||||
|
|
||||||
[self removeObjectAtArrangedObjectIndex:removeIndex];
|
while(NSNotFound != index) {
|
||||||
[self insertObject:object atArrangedObjectIndex:insertIndex];
|
if(index >= insertIndex) {
|
||||||
|
removeIndex = index + aboveInsertIndexCount;
|
||||||
|
aboveInsertIndexCount += 1;
|
||||||
|
} else {
|
||||||
|
removeIndex = index;
|
||||||
|
insertIndex -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
index = [indexSet indexLessThanIndex:index];
|
object = objects[removeIndex];
|
||||||
}
|
|
||||||
|
[self removeObjectAtArrangedObjectIndex:removeIndex];
|
||||||
|
[self insertObject:object atArrangedObjectIndex:insertIndex];
|
||||||
|
|
||||||
|
index = [indexSet indexLessThanIndex:index];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)moveObjectsFromIndex:(NSUInteger)fromIndex
|
- (void)moveObjectsFromIndex:(NSUInteger)fromIndex
|
||||||
toArrangedObjectIndexes:(NSIndexSet *)indexSet {
|
toArrangedObjectIndexes:(NSIndexSet *)indexSet {
|
||||||
__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 &&
|
|
||||||
(fromIndex >= firstIndex &&
|
|
||||||
fromIndex < firstIndex + [indexSet count])) // Null operation
|
|
||||||
return;
|
|
||||||
|
|
||||||
fromIndex = _fromIndex;
|
if(rangeCount == 1 &&
|
||||||
|
(fromIndex >= firstIndex &&
|
||||||
NSArray *objects = [[self arrangedObjects] subarrayWithRange:NSMakeRange(fromIndex, [indexSet count])];
|
fromIndex < firstIndex + [indexSet count])) // Null operation
|
||||||
NSUInteger index = [indexSet firstIndex];
|
return;
|
||||||
|
|
||||||
NSUInteger itemIndex = 0;
|
fromIndex = _fromIndex;
|
||||||
id object;
|
|
||||||
|
|
||||||
fromIndex += [objects count];
|
|
||||||
for (NSUInteger i = 0; i < [objects count]; i++) {
|
|
||||||
[self removeObjectAtArrangedObjectIndex:--fromIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
while (NSNotFound != index) {
|
NSArray *objects = [[self arrangedObjects] subarrayWithRange:NSMakeRange(fromIndex, [indexSet count])];
|
||||||
object = objects[itemIndex++];
|
NSUInteger index = [indexSet firstIndex];
|
||||||
|
|
||||||
[self insertObject:object atArrangedObjectIndex:index];
|
NSUInteger itemIndex = 0;
|
||||||
|
id object;
|
||||||
|
|
||||||
index = [indexSet indexGreaterThanIndex:index];
|
fromIndex += [objects count];
|
||||||
}
|
for(NSUInteger i = 0; i < [objects count]; i++) {
|
||||||
|
[self removeObjectAtArrangedObjectIndex:--fromIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
while(NSNotFound != index) {
|
||||||
|
object = objects[itemIndex++];
|
||||||
|
|
||||||
|
[self insertObject:object atArrangedObjectIndex:index];
|
||||||
|
|
||||||
|
index = [indexSet indexGreaterThanIndex:index];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@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;
|
||||||
|
@ -16,60 +16,62 @@
|
||||||
@class PlaybackController;
|
@class PlaybackController;
|
||||||
|
|
||||||
typedef NS_ENUM(NSInteger, RepeatMode) {
|
typedef NS_ENUM(NSInteger, RepeatMode) {
|
||||||
RepeatModeNoRepeat = 0,
|
RepeatModeNoRepeat = 0,
|
||||||
RepeatModeRepeatOne,
|
RepeatModeRepeatOne,
|
||||||
RepeatModeRepeatAlbum,
|
RepeatModeRepeatAlbum,
|
||||||
RepeatModeRepeatAll
|
RepeatModeRepeatAll
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline BOOL IsRepeatOneSet() {
|
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,
|
||||||
URLOriginExternal
|
URLOriginExternal
|
||||||
};
|
};
|
||||||
|
|
||||||
@interface PlaylistController : DNDArrayController <NSTableViewDelegate> {
|
@interface PlaylistController : DNDArrayController <NSTableViewDelegate> {
|
||||||
IBOutlet PlaylistLoader *playlistLoader;
|
IBOutlet PlaylistLoader *playlistLoader;
|
||||||
IBOutlet SpotlightWindowController *spotlightWindowController;
|
IBOutlet SpotlightWindowController *spotlightWindowController;
|
||||||
IBOutlet PlaybackController *playbackController;
|
IBOutlet PlaybackController *playbackController;
|
||||||
|
|
||||||
NSValueTransformer * statusImageTransformer;
|
|
||||||
|
|
||||||
NSMutableArray *shuffleList;
|
NSValueTransformer *statusImageTransformer;
|
||||||
NSMutableArray *queueList;
|
|
||||||
|
|
||||||
NSString *totalTime;
|
NSMutableArray *shuffleList;
|
||||||
|
NSMutableArray *queueList;
|
||||||
|
|
||||||
PlaylistEntry *currentEntry;
|
NSString *totalTime;
|
||||||
|
|
||||||
NSUndoManager *undoManager;
|
PlaylistEntry *currentEntry;
|
||||||
|
|
||||||
|
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
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue