annotate ape.js @ 240:5fd3ba494551 Dev_main

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