annotate ape.js @ 2047:6118a9aea1f5

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