annotate ape.js @ 1037:309a63c5d360

Merge into dev_main
author Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk>
date Thu, 18 Jun 2015 16:26:45 +0100
parents a049c6cf7eb3
children db70840ba8bb
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
n@907 150 // Bindings for audioObjects
n@907 151
nicholas@2 152 // Create the top div for the Title element
n@911 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@911 161 titleSpan.textContent = titleAttr;
nicholas@2 162 } else {
n@911 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@671 168 var pagetitle = document.createElement('div');
n@671 169 pagetitle.className = "pageTitle";
n@671 170 pagetitle.align = "center";
n@671 171 var titleSpan = document.createElement('span');
n@671 172 titleSpan.id = "pageTitle";
n@671 173 pagetitle.appendChild(titleSpan);
n@671 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");
BrechtDeMan@939 181 playback.innerHTML = 'Stop';
n@673 182 playback.id = 'playback-button';
n@701 183 // onclick function. Check if it is playing or not, call the correct function in the
n@701 184 // audioEngine, change the button text to reflect the next state.
nicholas@7 185 playback.onclick = function() {
BrechtDeMan@939 186 if (audioEngineContext.status == 1) {
BrechtDeMan@939 187 audioEngineContext.stop();
n@709 188 this.innerHTML = 'Stop';
BrechtDeMan@936 189 var time = audioEngineContext.timer.getTestTime();
BrechtDeMan@936 190 console.log('Stopped at ' + time); // DEBUG/SAFETY
nicholas@7 191 }
n@701 192 };
nicholas@7 193 // Create Submit (save) button
nicholas@7 194 var submit = document.createElement("button");
n@709 195 submit.innerHTML = 'Submit';
n@667 196 submit.onclick = buttonSubmitClick;
n@673 197 submit.id = 'submit-button';
n@701 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@701 204 // Create the div box to center align
nicholas@2 205 var sliderBox = document.createElement('div');
nicholas@2 206 sliderBox.className = 'sliderCanvasDiv';
n@701 207 sliderBox.id = 'sliderCanvasHolder';
nicholas@2 208
n@701 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@963 212 canvas.align = "left";
n@963 213 canvas.addEventListener('dragover',function(event){
n@963 214 event.preventDefault();
n@963 215 return false;
n@963 216 },false);
n@963 217 var sliderMargin = document.createAttribute('marginsize');
n@963 218 sliderMargin.nodeValue = 42; // Set default margins to 42px either side
n@701 219 // Must have a known EXACT width, as this is used later to determine the ratings
n@963 220 var w = (Number(sliderMargin.nodeValue)+8)*2;
n@963 221 canvas.style.width = width - w +"px";
n@963 222 canvas.style.marginLeft = sliderMargin.nodeValue +'px';
n@963 223 canvas.setAttributeNode(sliderMargin);
nicholas@2 224 sliderBox.appendChild(canvas);
n@701 225
n@671 226 // Create the div to hold any scale objects
n@671 227 var scale = document.createElement('div');
n@671 228 scale.className = 'sliderScale';
n@671 229 scale.id = 'sliderScaleHolder';
n@671 230 scale.align = 'left';
n@671 231 sliderBox.appendChild(scale);
n@671 232
n@701 233 // Global parent for the comment boxes on the page
nicholas@3 234 var feedbackHolder = document.createElement('div');
n@658 235 feedbackHolder.id = 'feedbackHolder';
n@656 236
n@662 237 testContent.style.zIndex = 1;
n@912 238 interfaceContext.insertPoint.innerHTML = null; // Clear the current schema
n@656 239
n@662 240 // Inject into HTML
n@662 241 testContent.appendChild(title); // Insert the title
n@671 242 testContent.appendChild(pagetitle);
n@662 243 testContent.appendChild(interfaceButtons);
n@662 244 testContent.appendChild(sliderBox);
n@662 245 testContent.appendChild(feedbackHolder);
n@912 246 interfaceContext.insertPoint.appendChild(testContent);
n@656 247
n@660 248 // Load the full interface
nicholas@964 249 testState.initialise();
nicholas@964 250 testState.advanceState();
n@663 251
n@656 252 }
n@656 253
n@911 254 function loadTest(audioHolderObject)
n@658 255 {
nicholas@947 256
nicholas@947 257 // Reset audioEngineContext.Metric globals for new test
n@950 258 audioEngineContext.newTestPage();
nicholas@947 259
n@911 260 var id = audioHolderObject.id;
n@658 261
n@658 262 var feedbackHolder = document.getElementById('feedbackHolder');
n@658 263 var canvas = document.getElementById('slider');
n@658 264 feedbackHolder.innerHTML = null;
n@658 265 canvas.innerHTML = null;
n@671 266
nicholas@892 267 //var playbackHolder = document.createElement('div');
nicholas@892 268 //playbackHolder.style.width = "100%";
nicholas@892 269 //playbackHolder.align = 'center';
nicholas@892 270 //playbackHolder.appendChild(interfaceContext.playhead.object);
nicholas@892 271 //feedbackHolder.appendChild(playbackHolder);
n@671 272 // Setup question title
n@914 273 var interfaceObj = audioHolderObject.interfaces;
n@914 274 var commentBoxPrefix = "Comment on track";
n@914 275 if (interfaceObj.length != 0) {
n@914 276 interfaceObj = interfaceObj[0];
n@914 277 var titleNode = interfaceObj.title;
n@914 278 if (titleNode != undefined)
n@914 279 {
n@914 280 document.getElementById('pageTitle').textContent = titleNode;
n@914 281 }
n@914 282 var positionScale = canvas.style.width.substr(0,canvas.style.width.length-2);
n@914 283 var offset = Number(document.getElementById('slider').attributes['marginsize'].value);
n@914 284 var scale = document.getElementById('sliderScaleHolder');
n@914 285 scale.innerHTML = null;
n@914 286 $(interfaceObj.scale).each(function(index,scaleObj){
n@914 287 var value = document.createAttribute('value');
n@914 288 var position = Number(scaleObj[0])*0.01;
n@914 289 value.nodeValue = position;
n@914 290 var pixelPosition = (position*positionScale)+offset;
n@914 291 var scaleDOM = document.createElement('span');
n@914 292 scaleDOM.textContent = scaleObj[1];
n@914 293 scale.appendChild(scaleDOM);
n@914 294 scaleDOM.style.left = Math.floor((pixelPosition-($(scaleDOM).width()/2)))+'px';
n@914 295 scaleDOM.setAttributeNode(value);
n@914 296 });
n@914 297
n@914 298 if (interfaceObj.commentBoxPrefix != undefined) {
n@914 299 commentBoxPrefix = interfaceObj.commentBoxPrefix;
n@914 300 }
n@1022 301 }
n@658 302
nicholas@7 303 /// CHECK FOR SAMPLE RATE COMPATIBILITY
n@911 304 if (audioHolderObject.sampleRate != undefined) {
n@911 305 if (Number(audioHolderObject.sampleRate) != audioContext.sampleRate) {
n@914 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.';
nicholas@7 307 alert(errStr);
nicholas@7 308 return;
nicholas@7 309 }
nicholas@7 310 }
n@669 311
n@911 312 var commentShow = audioHolderObject.elementComments;
nicholas@689 313
n@911 314 var loopPlayback = audioHolderObject.loop;
n@911 315
n@681 316 audioEngineContext.loopPlayback = loopPlayback;
n@681 317 // Create AudioEngine bindings for playback
n@895 318 audioEngineContext.selectedTrack = function(id) {
n@895 319 console.log('Deprecated');
n@895 320 };
n@681 321
n@670 322 currentTestHolder = document.createElement('audioHolder');
n@911 323 currentTestHolder.id = audioHolderObject.id;
n@911 324 currentTestHolder.repeatCount = audioHolderObject.repeatCount;
n@670 325
n@911 326 var randomise = audioHolderObject.randomiseOrder;
n@669 327
n@911 328 var audioElements = audioHolderObject.audioElements;
nicholas@682 329 currentTrackOrder = [];
n@669 330 if (randomise) {
n@911 331 audioHolderObject.audioElements = randomiseOrder(audioHolderObject.audioElements);
n@669 332 }
n@669 333
nicholas@682 334 // Delete any previous audioObjects associated with the audioEngine
nicholas@682 335 audioEngineContext.audioObjects = [];
nicholas@900 336 interfaceContext.deleteCommentBoxes();
nicholas@682 337
n@701 338 // Find all the audioElements from the audioHolder
n@911 339 $(audioHolderObject.audioElements).each(function(index,element){
nicholas@7 340 // Find URL of track
n@701 341 // In this jQuery loop, variable 'this' holds the current audioElement.
n@701 342
n@701 343 // Now load each audio sample. First create the new track by passing the full URL
n@911 344 var trackURL = audioHolderObject.hostURL + element.url;
n@912 345 var audioObject = audioEngineContext.newTrack(element);
nicholas@689 346
n@1029 347 var node = interfaceContext.createCommentBox(audioObject);
n@701 348
nicholas@5 349 // Create a slider per track
n@913 350 audioObject.interfaceDOM = new sliderObject(audioObject);
n@1008 351
nicholas@5 352 // Distribute it randomnly
n@1000 353 var w = window.innerWidth - (offset+8)*2;
nicholas@5 354 w = Math.random()*w;
n@1000 355 w = Math.floor(w+(offset+8));
n@913 356 audioObject.interfaceDOM.trackSliderObj.style.left = w+'px';
nicholas@8 357
n@913 358 canvas.appendChild(audioObject.interfaceDOM.trackSliderObj);
n@913 359 audioObject.metric.initialised(convSliderPosToRate(audioObject.interfaceDOM.trackSliderObj));
BrechtDeMan@940 360
n@700 361 });
n@912 362 if (commentShow) {
n@912 363 interfaceContext.showCommentBoxes(feedbackHolder,true);
n@912 364 }
nicholas@3 365
n@911 366 $(audioHolderObject.commentQuestions).each(function(index,element) {
n@1026 367 var node = interfaceContext.createCommentQuestion(element);
n@1026 368 feedbackHolder.appendChild(node.holder);
nicholas@688 369 });
n@1007 370
n@1007 371
n@1007 372 testWaitIndicator();
n@663 373 }
n@663 374
n@913 375 function sliderObject(audioObject) {
n@913 376 // Create a new slider object;
n@913 377 this.parent = audioObject;
n@913 378 this.trackSliderObj = document.createElement('div');
n@913 379 this.trackSliderObj.className = 'track-slider';
n@913 380 this.trackSliderObj.id = 'track-slider-'+audioObject.id;
n@913 381
n@913 382 this.trackSliderObj.setAttribute('trackIndex',audioObject.id);
n@913 383 this.trackSliderObj.innerHTML = '<span>'+audioObject.id+'</span>';
n@913 384 this.trackSliderObj.draggable = true;
n@913 385 this.trackSliderObj.ondragend = dragEnd;
n@913 386
n@913 387 // Onclick, switch playback to that track
n@913 388 this.trackSliderObj.onclick = function() {
n@913 389 // Start the test on first click, that way timings are more accurate.
n@913 390 audioEngineContext.play();
n@913 391 if (audioEngineContext.audioObjectsReady) {
n@913 392 // Cannot continue to issue play command until audioObjects reported as ready!
n@913 393 // Get the track ID from the object ID
nicholas@899 394 var element;
nicholas@899 395 if (event.srcElement.nodeName == "SPAN") {
nicholas@899 396 element = event.srcElement.parentNode;
nicholas@899 397 } else {
nicholas@899 398 element = event.srcElement;
nicholas@899 399 }
nicholas@899 400 var id = Number(element.attributes['trackIndex'].value);
n@913 401 //audioEngineContext.metric.sliderPlayed(id);
n@895 402 audioEngineContext.play(id);
n@913 403 // Currently playing track red, rest green
n@913 404
n@913 405 //document.getElementById('track-slider-'+index).style.backgroundColor = "#FF0000";
n@913 406 $('.track-slider').removeClass('track-slider-playing');
nicholas@899 407 $(element).addClass('track-slider-playing');
n@913 408 $('.comment-div').removeClass('comment-box-playing');
n@913 409 $('#comment-div-'+id).addClass('comment-box-playing');
n@913 410 }
n@913 411 };
n@913 412
nicholas@891 413 this.exportXMLDOM = function(audioObject) {
n@913 414 // Called by the audioObject holding this element. Must be present
n@913 415 var node = document.createElement('value');
n@913 416 node.textContent = convSliderPosToRate(this.trackSliderObj);
n@913 417 return node;
n@913 418 };
nicholas@891 419 this.getValue = function() {
nicholas@891 420 return convSliderPosToRate(this.trackSliderObj);
nicholas@892 421 };
n@913 422 }
nicholas@5 423
nicholas@5 424 function dragEnd(ev) {
nicholas@5 425 // Function call when a div has been dropped
n@657 426 var slider = document.getElementById('slider');
n@963 427 var marginSize = Number(slider.attributes['marginsize'].value);
n@675 428 var w = slider.style.width;
n@675 429 w = Number(w.substr(0,w.length-2));
n@675 430 var x = ev.x;
n@963 431 if (x >= marginSize && x < w+marginSize) {
n@675 432 this.style.left = (x)+'px';
nicholas@5 433 } else {
n@963 434 if (x<marginSize) {
n@963 435 this.style.left = marginSize+'px';
nicholas@5 436 } else {
n@963 437 this.style.left = (w+marginSize) + 'px';
nicholas@5 438 }
nicholas@5 439 }
n@913 440 var time = audioEngineContext.timer.getTestTime();
n@913 441 var id = Number(ev.srcElement.getAttribute('trackindex'));
n@913 442 audioEngineContext.audioObjects[id].metric.moved(time,convSliderPosToRate(ev.srcElement));
n@656 443 }
n@656 444
BrechtDeMan@939 445 function buttonSubmitClick() // TODO: Only when all songs have been played!
n@663 446 {
nicholas@887 447 var checks = specification.commonInterface.options;
nicholas@887 448 var canContinue = true;
nicholas@891 449
nicholas@891 450 // Check that the anchor and reference objects are correctly placed
nicholas@891 451 var audioObjs = audioEngineContext.audioObjects;
nicholas@891 452 var audioHolder = testState.stateMap[testState.stateIndex];
nicholas@891 453 var anchorId = null;
nicholas@891 454 var referenceId = null;
nicholas@891 455 for (var i=0; i<audioObjs.length; i++) {
nicholas@891 456 if (audioObjs[i].specification.anchor == true && anchorId == null) {anchorId = i;}
nicholas@891 457 if (audioObjs[i].specification.reference == true && referenceId == null) {referenceId = i;}
nicholas@891 458 }
nicholas@891 459 if (anchorId != null) {
nicholas@891 460 if (audioObjs[anchorId].specification.marker != null) {
nicholas@891 461 if (audioObjs[anchorId].interfaceDOM.getValue() > audioObjs[anchorId].specification.marker)
nicholas@891 462 {
nicholas@891 463 // Anchor is not set below
nicholas@891 464 console.log('Anchor node not below marker value');
nicholas@891 465 alert('Please keep listening');
nicholas@891 466 return;
nicholas@891 467 }
nicholas@891 468 } else {
nicholas@891 469 // No marker value given, ensure it is the minimum value
nicholas@891 470 var anchorVal = audioObjs[anchorId].interfaceDOM.getValue();
nicholas@891 471 for (var i=0; i<audioObjs.length; i++) {
nicholas@891 472 if (i != anchorId) {
nicholas@891 473 if (anchorVal > audioObjs[i].interfaceDOM.getValue()) {
nicholas@891 474 // Anchor not the minimum
nicholas@891 475 console.log('No marker set, anchor node not the minimum');
nicholas@891 476 alert('Please keep listening');
nicholas@891 477 return;
nicholas@891 478 }
nicholas@891 479 }
nicholas@891 480 }
nicholas@891 481 }
nicholas@891 482 }
nicholas@891 483 if (referenceId != null) {
nicholas@891 484 if (audioObjs[referenceId].specification.marker != null) {
nicholas@891 485 if (audioObjs[referenceId].interfaceDOM.getValue() < audioObjs[referenceId].specification.marker)
nicholas@891 486 {
nicholas@891 487 // Anchor is not set below
nicholas@891 488 console.log('Reference node not above marker value');
nicholas@891 489 alert('Please keep listening');
nicholas@891 490 return;
nicholas@891 491 }
nicholas@891 492 } else {
nicholas@891 493 // No marker value given, ensure it is the minimum value
nicholas@891 494 var referenceVal = audioObjs[referenceId].interfaceDOM.getValue();
nicholas@891 495 for (var i=0; i<audioObjs.length; i++) {
nicholas@891 496 if (i != referenceId) {
nicholas@891 497 if (referenceVal > audioObjs[i].interfaceDOM.getValue()) {
nicholas@891 498 // Anchor not the minimum
nicholas@891 499 console.log('No marker set, reference node not the maximum');
nicholas@891 500 alert('Please keep listening');
nicholas@891 501 return;
nicholas@891 502 }
nicholas@891 503 }
nicholas@891 504 }
nicholas@891 505 }
nicholas@891 506 }
nicholas@891 507
nicholas@887 508 for (var i=0; i<checks.length; i++) {
nicholas@887 509 if (checks[i].type == 'check')
nicholas@887 510 {
nicholas@887 511 switch(checks[i].check) {
nicholas@887 512 case 'fragmentPlayed':
nicholas@887 513 // Check if all fragments have been played
nicholas@887 514 var checkState = interfaceContext.checkAllPlayed();
nicholas@887 515 if (checkState == false) {canContinue = false;}
nicholas@887 516 break;
nicholas@887 517 case 'fragmentFullPlayback':
nicholas@887 518 // Check all fragments have been played to their full length
nicholas@887 519 var checkState = interfaceContext.checkAllPlayed();
nicholas@887 520 if (checkState == false) {canContinue = false;}
nicholas@887 521 console.log('NOTE: fragmentFullPlayback not currently implemented, performing check fragmentPlayed instead');
nicholas@887 522 break;
nicholas@887 523 case 'fragmentMoved':
nicholas@887 524 // Check all fragment sliders have been moved.
nicholas@887 525 var checkState = interfaceContext.checkAllMoved();
nicholas@887 526 if (checkState == false) {canContinue = false;}
nicholas@887 527 break;
nicholas@887 528 case 'fragmentComments':
nicholas@887 529 // Check all fragment sliders have been moved.
nicholas@887 530 var checkState = interfaceContext.checkAllCommented();
nicholas@887 531 if (checkState == false) {canContinue = false;}
nicholas@887 532 break;
nicholas@887 533 }
nicholas@887 534
nicholas@887 535 }
nicholas@887 536 }
nicholas@887 537
nicholas@887 538 if (canContinue) {
nicholas@944 539 if (audioEngineContext.status == 1) {
nicholas@944 540 var playback = document.getElementById('playback-button');
nicholas@944 541 playback.click();
nicholas@944 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@944 543 } else
nicholas@944 544 {
nicholas@944 545 if (audioEngineContext.timer.testStarted == false)
nicholas@944 546 {
nicholas@944 547 alert('You have not started the test! Please press start to begin the test!');
nicholas@944 548 return;
nicholas@944 549 }
nicholas@944 550 }
nicholas@964 551 testState.advanceState();
nicholas@887 552 }
n@664 553 }
n@664 554
n@913 555 function convSliderPosToRate(slider)
n@675 556 {
n@675 557 var w = document.getElementById('slider').style.width;
n@963 558 var marginsize = Number(document.getElementById('slider').attributes['marginsize'].value);
n@675 559 var maxPix = w.substr(0,w.length-2);
n@675 560 var pix = slider.style.left;
n@675 561 pix = pix.substr(0,pix.length-2);
n@963 562 var rate = (pix-marginsize)/maxPix;
n@675 563 return rate;
n@675 564 }
n@675 565
n@963 566 function resizeWindow(event){
n@963 567 // Function called when the window has been resized.
n@963 568 // MANDATORY FUNCTION
n@963 569
n@963 570 // Store the slider marker values
n@963 571 var holdValues = [];
n@963 572 $(".track-slider").each(function(index,sliderObj){
n@963 573 holdValues.push(convSliderPosToRate(index));
n@963 574 });
n@963 575
n@963 576 var width = event.target.innerWidth;
n@963 577 var canvas = document.getElementById('sliderCanvasHolder');
n@963 578 var sliderDiv = canvas.children[0];
n@963 579 var sliderScaleDiv = canvas.children[1];
n@963 580 var marginsize = Number(sliderDiv.attributes['marginsize'].value);
n@963 581 var w = (marginsize+8)*2;
n@963 582 sliderDiv.style.width = width - w + 'px';
n@963 583 var width = width - w;
n@963 584 // Move sliders into new position
n@963 585 $(".track-slider").each(function(index,sliderObj){
n@963 586 var pos = holdValues[index];
n@963 587 var pix = pos * width;
n@963 588 sliderObj.style.left = pix+marginsize+'px';
n@963 589 });
n@963 590
n@963 591 // Move scale labels
n@963 592 $(sliderScaleDiv.children).each(function(index,scaleObj){
n@963 593 var position = Number(scaleObj.attributes['value'].value);
n@963 594 var pixelPosition = (position*width)+marginsize;
n@963 595 scaleObj.style.left = Math.floor((pixelPosition-($(scaleObj).width()/2)))+'px';
n@963 596 });
n@963 597 }
n@963 598
n@911 599 function pageXMLSave(store, testXML)
n@668 600 {
n@668 601 // Saves a specific test page
nicholas@964 602 var xmlDoc = store;
n@674 603 // Check if any session wide metrics are enabled
nicholas@690 604
n@911 605 var commentShow = testXML.elementComments;
nicholas@690 606
n@674 607 var metric = document.createElement('metric');
n@674 608 if (audioEngineContext.metric.enableTestTimer)
n@674 609 {
n@674 610 var testTime = document.createElement('metricResult');
n@674 611 testTime.id = 'testTime';
n@674 612 testTime.textContent = audioEngineContext.timer.testDuration;
n@674 613 metric.appendChild(testTime);
n@674 614 }
n@674 615 xmlDoc.appendChild(metric);
n@908 616 var audioObjects = audioEngineContext.audioObjects;
n@908 617 for (var i=0; i<audioObjects.length; i++)
n@669 618 {
n@913 619 var audioElement = audioEngineContext.audioObjects[i].exportXMLDOM();
n@669 620 xmlDoc.appendChild(audioElement);
n@669 621 }
n@1026 622
n@1026 623 $(interfaceContext.commentQuestions).each(function(index,element){
n@1026 624 var node = element.exportXMLDOM();
n@1026 625 xmlDoc.appendChild(node);
n@1026 626 });
nicholas@964 627 store = xmlDoc;
nicholas@690 628 }