| 1 |
/* |
| 2 |
|
| 3 |
CsoundButtonBinding.m: |
| 4 |
|
| 5 |
Copyright (C) 2014 Steven Yi, Aurelius Prochazka |
| 6 |
|
| 7 |
|
| 8 |
This file is part of Csound for iOS. |
| 9 |
|
| 10 |
The Csound for iOS Library is free software; you can redistribute it |
| 11 |
and/or modify it under the terms of the GNU Lesser General Public |
| 12 |
License as published by the Free Software Foundation; either |
| 13 |
version 2.1 of the License, or (at your option) any later version. |
| 14 |
|
| 15 |
Csound is distributed in the hope that it will be useful, |
| 16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
GNU Lesser General Public License for more details. |
| 19 |
|
| 20 |
You should have received a copy of the GNU Lesser General Public |
| 21 |
License along with Csound; if not, write to the Free Software |
| 22 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 23 |
02111-1307 USA |
| 24 |
|
| 25 |
*/ |
| 26 |
|
| 27 |
#import "CsoundButtonBinding.h" |
| 28 |
|
| 29 |
@interface CsoundButtonBinding () { |
| 30 |
float channelValue; |
| 31 |
float *channelPtr; |
| 32 |
} |
| 33 |
|
| 34 |
@property (nonatomic, strong) NSString *channelName; |
| 35 |
@property (nonatomic, strong) UIButton *button; |
| 36 |
@end |
| 37 |
|
| 38 |
@implementation CsoundButtonBinding |
| 39 |
|
| 40 |
-(instancetype)initButton:(UIButton *)button channelName:(NSString *)channelName |
| 41 |
{ |
| 42 |
if (self = [super init]) { |
| 43 |
self.channelName = channelName; |
| 44 |
self.button = button; |
| 45 |
} |
| 46 |
return self; |
| 47 |
} |
| 48 |
|
| 49 |
-(void)updateChannelValueButtonIsDown:(id)sender { |
| 50 |
channelValue = 1; |
| 51 |
} |
| 52 |
|
| 53 |
-(void)updateChannelValueButtonIsUp:(id)sender { |
| 54 |
channelValue = 0; |
| 55 |
} |
| 56 |
|
| 57 |
-(void)setup:(CsoundObj *)csoundObj |
| 58 |
{ |
| 59 |
channelValue = self.button.selected ? 1 : 0; |
| 60 |
channelPtr = [csoundObj getInputChannelPtr:self.channelName |
| 61 |
channelType:CSOUND_CONTROL_CHANNEL]; |
| 62 |
[self.button addTarget:self |
| 63 |
action:@selector(updateChannelValueButtonIsDown:) |
| 64 |
forControlEvents:UIControlEventTouchDown]; |
| 65 |
[self.button addTarget:self |
| 66 |
action:@selector(updateChannelValueButtonIsUp:) |
| 67 |
forControlEvents:UIControlEventTouchUpInside]; |
| 68 |
[self.button addTarget:self |
| 69 |
action:@selector(updateChannelValueButtonIsUp:) |
| 70 |
forControlEvents:UIControlEventTouchUpOutside]; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
-(void)updateValuesToCsound |
| 75 |
{ |
| 76 |
*channelPtr = channelValue; |
| 77 |
} |
| 78 |
|
| 79 |
-(void)cleanup |
| 80 |
{ |
| 81 |
[self.button removeTarget:self |
| 82 |
action:@selector(updateChannelValueButtonIsDown:) |
| 83 |
forControlEvents:UIControlEventTouchDown]; |
| 84 |
[self.button removeTarget:self |
| 85 |
action:@selector(updateChannelValueButtonIsUp:) |
| 86 |
forControlEvents:UIControlEventTouchUpInside]; |
| 87 |
[self.button removeTarget:self |
| 88 |
action:@selector(updateChannelValueButtonIsUp:) |
| 89 |
forControlEvents:UIControlEventTouchUpOutside]; |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
@end |