amuse/AudioUnit/AmuseContainingApp.mm

213 lines
5.1 KiB
Plaintext
Raw Normal View History

#import <AppKit/AppKit.h>
#import <AudioUnit/AudioUnit.h>
#import <CoreAudioKit/AUViewController.h>
#import "AudioUnitViewController.hpp"
2016-06-04 22:38:55 +00:00
#import "AmuseContainingApp.hpp"
2016-06-04 02:34:35 +00:00
#include <amuse/amuse.hpp>
2016-06-03 02:53:52 +00:00
@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
2016-06-04 22:38:55 +00:00
@implementation DataOutlineView
- (id)initWithCoder:(NSCoder *)coder
2016-06-03 02:53:52 +00:00
{
self = [super initWithCoder:coder];
[self registerForDraggedTypes:@[NSURLPboardType]];
2016-06-04 22:38:55 +00:00
return self;
}
- (id)initWithFrame:(NSRect)frameRect
2016-06-04 22:38:55 +00:00
{
self = [super initWithFrame:frameRect];
[self registerForDraggedTypes:@[NSURLPboardType]];
return self;
2016-06-03 02:53:52 +00:00
}
@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
2016-06-03 02:53:52 +00:00
@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
{
}
2016-06-03 02:53:52 +00:00
- (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"];
2016-06-03 02:53:52 +00:00
groupFilePresenter = [AudioGroupFilePresenter new];
2016-06-04 02:34:35 +00:00
dataOutline.dataSource = groupFilePresenter;
dataOutline.delegate = groupFilePresenter;
2016-06-03 02:53:52 +00:00
[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;
}
2016-06-04 02:34:35 +00:00
- (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;
2016-06-04 02:34:35 +00:00
return [groupFilePresenter addCollectionName:std::move(name) items:std::move(data)];
}
- (IBAction)importFile:(id)sender
{
2016-06-04 02:34:35 +00:00
__block NSOpenPanel* panel = [NSOpenPanel openPanel];
[panel beginSheetModalForWindow:mainWindow completionHandler:^(NSInteger result) {
if (result == NSFileHandlingPanelOKButton)
{
[self importURL:panel.URL];
}
}];
}
2016-06-04 22:38:55 +00:00
- (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);
}