annotate ape.js @ 1044:dc531fbf64c3

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