annotate ape.js @ 1043:f6e8b7156017

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