11 #import "AppViewController.h" 12 #import "IPlugAUPlayer.h" 13 #import "IPlugAUAudioUnit.h" 17 #import "IPlugAUViewController.h" 18 #import <CoreAudioKit/CoreAudioKit.h> 20 #if !__has_feature(objc_arc) 21 #error This file must be compiled with Arc. Use -fobjc-arc flag 24 @interface AppViewController ()
26 IPlugAUPlayer* player;
27 IPlugAUViewController* iplugViewController;
28 IBOutlet UIView *auView;
32 @implementation AppViewController
34 - (BOOL)prefersStatusBarHidden
44 NSString* storyBoardName = [NSString stringWithFormat:@"%s-iOS-MainInterface", PLUG_NAME];
45 UIStoryboard* storyboard = [UIStoryboard storyboardWithName:storyBoardName bundle: nil];
46 iplugViewController = [storyboard instantiateViewControllerWithIdentifier:@"main"];
47 [
self addChildViewController:iplugViewController];
50 AudioComponentDescription desc;
54 desc.componentType = kAudioUnitType_MusicEffect;
56 desc.componentType = kAudioUnitType_Effect;
59 desc.componentType = kAudioUnitType_MusicDevice;
61 desc.componentType =
'aumi';
64 desc.componentSubType = PLUG_UNIQUE_ID;
65 desc.componentManufacturer = PLUG_MFR_ID;
66 desc.componentFlags = 0;
67 desc.componentFlagsMask = 0;
69 [AUAudioUnit registerSubclass: IPlugAUAudioUnit.class asComponentDescription:desc name:@"Local AUv3" version: UINT32_MAX];
71 player = [[IPlugAUPlayer alloc] initWithComponentType:desc.componentType];
73 [player loadAudioUnitWithComponentDescription:desc completion:^{
74 self->iplugViewController.audioUnit = (IPlugAUAudioUnit*) self->player.currentAudioUnit;
76 [
self embedPlugInView];
79 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNotification:) name:@"LaunchBTMidiDialog" object:nil];
82 -(void) receiveNotification:(NSNotification*) notification
84 if ([notification.name isEqualToString:
@"LaunchBTMidiDialog"])
86 NSDictionary* dic = notification.userInfo;
87 NSNumber* x = (NSNumber*) dic[
@"x"];
88 NSNumber* y = (NSNumber*) dic[
@"y"];
90 CABTMIDICentralViewController* vc = [[CABTMIDICentralViewController alloc] init];
91 UINavigationController* nc = [[UINavigationController alloc] initWithRootViewController:vc];
92 nc.modalPresentationStyle = UIModalPresentationPopover;
94 UIPopoverPresentationController* ppc = nc.popoverPresentationController;
95 ppc.permittedArrowDirections = UIPopoverArrowDirectionAny;
96 ppc.sourceView =
self.view;
97 ppc.sourceRect = CGRectMake([x floatValue], [y floatValue], 1., 1.);
99 [
self presentViewController:nc animated:YES completion:nil];
103 - (void) embedPlugInView
106 UIView* view = iplugViewController.view;
107 view.frame = auView.bounds;
108 [auView addSubview: view];
110 view.translatesAutoresizingMaskIntoConstraints = NO;
112 NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat: @"H:|[view]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(view)];
113 [auView addConstraints: constraints];
115 constraints = [NSLayoutConstraint constraintsWithVisualFormat: @"V:|[view]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(view)];
116 [auView addConstraints: constraints];
120 - (UIRectEdge) preferredScreenEdgesDeferringSystemGestures
122 return UIRectEdgeAll;