Debian Codegraph @

iOS/Csound iOS Obj-C Examples/Csound iOS Examples/ViewControllers/AudioFileTest/AudioFileTestViewController.m

raw
1 /*
2
3 AudioFileTestViewController.m:
4
5 Copyright (C) 2014 Thomas Hass, 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 "AudioFileTestViewController.h"
28
29 @implementation AudioFileTestViewController
30
31 - (void)viewDidLoad
32 {
33 [super viewDidLoad];
34 [self setTitle:@"10. Soundfile: Pitch Shifter"];
35 self.csound = [[CsoundObj alloc] init];
36 NSString *csdPath = [[NSBundle mainBundle] pathForResource:@"audiofiletest" ofType:@"csd"];
37 [self.pitchKnob setMinimumValue:0.5f];
38 [self.pitchKnob setMaximumValue:2.0f];
39 [self.pitchKnob setValue:1.0f];
40 [self.csound addBinding:self.pitchKnob];
41 [self.csound play:csdPath];
42 }
43
44 - (IBAction)play:(UIButton *)sender
45 {
46 NSString *audioFilePath = [[NSBundle mainBundle] pathForResource:@"testAudioFile"
47 ofType:@"aif"];
48 NSString *score = [NSString stringWithFormat:@"i1 0 1 \"%@\"", audioFilePath];
49 [self.csound sendScore:score];
50 }
51
52 - (IBAction)changePitch:(ControlKnob *)sender
53 {
54 [self.pitchLabel setText:[NSString stringWithFormat:@"%.2f", [sender value]]];
55 }
56
57
58 - (IBAction)stop:(UIButton *)sender {
59 [self.csound sendScore:@"i3 0 1 2"];
60 }
61
62 - (IBAction)showInfo:(UIButton *)sender {
63 UIViewController *infoVC = [[UIViewController alloc] init];
64 infoVC.modalPresentationStyle = UIModalPresentationPopover;
65
66 UIPopoverPresentationController *popover = infoVC.popoverPresentationController;
67 popover.sourceView = sender;
68 popover.sourceRect = sender.bounds;
69 [infoVC setPreferredContentSize:CGSizeMake(300, 140)];
70
71 UITextView *infoText = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, infoVC.preferredContentSize.width, infoVC.preferredContentSize.height)];
72 infoText.editable = NO;
73 infoText.selectable = NO;
74 NSString *description = @"Soundfile PitchShifter uses the URL of a bundled AIFF file and playing it with Csound. Also demonstrated is a custom UI control knob widget, used to change playback pitch.";
75 [infoText setAttributedText:[[NSAttributedString alloc] initWithString:description]];
76 infoText.font = [UIFont fontWithName:@"Menlo" size:16];
77 [infoVC.view addSubview:infoText];
78 popover.delegate = self;
79
80 [popover setPermittedArrowDirections:UIPopoverArrowDirectionUp];
81
82 [self presentViewController:infoVC animated:YES completion:nil];
83 }
84
85 - (void)viewDidUnload
86 {
87 [super viewDidUnload];
88 [self.csound stop];
89 }
90
91
92 @end