annotate ape.js @ 1041:6a188a912b0f

Feature #1288: Fragments now have 'id', holding their given ID from the set up XML, and 'presentedid' giving their on page order.
author Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk>
date Sat, 20 Jun 2015 11:04:44 +0100
parents aef4cbbd66d1
children f6e8b7156017
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
n@911 358 var randomise = audioHolderObject.randomiseOrder;
n@669 359
n@911 360 var audioElements = audioHolderObject.audioElements;
nicholas@682 361 currentTrackOrder = [];
n@669 362 if (randomise) {
n@911 363 audioHolderObject.audioElements = randomiseOrder(audioHolderObject.audioElements);
n@669 364 }
n@669 365
nicholas@682 366 // Delete any previous audioObjects associated with the audioEngine
nicholas@682 367 audioEngineContext.audioObjects = [];
nicholas@900 368 interfaceContext.deleteCommentBoxes();
nicholas@682 369
n@701 370 // Find all the audioElements from the audioHolder
n@911 371 $(audioHolderObject.audioElements).each(function(index,element){
nicholas@7 372 // Find URL of track
n@701 373 // In this jQuery loop, variable 'this' holds the current audioElement.
n@701 374
n@701 375 // Now load each audio sample. First create the new track by passing the full URL
n@911 376 var trackURL = audioHolderObject.hostURL + element.url;
n@912 377 var audioObject = audioEngineContext.newTrack(element);
nicholas@689 378
n@1029 379 var node = interfaceContext.createCommentBox(audioObject);
n@701 380
nicholas@5 381 // Create a slider per track
n@913 382 audioObject.interfaceDOM = new sliderObject(audioObject);
n@1008 383
nicholas@5 384 // Distribute it randomnly
n@1000 385 var w = window.innerWidth - (offset+8)*2;
nicholas@5 386 w = Math.random()*w;
n@1000 387 w = Math.floor(w+(offset+8));
n@913 388 audioObject.interfaceDOM.trackSliderObj.style.left = w+'px';
nicholas@8 389
n@913 390 canvas.appendChild(audioObject.interfaceDOM.trackSliderObj);
n@913 391 audioObject.metric.initialised(convSliderPosToRate(audioObject.interfaceDOM.trackSliderObj));
BrechtDeMan@940 392
n@700 393 });
n@912 394 if (commentShow) {
n@912 395 interfaceContext.showCommentBoxes(feedbackHolder,true);
n@912 396 }
nicholas@3 397
n@911 398 $(audioHolderObject.commentQuestions).each(function(index,element) {
n@1026 399 var node = interfaceContext.createCommentQuestion(element);
n@1026 400 feedbackHolder.appendChild(node.holder);
nicholas@688 401 });
n@1007 402
n@1007 403
n@1007 404 testWaitIndicator();
n@663 405 }
n@663 406
n@913 407 function sliderObject(audioObject) {
n@913 408 // Create a new slider object;
n@913 409 this.parent = audioObject;
n@913 410 this.trackSliderObj = document.createElement('div');
n@913 411 this.trackSliderObj.className = 'track-slider';
n@913 412 this.trackSliderObj.id = 'track-slider-'+audioObject.id;
n@913 413
n@913 414 this.trackSliderObj.setAttribute('trackIndex',audioObject.id);
n@913 415 this.trackSliderObj.innerHTML = '<span>'+audioObject.id+'</span>';
n@913 416 this.trackSliderObj.draggable = true;
n@913 417 this.trackSliderObj.ondragend = dragEnd;
n@913 418
n@913 419 // Onclick, switch playback to that track
n@913 420 this.trackSliderObj.onclick = function() {
n@913 421 // Start the test on first click, that way timings are more accurate.
n@913 422 audioEngineContext.play();
n@913 423 if (audioEngineContext.audioObjectsReady) {
n@913 424 // Cannot continue to issue play command until audioObjects reported as ready!
n@913 425 // Get the track ID from the object ID
nicholas@899 426 var element;
nicholas@899 427 if (event.srcElement.nodeName == "SPAN") {
nicholas@899 428 element = event.srcElement.parentNode;
nicholas@899 429 } else {
nicholas@899 430 element = event.srcElement;
nicholas@899 431 }
nicholas@899 432 var id = Number(element.attributes['trackIndex'].value);
n@913 433 //audioEngineContext.metric.sliderPlayed(id);
n@895 434 audioEngineContext.play(id);
n@913 435 // Currently playing track red, rest green
n@913 436
n@913 437 //document.getElementById('track-slider-'+index).style.backgroundColor = "#FF0000";
n@913 438 $('.track-slider').removeClass('track-slider-playing');
nicholas@899 439 $(element).addClass('track-slider-playing');
n@913 440 $('.comment-div').removeClass('comment-box-playing');
n@913 441 $('#comment-div-'+id).addClass('comment-box-playing');
n@913 442 }
n@913 443 };
n@913 444
nicholas@891 445 this.exportXMLDOM = function(audioObject) {
n@913 446 // Called by the audioObject holding this element. Must be present
n@913 447 var node = document.createElement('value');
n@913 448 node.textContent = convSliderPosToRate(this.trackSliderObj);
n@913 449 return node;
n@913 450 };
nicholas@891 451 this.getValue = function() {
nicholas@891 452 return convSliderPosToRate(this.trackSliderObj);
nicholas@892 453 };
n@913 454 }
nicholas@5 455
nicholas@5 456 function dragEnd(ev) {
nicholas@5 457 // Function call when a div has been dropped
n@657 458 var slider = document.getElementById('slider');
n@963 459 var marginSize = Number(slider.attributes['marginsize'].value);
n@675 460 var w = slider.style.width;
n@675 461 w = Number(w.substr(0,w.length-2));
n@675 462 var x = ev.x;
n@963 463 if (x >= marginSize && x < w+marginSize) {
n@675 464 this.style.left = (x)+'px';
nicholas@5 465 } else {
n@963 466 if (x<marginSize) {
n@963 467 this.style.left = marginSize+'px';
nicholas@5 468 } else {
n@963 469 this.style.left = (w+marginSize) + 'px';
nicholas@5 470 }
nicholas@5 471 }
n@913 472 var time = audioEngineContext.timer.getTestTime();
n@913 473 var id = Number(ev.srcElement.getAttribute('trackindex'));
n@913 474 audioEngineContext.audioObjects[id].metric.moved(time,convSliderPosToRate(ev.srcElement));
n@656 475 }
n@656 476
BrechtDeMan@939 477 function buttonSubmitClick() // TODO: Only when all songs have been played!
n@663 478 {
nicholas@1040 479 var checks = testState.currentStateMap[testState.currentIndex].interfaces[0].options;
nicholas@887 480 var canContinue = true;
nicholas@891 481
nicholas@891 482 // Check that the anchor and reference objects are correctly placed
nicholas@891 483 var audioObjs = audioEngineContext.audioObjects;
nicholas@891 484 var audioHolder = testState.stateMap[testState.stateIndex];
nicholas@891 485 var anchorId = null;
nicholas@891 486 var referenceId = null;
nicholas@891 487 for (var i=0; i<audioObjs.length; i++) {
nicholas@891 488 if (audioObjs[i].specification.anchor == true && anchorId == null) {anchorId = i;}
nicholas@891 489 if (audioObjs[i].specification.reference == true && referenceId == null) {referenceId = i;}
nicholas@891 490 }
nicholas@891 491 if (anchorId != null) {
nicholas@891 492 if (audioObjs[anchorId].specification.marker != null) {
nicholas@891 493 if (audioObjs[anchorId].interfaceDOM.getValue() > audioObjs[anchorId].specification.marker)
nicholas@891 494 {
nicholas@891 495 // Anchor is not set below
nicholas@891 496 console.log('Anchor node not below marker value');
nicholas@891 497 alert('Please keep listening');
nicholas@891 498 return;
nicholas@891 499 }
nicholas@891 500 } else {
nicholas@891 501 // No marker value given, ensure it is the minimum value
nicholas@891 502 var anchorVal = audioObjs[anchorId].interfaceDOM.getValue();
nicholas@891 503 for (var i=0; i<audioObjs.length; i++) {
nicholas@891 504 if (i != anchorId) {
nicholas@891 505 if (anchorVal > audioObjs[i].interfaceDOM.getValue()) {
nicholas@891 506 // Anchor not the minimum
nicholas@891 507 console.log('No marker set, anchor node not the minimum');
nicholas@891 508 alert('Please keep listening');
nicholas@891 509 return;
nicholas@891 510 }
nicholas@891 511 }
nicholas@891 512 }
nicholas@891 513 }
nicholas@891 514 }
nicholas@891 515 if (referenceId != null) {
nicholas@891 516 if (audioObjs[referenceId].specification.marker != null) {
nicholas@891 517 if (audioObjs[referenceId].interfaceDOM.getValue() < audioObjs[referenceId].specification.marker)
nicholas@891 518 {
nicholas@891 519 // Anchor is not set below
nicholas@891 520 console.log('Reference node not above marker value');
nicholas@891 521 alert('Please keep listening');
nicholas@891 522 return;
nicholas@891 523 }
nicholas@891 524 } else {
nicholas@891 525 // No marker value given, ensure it is the minimum value
nicholas@891 526 var referenceVal = audioObjs[referenceId].interfaceDOM.getValue();
nicholas@891 527 for (var i=0; i<audioObjs.length; i++) {
nicholas@891 528 if (i != referenceId) {
nicholas@891 529 if (referenceVal > audioObjs[i].interfaceDOM.getValue()) {
nicholas@891 530 // Anchor not the minimum
nicholas@891 531 console.log('No marker set, reference node not the maximum');
nicholas@891 532 alert('Please keep listening');
nicholas@891 533 return;
nicholas@891 534 }
nicholas@891 535 }
nicholas@891 536 }
nicholas@891 537 }
nicholas@891 538 }
nicholas@891 539
nicholas@887 540 for (var i=0; i<checks.length; i++) {
nicholas@887 541 if (checks[i].type == 'check')
nicholas@887 542 {
nicholas@887 543 switch(checks[i].check) {
nicholas@887 544 case 'fragmentPlayed':
nicholas@887 545 // Check if all fragments have been played
nicholas@887 546 var checkState = interfaceContext.checkAllPlayed();
nicholas@887 547 if (checkState == false) {canContinue = false;}
nicholas@887 548 break;
nicholas@887 549 case 'fragmentFullPlayback':
nicholas@887 550 // Check all fragments have been played to their full length
nicholas@887 551 var checkState = interfaceContext.checkAllPlayed();
nicholas@887 552 if (checkState == false) {canContinue = false;}
nicholas@887 553 console.log('NOTE: fragmentFullPlayback not currently implemented, performing check fragmentPlayed instead');
nicholas@887 554 break;
nicholas@887 555 case 'fragmentMoved':
nicholas@887 556 // Check all fragment sliders have been moved.
nicholas@887 557 var checkState = interfaceContext.checkAllMoved();
nicholas@887 558 if (checkState == false) {canContinue = false;}
nicholas@887 559 break;
nicholas@887 560 case 'fragmentComments':
nicholas@887 561 // Check all fragment sliders have been moved.
nicholas@887 562 var checkState = interfaceContext.checkAllCommented();
nicholas@887 563 if (checkState == false) {canContinue = false;}
nicholas@887 564 break;
nicholas@1039 565 case 'scalerange':
nicholas@1039 566 // Check the scale is used to its full width outlined by the node
nicholas@1039 567 var checkState = interfaceContext.checkScaleRange();
nicholas@1039 568 if (checkState == false) {canContinue = false;}
nicholas@1039 569 break;
nicholas@887 570 }
nicholas@887 571
nicholas@887 572 }
nicholas@1039 573 if (!canContinue) {break;}
nicholas@887 574 }
nicholas@887 575
nicholas@887 576 if (canContinue) {
nicholas@944 577 if (audioEngineContext.status == 1) {
nicholas@944 578 var playback = document.getElementById('playback-button');
nicholas@944 579 playback.click();
nicholas@944 580 // 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 581 } else
nicholas@944 582 {
nicholas@944 583 if (audioEngineContext.timer.testStarted == false)
nicholas@944 584 {
nicholas@944 585 alert('You have not started the test! Please press start to begin the test!');
nicholas@944 586 return;
nicholas@944 587 }
nicholas@944 588 }
nicholas@964 589 testState.advanceState();
nicholas@887 590 }
n@664 591 }
n@664 592
n@913 593 function convSliderPosToRate(slider)
n@675 594 {
n@675 595 var w = document.getElementById('slider').style.width;
n@963 596 var marginsize = Number(document.getElementById('slider').attributes['marginsize'].value);
n@675 597 var maxPix = w.substr(0,w.length-2);
n@675 598 var pix = slider.style.left;
n@675 599 pix = pix.substr(0,pix.length-2);
n@963 600 var rate = (pix-marginsize)/maxPix;
n@675 601 return rate;
n@675 602 }
n@675 603
n@963 604 function resizeWindow(event){
n@963 605 // Function called when the window has been resized.
n@963 606 // MANDATORY FUNCTION
n@963 607
n@963 608 // Store the slider marker values
n@963 609 var holdValues = [];
n@963 610 $(".track-slider").each(function(index,sliderObj){
n@963 611 holdValues.push(convSliderPosToRate(index));
n@963 612 });
n@963 613
n@963 614 var width = event.target.innerWidth;
n@963 615 var canvas = document.getElementById('sliderCanvasHolder');
n@963 616 var sliderDiv = canvas.children[0];
n@963 617 var sliderScaleDiv = canvas.children[1];
n@963 618 var marginsize = Number(sliderDiv.attributes['marginsize'].value);
n@963 619 var w = (marginsize+8)*2;
n@963 620 sliderDiv.style.width = width - w + 'px';
n@963 621 var width = width - w;
n@963 622 // Move sliders into new position
n@963 623 $(".track-slider").each(function(index,sliderObj){
n@963 624 var pos = holdValues[index];
n@963 625 var pix = pos * width;
n@963 626 sliderObj.style.left = pix+marginsize+'px';
n@963 627 });
n@963 628
n@963 629 // Move scale labels
n@963 630 $(sliderScaleDiv.children).each(function(index,scaleObj){
n@963 631 var position = Number(scaleObj.attributes['value'].value);
n@963 632 var pixelPosition = (position*width)+marginsize;
n@963 633 scaleObj.style.left = Math.floor((pixelPosition-($(scaleObj).width()/2)))+'px';
n@963 634 });
n@963 635 }
n@963 636
n@911 637 function pageXMLSave(store, testXML)
n@668 638 {
n@668 639 // Saves a specific test page
nicholas@964 640 var xmlDoc = store;
n@674 641 // Check if any session wide metrics are enabled
nicholas@690 642
n@911 643 var commentShow = testXML.elementComments;
nicholas@690 644
n@674 645 var metric = document.createElement('metric');
n@674 646 if (audioEngineContext.metric.enableTestTimer)
n@674 647 {
n@674 648 var testTime = document.createElement('metricResult');
n@674 649 testTime.id = 'testTime';
n@674 650 testTime.textContent = audioEngineContext.timer.testDuration;
n@674 651 metric.appendChild(testTime);
n@674 652 }
n@674 653 xmlDoc.appendChild(metric);
n@908 654 var audioObjects = audioEngineContext.audioObjects;
n@908 655 for (var i=0; i<audioObjects.length; i++)
n@669 656 {
n@913 657 var audioElement = audioEngineContext.audioObjects[i].exportXMLDOM();
nicholas@1041 658 audioElement.setAttribute('presentedId',i);
n@669 659 xmlDoc.appendChild(audioElement);
n@669 660 }
n@1026 661
n@1026 662 $(interfaceContext.commentQuestions).each(function(index,element){
n@1026 663 var node = element.exportXMLDOM();
n@1026 664 xmlDoc.appendChild(node);
n@1026 665 });
nicholas@964 666 store = xmlDoc;
nicholas@690 667 }