Debian Codegraph @

iOS/Csound iOS Swift Examples/Csound iOS SwiftExamples/csound-iOS/classes/bindings/ui/CsoundLabelBinding.m

raw
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 #import "CsoundLabelBinding.h"
27
28 @interface CsoundLabelBinding () {
29 float *channelPtr;
30 }
31
32 @property (nonatomic, strong) NSString *channelName;
33 @property (nonatomic, strong) UILabel *label;
34 @end
35
36 @implementation CsoundLabelBinding
37
38 -(instancetype)initLabel:(UILabel *)label channelName:(NSString *)channelName
39 {
40 if (self = [super init]) {
41 self.channelName = channelName;
42 self.label = label;
43 }
44 return self;
45 }
46
47
48 -(void)setup:(CsoundObj *)csoundObj
49 {
50 channelPtr = [csoundObj getOutputChannelPtr:self.channelName
51 channelType:CSOUND_CONTROL_CHANNEL];
52 }
53
54
55 -(void)updateValuesFromCsound
56 {
57 [self performSelectorOnMainThread:@selector(updateLabelText:)
58 withObject:nil
59 waitUntilDone:NO];
60 }
61
62 -(void)updateLabelText:(id)sender
63 {
64 self.label.text = [NSString stringWithFormat:@"%.*f", _precision, *channelPtr];
65 [self.label setNeedsDisplay];
66 }
67
68
69 @end