-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoalTouchAppDelegate.m
executable file
·76 lines (61 loc) · 2.14 KB
/
oalTouchAppDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
Copyright (C) 2015 Apple Inc. All Rights Reserved.
See LICENSE.txt for this sample’s licensing information
Abstract:
pp delegate. Ties everything together, and handles some high-level UI input.
*/
#import "oalTouchAppDelegate.h"
#import "oalPlayback.h"
@interface oalTouchAppDelegate ()
@property (nonatomic, retain) IBOutlet UIViewController *viewController;
@end
@implementation oalTouchAppDelegate
@synthesize view;
@synthesize playback;
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
// Get accelerometer updates at 15 hz
motionManager = [CMMotionManager new];
motionManager.accelerometerUpdateInterval = (1.0 / 45.);
}
- (void)dealloc
{
[motionManager stopAccelerometerUpdates];
[motionManager release];
[playback release];
[view release];
[_window release];
[super dealloc];
}
- (IBAction)playPause:(UIButton *)sender
{
// Toggle the playback
if (playback.isPlaying) [playback stopSound];
else [playback startSound];
sender.selected = playback.isPlaying;
}
- (IBAction)toggleAccelerometer:(UISwitch *)sender
{
// Toggle the accelerometer
// Note: With the accelerometer on, the device should be held vertically, not laid down flat.
// As the device is rotated, the orientation of the listener will adjust so as as to be looking upward.
if (sender.on) {
[motionManager startAccelerometerUpdatesToQueue:[[[NSOperationQueue alloc] init] autorelease]
withHandler:^(CMAccelerometerData *data, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
CGFloat zRot;
// Find out the Z rotation of the device by doing some trig on the accelerometer values for X and Y
zRot = (atan2(data.acceleration.x, data.acceleration.y) + M_PI);
// Set our listener's rotation
playback.listenerRotation = zRot;
});
}
];
} else {
[motionManager stopAccelerometerUpdates];
}
}
@end