amuse/AudioUnit/AudioUnitViewController.mm

171 lines
5.0 KiB
Plaintext
Raw Normal View History

#import "AudioUnitViewController.hpp"
#import "AudioUnitBackend.hpp"
#if !__has_feature(objc_arc)
#error ARC Required
#endif
2016-06-07 03:42:51 +00:00
@implementation GroupBrowserDelegate
- (BOOL)browser:(NSBrowser *)sender isColumnValid:(NSInteger)column
{
2016-06-07 03:42:51 +00:00
if (column == 0)
return YES;
else if (column == 1)
{
AudioGroupCollectionToken* collection = [sender selectedCellInColumn:0];
if (collection)
return YES;
}
else if (column == 2)
{
AudioGroupDataToken* groupFile = [sender selectedCellInColumn:1];
if (groupFile)
return YES;
}
return NO;
}
2016-06-07 03:42:51 +00:00
- (NSInteger)browser:(NSBrowser *)sender numberOfRowsInColumn:(NSInteger)column
{
2016-06-07 03:42:51 +00:00
if (column == 0)
return m_audioUnit->m_filePresenter->m_filterAudioGroupCollections.size();
else if (column == 1)
{
AudioGroupCollectionToken* collection = [sender selectedCellInColumn:0];
if (!collection)
return 0;
return collection->m_collection->m_filterGroups.size();
}
else if (column == 2)
{
AudioGroupDataToken* groupFile = [sender selectedCellInColumn:1];
if (!groupFile)
return 0;
const amuse::AudioGroup* audioGroupFile = groupFile->m_collection->m_loadedGroup;
return audioGroupFile->getProj().songGroups().size() + audioGroupFile->getProj().sfxGroups().size();
}
return 0;
}
2016-06-07 03:42:51 +00:00
- (NSInteger)browser:(NSBrowser *)browser numberOfChildrenOfItem:(id)item
{
2016-06-07 03:42:51 +00:00
if (!item)
return m_audioUnit->m_filePresenter->m_filterAudioGroupCollections.size();
else if ([item isKindOfClass:[AudioGroupCollectionToken class]])
{
AudioGroupCollectionToken* collection = item;
return collection->m_collection->m_filterGroups.size();
}
else if ([item isKindOfClass:[AudioGroupDataToken class]])
{
AudioGroupDataToken* groupFile = item;
const amuse::AudioGroup* audioGroupFile = groupFile->m_collection->m_loadedGroup;
return audioGroupFile->getProj().songGroups().size() + audioGroupFile->getProj().sfxGroups().size();
}
else
return 0;
}
2016-06-07 03:42:51 +00:00
- (NSString *)browser:(NSBrowser *)sender titleOfColumn:(NSInteger)column
{
if (column == 0)
return @"Collection";
else if (column == 1)
return @"File";
else if (column == 2)
return @"Group";
return nil;
}
2016-06-07 03:42:51 +00:00
- (id)browser:(NSBrowser *)browser child:(NSInteger)index ofItem:(id)item
{
if (!item)
return m_audioUnit->m_filePresenter->m_filterAudioGroupCollections[index]->second->m_token;
else if ([item isKindOfClass:[AudioGroupCollectionToken class]])
{
AudioGroupCollectionToken* collection = item;
return collection->m_collection->m_filterGroups[index]->second->m_token;
}
2016-06-07 03:42:51 +00:00
else if ([item isKindOfClass:[AudioGroupDataToken class]])
{
AudioGroupDataToken* groupFile = item;
return groupFile->m_collection->m_groupTokens[index];
}
else
return 0;
}
2016-06-07 03:42:51 +00:00
- (BOOL)browser:(NSBrowser *)browser isLeafItem:(id)item
{
2016-06-07 03:42:51 +00:00
if ([item isKindOfClass:[AudioGroupToken class]])
return YES;
return NO;
}
2016-06-07 03:42:51 +00:00
- (BOOL)browser:(NSBrowser *)browser shouldEditItem:(id)item
{
2016-06-07 03:42:51 +00:00
return NO;
}
2016-06-07 03:42:51 +00:00
- (id)browser:(NSBrowser *)browser objectValueForItem:(id)item
{
2016-06-07 03:42:51 +00:00
if ([item isKindOfClass:[AudioGroupCollectionToken class]])
{
AudioGroupCollectionToken* collection = item;
return collection->m_collection->m_url.lastPathComponent;
}
else if ([item isKindOfClass:[AudioGroupDataToken class]])
{
AudioGroupDataToken* groupFile = item;
return @(groupFile->m_collection->m_name.c_str());
}
else if ([item isKindOfClass:[AudioGroupToken class]])
{
AudioGroupToken* group = item;
return group->m_name;
}
return nil;
}
2016-06-08 04:33:15 +00:00
- (NSIndexSet *)browser:(NSBrowser *)browser selectionIndexesForProposedSelection:(NSIndexSet *)proposedSelectionIndexes inColumn:(NSInteger)column
{
if (column == 2)
{
AudioGroupToken* token = [browser itemAtRow:proposedSelectionIndexes.firstIndex inColumn:column];
[m_audioUnit requestAudioGroup:token];
}
return proposedSelectionIndexes;
}
2016-06-07 03:42:51 +00:00
- (id)initWithAudioUnit:(AmuseAudioUnit*)au
{
2016-06-07 03:42:51 +00:00
self = [super init];
m_audioUnit = au;
return self;
}
@end
@implementation AudioUnitViewController
- (void) viewDidLoad {
[super viewDidLoad];
self.preferredContentSize = NSMakeSize(510, 312);
// Get the parameter tree and add observers for any parameters that the UI needs to keep in sync with the AudioUnit
}
- (AUAudioUnit*)createAudioUnitWithComponentDescription:(AudioComponentDescription)desc error:(NSError**)error {
2016-06-07 03:42:51 +00:00
m_audioUnit = [[AmuseAudioUnit alloc] initWithComponentDescription:desc error:error viewController:self];
m_groupBrowserDelegate = [[GroupBrowserDelegate alloc] initWithAudioUnit:m_audioUnit];
dispatch_sync(dispatch_get_main_queue(), ^
{
m_groupBrowser.delegate = m_groupBrowserDelegate;
2016-06-08 04:33:15 +00:00
[m_groupBrowser loadColumnZero];
2016-06-07 03:42:51 +00:00
});
return m_audioUnit;
}
@end