iPlug2 - C++ Audio Plug-in Framework
AppViewController.mm
1  /*
2  ==============================================================================
3 
4  This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5 
6  See LICENSE.txt for more info.
7 
8  ==============================================================================
9 */
10 
11 #import "AppViewController.h"
12 #import "IPlugAUPlayer.h"
13 #import "IPlugAUAudioUnit.h"
14 
15 #include "config.h"
16 
17 #import "IPlugAUViewController.h"
18 #import <CoreAudioKit/CoreAudioKit.h>
19 
20 #if !__has_feature(objc_arc)
21 #error This file must be compiled with Arc. Use -fobjc-arc flag
22 #endif
23 
24 @interface AppViewController ()
25 {
26  IPlugAUPlayer* player;
27  IPlugAUViewController* iplugViewController;
28  IBOutlet UIView *auView;
29 }
30 @end
31 
32 @implementation AppViewController
33 
34 - (BOOL)prefersStatusBarHidden
35 {
36  return YES;
37 }
38 
39 - (void) viewDidLoad
40 {
41  [super viewDidLoad];
42 
43 #if PLUG_HAS_UI
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];
48 #endif
49 
50  AudioComponentDescription desc;
51 
52 #if PLUG_TYPE==0
53 #if PLUG_DOES_MIDI_IN
54  desc.componentType = kAudioUnitType_MusicEffect;
55 #else
56  desc.componentType = kAudioUnitType_Effect;
57 #endif
58 #elif PLUG_TYPE==1
59  desc.componentType = kAudioUnitType_MusicDevice;
60 #elif PLUG_TYPE==2
61  desc.componentType = 'aumi';
62 #endif
63 
64  desc.componentSubType = PLUG_UNIQUE_ID;
65  desc.componentManufacturer = PLUG_MFR_ID;
66  desc.componentFlags = 0;
67  desc.componentFlagsMask = 0;
68 
69  [AUAudioUnit registerSubclass: IPlugAUAudioUnit.class asComponentDescription:desc name:@"Local AUv3" version: UINT32_MAX];
70 
71  player = [[IPlugAUPlayer alloc] initWithComponentType:desc.componentType];
72 
73  [player loadAudioUnitWithComponentDescription:desc completion:^{
74  self->iplugViewController.audioUnit = (IPlugAUAudioUnit*) self->player.currentAudioUnit;
75 
76  [self embedPlugInView];
77  }];
78 
79  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNotification:) name:@"LaunchBTMidiDialog" object:nil];
80 }
81 
82 -(void) receiveNotification:(NSNotification*) notification
83 {
84  if ([notification.name isEqualToString:@"LaunchBTMidiDialog"])
85  {
86  NSDictionary* dic = notification.userInfo;
87  NSNumber* x = (NSNumber*) dic[@"x"];
88  NSNumber* y = (NSNumber*) dic[@"y"];
89 
90  CABTMIDICentralViewController* vc = [[CABTMIDICentralViewController alloc] init];
91  UINavigationController* nc = [[UINavigationController alloc] initWithRootViewController:vc];
92  nc.modalPresentationStyle = UIModalPresentationPopover;
93 
94  UIPopoverPresentationController* ppc = nc.popoverPresentationController;
95  ppc.permittedArrowDirections = UIPopoverArrowDirectionAny;
96  ppc.sourceView = self.view;
97  ppc.sourceRect = CGRectMake([x floatValue], [y floatValue], 1., 1.);
98 
99  [self presentViewController:nc animated:YES completion:nil];
100  }
101 }
102 
103 - (void) embedPlugInView
104 {
105 #if PLUG_HAS_UI
106  UIView* view = iplugViewController.view;
107  view.frame = auView.bounds;
108  [auView addSubview: view];
109 
110  view.translatesAutoresizingMaskIntoConstraints = NO;
111 
112  NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat: @"H:|[view]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(view)];
113  [auView addConstraints: constraints];
114 
115  constraints = [NSLayoutConstraint constraintsWithVisualFormat: @"V:|[view]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(view)];
116  [auView addConstraints: constraints];
117 #endif
118 }
119 
120 - (UIRectEdge) preferredScreenEdgesDeferringSystemGestures
121 {
122  return UIRectEdgeAll;
123 }
124 @end
125