Debian Codegraph @

iOS/Csound iOS Obj-C Examples/Csound iOS Examples/ViewControllers/Waveview/WaveviewViewController.m

raw
1 /*
2
3 WaveviewViewController.h:
4
5 Copyright (C) 2011 Steven Yi, Ed Costello
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 "WaveviewViewController.h"
28
29 @implementation WaveviewViewController {
30 int fTableIndex;
31 NSArray *fTables;
32 }
33
34 -(void)viewDidLoad {
35 self.title = @"09. F-table Viewer";
36 [super viewDidLoad];
37 fTableIndex = 0;
38 fTables = @[@"Sine", @"Exponential Curves", @"Data Points", @"Normalizing Function", @"Triangle"];
39 }
40
41 -(void)viewDidAppear:(BOOL)animated {
42 [super viewDidAppear:animated];
43
44 NSString *tempFile = [[NSBundle mainBundle] pathForResource:@"Waveviewtest" ofType:@"csd"];
45 NSLog(@"FILE PATH: %@", tempFile);
46
47 [self.csound stop];
48 self.csound = [[CsoundObj alloc] init];
49 [self.csound addBinding:waveview];
50
51
52 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(incrementFTable:)];
53 [waveview addGestureRecognizer:tap];
54
55 [self.csound play:tempFile];
56
57 }
58
59 - (IBAction)incrementFTable:(UITapGestureRecognizer *)tap {
60 fTableIndex++;
61 if (fTableIndex >= fTables.count) {
62 fTableIndex = 0;
63 }
64 titleLabel.text = fTables[fTableIndex];
65 [waveview displayFTable:fTableIndex+1];
66 }
67
68 - (IBAction)showInfo:(UIButton *)sender {
69 UIViewController *infoVC = [[UIViewController alloc] init];
70 infoVC.modalPresentationStyle = UIModalPresentationPopover;
71
72 UIPopoverPresentationController *popover = infoVC.popoverPresentationController;
73 popover.sourceView = sender;
74 popover.sourceRect = sender.bounds;
75 [infoVC setPreferredContentSize:CGSizeMake(300, 120)];
76
77 UITextView *infoText = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, infoVC.preferredContentSize.width, infoVC.preferredContentSize.height)];
78 infoText.editable = NO;
79 infoText.selectable = NO;
80 NSString *description = @"Demonstrates using a Csound binding to draw F-table content to a view. Tap the screen to cycle through available F-tables.";
81 [infoText setAttributedText:[[NSAttributedString alloc] initWithString:description]];
82 infoText.font = [UIFont fontWithName:@"Menlo" size:16];
83 [infoVC.view addSubview:infoText];
84 popover.delegate = self;
85
86 [popover setPermittedArrowDirections:UIPopoverArrowDirectionUp];
87
88 [self presentViewController:infoVC animated:YES completion:nil];
89
90 }
91
92 @end