3
RecordTestViewController.m:
5
Copyright (C) 2011 Thomas Hass
7
This file is part of Csound iOS Examples.
9
The Csound for iOS Library is free software; you can redistribute it
10
and/or modify it under the terms of the GNU Lesser General Public
11
License as published by the Free Software Foundation; either
12
version 2.1 of the License, or (at your option) any later version.
14
Csound is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU Lesser General Public License for more details.
19
You should have received a copy of the GNU Lesser General Public
20
License along with Csound; if not, write to the Free Software
21
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26
#import "RecordTestViewController.h"
28
@implementation RecordTestViewController
31
self.title = @"Record Test";
33
mPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[self recordingURL] error:nil];
34
[mPlayer setDelegate:self];
37
-(IBAction) toggleOnOff:(id)component {
38
UISwitch* uiswitch = (UISwitch*)component;
39
NSLog(@"Status: %d", [uiswitch isOn]);
43
NSString *tempFile = [[NSBundle mainBundle] pathForResource:@"recordTest" ofType:@"csd"];
45
[self.csound stopCsound];
46
self.csound = [[CsoundObj alloc] init];
47
[self.csound addCompletionListener:self];
48
[self.csound addSlider:mGainSlider forChannelName:@"gain"];
49
[mLevelMeter addToCsoundObj:self.csound forChannelName:@"meter"];
50
[self.csound startCsound:tempFile];
52
[self.csound stopRecording];
53
[self.csound stopCsound];
57
- (IBAction)changeGain:(UISlider *)sender
59
[mGainLabel setText:[NSString stringWithFormat:@"%.2f", [sender value]]];
62
- (IBAction)play:(UIButton *)sender
65
[sender removeTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];
66
[sender addTarget:self action:@selector(stop:) forControlEvents:UIControlEventTouchUpInside];
67
[sender setTitle:@"Stop" forState:UIControlStateNormal];
70
- (IBAction)stop:(UIButton *)sender
73
[mPlayer setCurrentTime:0];
74
[sender removeTarget:self action:@selector(stop:) forControlEvents:UIControlEventTouchUpInside];
75
[sender addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];
76
[sender setTitle:@"Play" forState:UIControlStateNormal];
79
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
81
[mPlayer setCurrentTime:0];
82
[mPlayButton removeTarget:self action:@selector(stop:) forControlEvents:UIControlEventTouchUpInside];
83
[mPlayButton addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];
84
[mPlayButton setTitle:@"Play" forState:UIControlStateNormal];
88
[mPlayButton release];
89
[mLevelMeter release];
95
- (NSURL *)recordingURL
97
NSURL *localDocDirURL = nil;
98
if (localDocDirURL == nil) {
99
NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)
101
localDocDirURL = [NSURL fileURLWithPath:docDirPath];
103
return [localDocDirURL URLByAppendingPathComponent:@"recording.wav"];
106
#pragma mark CsoundObjCompletionListener
108
-(void)csoundObjDidStart:(CsoundObj *)csoundObj {
109
[self.csound recordToURL:[self recordingURL]];
112
-(void)csoundObjComplete:(CsoundObj *)csoundObj {
113
[mSwitch setOn:NO animated:YES];
114
if (mPlayer != nil) {
117
mPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[self recordingURL] error:nil];
118
[mPlayer setDelegate:self];