Debian Codegraph @

iOS/Csound iOS Obj-C Examples/csound-iOS/classes/bindings/ui/CsoundMomentaryButtonBinding.m

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