| 1 |
/* |
| 2 |
|
| 3 |
SliderMidiWidgetWrapper.m: |
| 4 |
|
| 5 |
Copyright (C) 2011 Steven Yi |
| 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 "SliderMidiWidgetWrapper.h" |
| 27 |
|
| 28 |
@implementation SliderMidiWidgetWrapper |
| 29 |
|
| 30 |
-(id)init:(UISlider *)slider { |
| 31 |
if (self = [super init]) { |
| 32 |
mSlider = slider; |
| 33 |
} |
| 34 |
return self; |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
-(void)setValueSelector:(NSNumber *)value { |
| 39 |
[mSlider setValue:[value floatValue] animated:YES]; |
| 40 |
[mSlider sendActionsForControlEvents:UIControlEventValueChanged]; |
| 41 |
|
| 42 |
} |
| 43 |
|
| 44 |
-(void)setMIDIValue:(int)midiValue { |
| 45 |
NSLog(@"SetMIDIValue: %d", midiValue); |
| 46 |
float percent = midiValue / 127.0f; |
| 47 |
float sliderRange = mSlider.maximumValue - mSlider.minimumValue; |
| 48 |
float newValue = (percent * sliderRange) + mSlider.minimumValue;; |
| 49 |
[self performSelectorOnMainThread:@selector(setValueSelector:) withObject:[NSNumber numberWithFloat:newValue] waitUntilDone:NO]; |
| 50 |
} |
| 51 |
|
| 52 |
@end |