annotate ape.js @ 220:d8bad6edaa95 Dev_main

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