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