rt300@16
|
1 //
|
rt300@16
|
2 // QuestionnaireViewController.m
|
rt300@16
|
3 // oscSenderExample
|
rt300@16
|
4 //
|
rt300@16
|
5 // Created by Robert Tubb on 16/01/2013.
|
rt300@16
|
6 //
|
rt300@16
|
7 //
|
rt300@16
|
8
|
rt300@16
|
9 #import "QuestionnaireViewController.h"
|
rt300@16
|
10
|
rt300@16
|
11 #include "testApp.h"
|
rt300@21
|
12
|
rt300@21
|
13 #pragma mark -
|
rt300@21
|
14 #pragma mark QuestionnaireViewController
|
rt300@21
|
15
|
rt300@16
|
16 @interface QuestionnaireViewController ()
|
rt300@22
|
17 // the "model" is an array of questions
|
rt300@21
|
18 @property (strong, nonatomic) NSArray * questionArray;
|
rt300@21
|
19 @property (nonatomic) NSInteger currentQuestionIndex;
|
rt300@21
|
20 @property (nonatomic, assign) id theOFAppRef;
|
rt300@21
|
21
|
rt300@16
|
22 /*
|
rt300@16
|
23
|
rt300@16
|
24
|
rt300@16
|
25 */
|
rt300@16
|
26
|
rt300@16
|
27 @end
|
rt300@16
|
28
|
rt300@16
|
29 @implementation QuestionnaireViewController
|
rt300@16
|
30
|
rt300@21
|
31 @synthesize picker;
|
rt300@16
|
32 @synthesize nextButton = _nextButton;
|
rt300@22
|
33 @synthesize questionArray;
|
rt300@22
|
34
|
rt300@16
|
35
|
rt300@16
|
36 //----------------------------------------------------------------
|
rt300@16
|
37 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
|
rt300@16
|
38 {
|
rt300@16
|
39 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
rt300@16
|
40 if (self) {
|
rt300@16
|
41 // Custom initialization
|
rt300@16
|
42
|
rt300@16
|
43 [self populateQuestionArray ];
|
rt300@16
|
44
|
rt300@16
|
45 }
|
rt300@16
|
46 return self;
|
rt300@16
|
47 }
|
rt300@16
|
48 - (void)setAppRef:(id)theOFApp{
|
rt300@16
|
49 self.theOFAppRef = theOFApp;
|
rt300@16
|
50
|
rt300@16
|
51 }
|
rt300@16
|
52 //----------------------------------------------------------------
|
rt300@16
|
53 - (void)viewDidLoad
|
rt300@16
|
54 {
|
rt300@16
|
55 [super viewDidLoad];
|
rt300@16
|
56 // Do any additional setup after loading the view from its nib.
|
rt300@16
|
57 self.currentQuestionIndex = 0;
|
rt300@21
|
58
|
rt300@22
|
59 // load question 1
|
rt300@22
|
60 [self loadQuestion:self.currentQuestionIndex];
|
rt300@21
|
61
|
rt300@22
|
62 self.previousButton.hidden = YES; // dont bother
|
rt300@28
|
63 self.commentText.hidden = YES;
|
rt300@28
|
64 self.finishButton.hidden = YES;
|
rt300@31
|
65 self.nextButton.hidden = YES;
|
rt300@31
|
66
|
rt300@31
|
67 self.lickertOptions.hidden = NO;
|
rt300@31
|
68 self.interfacePreferenceOptions.hidden = YES;
|
rt300@16
|
69 }
|
rt300@16
|
70 //----------------------------------------------------------------
|
rt300@16
|
71 - (void)didReceiveMemoryWarning
|
rt300@16
|
72 {
|
rt300@16
|
73 [super didReceiveMemoryWarning];
|
rt300@16
|
74 // Dispose of any resources that can be recreated.
|
rt300@16
|
75 }
|
rt300@16
|
76 //----------------------------------------------------------------
|
rt300@16
|
77 - (void)dealloc {
|
rt300@16
|
78
|
rt300@16
|
79 [_questionText release];
|
rt300@16
|
80 [_titleText release];
|
rt300@16
|
81 [_finishButton release];
|
rt300@16
|
82 [_nextButton release];
|
rt300@22
|
83 [_previousButton release];
|
rt300@28
|
84 [_commentText release];
|
rt300@31
|
85 [_numberChooser release];
|
rt300@31
|
86 [_interfacePreferenceOptions release];
|
rt300@31
|
87 [_lickertOptions release];
|
rt300@31
|
88 [_pleaseAnswer release];
|
rt300@16
|
89 [super dealloc];
|
rt300@16
|
90 }
|
rt300@16
|
91 //----------------------------------------------------------------
|
rt300@16
|
92 - (void)viewDidUnload {
|
rt300@16
|
93 [self setQuestionText:nil];
|
rt300@16
|
94 [self setTitleText:nil];
|
rt300@16
|
95 [self setFinishButton:nil];
|
rt300@16
|
96 [self setNextButton:nil];
|
rt300@22
|
97 [self setPreviousButton:nil];
|
rt300@28
|
98 [self setCommentText:nil];
|
rt300@31
|
99 [self setNumberChooser:nil];
|
rt300@31
|
100 [self setInterfacePreferenceOptions:nil];
|
rt300@31
|
101 [self setLickertOptions:nil];
|
rt300@31
|
102 [self setPleaseAnswer:nil];
|
rt300@16
|
103 [super viewDidUnload];
|
rt300@16
|
104 }
|
rt300@16
|
105 //----------------------------------------------------------------
|
rt300@22
|
106 -(IBAction)hide:(id)sender{
|
rt300@22
|
107 // called when finish button hit
|
rt300@22
|
108 // c++ call with NSArray argument??
|
rt300@22
|
109 // load answers into a c++ vector;
|
rt300@22
|
110 vector<int> answersArray;
|
rt300@22
|
111
|
rt300@22
|
112 Question *q;
|
rt300@16
|
113
|
rt300@22
|
114 for(int i=0;i<[questionArray count];i++){
|
rt300@22
|
115 q = [questionArray objectAtIndex:i];
|
rt300@22
|
116 answersArray.push_back(q.answer);
|
rt300@22
|
117
|
rt300@22
|
118 }
|
rt300@28
|
119 const char *userComments = [self.commentText.text cStringUsingEncoding: NSUTF8StringEncoding];
|
rt300@28
|
120 [self.commentText resignFirstResponder];
|
rt300@28
|
121
|
rt300@16
|
122 self.view.hidden = YES;
|
rt300@29
|
123 ((testApp *)self.theOFAppRef)->questionnaireHidden(answersArray, userComments);
|
rt300@29
|
124
|
rt300@16
|
125 }
|
rt300@28
|
126
|
rt300@16
|
127 //----------------------------------------------------------------
|
rt300@16
|
128 -(IBAction)show:(id)sender{
|
rt300@16
|
129 self.view.hidden = NO;
|
rt300@16
|
130 }
|
rt300@16
|
131 //----------------------------------------------------------------
|
rt300@16
|
132
|
rt300@16
|
133 - (IBAction)nextQuestionPressed:(id)sender {
|
rt300@16
|
134 // save answer ? no button did that hopefully
|
rt300@16
|
135
|
rt300@16
|
136 // if last question show thanks
|
rt300@16
|
137 // else go to next
|
rt300@16
|
138 self.currentQuestionIndex++;
|
rt300@16
|
139 if(self.currentQuestionIndex >= [self.questionArray count]){
|
rt300@16
|
140 [self showThanks];
|
rt300@16
|
141 }else{
|
rt300@16
|
142 [self loadQuestion:self.currentQuestionIndex];
|
rt300@16
|
143
|
rt300@16
|
144 }
|
rt300@16
|
145 }
|
rt300@16
|
146 //----------------------------------------------------------------
|
rt300@16
|
147 - (IBAction)previousQuestionPressed:(id)sender {
|
rt300@16
|
148 self.currentQuestionIndex--;
|
rt300@16
|
149 if(self.currentQuestionIndex < 0){
|
rt300@16
|
150 // nothing
|
rt300@16
|
151 self.currentQuestionIndex = 0;
|
rt300@16
|
152 }else{
|
rt300@16
|
153 [self loadQuestion:self.currentQuestionIndex];
|
rt300@16
|
154 }
|
rt300@16
|
155 }
|
rt300@16
|
156
|
rt300@16
|
157 //----------------------------------------------------------------
|
rt300@16
|
158
|
rt300@16
|
159 - (void)showThanks{
|
rt300@16
|
160 // hide next question button
|
rt300@16
|
161 self.nextButton.hidden = YES;
|
rt300@16
|
162 // hide selector
|
rt300@22
|
163 self.picker.hidden = YES;
|
rt300@22
|
164 self.previousButton.hidden = YES;
|
rt300@28
|
165 self.finishButton.hidden = NO;
|
rt300@16
|
166
|
rt300@31
|
167 self.lickertOptions.hidden = YES;
|
rt300@31
|
168 self.interfacePreferenceOptions.hidden = YES;
|
rt300@31
|
169
|
rt300@16
|
170 self.titleText.text = @"Thank you!";
|
rt300@31
|
171 self.numberChooser.hidden = YES;
|
rt300@28
|
172 self.commentText.hidden = NO;
|
rt300@28
|
173
|
rt300@29
|
174 self.questionText.text = @"Thanks for helping science help you. Feel free to add further comments in the text box below, and then press 'finish' to go back and use the app, unhassled.";
|
rt300@16
|
175 }
|
rt300@16
|
176
|
rt300@16
|
177 //----------------------------------------------------------------
|
rt300@16
|
178 - (void)loadQuestion:(NSInteger)questionIndex {
|
rt300@16
|
179 // populate text fields with question
|
rt300@16
|
180 NSString *qtitle;
|
rt300@23
|
181 qtitle = [@"Question " stringByAppendingFormat:@"%d / %d",questionIndex+1, [questionArray count]];
|
rt300@16
|
182 self.titleText.text = qtitle;
|
rt300@16
|
183
|
rt300@22
|
184 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex];
|
rt300@16
|
185
|
rt300@22
|
186 self.questionText.text = curQ.questionText;
|
rt300@21
|
187
|
rt300@22
|
188
|
rt300@22
|
189 // refresh picker view content
|
rt300@21
|
190 [picker reloadComponent:0];
|
rt300@21
|
191
|
rt300@31
|
192 // show correct option number labels
|
rt300@31
|
193 if(curQ.questionType == AGREE_DISAGREE){
|
rt300@31
|
194 self.lickertOptions.hidden = NO;
|
rt300@31
|
195 self.interfacePreferenceOptions.hidden = YES;
|
rt300@31
|
196 }else if(curQ.questionType == SLIDERS_ZOOMER){
|
rt300@31
|
197 self.lickertOptions.hidden = YES;
|
rt300@31
|
198 self.interfacePreferenceOptions.hidden = NO;
|
rt300@31
|
199 }
|
rt300@31
|
200
|
rt300@31
|
201 //NSLog(@"Prev answer answerInt %d", curQ.answer);
|
rt300@27
|
202 [picker selectRow:2 inComponent:0 animated:YES];
|
rt300@22
|
203
|
rt300@16
|
204 }
|
rt300@32
|
205 // 1/3/13 removed q 6 and 15. now only 15 qs
|
rt300@16
|
206 //----------------------------------------------------------------
|
rt300@16
|
207 - (void)populateQuestionArray{
|
rt300@22
|
208
|
rt300@22
|
209 self.questionArray = [NSArray arrayWithObjects:
|
rt300@22
|
210 [[Question alloc] initWithTextAndType:@"I am familiar with music software and sound synthesis.":AGREE_DISAGREE],
|
rt300@27
|
211 [[Question alloc] initWithTextAndType:@"The best interface to get a feel for the possibilities of the synth was...":SLIDERS_ZOOMER],
|
rt300@27
|
212 [[Question alloc] initWithTextAndType:@"The best interface for discovering interesting sounds quickly was...":SLIDERS_ZOOMER],
|
rt300@27
|
213 [[Question alloc] initWithTextAndType:@"The best interface for fine tuning a sound was...":SLIDERS_ZOOMER],
|
rt300@22
|
214 [[Question alloc] initWithTextAndType:@"The correspondence between the sliders and the grid was understandable.":AGREE_DISAGREE],
|
rt300@27
|
215 [[Question alloc] initWithTextAndType:@"Scrolling a greater distance on the grid seemed to correspond to larger difference in the sound.":AGREE_DISAGREE],
|
rt300@27
|
216 [[Question alloc] initWithTextAndType:@"The interface that I felt more in control using was...":SLIDERS_ZOOMER],
|
rt300@32
|
217 [[Question alloc] initWithTextAndType:@"Being able to see previously saved presets laid on the grid is useful.":AGREE_DISAGREE], //
|
rt300@27
|
218 [[Question alloc] initWithTextAndType:@"The interface that felt more creative was...":SLIDERS_ZOOMER],
|
rt300@32
|
219 [[Question alloc] initWithTextAndType:@"The range of sounds was too limited to be able to judge the eventual usefulness of the interface.":AGREE_DISAGREE],
|
rt300@27
|
220 [[Question alloc] initWithTextAndType:@"The interface better for generating new ideas was...":SLIDERS_ZOOMER],
|
rt300@27
|
221 [[Question alloc] initWithTextAndType:@"The interface better for performing live would be...":SLIDERS_ZOOMER],
|
rt300@22
|
222 [[Question alloc] initWithTextAndType:@"The Zoomer was an improvement on just using a randomiser.":AGREE_DISAGREE],
|
rt300@27
|
223
|
rt300@22
|
224 [[Question alloc] initWithTextAndType:@"The combination of Zoomer and Sliders was better than either individually.":AGREE_DISAGREE],
|
rt300@27
|
225 [[Question alloc] initWithTextAndType:@"Overall, the interface I preferred using was...":SLIDERS_ZOOMER], // ??????
|
rt300@16
|
226 nil];
|
rt300@32
|
227 // The zoomer seemed more appropriate to explore the synth sound controls (red) than the note sequence controls (blue)
|
rt300@32
|
228 // I enjoyed the sounds produced
|
rt300@32
|
229
|
rt300@16
|
230 }
|
rt300@16
|
231
|
rt300@21
|
232 //----------------------------------------------------------------
|
rt300@21
|
233 #pragma mark -
|
rt300@21
|
234 #pragma mark PickerView DataSource
|
rt300@16
|
235
|
rt300@21
|
236 - (NSInteger)numberOfComponentsInPickerView:
|
rt300@21
|
237 (UIPickerView *)pickerView
|
rt300@21
|
238 {
|
rt300@21
|
239 return 1;
|
rt300@21
|
240 }
|
rt300@22
|
241 //----------------------------------------------------------------
|
rt300@21
|
242 - (NSInteger)pickerView:(UIPickerView *)pickerView
|
rt300@21
|
243 numberOfRowsInComponent:(NSInteger)component
|
rt300@21
|
244 {
|
rt300@27
|
245
|
rt300@27
|
246 return NUM_CHOICES; // always 6
|
rt300@21
|
247 }
|
rt300@22
|
248 //----------------------------------------------------------------
|
rt300@21
|
249 - (NSString *)pickerView:(UIPickerView *)pickerView
|
rt300@21
|
250 titleForRow:(NSInteger)row
|
rt300@21
|
251 forComponent:(NSInteger)component
|
rt300@21
|
252 {
|
rt300@22
|
253 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex];
|
rt300@22
|
254
|
rt300@22
|
255 // get array of answers from Question class
|
rt300@22
|
256 NSArray * answers = [Question answersWithType:curQ.questionType];
|
rt300@22
|
257 return [answers objectAtIndex:row];
|
rt300@22
|
258
|
rt300@21
|
259 }
|
rt300@22
|
260 //----------------------------------------------------------------
|
rt300@21
|
261 #pragma mark -
|
rt300@21
|
262 #pragma mark PickerView Delegate
|
rt300@21
|
263 -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
|
rt300@21
|
264 inComponent:(NSInteger)component
|
rt300@21
|
265 {
|
rt300@22
|
266 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex];
|
rt300@21
|
267 // set question answerArray
|
rt300@22
|
268 curQ.answer = row;
|
rt300@21
|
269
|
rt300@21
|
270 // chek wot we just rote
|
rt300@21
|
271
|
rt300@22
|
272 NSLog(@"Answer: %d",curQ.answer);
|
rt300@22
|
273
|
rt300@21
|
274 }
|
rt300@28
|
275 //----------------------------------------------------------------
|
rt300@28
|
276 #pragma mark UITextViewDelegate functions
|
rt300@28
|
277 /*
|
rt300@28
|
278 This answer was useful to me, but I was also looking for the callback function from the "Go" button, which I found is:
|
rt300@28
|
279 - (BOOL) textFieldShouldReturn:(UITextField *)textField { // Customer code return YES; }
|
rt300@28
|
280
|
rt300@28
|
281 You will need to send the UITextField delegate to your view controller for that to work.
|
rt300@28
|
282
|
rt300@28
|
283 */
|
rt300@28
|
284 - (BOOL) textFieldShouldReturn:(UITextField *)textField {
|
rt300@28
|
285 // Customer code
|
rt300@28
|
286 NSLog(@"RETURN DELEGATE");
|
rt300@28
|
287 [self hide:self ];
|
rt300@28
|
288 return NO;
|
rt300@28
|
289 }
|
rt300@31
|
290 - (IBAction)answerChosen:(id)sender {
|
rt300@31
|
291 self.pleaseAnswer.hidden = YES;
|
rt300@31
|
292 UISegmentedControl *seg = (UISegmentedControl *)sender;
|
rt300@31
|
293 Question *curQ = [questionArray objectAtIndex:self.currentQuestionIndex];
|
rt300@31
|
294 // set question answerArray
|
rt300@31
|
295 curQ.answer = seg.selectedSegmentIndex;
|
rt300@31
|
296
|
rt300@31
|
297 // chek wot we just rote
|
rt300@31
|
298
|
rt300@31
|
299 NSLog(@"Answer: %d",curQ.answer);
|
rt300@31
|
300
|
rt300@31
|
301 // automatically go next q
|
rt300@31
|
302 self.currentQuestionIndex++;
|
rt300@31
|
303 if(self.currentQuestionIndex >= [self.questionArray count]){
|
rt300@31
|
304 [self showThanks];
|
rt300@31
|
305 }else{
|
rt300@31
|
306 [self loadQuestion:self.currentQuestionIndex];
|
rt300@31
|
307
|
rt300@31
|
308 }
|
rt300@31
|
309
|
rt300@31
|
310 }
|
rt300@21
|
311 @end // end implementation
|
rt300@21
|
312 //----------------------------------------------------------------
|
rt300@21
|
313 //----------------------------------------------------------------
|