| 1 |
/* |
| 2 |
|
| 3 |
CsoundAccelerometerBinding.m: |
| 4 |
|
| 5 |
Copyright (C) 2014 Steven Yi, Aurelius Prochazka |
| 6 |
|
| 7 |
This file is part of Csound for iOS. |
| 8 |
|
| 9 |
The Csound for iOS Library is free software; you can redistribute it |
| 10 |
and/or modify it under the terms of the GNU Lesser General Public |
| 11 |
License as published by the Free Software Foundation; either |
| 12 |
version 2.1 of the License, or (at your option) any later version. |
| 13 |
|
| 14 |
Csound is distributed in the hope that it will be useful, |
| 15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
GNU Lesser General Public License for more details. |
| 18 |
|
| 19 |
You should have received a copy of the GNU Lesser General Public |
| 20 |
License along with Csound; if not, write to the Free Software |
| 21 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 22 |
02111-1307 USA |
| 23 |
|
| 24 |
*/ |
| 25 |
|
| 26 |
#import "CsoundAccelerometerBinding.h" |
| 27 |
|
| 28 |
@interface CsoundAccelerometerBinding () { |
| 29 |
float *channelPtrX; |
| 30 |
float *channelPtrY; |
| 31 |
float *channelPtrZ; |
| 32 |
|
| 33 |
CMMotionManager* manager; |
| 34 |
} |
| 35 |
@end |
| 36 |
|
| 37 |
@implementation CsoundAccelerometerBinding |
| 38 |
|
| 39 |
static NSString *CS_ACCEL_X = @"accelerometerX"; |
| 40 |
static NSString *CS_ACCEL_Y = @"accelerometerY"; |
| 41 |
static NSString *CS_ACCEL_Z = @"accelerometerZ"; |
| 42 |
|
| 43 |
-(id)init:(CMMotionManager *)cmManager { |
| 44 |
if (self = [super init]) { |
| 45 |
manager = cmManager; |
| 46 |
} |
| 47 |
return self; |
| 48 |
} |
| 49 |
|
| 50 |
-(void)setup:(CsoundObj *)csoundObj { |
| 51 |
channelPtrX = [csoundObj getInputChannelPtr:CS_ACCEL_X |
| 52 |
channelType:CSOUND_CONTROL_CHANNEL]; |
| 53 |
channelPtrY = [csoundObj getInputChannelPtr:CS_ACCEL_Y |
| 54 |
channelType:CSOUND_CONTROL_CHANNEL]; |
| 55 |
channelPtrZ = [csoundObj getInputChannelPtr:CS_ACCEL_Z |
| 56 |
channelType:CSOUND_CONTROL_CHANNEL]; |
| 57 |
|
| 58 |
*channelPtrX = manager.accelerometerData.acceleration.x; |
| 59 |
*channelPtrY = manager.accelerometerData.acceleration.y; |
| 60 |
*channelPtrZ = manager.accelerometerData.acceleration.z; |
| 61 |
} |
| 62 |
|
| 63 |
-(void)updateValuesToCsound { |
| 64 |
@autoreleasepool { |
| 65 |
*channelPtrX = manager.accelerometerData.acceleration.x; |
| 66 |
*channelPtrY = manager.accelerometerData.acceleration.y; |
| 67 |
*channelPtrZ = manager.accelerometerData.acceleration.z; |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
@end |