annotate ape.js @ 907:1b6f4304dedc

audioObjects.metric object export their XML rather than ape.js
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Thu, 04 Jun 2015 11:01:19 +0100
parents 6d37dd0f1dc7
children 40f9b1725279
rev   line source
n@905 1 /**
n@905 2 * ape.js
n@905 3 * Create the APE interface
n@905 4 */
n@905 5
n@905 6 // preTest - In preTest state
n@905 7 // testRun-ID - In test running, test Id number at the end 'testRun-2'
n@905 8 // testRunPost-ID - Post test of test ID
n@905 9 // testRunPre-ID - Pre-test of test ID
n@905 10 // postTest - End of test, final submission!
n@905 11
n@905 12
n@905 13 // Once this is loaded and parsed, begin execution
n@905 14 loadInterface(projectXML);
n@905 15
n@905 16 function loadInterface(xmlDoc) {
n@905 17
n@905 18 // Get the dimensions of the screen available to the page
n@905 19 var width = window.innerWidth;
n@905 20 var height = window.innerHeight;
n@905 21
n@905 22 // The injection point into the HTML page
n@905 23 var insertPoint = document.getElementById("topLevelBody");
n@905 24 var testContent = document.createElement('div');
n@905 25
n@905 26 testContent.id = 'testContent';
n@905 27
n@905 28
n@905 29 // Decode parts of the xmlDoc that are needed
n@905 30 // xmlDoc MUST already be parsed by jQuery!
n@905 31 var xmlSetup = xmlDoc.find('setup');
n@905 32 // Should put in an error function here incase of malprocessed or malformed XML
n@906 33
n@905 34
n@905 35 // Create APE specific metric functions
n@905 36 audioEngineContext.metric.initialiseTest = function()
n@905 37 {
n@905 38 };
n@905 39
n@905 40 audioEngineContext.metric.sliderMoveStart = function(id)
n@905 41 {
n@905 42 if (this.data == -1)
n@905 43 {
n@905 44 this.data = id;
n@905 45 } else {
n@905 46 console.log('ERROR: Metric tracker detecting two moves!');
n@905 47 this.data = -1;
n@905 48 }
n@905 49 };
n@905 50 audioEngineContext.metric.sliderMoved = function()
n@905 51 {
n@905 52 var time = audioEngineContext.timer.getTestTime();
n@905 53 var id = this.data;
n@905 54 this.data = -1;
n@905 55 var position = convSliderPosToRate(id);
n@905 56 console.log('slider ' + id + ': '+ position + ' (' + time + ')'); // DEBUG/SAFETY: show position and slider id
n@905 57 if (audioEngineContext.timer.testStarted)
n@905 58 {
n@905 59 audioEngineContext.audioObjects[id].metric.moved(time,position);
n@905 60 }
n@905 61 };
n@905 62
n@905 63 audioEngineContext.metric.sliderPlayed = function(id)
n@905 64 {
n@905 65 var time = audioEngineContext.timer.getTestTime();
n@905 66 if (audioEngineContext.timer.testStarted)
n@905 67 {
n@905 68 if (this.lastClicked >= 0)
n@905 69 {
n@905 70 audioEngineContext.audioObjects[this.lastClicked].metric.listening(time);
n@905 71 }
n@905 72 this.lastClicked = id;
n@905 73 audioEngineContext.audioObjects[id].metric.listening(time);
n@905 74 }
n@905 75 console.log('slider ' + id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id
n@905 76 };
n@905 77
n@907 78 // Bindings for audioObjects
n@907 79
n@905 80 // Create the top div for the Title element
n@905 81 var titleAttr = xmlSetup[0].attributes['title'];
n@905 82 var title = document.createElement('div');
n@905 83 title.className = "title";
n@905 84 title.align = "center";
n@905 85 var titleSpan = document.createElement('span');
n@905 86
n@905 87 // Set title to that defined in XML, else set to default
n@905 88 if (titleAttr != undefined) {
n@905 89 titleSpan.innerHTML = titleAttr.value;
n@905 90 } else {
n@905 91 titleSpan.innerHTML = 'Listening test';
n@905 92 }
n@905 93 // Insert the titleSpan element into the title div element.
n@905 94 title.appendChild(titleSpan);
n@905 95
n@905 96 var pagetitle = document.createElement('div');
n@905 97 pagetitle.className = "pageTitle";
n@905 98 pagetitle.align = "center";
n@905 99 var titleSpan = document.createElement('span');
n@905 100 titleSpan.id = "pageTitle";
n@905 101 pagetitle.appendChild(titleSpan);
n@905 102
n@905 103 // Store the return URL path in global projectReturn
n@905 104 projectReturn = xmlSetup[0].attributes['projectReturn'];
n@905 105 if (projectReturn == undefined) {
n@905 106 console.log("WARNING - projectReturn not specified! Will assume null.");
n@905 107 projectReturn = "null";
n@905 108 } else {
n@905 109 projectReturn = projectReturn.value;
n@905 110 }
n@905 111
n@905 112 // Create Interface buttons!
n@905 113 var interfaceButtons = document.createElement('div');
n@905 114 interfaceButtons.id = 'interface-buttons';
n@905 115
n@905 116 // MANUAL DOWNLOAD POINT
n@905 117 // If project return is null, this MUST be specified as the location to create the download link
n@905 118 var downloadPoint = document.createElement('div');
n@905 119 downloadPoint.id = 'download-point';
n@905 120
n@905 121 // Create playback start/stop points
n@905 122 var playback = document.createElement("button");
n@905 123 playback.innerHTML = 'Stop';
n@905 124 playback.id = 'playback-button';
n@905 125 // onclick function. Check if it is playing or not, call the correct function in the
n@905 126 // audioEngine, change the button text to reflect the next state.
n@905 127 playback.onclick = function() {
n@905 128 if (audioEngineContext.status == 1) {
n@905 129 audioEngineContext.stop();
n@905 130 this.innerHTML = 'Stop';
n@905 131 var time = audioEngineContext.timer.getTestTime();
n@905 132 console.log('Stopped at ' + time); // DEBUG/SAFETY
n@905 133 }
n@905 134 };
n@905 135 // Create Submit (save) button
n@905 136 var submit = document.createElement("button");
n@905 137 submit.innerHTML = 'Submit';
n@905 138 submit.onclick = buttonSubmitClick;
n@905 139 submit.id = 'submit-button';
n@905 140 // Append the interface buttons into the interfaceButtons object.
n@905 141 interfaceButtons.appendChild(playback);
n@905 142 interfaceButtons.appendChild(submit);
n@905 143 interfaceButtons.appendChild(downloadPoint);
n@905 144
n@905 145 // Now create the slider and HTML5 canvas boxes
n@905 146
n@905 147 // Create the div box to center align
n@905 148 var sliderBox = document.createElement('div');
n@905 149 sliderBox.className = 'sliderCanvasDiv';
n@905 150 sliderBox.id = 'sliderCanvasHolder';
n@905 151
n@905 152 // Create the slider box to hold the slider elements
n@905 153 var canvas = document.createElement('div');
n@905 154 canvas.id = 'slider';
n@905 155 canvas.align = "left";
n@905 156 canvas.addEventListener('dragover',function(event){
n@905 157 event.preventDefault();
n@905 158 return false;
n@905 159 },false);
n@905 160 var sliderMargin = document.createAttribute('marginsize');
n@905 161 sliderMargin.nodeValue = 42; // Set default margins to 42px either side
n@905 162 // Must have a known EXACT width, as this is used later to determine the ratings
n@905 163 var w = (Number(sliderMargin.nodeValue)+8)*2;
n@905 164 canvas.style.width = width - w +"px";
n@905 165 canvas.style.marginLeft = sliderMargin.nodeValue +'px';
n@905 166 canvas.setAttributeNode(sliderMargin);
n@905 167 sliderBox.appendChild(canvas);
n@905 168
n@905 169 // Create the div to hold any scale objects
n@905 170 var scale = document.createElement('div');
n@905 171 scale.className = 'sliderScale';
n@905 172 scale.id = 'sliderScaleHolder';
n@905 173 scale.align = 'left';
n@905 174 sliderBox.appendChild(scale);
n@905 175
n@905 176 // Global parent for the comment boxes on the page
n@905 177 var feedbackHolder = document.createElement('div');
n@905 178 feedbackHolder.id = 'feedbackHolder';
n@905 179
n@905 180 testContent.style.zIndex = 1;
n@905 181 insertPoint.innerHTML = null; // Clear the current schema
n@905 182
n@905 183 // Inject into HTML
n@905 184 testContent.appendChild(title); // Insert the title
n@905 185 testContent.appendChild(pagetitle);
n@905 186 testContent.appendChild(interfaceButtons);
n@905 187 testContent.appendChild(sliderBox);
n@905 188 testContent.appendChild(feedbackHolder);
n@905 189 insertPoint.appendChild(testContent);
n@905 190
n@905 191 // Load the full interface
n@905 192 testState.initialise();
n@905 193 testState.advanceState();
n@905 194
n@905 195 }
n@905 196
n@905 197 function loadTest(textXML)
n@905 198 {
n@905 199
n@905 200 // Reset audioEngineContext.Metric globals for new test
n@905 201 audioEngineContext.newTestPage();
n@905 202
n@905 203 var id = textXML.id;
n@905 204
n@905 205 var feedbackHolder = document.getElementById('feedbackHolder');
n@905 206 var canvas = document.getElementById('slider');
n@905 207 feedbackHolder.innerHTML = null;
n@905 208 canvas.innerHTML = null;
n@905 209
n@905 210 // Setup question title
n@905 211 var interfaceObj = $(textXML).find('interface');
n@905 212 var titleNode = interfaceObj.find('title');
n@905 213 if (titleNode[0] != undefined)
n@905 214 {
n@905 215 document.getElementById('pageTitle').textContent = titleNode[0].textContent;
n@905 216 }
n@905 217 var positionScale = canvas.style.width.substr(0,canvas.style.width.length-2);
n@905 218 var offset = Number(document.getElementById('slider').attributes['marginsize'].value);
n@905 219 var scale = document.getElementById('sliderScaleHolder');
n@905 220 scale.innerHTML = null;
n@905 221 interfaceObj.find('scale').each(function(index,scaleObj){
n@905 222 var value = document.createAttribute('value');
n@905 223 var position = Number(scaleObj.attributes['position'].value)*0.01;
n@905 224 value.nodeValue = position;
n@905 225 var pixelPosition = (position*positionScale)+offset;
n@905 226 var scaleDOM = document.createElement('span');
n@905 227 scaleDOM.textContent = scaleObj.textContent;
n@905 228 scale.appendChild(scaleDOM);
n@905 229 scaleDOM.style.left = Math.floor((pixelPosition-($(scaleDOM).width()/2)))+'px';
n@905 230 scaleDOM.setAttributeNode(value);
n@905 231 });
n@905 232
n@905 233 var commentBoxPrefix = interfaceObj.find('commentBoxPrefix');
n@905 234 if (commentBoxPrefix.length != 0) {
n@905 235 commentBoxPrefix = commentBoxPrefix[0].textContent;
n@905 236 } else {
n@905 237 commentBoxPrefix = "Comment on track";
n@905 238 }
n@905 239
n@905 240 // Extract the hostURL attribute. If not set, create an empty string.
n@905 241 var hostURL = textXML.attributes['hostURL'];
n@905 242 if (hostURL == undefined) {
n@905 243 hostURL = "";
n@905 244 } else {
n@905 245 hostURL = hostURL.value;
n@905 246 }
n@905 247 // Extract the sampleRate. If set, convert the string to a Number.
n@905 248 var hostFs = textXML.attributes['sampleRate'];
n@905 249 if (hostFs != undefined) {
n@905 250 hostFs = Number(hostFs.value);
n@905 251 }
n@905 252
n@905 253 /// CHECK FOR SAMPLE RATE COMPATIBILITY
n@905 254 if (hostFs != undefined) {
n@905 255 if (Number(hostFs) != audioContext.sampleRate) {
n@905 256 var errStr = 'Sample rates do not match! Requested '+Number(hostFs)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.';
n@905 257 alert(errStr);
n@905 258 return;
n@905 259 }
n@905 260 }
n@905 261
n@905 262 var commentShow = textXML.attributes['elementComments'];
n@905 263 if (commentShow != undefined) {
n@905 264 if (commentShow.value == 'false') {commentShow = false;}
n@905 265 else {commentShow = true;}
n@905 266 } else {commentShow = true;}
n@905 267
n@905 268 var loopPlayback = textXML.attributes['loop'];
n@905 269 if (loopPlayback != undefined)
n@905 270 {
n@905 271 loopPlayback = loopPlayback.value;
n@905 272 if (loopPlayback == 'true') {
n@905 273 loopPlayback = true;
n@905 274 } else {
n@905 275 loopPlayback = false;
n@905 276 }
n@905 277 } else {
n@905 278 loopPlayback = false;
n@905 279 }
n@905 280 audioEngineContext.loopPlayback = loopPlayback;
n@905 281 // Create AudioEngine bindings for playback
n@905 282 if (loopPlayback) {
n@905 283 audioEngineContext.selectedTrack = function(id) {
n@905 284 for (var i=0; i<this.audioObjects.length; i++)
n@905 285 {
n@905 286 if (id == i) {
n@905 287 this.audioObjects[i].loopStart();
n@905 288 } else {
n@905 289 this.audioObjects[i].loopStop();
n@905 290 }
n@905 291 }
n@905 292 };
n@905 293 } else {
n@905 294 audioEngineContext.selectedTrack = function(id) {
n@905 295 for (var i=0; i<this.audioObjects.length; i++)
n@905 296 {
n@905 297 this.audioObjects[i].outputGain.gain.value = 0.0;
n@905 298 this.audioObjects[i].stop();
n@905 299 }
n@905 300 if (this.status == 1) {
n@905 301 this.audioObjects[id].outputGain.gain.value = 1.0;
n@905 302 this.audioObjects[id].play(audioContext.currentTime+0.01);
n@905 303 }
n@905 304 };
n@905 305 }
n@905 306
n@905 307 currentTestHolder = document.createElement('audioHolder');
n@905 308 currentTestHolder.id = textXML.id;
n@905 309 currentTestHolder.repeatCount = textXML.attributes['repeatCount'].value;
n@905 310
n@905 311 var randomise = textXML.attributes['randomiseOrder'];
n@905 312 if (randomise != undefined) {randomise = randomise.value;}
n@905 313 else {randomise = false;}
n@905 314
n@905 315 var audioElements = $(textXML).find('audioElements');
n@905 316 currentTrackOrder = [];
n@905 317 audioElements.each(function(index,element){
n@905 318 // Find any blind-repeats
n@905 319 // Not implemented yet, but just in case
n@905 320 currentTrackOrder[index] = element;
n@905 321 });
n@905 322 if (randomise) {
n@905 323 currentTrackOrder = randomiseOrder(currentTrackOrder);
n@905 324 }
n@905 325
n@905 326 // Delete any previous audioObjects associated with the audioEngine
n@905 327 audioEngineContext.audioObjects = [];
n@905 328
n@905 329 // Find all the audioElements from the audioHolder
n@905 330 $(currentTrackOrder).each(function(index,element){
n@905 331 // Find URL of track
n@905 332 // In this jQuery loop, variable 'this' holds the current audioElement.
n@905 333
n@905 334 // Now load each audio sample. First create the new track by passing the full URL
n@905 335 var trackURL = hostURL + this.attributes['url'].value;
n@905 336 audioEngineContext.newTrack(trackURL);
n@905 337
n@905 338 if (commentShow) {
n@905 339 // Create document objects to hold the comment boxes
n@905 340 var trackComment = document.createElement('div');
n@905 341 trackComment.className = 'comment-div';
n@905 342 trackComment.id = 'comment-div-'+index;
n@905 343 // Create a string next to each comment asking for a comment
n@905 344 var trackString = document.createElement('span');
n@905 345 trackString.innerHTML = commentBoxPrefix+' '+index;
n@905 346 // Create the HTML5 comment box 'textarea'
n@905 347 var trackCommentBox = document.createElement('textarea');
n@905 348 trackCommentBox.rows = '4';
n@905 349 trackCommentBox.cols = '100';
n@905 350 trackCommentBox.name = 'trackComment'+index;
n@905 351 trackCommentBox.className = 'trackComment';
n@905 352 var br = document.createElement('br');
n@905 353 // Add to the holder.
n@905 354 trackComment.appendChild(trackString);
n@905 355 trackComment.appendChild(br);
n@905 356 trackComment.appendChild(trackCommentBox);
n@905 357 feedbackHolder.appendChild(trackComment);
n@907 358 audioEngineContext.audioObjects[index].commentDOM = trackCommentBox;
n@905 359 }
n@905 360
n@905 361 // Create a slider per track
n@905 362
n@905 363 var trackSliderObj = document.createElement('div');
n@905 364 trackSliderObj.className = 'track-slider';
n@905 365 trackSliderObj.id = 'track-slider-'+index;
n@905 366
n@905 367 var trackSliderAOIndex = document.createAttribute('trackIndex');
n@905 368 trackSliderAOIndex.nodeValue = index;
n@905 369 trackSliderObj.setAttributeNode(trackSliderAOIndex);
n@905 370
n@905 371 // Distribute it randomnly
n@905 372 var w = window.innerWidth - (offset+8)*2;
n@905 373 w = Math.random()*w;
n@905 374 w = Math.floor(w+(offset+8));
n@905 375 trackSliderObj.style.left = w+'px';
n@905 376 trackSliderObj.innerHTML = '<span>'+index+'</span>';
n@905 377 trackSliderObj.draggable = true;
n@905 378 trackSliderObj.ondragend = dragEnd;
n@905 379 trackSliderObj.ondragstart = function()
n@905 380 {
n@905 381 var id = Number(event.srcElement.attributes['trackIndex'].value);
n@905 382 audioEngineContext.metric.sliderMoveStart(id);
n@905 383 };
n@905 384
n@905 385 // Onclick, switch playback to that track
n@905 386 trackSliderObj.onclick = function() {
n@905 387 // Start the test on first click, that way timings are more accurate.
n@905 388 audioEngineContext.play();
n@905 389 if (audioEngineContext.audioObjectsReady) {
n@905 390 // Cannot continue to issue play command until audioObjects reported as ready!
n@905 391 // Get the track ID from the object ID
n@905 392 var id = Number(event.srcElement.attributes['trackIndex'].value);
n@905 393 //audioEngineContext.metric.sliderPlayed(id);
n@905 394 audioEngineContext.selectedTrack(id);
n@905 395 // Currently playing track red, rest green
n@905 396
n@905 397 //document.getElementById('track-slider-'+index).style.backgroundColor = "#FF0000";
n@905 398 $('.track-slider').removeClass('track-slider-playing');
n@905 399 $(event.srcElement).addClass('track-slider-playing');
n@905 400 $('.comment-div').removeClass('comment-box-playing');
n@905 401 $('#comment-div-'+id).addClass('comment-box-playing');
n@905 402 }
n@905 403 };
n@905 404
n@907 405 // Attach binding
n@907 406 audioEngineContext.audioObjects[index].sliderDOM = trackSliderObj;
n@907 407
n@905 408 canvas.appendChild(trackSliderObj);
n@905 409 audioEngineContext.audioObjects[index].metric.initialised(convSliderPosToRate(index));
n@905 410
n@905 411 });
n@905 412
n@905 413 // Append any commentQuestion boxes
n@905 414 var commentQuestions = $(textXML).find('CommentQuestion');
n@905 415 $(commentQuestions).each(function(index,element) {
n@905 416 // Create document objects to hold the comment boxes
n@905 417 var trackComment = document.createElement('div');
n@905 418 trackComment.className = 'comment-div commentQuestion';
n@905 419 trackComment.id = element.attributes['id'].value;
n@905 420 // Create a string next to each comment asking for a comment
n@905 421 var trackString = document.createElement('span');
n@905 422 trackString.innerHTML = element.textContent;
n@905 423 // Create the HTML5 comment box 'textarea'
n@905 424 var trackCommentBox = document.createElement('textarea');
n@905 425 trackCommentBox.rows = '4';
n@905 426 trackCommentBox.cols = '100';
n@905 427 trackCommentBox.name = 'commentQuestion'+index;
n@905 428 trackCommentBox.className = 'trackComment';
n@905 429 var br = document.createElement('br');
n@905 430 // Add to the holder.
n@905 431 trackComment.appendChild(trackString);
n@905 432 trackComment.appendChild(br);
n@905 433 trackComment.appendChild(trackCommentBox);
n@905 434 feedbackHolder.appendChild(trackComment);
n@905 435 });
n@905 436
n@905 437
n@905 438 testWaitIndicator();
n@905 439 }
n@905 440
n@905 441
n@905 442 function dragEnd(ev) {
n@905 443 // Function call when a div has been dropped
n@905 444 var slider = document.getElementById('slider');
n@905 445 var marginSize = Number(slider.attributes['marginsize'].value);
n@905 446 var w = slider.style.width;
n@905 447 w = Number(w.substr(0,w.length-2));
n@905 448 var x = ev.x;
n@905 449 if (x >= marginSize && x < w+marginSize) {
n@905 450 this.style.left = (x)+'px';
n@905 451 } else {
n@905 452 if (x<marginSize) {
n@905 453 this.style.left = marginSize+'px';
n@905 454 } else {
n@905 455 this.style.left = (w+marginSize) + 'px';
n@905 456 }
n@905 457 }
n@905 458 audioEngineContext.metric.sliderMoved();
n@905 459 }
n@905 460
n@905 461 function buttonSubmitClick() // TODO: Only when all songs have been played!
n@905 462 {
n@905 463 hasBeenPlayed = audioEngineContext.checkAllPlayed();
n@905 464 if (hasBeenPlayed.length == 0) {
n@905 465 if (audioEngineContext.status == 1) {
n@905 466 var playback = document.getElementById('playback-button');
n@905 467 playback.click();
n@905 468 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
n@905 469 } else
n@905 470 {
n@905 471 if (audioEngineContext.timer.testStarted == false)
n@905 472 {
n@905 473 alert('You have not started the test! Please press start to begin the test!');
n@905 474 return;
n@905 475 }
n@905 476 }
n@905 477 testState.advanceState();
n@905 478 } else // if a fragment has not been played yet
n@905 479 {
n@905 480 str = "";
n@905 481 if (hasBeenPlayed.length > 1) {
n@905 482 for (var i=0; i<hasBeenPlayed.length; i++) {
n@905 483 str = str + hasBeenPlayed[i];
n@905 484 if (i < hasBeenPlayed.length-2){
n@905 485 str += ", ";
n@905 486 } else if (i == hasBeenPlayed.length-2) {
n@905 487 str += " or ";
n@905 488 }
n@905 489 }
n@905 490 alert('You have not played fragments ' + str + ' yet. Please listen, rate and comment all samples before submitting.');
n@905 491 } else {
n@905 492 alert('You have not played fragment ' + hasBeenPlayed[0] + ' yet. Please listen, rate and comment all samples before submitting.');
n@905 493 }
n@905 494 return;
n@905 495 }
n@905 496 }
n@905 497
n@905 498 function convSliderPosToRate(id)
n@905 499 {
n@905 500 var w = document.getElementById('slider').style.width;
n@905 501 var marginsize = Number(document.getElementById('slider').attributes['marginsize'].value);
n@905 502 var maxPix = w.substr(0,w.length-2);
n@905 503 var slider = document.getElementsByClassName('track-slider')[id];
n@905 504 var pix = slider.style.left;
n@905 505 pix = pix.substr(0,pix.length-2);
n@905 506 var rate = (pix-marginsize)/maxPix;
n@905 507 return rate;
n@905 508 }
n@905 509
n@905 510 function resizeWindow(event){
n@905 511 // Function called when the window has been resized.
n@905 512 // MANDATORY FUNCTION
n@905 513
n@905 514 // Store the slider marker values
n@905 515 var holdValues = [];
n@905 516 $(".track-slider").each(function(index,sliderObj){
n@905 517 holdValues.push(convSliderPosToRate(index));
n@905 518 });
n@905 519
n@905 520 var width = event.target.innerWidth;
n@905 521 var canvas = document.getElementById('sliderCanvasHolder');
n@905 522 var sliderDiv = canvas.children[0];
n@905 523 var sliderScaleDiv = canvas.children[1];
n@905 524 var marginsize = Number(sliderDiv.attributes['marginsize'].value);
n@905 525 var w = (marginsize+8)*2;
n@905 526 sliderDiv.style.width = width - w + 'px';
n@905 527 var width = width - w;
n@905 528 // Move sliders into new position
n@905 529 $(".track-slider").each(function(index,sliderObj){
n@905 530 var pos = holdValues[index];
n@905 531 var pix = pos * width;
n@905 532 sliderObj.style.left = pix+marginsize+'px';
n@905 533 });
n@905 534
n@905 535 // Move scale labels
n@905 536 $(sliderScaleDiv.children).each(function(index,scaleObj){
n@905 537 var position = Number(scaleObj.attributes['value'].value);
n@905 538 var pixelPosition = (position*width)+marginsize;
n@905 539 scaleObj.style.left = Math.floor((pixelPosition-($(scaleObj).width()/2)))+'px';
n@905 540 });
n@905 541 }
n@905 542
n@905 543 function pageXMLSave(store, testXML, testId)
n@905 544 {
n@905 545 // Saves a specific test page
n@905 546 var xmlDoc = store;
n@905 547 // Check if any session wide metrics are enabled
n@905 548
n@905 549 var commentShow = testXML.attributes['elementComments'];
n@905 550 if (commentShow != undefined) {
n@905 551 if (commentShow.value == 'false') {commentShow = false;}
n@905 552 else {commentShow = true;}
n@905 553 } else {commentShow = true;}
n@905 554
n@905 555 var metric = document.createElement('metric');
n@905 556 if (audioEngineContext.metric.enableTestTimer)
n@905 557 {
n@905 558 var testTime = document.createElement('metricResult');
n@905 559 testTime.id = 'testTime';
n@905 560 testTime.textContent = audioEngineContext.timer.testDuration;
n@905 561 metric.appendChild(testTime);
n@905 562 }
n@905 563 xmlDoc.appendChild(metric);
n@905 564 var trackSliderObjects = document.getElementsByClassName('track-slider');
n@905 565 var commentObjects = document.getElementsByClassName('comment-div');
n@905 566 for (var i=0; i<trackSliderObjects.length; i++)
n@905 567 {
n@905 568 var audioElement = document.createElement('audioElement');
n@905 569 audioElement.id = currentTrackOrder[i].attributes['id'].value;
n@907 570 audioElement.setAttribute('url',currentTrackOrder[i].attributes['url'].value);
n@905 571 var value = document.createElement('value');
n@905 572 value.innerHTML = convSliderPosToRate(i);
n@905 573 if (commentShow) {
n@905 574 var comment = document.createElement("comment");
n@905 575 var question = document.createElement("question");
n@905 576 var response = document.createElement("response");
n@905 577 question.textContent = commentObjects[i].children[0].textContent;
n@905 578 response.textContent = commentObjects[i].children[2].value;
n@905 579 console.log('Comment ' + i + ': ' + commentObjects[i].children[2].value); // DEBUG/SAFETY
n@905 580 comment.appendChild(question);
n@905 581 comment.appendChild(response);
n@905 582 audioElement.appendChild(comment);
n@905 583 }
n@905 584 audioElement.appendChild(value);
n@905 585 // Check for any per element metrics
n@907 586
n@907 587 audioElement.appendChild(audioEngineContext.audioObjects[i].metric.exportXMLDOM());
n@905 588 xmlDoc.appendChild(audioElement);
n@905 589 }
n@905 590 var commentQuestion = document.getElementsByClassName('commentQuestion');
n@905 591 for (var i=0; i<commentQuestion.length; i++)
n@905 592 {
n@905 593 var cqHolder = document.createElement('CommentQuestion');
n@905 594 var comment = document.createElement('comment');
n@905 595 var question = document.createElement('question');
n@905 596 cqHolder.id = commentQuestion[i].id;
n@905 597 comment.textContent = commentQuestion[i].children[2].value;
n@905 598 question.textContent = commentQuestion[i].children[0].textContent;
n@905 599 console.log('Question ' + i + ': ' + commentQuestion[i].children[2].value); // DEBUG/SAFETY
n@905 600 cqHolder.appendChild(question);
n@905 601 cqHolder.appendChild(comment);
n@905 602 xmlDoc.appendChild(cqHolder);
n@905 603 }
n@905 604 store = xmlDoc;
n@905 605 }