nicholas@2
|
1 /**
|
nicholas@2
|
2 * ape.js
|
nicholas@2
|
3 * Create the APE interface
|
nicholas@2
|
4 */
|
nicholas@2
|
5
|
n@38
|
6 // preTest - In preTest state
|
n@38
|
7 // testRun-ID - In test running, test Id number at the end 'testRun-2'
|
n@38
|
8 // testRunPost-ID - Post test of test ID
|
n@38
|
9 // testRunPre-ID - Pre-test of test ID
|
n@38
|
10 // postTest - End of test, final submission!
|
n@38
|
11
|
n@32
|
12
|
nicholas@2
|
13 // Once this is loaded and parsed, begin execution
|
n@181
|
14 loadInterface();
|
nicholas@2
|
15
|
n@181
|
16 function loadInterface() {
|
nicholas@2
|
17
|
n@16
|
18 // Get the dimensions of the screen available to the page
|
nicholas@2
|
19 var width = window.innerWidth;
|
nicholas@2
|
20 var height = window.innerHeight;
|
nicholas@2
|
21
|
nicholas@2
|
22 // The injection point into the HTML page
|
n@182
|
23 interfaceContext.insertPoint = document.getElementById("topLevelBody");
|
n@22
|
24 var testContent = document.createElement('div');
|
nicholas@135
|
25
|
n@22
|
26 testContent.id = 'testContent';
|
n@176
|
27
|
n@34
|
28
|
n@52
|
29 // Create APE specific metric functions
|
n@52
|
30 audioEngineContext.metric.initialiseTest = function()
|
n@52
|
31 {
|
n@52
|
32 };
|
n@52
|
33
|
n@52
|
34 audioEngineContext.metric.sliderMoved = function()
|
n@52
|
35 {
|
n@52
|
36 var id = this.data;
|
n@52
|
37 this.data = -1;
|
n@52
|
38 var position = convSliderPosToRate(id);
|
b@115
|
39 console.log('slider ' + id + ': '+ position + ' (' + time + ')'); // DEBUG/SAFETY: show position and slider id
|
n@52
|
40 if (audioEngineContext.timer.testStarted)
|
n@52
|
41 {
|
n@52
|
42 audioEngineContext.audioObjects[id].metric.moved(time,position);
|
n@52
|
43 }
|
n@52
|
44 };
|
n@52
|
45
|
n@52
|
46 audioEngineContext.metric.sliderPlayed = function(id)
|
n@52
|
47 {
|
n@52
|
48 var time = audioEngineContext.timer.getTestTime();
|
n@52
|
49 if (audioEngineContext.timer.testStarted)
|
n@52
|
50 {
|
n@52
|
51 if (this.lastClicked >= 0)
|
n@52
|
52 {
|
n@52
|
53 audioEngineContext.audioObjects[this.lastClicked].metric.listening(time);
|
n@52
|
54 }
|
n@52
|
55 this.lastClicked = id;
|
n@52
|
56 audioEngineContext.audioObjects[id].metric.listening(time);
|
n@52
|
57 }
|
b@115
|
58 console.log('slider ' + id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id
|
n@52
|
59 };
|
n@52
|
60
|
nicholas@214
|
61 // Bindings for interfaceContext
|
nicholas@214
|
62 Interface.prototype.checkAllPlayed = function()
|
nicholas@214
|
63 {
|
nicholas@214
|
64 hasBeenPlayed = audioEngineContext.checkAllPlayed();
|
nicholas@214
|
65 if (hasBeenPlayed.length > 0) // if a fragment has not been played yet
|
nicholas@214
|
66 {
|
nicholas@214
|
67 str = "";
|
nicholas@214
|
68 if (hasBeenPlayed.length > 1) {
|
nicholas@214
|
69 for (var i=0; i<hasBeenPlayed.length; i++) {
|
nicholas@214
|
70 str = str + hasBeenPlayed[i];
|
nicholas@214
|
71 if (i < hasBeenPlayed.length-2){
|
nicholas@214
|
72 str += ", ";
|
nicholas@214
|
73 } else if (i == hasBeenPlayed.length-2) {
|
nicholas@214
|
74 str += " or ";
|
nicholas@214
|
75 }
|
nicholas@214
|
76 }
|
nicholas@214
|
77 alert('You have not played fragments ' + str + ' yet. Please listen, rate and comment all samples before submitting.');
|
nicholas@214
|
78 } else {
|
nicholas@214
|
79 alert('You have not played fragment ' + hasBeenPlayed[0] + ' yet. Please listen, rate and comment all samples before submitting.');
|
nicholas@214
|
80 }
|
nicholas@214
|
81 return false;
|
nicholas@214
|
82 }
|
nicholas@214
|
83 return true;
|
nicholas@219
|
84 };
|
nicholas@214
|
85
|
nicholas@214
|
86 Interface.prototype.checkAllMoved = function() {
|
nicholas@214
|
87 var audioObjs = audioEngineContext.audioObjects;
|
nicholas@214
|
88 var state = true;
|
nicholas@214
|
89 var strNums = [];
|
nicholas@214
|
90 for (var i=0; i<audioObjs.length; i++)
|
nicholas@214
|
91 {
|
nicholas@214
|
92 if (audioObjs[i].metric.wasMoved == false) {
|
nicholas@214
|
93 state = false;
|
nicholas@214
|
94 strNums.push(i);
|
nicholas@214
|
95 }
|
nicholas@214
|
96 }
|
nicholas@214
|
97 if (state == false) {
|
nicholas@214
|
98 if (strNums.length > 1) {
|
nicholas@214
|
99 var str = "";
|
nicholas@214
|
100 for (var i=0; i<strNums.length; i++) {
|
nicholas@214
|
101 str = str + strNums[i];
|
nicholas@214
|
102 if (i < strNums.length-2){
|
nicholas@214
|
103 str += ", ";
|
nicholas@214
|
104 } else if (i == strNums.length-2) {
|
nicholas@214
|
105 str += " or ";
|
nicholas@214
|
106 }
|
nicholas@214
|
107 }
|
nicholas@214
|
108 alert('You have not moved fragments ' + str + ' yet. Please listen, rate and comment all samples before submitting.');
|
nicholas@214
|
109 } else {
|
nicholas@214
|
110 alert('You have not moved fragment ' + strNums[0] + ' yet. Please listen, rate and comment all samples before submitting.');
|
nicholas@214
|
111 }
|
nicholas@214
|
112 }
|
nicholas@214
|
113 return state;
|
nicholas@219
|
114 };
|
nicholas@214
|
115
|
nicholas@214
|
116 Interface.prototype.checkAllCommented = function() {
|
nicholas@214
|
117 var audioObjs = audioEngineContext.audioObjects;
|
nicholas@214
|
118 var audioHolder = testState.stateMap[testState.stateIndex];
|
nicholas@214
|
119 var state = true;
|
nicholas@214
|
120 if (audioHolder.elementComments) {
|
nicholas@214
|
121 var strNums = [];
|
nicholas@214
|
122 for (var i=0; i<audioObjs.length; i++)
|
nicholas@214
|
123 {
|
nicholas@214
|
124 if (audioObjs[i].commentDOM.trackCommentBox.value.length == 0) {
|
nicholas@214
|
125 state = false;
|
nicholas@214
|
126 strNums.push(i);
|
nicholas@214
|
127 }
|
nicholas@214
|
128 }
|
nicholas@214
|
129 if (state == false) {
|
nicholas@214
|
130 if (strNums.length > 1) {
|
nicholas@214
|
131 var str = "";
|
nicholas@214
|
132 for (var i=0; i<strNums.length; i++) {
|
nicholas@214
|
133 str = str + strNums[i];
|
nicholas@214
|
134 if (i < strNums.length-2){
|
nicholas@214
|
135 str += ", ";
|
nicholas@214
|
136 } else if (i == strNums.length-2) {
|
nicholas@214
|
137 str += " or ";
|
nicholas@214
|
138 }
|
nicholas@214
|
139 }
|
nicholas@214
|
140 alert('You have not commented on fragments ' + str + ' yet. Please listen, rate and comment all samples before submitting.');
|
nicholas@214
|
141 } else {
|
nicholas@214
|
142 alert('You have not commented on fragment ' + strNums[0] + ' yet. Please listen, rate and comment all samples before submitting.');
|
nicholas@214
|
143 }
|
nicholas@214
|
144 }
|
nicholas@214
|
145 }
|
nicholas@214
|
146 return state;
|
nicholas@219
|
147 };
|
nicholas@214
|
148
|
nicholas@231
|
149 Interface.prototype.checkScaleRange = function()
|
nicholas@231
|
150 {
|
nicholas@231
|
151 var audioObjs = audioEngineContext.audioObjects;
|
nicholas@231
|
152 var audioHolder = testState.stateMap[testState.stateIndex];
|
nicholas@231
|
153 var interfaces = audioHolder.interfaces;
|
nicholas@231
|
154
|
nicholas@231
|
155 var minRanking = audioObjs[0].interfaceDOM.getValue();
|
nicholas@231
|
156 var maxRanking = minRanking;
|
nicholas@231
|
157
|
nicholas@231
|
158 var minScale;
|
nicholas@231
|
159 var maxScale;
|
nicholas@231
|
160 for (var i=0; i<interfaces[0].options.length; i++)
|
nicholas@231
|
161 {
|
nicholas@231
|
162 if (interfaces[0].options[i].check == "scalerange") {
|
nicholas@231
|
163 minScale = interfaces[0].options[i].min;
|
nicholas@231
|
164 maxScale = interfaces[0].options[i].max;
|
nicholas@231
|
165 }
|
nicholas@231
|
166 }
|
nicholas@231
|
167
|
nicholas@231
|
168 for (var i=1; i<audioObjs.length; i++){
|
nicholas@236
|
169 if (audioObjs[i].specification.type != 'outsidereference') {
|
nicholas@236
|
170 var ranking = audioObjs[i].interfaceDOM.getValue();
|
nicholas@236
|
171 if (ranking < minRanking) { minRanking = ranking;}
|
nicholas@236
|
172 if (ranking > maxRanking) { maxRanking = ranking;}
|
nicholas@236
|
173 }
|
nicholas@231
|
174 }
|
nicholas@231
|
175 if (minRanking > minScale || maxRanking < maxScale) {
|
nicholas@231
|
176 alert('Please use the full width of the scale');
|
nicholas@231
|
177 return false;
|
nicholas@231
|
178 } else {
|
nicholas@231
|
179 return true;
|
nicholas@231
|
180 }
|
nicholas@231
|
181 };
|
nicholas@231
|
182
|
n@177
|
183 // Bindings for audioObjects
|
n@177
|
184
|
nicholas@2
|
185 // Create the top div for the Title element
|
n@181
|
186 var titleAttr = specification.title;
|
nicholas@2
|
187 var title = document.createElement('div');
|
nicholas@2
|
188 title.className = "title";
|
nicholas@2
|
189 title.align = "center";
|
nicholas@2
|
190 var titleSpan = document.createElement('span');
|
nicholas@2
|
191
|
nicholas@2
|
192 // Set title to that defined in XML, else set to default
|
nicholas@2
|
193 if (titleAttr != undefined) {
|
n@181
|
194 titleSpan.textContent = titleAttr;
|
nicholas@2
|
195 } else {
|
n@181
|
196 titleSpan.textContent = 'Listening test';
|
nicholas@2
|
197 }
|
nicholas@2
|
198 // Insert the titleSpan element into the title div element.
|
nicholas@2
|
199 title.appendChild(titleSpan);
|
nicholas@2
|
200
|
n@47
|
201 var pagetitle = document.createElement('div');
|
n@47
|
202 pagetitle.className = "pageTitle";
|
n@47
|
203 pagetitle.align = "center";
|
n@47
|
204 var titleSpan = document.createElement('span');
|
n@47
|
205 titleSpan.id = "pageTitle";
|
n@47
|
206 pagetitle.appendChild(titleSpan);
|
n@47
|
207
|
nicholas@7
|
208 // Create Interface buttons!
|
nicholas@7
|
209 var interfaceButtons = document.createElement('div');
|
nicholas@7
|
210 interfaceButtons.id = 'interface-buttons';
|
nicholas@7
|
211
|
nicholas@7
|
212 // Create playback start/stop points
|
nicholas@7
|
213 var playback = document.createElement("button");
|
b@101
|
214 playback.innerHTML = 'Stop';
|
n@49
|
215 playback.id = 'playback-button';
|
n@16
|
216 // onclick function. Check if it is playing or not, call the correct function in the
|
n@16
|
217 // audioEngine, change the button text to reflect the next state.
|
nicholas@7
|
218 playback.onclick = function() {
|
b@101
|
219 if (audioEngineContext.status == 1) {
|
b@101
|
220 audioEngineContext.stop();
|
n@25
|
221 this.innerHTML = 'Stop';
|
b@115
|
222 var time = audioEngineContext.timer.getTestTime();
|
b@115
|
223 console.log('Stopped at ' + time); // DEBUG/SAFETY
|
nicholas@7
|
224 }
|
n@16
|
225 };
|
nicholas@7
|
226 // Create Submit (save) button
|
nicholas@7
|
227 var submit = document.createElement("button");
|
n@25
|
228 submit.innerHTML = 'Submit';
|
n@43
|
229 submit.onclick = buttonSubmitClick;
|
n@49
|
230 submit.id = 'submit-button';
|
n@16
|
231 // Append the interface buttons into the interfaceButtons object.
|
nicholas@7
|
232 interfaceButtons.appendChild(playback);
|
nicholas@7
|
233 interfaceButtons.appendChild(submit);
|
nicholas@7
|
234
|
nicholas@2
|
235 // Now create the slider and HTML5 canvas boxes
|
nicholas@2
|
236
|
n@16
|
237 // Create the div box to center align
|
nicholas@2
|
238 var sliderBox = document.createElement('div');
|
nicholas@2
|
239 sliderBox.className = 'sliderCanvasDiv';
|
n@16
|
240 sliderBox.id = 'sliderCanvasHolder';
|
nicholas@2
|
241
|
n@16
|
242 // Create the slider box to hold the slider elements
|
nicholas@5
|
243 var canvas = document.createElement('div');
|
nicholas@2
|
244 canvas.id = 'slider';
|
n@127
|
245 canvas.align = "left";
|
n@127
|
246 canvas.addEventListener('dragover',function(event){
|
n@127
|
247 event.preventDefault();
|
n@127
|
248 return false;
|
n@127
|
249 },false);
|
n@127
|
250 var sliderMargin = document.createAttribute('marginsize');
|
n@127
|
251 sliderMargin.nodeValue = 42; // Set default margins to 42px either side
|
n@16
|
252 // Must have a known EXACT width, as this is used later to determine the ratings
|
n@127
|
253 var w = (Number(sliderMargin.nodeValue)+8)*2;
|
n@127
|
254 canvas.style.width = width - w +"px";
|
n@127
|
255 canvas.style.marginLeft = sliderMargin.nodeValue +'px';
|
n@127
|
256 canvas.setAttributeNode(sliderMargin);
|
nicholas@2
|
257 sliderBox.appendChild(canvas);
|
n@16
|
258
|
n@47
|
259 // Create the div to hold any scale objects
|
n@47
|
260 var scale = document.createElement('div');
|
n@47
|
261 scale.className = 'sliderScale';
|
n@47
|
262 scale.id = 'sliderScaleHolder';
|
n@47
|
263 scale.align = 'left';
|
n@47
|
264 sliderBox.appendChild(scale);
|
n@47
|
265
|
n@16
|
266 // Global parent for the comment boxes on the page
|
nicholas@3
|
267 var feedbackHolder = document.createElement('div');
|
n@34
|
268 feedbackHolder.id = 'feedbackHolder';
|
nicholas@2
|
269
|
n@38
|
270 testContent.style.zIndex = 1;
|
n@182
|
271 interfaceContext.insertPoint.innerHTML = null; // Clear the current schema
|
n@38
|
272
|
n@38
|
273 // Inject into HTML
|
n@38
|
274 testContent.appendChild(title); // Insert the title
|
n@47
|
275 testContent.appendChild(pagetitle);
|
n@38
|
276 testContent.appendChild(interfaceButtons);
|
n@38
|
277 testContent.appendChild(sliderBox);
|
n@38
|
278 testContent.appendChild(feedbackHolder);
|
n@182
|
279 interfaceContext.insertPoint.appendChild(testContent);
|
n@22
|
280
|
n@36
|
281 // Load the full interface
|
nicholas@129
|
282 testState.initialise();
|
nicholas@129
|
283 testState.advanceState();
|
nicholas@135
|
284
|
nicholas@2
|
285 }
|
nicholas@5
|
286
|
n@181
|
287 function loadTest(audioHolderObject)
|
n@34
|
288 {
|
nicholas@110
|
289
|
nicholas@110
|
290 // Reset audioEngineContext.Metric globals for new test
|
n@113
|
291 audioEngineContext.newTestPage();
|
nicholas@110
|
292
|
n@181
|
293 var id = audioHolderObject.id;
|
n@34
|
294
|
n@34
|
295 var feedbackHolder = document.getElementById('feedbackHolder');
|
n@34
|
296 var canvas = document.getElementById('slider');
|
n@34
|
297 feedbackHolder.innerHTML = null;
|
n@34
|
298 canvas.innerHTML = null;
|
n@47
|
299
|
nicholas@256
|
300 var interfaceObj = audioHolderObject.interfaces;
|
nicholas@256
|
301 for (var k=0; k<interfaceObj.length; k++) {
|
nicholas@256
|
302 for (var i=0; i<interfaceObj[k].options.length; i++)
|
nicholas@256
|
303 {
|
nicholas@256
|
304 if (interfaceObj[k].options[i].type == 'option' && interfaceObj[k].options[i].name == 'playhead')
|
nicholas@256
|
305 {
|
nicholas@256
|
306 var playbackHolder = document.getElementById('playback-holder');
|
nicholas@256
|
307 if (playbackHolder == null)
|
nicholas@256
|
308 {
|
nicholas@256
|
309 playbackHolder = document.createElement('div');
|
nicholas@256
|
310 playbackHolder.style.width = "100%";
|
nicholas@256
|
311 playbackHolder.align = 'center';
|
nicholas@256
|
312 playbackHolder.appendChild(interfaceContext.playhead.object);
|
nicholas@256
|
313 feedbackHolder.appendChild(playbackHolder);
|
nicholas@256
|
314 }
|
nicholas@256
|
315 break;
|
nicholas@256
|
316 }
|
nicholas@256
|
317 }
|
nicholas@256
|
318 }
|
n@47
|
319 // Setup question title
|
nicholas@256
|
320
|
n@184
|
321 var commentBoxPrefix = "Comment on track";
|
n@184
|
322 if (interfaceObj.length != 0) {
|
n@184
|
323 interfaceObj = interfaceObj[0];
|
n@184
|
324 var titleNode = interfaceObj.title;
|
n@184
|
325 if (titleNode != undefined)
|
n@184
|
326 {
|
n@184
|
327 document.getElementById('pageTitle').textContent = titleNode;
|
n@184
|
328 }
|
n@184
|
329 var positionScale = canvas.style.width.substr(0,canvas.style.width.length-2);
|
n@184
|
330 var offset = Number(document.getElementById('slider').attributes['marginsize'].value);
|
n@184
|
331 var scale = document.getElementById('sliderScaleHolder');
|
n@184
|
332 scale.innerHTML = null;
|
n@184
|
333 $(interfaceObj.scale).each(function(index,scaleObj){
|
n@184
|
334 var value = document.createAttribute('value');
|
n@184
|
335 var position = Number(scaleObj[0])*0.01;
|
n@184
|
336 value.nodeValue = position;
|
n@184
|
337 var pixelPosition = (position*positionScale)+offset;
|
n@184
|
338 var scaleDOM = document.createElement('span');
|
n@184
|
339 scaleDOM.textContent = scaleObj[1];
|
n@184
|
340 scale.appendChild(scaleDOM);
|
n@184
|
341 scaleDOM.style.left = Math.floor((pixelPosition-($(scaleDOM).width()/2)))+'px';
|
n@184
|
342 scaleDOM.setAttributeNode(value);
|
n@184
|
343 });
|
n@184
|
344
|
n@184
|
345 if (interfaceObj.commentBoxPrefix != undefined) {
|
n@184
|
346 commentBoxPrefix = interfaceObj.commentBoxPrefix;
|
n@184
|
347 }
|
n@174
|
348 }
|
n@34
|
349
|
n@34
|
350 /// CHECK FOR SAMPLE RATE COMPATIBILITY
|
n@181
|
351 if (audioHolderObject.sampleRate != undefined) {
|
n@181
|
352 if (Number(audioHolderObject.sampleRate) != audioContext.sampleRate) {
|
n@184
|
353 var errStr = 'Sample rates do not match! Requested '+Number(audioHolderObject.sampleRate)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.';
|
n@34
|
354 alert(errStr);
|
n@34
|
355 return;
|
n@34
|
356 }
|
n@34
|
357 }
|
n@45
|
358
|
n@181
|
359 var commentShow = audioHolderObject.elementComments;
|
nicholas@66
|
360
|
n@181
|
361 var loopPlayback = audioHolderObject.loop;
|
n@181
|
362
|
n@57
|
363 audioEngineContext.loopPlayback = loopPlayback;
|
n@57
|
364 // Create AudioEngine bindings for playback
|
n@202
|
365 audioEngineContext.selectedTrack = function(id) {
|
n@202
|
366 console.log('Deprecated');
|
n@202
|
367 };
|
n@57
|
368
|
n@46
|
369 currentTestHolder = document.createElement('audioHolder');
|
n@181
|
370 currentTestHolder.id = audioHolderObject.id;
|
n@181
|
371 currentTestHolder.repeatCount = audioHolderObject.repeatCount;
|
n@46
|
372
|
nicholas@58
|
373 // Delete any previous audioObjects associated with the audioEngine
|
nicholas@58
|
374 audioEngineContext.audioObjects = [];
|
nicholas@211
|
375 interfaceContext.deleteCommentBoxes();
|
nicholas@237
|
376 interfaceContext.deleteCommentQuestions();
|
nicholas@58
|
377
|
n@45
|
378 // Find all the audioElements from the audioHolder
|
n@181
|
379 $(audioHolderObject.audioElements).each(function(index,element){
|
n@34
|
380 // Find URL of track
|
n@34
|
381 // In this jQuery loop, variable 'this' holds the current audioElement.
|
n@34
|
382
|
n@34
|
383 // Now load each audio sample. First create the new track by passing the full URL
|
n@181
|
384 var trackURL = audioHolderObject.hostURL + element.url;
|
n@182
|
385 var audioObject = audioEngineContext.newTrack(element);
|
nicholas@66
|
386
|
n@205
|
387 var node = interfaceContext.createCommentBox(audioObject);
|
n@34
|
388
|
n@34
|
389 // Create a slider per track
|
n@183
|
390 audioObject.interfaceDOM = new sliderObject(audioObject);
|
n@154
|
391
|
n@34
|
392 // Distribute it randomnly
|
n@138
|
393 var w = window.innerWidth - (offset+8)*2;
|
n@34
|
394 w = Math.random()*w;
|
n@138
|
395 w = Math.floor(w+(offset+8));
|
n@183
|
396 audioObject.interfaceDOM.trackSliderObj.style.left = w+'px';
|
n@34
|
397
|
n@183
|
398 canvas.appendChild(audioObject.interfaceDOM.trackSliderObj);
|
n@183
|
399 audioObject.metric.initialised(convSliderPosToRate(audioObject.interfaceDOM.trackSliderObj));
|
b@102
|
400
|
n@34
|
401 });
|
n@182
|
402 if (commentShow) {
|
n@182
|
403 interfaceContext.showCommentBoxes(feedbackHolder,true);
|
n@182
|
404 }
|
n@39
|
405
|
n@181
|
406 $(audioHolderObject.commentQuestions).each(function(index,element) {
|
n@193
|
407 var node = interfaceContext.createCommentQuestion(element);
|
n@193
|
408 feedbackHolder.appendChild(node.holder);
|
nicholas@65
|
409 });
|
n@153
|
410
|
nicholas@236
|
411 // Construct outside reference;
|
nicholas@236
|
412 if (audioHolderObject.outsideReference != null) {
|
nicholas@236
|
413 var outsideReferenceHolder = document.createElement('div');
|
nicholas@236
|
414 outsideReferenceHolder.id = 'outside-reference';
|
nicholas@236
|
415 outsideReferenceHolderspan = document.createElement('span');
|
nicholas@236
|
416 outsideReferenceHolderspan.textContent = 'Reference';
|
nicholas@236
|
417 outsideReferenceHolder.appendChild(outsideReferenceHolderspan);
|
nicholas@236
|
418
|
nicholas@236
|
419 var audioObject = audioEngineContext.newTrack(audioHolderObject.outsideReference);
|
nicholas@236
|
420
|
nicholas@236
|
421 outsideReferenceHolder.onclick = function()
|
nicholas@236
|
422 {
|
nicholas@236
|
423 audioEngineContext.play(audioEngineContext.audioObjects.length-1);
|
nicholas@236
|
424 $('.track-slider').removeClass('track-slider-playing');
|
nicholas@236
|
425 $('.comment-div').removeClass('comment-box-playing');
|
nicholas@236
|
426 if (event.srcElement.nodeName == 'DIV') {
|
nicholas@236
|
427 $(event.srcElement).addClass('track-slider-playing');
|
nicholas@236
|
428 } else {
|
nicholas@236
|
429 $(event.srcElement.parentElement).addClass('track-slider-playing');
|
nicholas@236
|
430 }
|
nicholas@236
|
431 };
|
nicholas@236
|
432
|
nicholas@236
|
433 document.getElementById('interface-buttons').appendChild(outsideReferenceHolder);
|
nicholas@236
|
434 }
|
nicholas@236
|
435
|
n@153
|
436
|
nicholas@271
|
437 //testWaitIndicator();
|
n@39
|
438 }
|
n@39
|
439
|
n@183
|
440 function sliderObject(audioObject) {
|
n@183
|
441 // Create a new slider object;
|
n@183
|
442 this.parent = audioObject;
|
n@183
|
443 this.trackSliderObj = document.createElement('div');
|
nicholas@271
|
444 this.trackSliderObj.className = 'track-slider track-slider-disabled';
|
n@183
|
445 this.trackSliderObj.id = 'track-slider-'+audioObject.id;
|
n@183
|
446
|
n@183
|
447 this.trackSliderObj.setAttribute('trackIndex',audioObject.id);
|
n@183
|
448 this.trackSliderObj.innerHTML = '<span>'+audioObject.id+'</span>';
|
n@183
|
449 this.trackSliderObj.draggable = true;
|
n@183
|
450 this.trackSliderObj.ondragend = dragEnd;
|
n@183
|
451
|
n@183
|
452 // Onclick, switch playback to that track
|
n@183
|
453 this.trackSliderObj.onclick = function() {
|
n@183
|
454 // Start the test on first click, that way timings are more accurate.
|
n@183
|
455 audioEngineContext.play();
|
n@183
|
456 if (audioEngineContext.audioObjectsReady) {
|
n@183
|
457 // Cannot continue to issue play command until audioObjects reported as ready!
|
n@183
|
458 // Get the track ID from the object ID
|
nicholas@210
|
459 var element;
|
nicholas@210
|
460 if (event.srcElement.nodeName == "SPAN") {
|
nicholas@210
|
461 element = event.srcElement.parentNode;
|
nicholas@210
|
462 } else {
|
nicholas@210
|
463 element = event.srcElement;
|
nicholas@210
|
464 }
|
nicholas@210
|
465 var id = Number(element.attributes['trackIndex'].value);
|
n@183
|
466 //audioEngineContext.metric.sliderPlayed(id);
|
n@202
|
467 audioEngineContext.play(id);
|
n@183
|
468 // Currently playing track red, rest green
|
n@183
|
469
|
n@183
|
470 //document.getElementById('track-slider-'+index).style.backgroundColor = "#FF0000";
|
n@183
|
471 $('.track-slider').removeClass('track-slider-playing');
|
nicholas@210
|
472 $(element).addClass('track-slider-playing');
|
n@183
|
473 $('.comment-div').removeClass('comment-box-playing');
|
n@183
|
474 $('#comment-div-'+id).addClass('comment-box-playing');
|
nicholas@236
|
475 var outsideReference = document.getElementById('outside-reference');
|
nicholas@236
|
476 if (outsideReference != undefined)
|
nicholas@236
|
477 $(outsideReference).removeClass('track-slider-playing');
|
n@183
|
478 }
|
n@183
|
479 };
|
n@183
|
480
|
nicholas@271
|
481 this.enable = function() {
|
nicholas@271
|
482 if (this.parent.state == 1)
|
nicholas@271
|
483 {
|
nicholas@271
|
484 $(this.trackSliderObj).removeClass('track-slider-disabled');
|
nicholas@271
|
485 }
|
nicholas@271
|
486 };
|
nicholas@271
|
487
|
nicholas@219
|
488 this.exportXMLDOM = function(audioObject) {
|
n@183
|
489 // Called by the audioObject holding this element. Must be present
|
n@183
|
490 var node = document.createElement('value');
|
n@183
|
491 node.textContent = convSliderPosToRate(this.trackSliderObj);
|
n@183
|
492 return node;
|
n@183
|
493 };
|
nicholas@219
|
494 this.getValue = function() {
|
nicholas@219
|
495 return convSliderPosToRate(this.trackSliderObj);
|
nicholas@220
|
496 };
|
n@183
|
497 }
|
nicholas@119
|
498
|
nicholas@5
|
499 function dragEnd(ev) {
|
nicholas@5
|
500 // Function call when a div has been dropped
|
n@33
|
501 var slider = document.getElementById('slider');
|
n@127
|
502 var marginSize = Number(slider.attributes['marginsize'].value);
|
n@51
|
503 var w = slider.style.width;
|
n@51
|
504 w = Number(w.substr(0,w.length-2));
|
nicholas@133
|
505 var x = ev.x;
|
n@127
|
506 if (x >= marginSize && x < w+marginSize) {
|
n@51
|
507 this.style.left = (x)+'px';
|
nicholas@5
|
508 } else {
|
n@127
|
509 if (x<marginSize) {
|
n@127
|
510 this.style.left = marginSize+'px';
|
nicholas@5
|
511 } else {
|
n@127
|
512 this.style.left = (w+marginSize) + 'px';
|
nicholas@5
|
513 }
|
nicholas@5
|
514 }
|
n@183
|
515 var time = audioEngineContext.timer.getTestTime();
|
n@183
|
516 var id = Number(ev.srcElement.getAttribute('trackindex'));
|
n@183
|
517 audioEngineContext.audioObjects[id].metric.moved(time,convSliderPosToRate(ev.srcElement));
|
b@254
|
518 console.log('slider '+id+' moved to '+convSliderPosToRate(ev.srcElement)+' ('+time+')');
|
nicholas@5
|
519 }
|
nicholas@7
|
520
|
b@101
|
521 function buttonSubmitClick() // TODO: Only when all songs have been played!
|
n@40
|
522 {
|
nicholas@232
|
523 var checks = testState.currentStateMap[testState.currentIndex].interfaces[0].options;
|
nicholas@214
|
524 var canContinue = true;
|
nicholas@219
|
525
|
nicholas@219
|
526 // Check that the anchor and reference objects are correctly placed
|
nicholas@235
|
527 if (interfaceContext.checkHiddenAnchor() == false) {return;}
|
nicholas@235
|
528 if (interfaceContext.checkHiddenReference() == false) {return;}
|
nicholas@219
|
529
|
nicholas@214
|
530 for (var i=0; i<checks.length; i++) {
|
nicholas@214
|
531 if (checks[i].type == 'check')
|
nicholas@214
|
532 {
|
nicholas@214
|
533 switch(checks[i].check) {
|
nicholas@214
|
534 case 'fragmentPlayed':
|
nicholas@214
|
535 // Check if all fragments have been played
|
nicholas@214
|
536 var checkState = interfaceContext.checkAllPlayed();
|
nicholas@214
|
537 if (checkState == false) {canContinue = false;}
|
nicholas@214
|
538 break;
|
nicholas@214
|
539 case 'fragmentFullPlayback':
|
nicholas@214
|
540 // Check all fragments have been played to their full length
|
nicholas@214
|
541 var checkState = interfaceContext.checkAllPlayed();
|
nicholas@214
|
542 if (checkState == false) {canContinue = false;}
|
nicholas@214
|
543 console.log('NOTE: fragmentFullPlayback not currently implemented, performing check fragmentPlayed instead');
|
nicholas@214
|
544 break;
|
nicholas@214
|
545 case 'fragmentMoved':
|
nicholas@214
|
546 // Check all fragment sliders have been moved.
|
nicholas@214
|
547 var checkState = interfaceContext.checkAllMoved();
|
nicholas@214
|
548 if (checkState == false) {canContinue = false;}
|
nicholas@214
|
549 break;
|
nicholas@214
|
550 case 'fragmentComments':
|
nicholas@214
|
551 // Check all fragment sliders have been moved.
|
nicholas@214
|
552 var checkState = interfaceContext.checkAllCommented();
|
nicholas@214
|
553 if (checkState == false) {canContinue = false;}
|
nicholas@214
|
554 break;
|
nicholas@231
|
555 case 'scalerange':
|
nicholas@231
|
556 // Check the scale is used to its full width outlined by the node
|
nicholas@231
|
557 var checkState = interfaceContext.checkScaleRange();
|
nicholas@231
|
558 if (checkState == false) {canContinue = false;}
|
nicholas@231
|
559 break;
|
nicholas@214
|
560 }
|
nicholas@214
|
561
|
nicholas@214
|
562 }
|
nicholas@231
|
563 if (!canContinue) {break;}
|
nicholas@214
|
564 }
|
nicholas@214
|
565
|
nicholas@214
|
566 if (canContinue) {
|
nicholas@107
|
567 if (audioEngineContext.status == 1) {
|
nicholas@107
|
568 var playback = document.getElementById('playback-button');
|
nicholas@107
|
569 playback.click();
|
nicholas@107
|
570 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
|
nicholas@107
|
571 } else
|
nicholas@107
|
572 {
|
nicholas@107
|
573 if (audioEngineContext.timer.testStarted == false)
|
nicholas@107
|
574 {
|
nicholas@107
|
575 alert('You have not started the test! Please press start to begin the test!');
|
nicholas@107
|
576 return;
|
nicholas@107
|
577 }
|
nicholas@107
|
578 }
|
nicholas@129
|
579 testState.advanceState();
|
nicholas@214
|
580 }
|
n@40
|
581 }
|
n@40
|
582
|
n@183
|
583 function convSliderPosToRate(slider)
|
n@51
|
584 {
|
n@51
|
585 var w = document.getElementById('slider').style.width;
|
n@127
|
586 var marginsize = Number(document.getElementById('slider').attributes['marginsize'].value);
|
n@51
|
587 var maxPix = w.substr(0,w.length-2);
|
n@51
|
588 var pix = slider.style.left;
|
n@51
|
589 pix = pix.substr(0,pix.length-2);
|
n@127
|
590 var rate = (pix-marginsize)/maxPix;
|
n@51
|
591 return rate;
|
n@51
|
592 }
|
n@51
|
593
|
n@127
|
594 function resizeWindow(event){
|
n@127
|
595 // Function called when the window has been resized.
|
n@127
|
596 // MANDATORY FUNCTION
|
n@127
|
597
|
n@127
|
598 // Store the slider marker values
|
n@127
|
599 var holdValues = [];
|
n@127
|
600 $(".track-slider").each(function(index,sliderObj){
|
n@127
|
601 holdValues.push(convSliderPosToRate(index));
|
n@127
|
602 });
|
n@127
|
603
|
n@127
|
604 var width = event.target.innerWidth;
|
n@127
|
605 var canvas = document.getElementById('sliderCanvasHolder');
|
n@127
|
606 var sliderDiv = canvas.children[0];
|
n@127
|
607 var sliderScaleDiv = canvas.children[1];
|
n@127
|
608 var marginsize = Number(sliderDiv.attributes['marginsize'].value);
|
n@127
|
609 var w = (marginsize+8)*2;
|
n@127
|
610 sliderDiv.style.width = width - w + 'px';
|
n@127
|
611 var width = width - w;
|
n@127
|
612 // Move sliders into new position
|
n@127
|
613 $(".track-slider").each(function(index,sliderObj){
|
n@127
|
614 var pos = holdValues[index];
|
n@127
|
615 var pix = pos * width;
|
n@127
|
616 sliderObj.style.left = pix+marginsize+'px';
|
n@127
|
617 });
|
n@127
|
618
|
n@127
|
619 // Move scale labels
|
n@127
|
620 $(sliderScaleDiv.children).each(function(index,scaleObj){
|
n@127
|
621 var position = Number(scaleObj.attributes['value'].value);
|
n@127
|
622 var pixelPosition = (position*width)+marginsize;
|
n@127
|
623 scaleObj.style.left = Math.floor((pixelPosition-($(scaleObj).width()/2)))+'px';
|
n@127
|
624 });
|
n@127
|
625 }
|
n@127
|
626
|
n@181
|
627 function pageXMLSave(store, testXML)
|
n@44
|
628 {
|
n@44
|
629 // Saves a specific test page
|
nicholas@129
|
630 var xmlDoc = store;
|
n@50
|
631 // Check if any session wide metrics are enabled
|
nicholas@67
|
632
|
n@181
|
633 var commentShow = testXML.elementComments;
|
nicholas@67
|
634
|
n@50
|
635 var metric = document.createElement('metric');
|
n@50
|
636 if (audioEngineContext.metric.enableTestTimer)
|
n@50
|
637 {
|
n@50
|
638 var testTime = document.createElement('metricResult');
|
n@50
|
639 testTime.id = 'testTime';
|
n@50
|
640 testTime.textContent = audioEngineContext.timer.testDuration;
|
n@50
|
641 metric.appendChild(testTime);
|
n@50
|
642 }
|
n@50
|
643 xmlDoc.appendChild(metric);
|
n@178
|
644 var audioObjects = audioEngineContext.audioObjects;
|
n@178
|
645 for (var i=0; i<audioObjects.length; i++)
|
n@45
|
646 {
|
n@183
|
647 var audioElement = audioEngineContext.audioObjects[i].exportXMLDOM();
|
nicholas@233
|
648 audioElement.setAttribute('presentedId',i);
|
n@45
|
649 xmlDoc.appendChild(audioElement);
|
n@45
|
650 }
|
n@193
|
651
|
n@193
|
652 $(interfaceContext.commentQuestions).each(function(index,element){
|
n@193
|
653 var node = element.exportXMLDOM();
|
n@193
|
654 xmlDoc.appendChild(node);
|
n@193
|
655 });
|
nicholas@129
|
656 store = xmlDoc;
|
nicholas@67
|
657 } |