3
ConsoleOutputViewController.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 "ConsoleOutputViewController.h"
28
@implementation ConsoleOutputViewController
30
@synthesize currentMessage = mCurrentMessage;
32
- (IBAction)run:(UIButton *)sender
36
[self.csound stopCsound];
37
self.csound = [[CsoundObj alloc] init];
38
[self.csound addCompletionListener:self];
40
[self.csound setMessageCallback:@selector(messageCallback:) withListener:self];
42
NSString *csdPath = nil;
43
csdPath = [[NSBundle mainBundle] pathForResource:@"consoleoutput" ofType:@"csd"];
44
[self.csound startCsound:csdPath];
47
- (void)updateUIWithNewMessage:(NSString *)newMessage
49
NSString *oldText = mTextView.text;
50
NSString *fullText = [oldText stringByAppendingString:newMessage];
51
mTextView.text = fullText;
54
- (void)messageCallback:(NSValue *)infoObj
56
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
58
[infoObj getValue:&info];
60
vsnprintf(message, 1024, info.format, info.valist);
61
NSString *messageStr = [NSString stringWithFormat:@"%s", message];
62
[self performSelectorOnMainThread:@selector(updateUIWithNewMessage:)
68
#pragma mark - CsoundObj Listener
70
- (void)csoundObjDidStart:(CsoundObj *)csoundObj {
74
- (void)csoundObjComplete:(CsoundObj *)csoundObj {
77
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
79
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
81
self.title = @"Console Output";
86
#pragma mark - View lifecycle
95
[super viewDidUnload];
98
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
100
return (interfaceOrientation == UIInterfaceOrientationPortrait);