mirror of https://github.com/AxioDL/amuse.git
213 lines
5.1 KiB
Plaintext
213 lines
5.1 KiB
Plaintext
#import <AppKit/AppKit.h>
|
|
#import <AudioUnit/AudioUnit.h>
|
|
#import <CoreAudioKit/AUViewController.h>
|
|
#import "AudioUnitViewController.hpp"
|
|
#import "AmuseContainingApp.hpp"
|
|
#include <amuse/amuse.hpp>
|
|
|
|
@class DataOutlineController;
|
|
@class SamplesTableController;
|
|
@class SFXTableController;
|
|
|
|
/* Blocks mousedown events */
|
|
@interface InactiveButton : NSButton {}
|
|
@end
|
|
@implementation InactiveButton
|
|
- (void)mouseDown:(NSEvent *)theEvent {}
|
|
@end
|
|
|
|
@interface MainView : NSView
|
|
{
|
|
AudioUnitViewController* amuseVC;
|
|
}
|
|
@end
|
|
|
|
@implementation MainView
|
|
|
|
- (id)initWithFrame:(NSRect)frameRect
|
|
{
|
|
self = [super initWithFrame:frameRect];
|
|
if (!self)
|
|
return nil;
|
|
amuseVC = [[AudioUnitViewController alloc] initWithNibName:nil bundle:nil];
|
|
[self addSubview:amuseVC.view];
|
|
return self;
|
|
}
|
|
|
|
- (BOOL)translatesAutoresizingMaskIntoConstraints
|
|
{
|
|
return NO;
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
@implementation DataOutlineView
|
|
- (id)initWithCoder:(NSCoder *)coder
|
|
{
|
|
self = [super initWithCoder:coder];
|
|
[self registerForDraggedTypes:@[NSURLPboardType]];
|
|
return self;
|
|
}
|
|
- (id)initWithFrame:(NSRect)frameRect
|
|
{
|
|
self = [super initWithFrame:frameRect];
|
|
[self registerForDraggedTypes:@[NSURLPboardType]];
|
|
return self;
|
|
}
|
|
@end
|
|
|
|
@interface MainTabView : NSTabView
|
|
{}
|
|
- (IBAction)selectDataTab:(id)sender;
|
|
- (IBAction)selectSFXTab:(id)sender;
|
|
- (IBAction)selectSamplesTab:(id)sender;
|
|
- (IBAction)selectCreditsTab:(id)sender;
|
|
@end
|
|
|
|
@implementation MainTabView
|
|
- (IBAction)selectDataTab:(id)sender
|
|
{
|
|
[self selectTabViewItemAtIndex:0];
|
|
}
|
|
- (IBAction)selectSFXTab:(id)sender
|
|
{
|
|
[self selectTabViewItemAtIndex:1];
|
|
}
|
|
- (IBAction)selectSamplesTab:(id)sender
|
|
{
|
|
[self selectTabViewItemAtIndex:2];
|
|
}
|
|
- (IBAction)selectCreditsTab:(id)sender
|
|
{
|
|
[self selectTabViewItemAtIndex:3];
|
|
}
|
|
@end
|
|
|
|
|
|
@implementation SamplesTableController
|
|
|
|
- (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView
|
|
{
|
|
|
|
}
|
|
|
|
- (nullable id)tableView:(NSTableView *)tableView objectValueForTableColumn:(nullable NSTableColumn*)tableColumn row:(NSInteger)row
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
@implementation SFXTableController
|
|
|
|
- (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView
|
|
{
|
|
}
|
|
|
|
- (nullable id)tableView:(NSTableView *)tableView objectValueForTableColumn:(nullable NSTableColumn*)tableColumn row:(NSInteger)row
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation AppDelegate
|
|
|
|
- (void)applicationWillFinishLaunching:(NSNotification*)notification
|
|
{
|
|
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints"];
|
|
[mainWindow.toolbar setSelectedItemIdentifier:@"DataTab"];
|
|
|
|
groupFilePresenter = [AudioGroupFilePresenter new];
|
|
|
|
dataOutline.dataSource = groupFilePresenter;
|
|
dataOutline.delegate = groupFilePresenter;
|
|
[dataOutline reloadItem:nil reloadChildren:YES];
|
|
|
|
samplesController = [SamplesTableController new];
|
|
samplesTable.dataSource = samplesController;
|
|
samplesTable.delegate = samplesController;
|
|
[samplesTable reloadData];
|
|
|
|
sfxController = [SFXTableController new];
|
|
sfxTable.dataSource = sfxController;
|
|
sfxTable.delegate = sfxController;
|
|
[sfxTable reloadData];
|
|
}
|
|
|
|
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
|
|
{
|
|
return YES;
|
|
}
|
|
|
|
- (BOOL)importURL:(NSURL*)url
|
|
{
|
|
amuse::ContainerRegistry::Type containerType;
|
|
std::vector<std::pair<std::string, amuse::IntrusiveAudioGroupData>> data =
|
|
amuse::ContainerRegistry::LoadContainer(url.path.UTF8String, containerType);
|
|
if (data.empty())
|
|
{
|
|
NSString* err = [NSString stringWithFormat:@"Unable to load Audio Groups from %s", url.path.UTF8String];
|
|
NSAlert* alert = [[NSAlert alloc] init];
|
|
alert.informativeText = err;
|
|
alert.messageText = @"Invalid Data File";
|
|
[alert runModal];
|
|
return false;
|
|
}
|
|
|
|
std::string name(amuse::ContainerRegistry::TypeToName(containerType));
|
|
if (containerType == amuse::ContainerRegistry::Type::Raw4)
|
|
name = url.URLByDeletingPathExtension.lastPathComponent.UTF8String;
|
|
return [groupFilePresenter addCollectionName:std::move(name) items:std::move(data)];
|
|
}
|
|
|
|
- (IBAction)importFile:(id)sender
|
|
{
|
|
__block NSOpenPanel* panel = [NSOpenPanel openPanel];
|
|
[panel beginSheetModalForWindow:mainWindow completionHandler:^(NSInteger result) {
|
|
if (result == NSFileHandlingPanelOKButton)
|
|
{
|
|
[self importURL:panel.URL];
|
|
}
|
|
}];
|
|
}
|
|
|
|
- (IBAction)filterDataOutline:(id)sender
|
|
{
|
|
[groupFilePresenter setSearchFilter:[sender stringValue]];
|
|
}
|
|
|
|
- (IBAction)removeDataItem:(id)sender
|
|
{
|
|
[groupFilePresenter removeSelectedItem];
|
|
}
|
|
|
|
- (void)outlineView:(DataOutlineView *)ov selectionChanged:(id)item
|
|
{
|
|
if ([item isKindOfClass:[AudioGroupCollectionToken class]])
|
|
{
|
|
removeDataButton.enabled = TRUE;
|
|
removeDataMenu.enabled = TRUE;
|
|
}
|
|
else
|
|
{
|
|
removeDataButton.enabled = FALSE;
|
|
removeDataMenu.enabled = FALSE;
|
|
}
|
|
}
|
|
|
|
- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename
|
|
{
|
|
NSURL* url = [NSURL fileURLWithPath:filename isDirectory:NO];
|
|
return [self importURL:url];
|
|
}
|
|
|
|
@end
|
|
|
|
int main(int argc, const char * argv[])
|
|
{
|
|
return NSApplicationMain(argc, argv);
|
|
}
|