| 1 |
/* |
| 2 |
|
| 3 |
CsoundSwitchBinding.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 "CsoundSwitchBinding.h" |
| 27 |
|
| 28 |
@interface CsoundSwitchBinding() { |
| 29 |
float channelValue; |
| 30 |
float *channelPtr; |
| 31 |
} |
| 32 |
@property (unsafe_unretained) NSString *channelName; |
| 33 |
@property (unsafe_unretained) UISwitch *switcher; |
| 34 |
@end |
| 35 |
|
| 36 |
@implementation CsoundSwitchBinding |
| 37 |
|
| 38 |
-(void)updateChannelValue:(id)sender { |
| 39 |
channelValue = ((UISwitch *)sender).on ? 1 : 0; |
| 40 |
} |
| 41 |
|
| 42 |
-(instancetype)initSwitch:(UISwitch *)uiSwitch channelName:(NSString *)channelName |
| 43 |
{ |
| 44 |
if (self = [super init]) { |
| 45 |
self.switcher = uiSwitch; |
| 46 |
self.channelName = channelName; |
| 47 |
} |
| 48 |
return self; |
| 49 |
} |
| 50 |
|
| 51 |
-(void)setup:(CsoundObj *)csoundObj |
| 52 |
{ |
| 53 |
channelValue = self.switcher.on ? 1 : 0; |
| 54 |
channelPtr = [csoundObj getInputChannelPtr:self.channelName |
| 55 |
channelType:CSOUND_CONTROL_CHANNEL]; |
| 56 |
[self.switcher addTarget:self |
| 57 |
action:@selector(updateChannelValue:) |
| 58 |
forControlEvents:UIControlEventValueChanged]; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
-(void)updateValuesToCsound { |
| 63 |
*channelPtr = channelValue; |
| 64 |
} |
| 65 |
|
| 66 |
-(void)cleanup { |
| 67 |
[self.switcher removeTarget:self |
| 68 |
action:@selector(updateChannelValue:) |
| 69 |
forControlEvents:UIControlEventValueChanged]; |
| 70 |
} |
| 71 |
|
| 72 |
@end |