Debian Codegraph @

iOS/Csound iOS Obj-C Examples/Csound iOS Examples/ViewControllers/ButtonTest/ButtonTestViewController.m

raw
1 /*
2
3 ButtonTestViewController.m:
4
5 Copyright (C) 2014 Steven Yi, 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 #import "ButtonTestViewController.h"
27
28 @implementation ButtonTestViewController
29
30 -(void)viewDidLoad {
31 self.title = @"03. Button Test";
32 self.csound = NULL;
33 [super viewDidLoad];
34 }
35
36 -(IBAction) eventButtonHit:(id)sender {
37 NSString *score = [NSString stringWithFormat:@"i2 0 %f", [mDurationSlider value]];
38
39 [self.csound sendScore:score];
40 }
41
42 -(IBAction) toggleOnOff:(id)component {
43 UISwitch *uiswitch = (UISwitch *)component;
44 NSLog(@"Status: %d", [uiswitch isOn]);
45
46 if(uiswitch.on) {
47
48 NSString *tempFile = [[NSBundle mainBundle] pathForResource:@"buttonTest" ofType:@"csd"];
49 NSLog(@"FILE PATH: %@", tempFile);
50
51 //[self.csound stop];
52 if(self.csound == NULL){
53 self.csound = [[CsoundObj alloc] init];
54 [self.csound addListener:self];
55
56 CsoundUI *csoundUI = [[CsoundUI alloc] initWithCsoundObj:self.csound];
57
58 [csoundUI addMomentaryButton:mValueButton forChannelName:@"button1"];
59
60 [csoundUI addSlider:mDurationSlider forChannelName:@"duration"];
61 [csoundUI addSlider:mAttackSlider forChannelName:@"attack"];
62 [csoundUI addSlider:mDecaySlider forChannelName:@"decay"];
63 [csoundUI addSlider:mSustainSlider forChannelName:@"sustain"];
64 [csoundUI addSlider:mReleaseSlider forChannelName:@"release"];
65
66 [self.csound play:tempFile];
67 }
68
69 } else {
70 [self.csound stop];
71 self.csound = NULL;
72 }
73 }
74
75 - (IBAction)showInfo:(UIButton *)sender {
76 UIViewController *infoVC = [[UIViewController alloc] init];
77 infoVC.modalPresentationStyle = UIModalPresentationPopover;
78
79 UIPopoverPresentationController *popover = infoVC.popoverPresentationController;
80 popover.sourceView = sender;
81 popover.sourceRect = sender.bounds;
82 [infoVC setPreferredContentSize:CGSizeMake(300, 160)];
83
84 UITextView *infoText = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, infoVC.preferredContentSize.width, infoVC.preferredContentSize.height)];
85 infoText.editable = NO;
86 infoText.selectable = NO;
87 NSString *description = @"Uses a .csd based on SimpleTest 2, but depends on the user to press a button to trigger each note. One button uses a binding and the other sends a score message to CsoundObj.";
88 [infoText setAttributedText:[[NSAttributedString alloc] initWithString:description]];
89 infoText.font = [UIFont fontWithName:@"Menlo" size:16];
90 [infoVC.view addSubview:infoText];
91 popover.delegate = self;
92
93 [popover setPermittedArrowDirections:UIPopoverArrowDirectionUp];
94
95 [self presentViewController:infoVC animated:YES completion:nil];
96
97 }
98
99 #pragma mark CsoundObjListener
100
101 -(void)csoundObjCompleted:(CsoundObj *)csoundObj {
102 [mSwitch setOn:NO animated:YES];
103 }
104
105 @end