~ubuntu-branches/ubuntu/precise/csound/precise

« back to all changes in this revision

Viewing changes to iOS/Csound iOS Examples/Csound iOS Examples/ViewControllers/RecordTest/RecordTestViewController.m

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler
  • Date: 2012-04-19 09:26:46 UTC
  • mfrom: (3.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20120419092646-96xbj1n6atuqosk2
Tags: 1:5.17.6~dfsg-1
* New upstream release
 - Do not build the wiimote opcodes (we need wiiuse).
* Add new API function to symbols file
* Disable lua opcodes, they were broken. Requires OpenMP to be enabled.
* Backport fixes from upstream:
  - Link dssi4cs with dl. Backport
  - Fix building of CsoundAC

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 
 
3
 RecordTestViewController.m:
 
4
 
 
5
 Copyright (C) 2011 Thomas Hass
 
6
 
 
7
 This file is part of Csound iOS Examples.
 
8
 
 
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.   
 
13
 
 
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.
 
18
 
 
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
 
22
 02111-1307 USA
 
23
 
 
24
 */
 
25
 
 
26
#import "RecordTestViewController.h"
 
27
 
 
28
@implementation RecordTestViewController
 
29
 
 
30
-(void)viewDidLoad {
 
31
    self.title = @"Record Test";
 
32
    [super viewDidLoad];
 
33
        mPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[self recordingURL] error:nil];
 
34
        [mPlayer setDelegate:self];
 
35
}
 
36
 
 
37
-(IBAction) toggleOnOff:(id)component {
 
38
        UISwitch* uiswitch = (UISwitch*)component;
 
39
        NSLog(@"Status: %d", [uiswitch isOn]);
 
40
    
 
41
        if(uiswitch.on) {
 
42
        
 
43
        NSString *tempFile = [[NSBundle mainBundle] pathForResource:@"recordTest" ofType:@"csd"];  
 
44
        
 
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];
 
51
        } else {
 
52
                [self.csound stopRecording];
 
53
        [self.csound stopCsound];
 
54
    }
 
55
}
 
56
 
 
57
- (IBAction)changeGain:(UISlider *)sender
 
58
{
 
59
        [mGainLabel setText:[NSString stringWithFormat:@"%.2f", [sender value]]];
 
60
}
 
61
 
 
62
- (IBAction)play:(UIButton *)sender
 
63
{
 
64
        [mPlayer play];
 
65
        [sender removeTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];
 
66
        [sender addTarget:self action:@selector(stop:) forControlEvents:UIControlEventTouchUpInside];
 
67
        [sender setTitle:@"Stop" forState:UIControlStateNormal];
 
68
}
 
69
 
 
70
- (IBAction)stop:(UIButton *)sender
 
71
{
 
72
        [mPlayer stop];
 
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];
 
77
}
 
78
 
 
79
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
 
80
{
 
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];
 
85
}
 
86
 
 
87
- (void)dealloc {
 
88
        [mPlayButton release];
 
89
        [mLevelMeter release];
 
90
        [mSwitch release];
 
91
        [mPlayer release];
 
92
    [super dealloc];
 
93
}
 
94
 
 
95
- (NSURL *)recordingURL
 
96
{
 
97
    NSURL *localDocDirURL = nil;
 
98
    if (localDocDirURL == nil) {
 
99
        NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) 
 
100
                                objectAtIndex:0];
 
101
        localDocDirURL = [NSURL fileURLWithPath:docDirPath];
 
102
    }
 
103
    return [localDocDirURL URLByAppendingPathComponent:@"recording.wav"];
 
104
}
 
105
 
 
106
#pragma mark CsoundObjCompletionListener
 
107
 
 
108
-(void)csoundObjDidStart:(CsoundObj *)csoundObj {
 
109
        [self.csound recordToURL:[self recordingURL]];
 
110
}
 
111
 
 
112
-(void)csoundObjComplete:(CsoundObj *)csoundObj {
 
113
        [mSwitch setOn:NO animated:YES];
 
114
        if (mPlayer != nil) {
 
115
                [mPlayer release];
 
116
        }
 
117
        mPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[self recordingURL] error:nil];
 
118
        [mPlayer setDelegate:self];
 
119
}
 
120
 
 
121
@end