Debian Codegraph @

iOS/Csound iOS Obj-C Examples/Csound iOS Examples/ViewControllers/SimpleTest1/SimpleTest1ViewController.m

raw
1 /*
2
3 SimpleTest1ViewController.m:
4
5 Copyright (C) 2014 Steven Yi, Victor Lazzarini, Aurelius Prochazka
6 Updated in 2017 by Dr. Richard Boulanger, Nikhil Singh
7
8 This file is part of Csound iOS Examples.
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 "SimpleTest1ViewController.h"
28
29 @interface SimpleTest1ViewController() {
30 IBOutlet UISlider *uiSlider;
31 IBOutlet UISwitch *uiSwitch;
32 IBOutlet UILabel *uiLabel;
33 }
34 @end
35
36 @implementation SimpleTest1ViewController
37
38 -(void)viewDidLoad {
39 self.title = @"01. Simple Test 1";
40 self.csound = NULL;
41 [super viewDidLoad];
42 }
43
44 -(IBAction) toggleOnOff:(id)sender {
45 NSLog(@"Status: %d", [uiSwitch isOn]);
46
47 if(uiSwitch.on) {
48
49 NSString *csdFile = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"csd"];
50 NSLog(@"FILE PATH: %@", csdFile);
51
52 //[self.csound stop];
53 if(self.csound == NULL){
54 self.csound = [[CsoundObj alloc] init];
55 [self.csound addListener:self];
56
57 CsoundUI *csoundUI = [[CsoundUI alloc] initWithCsoundObj:self.csound];
58 [csoundUI setLabelPrecision:2];
59 [csoundUI addLabel:uiLabel forChannelName:@"slider"];
60 [csoundUI addSlider:uiSlider forChannelName:@"slider"];
61
62 [self.csound play:csdFile];
63 }
64
65 } else {
66 [self.csound stop];
67 self.csound = NULL;
68 }
69 }
70
71 - (IBAction)showInfo:(UIButton *)sender {
72 UIViewController *infoVC = [[UIViewController alloc] init];
73 infoVC.modalPresentationStyle = UIModalPresentationPopover;
74
75 UIPopoverPresentationController *popover = infoVC.popoverPresentationController;
76 popover.sourceView = sender;
77 popover.sourceRect = sender.bounds;
78 [infoVC setPreferredContentSize:CGSizeMake(200, 100)];
79
80 UITextView *infoText = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, infoVC.preferredContentSize.width, infoVC.preferredContentSize.height)];
81 infoText.editable = NO;
82 infoText.selectable = NO;
83 NSString *description = @"Flip the switch to begin rendering Csound. Use the slider to control pitch.";
84 [infoText setAttributedText:[[NSAttributedString alloc] initWithString:description]];
85 infoText.font = [UIFont fontWithName:@"Menlo" size:16];
86 [infoVC.view addSubview:infoText];
87 popover.delegate = self;
88
89 [popover setPermittedArrowDirections:UIPopoverArrowDirectionUp];
90
91 [self presentViewController:infoVC animated:YES completion:nil];
92
93 }
94
95 #pragma mark CsoundObjListener
96
97 -(void)csoundObjCompleted:(CsoundObj *)csoundObj {
98 [uiSwitch setOn:NO animated:YES];
99 [uiLabel performSelectorOnMainThread:@selector(setText:) withObject:@"" waitUntilDone:NO];
100 }
101
102
103 @end