annotate interfaces/mushra.js @ 1383:1c5fa95cf158

Small MUSHRA bug fix. Playback was blocked from ever happening due to play getting called twice.
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Mon, 15 Feb 2016 12:52:55 +0000
parents a03b04ea3357
children a4ad9e55b5b8
rev   line source
nickjillings@1341 1 /**
nickjillings@1341 2 * mushra.js
nickjillings@1341 3 * Create the MUSHRA interface
nickjillings@1341 4 */
nickjillings@1341 5
nickjillings@1341 6 // Once this is loaded and parsed, begin execution
nickjillings@1341 7 loadInterface();
nickjillings@1341 8
nickjillings@1341 9 function loadInterface() {
nickjillings@1341 10 // Get the dimensions of the screen available to the page
nickjillings@1341 11 var width = window.innerWidth;
nickjillings@1341 12 var height = window.innerHeight;
nickjillings@1341 13
nickjillings@1341 14 // The injection point into the HTML page
nickjillings@1341 15 interfaceContext.insertPoint = document.getElementById("topLevelBody");
nickjillings@1341 16 var testContent = document.createElement('div');
nickjillings@1341 17 testContent.id = 'testContent';
nickjillings@1341 18
nickjillings@1341 19 // Create the top div for the Title element
nickjillings@1341 20 var titleAttr = specification.title;
nickjillings@1341 21 var title = document.createElement('div');
nickjillings@1341 22 title.className = "title";
nickjillings@1341 23 title.align = "center";
nickjillings@1341 24 var titleSpan = document.createElement('span');
nickjillings@1341 25
nickjillings@1341 26 // Set title to that defined in XML, else set to default
nickjillings@1341 27 if (titleAttr != undefined) {
nickjillings@1341 28 titleSpan.textContent = titleAttr;
nickjillings@1341 29 } else {
nickjillings@1341 30 titleSpan.textContent = 'Listening test';
nickjillings@1341 31 }
nickjillings@1341 32 // Insert the titleSpan element into the title div element.
nickjillings@1341 33 title.appendChild(titleSpan);
nickjillings@1341 34
nickjillings@1341 35 var pagetitle = document.createElement('div');
nickjillings@1341 36 pagetitle.className = "pageTitle";
nickjillings@1341 37 pagetitle.align = "center";
nickjillings@1341 38 var titleSpan = document.createElement('span');
nickjillings@1341 39 titleSpan.id = "pageTitle";
nickjillings@1341 40 pagetitle.appendChild(titleSpan);
nickjillings@1341 41
nickjillings@1341 42 // Create Interface buttons!
nickjillings@1341 43 var interfaceButtons = document.createElement('div');
nickjillings@1341 44 interfaceButtons.id = 'interface-buttons';
nickjillings@1341 45 interfaceButtons.style.height = '25px';
nickjillings@1341 46
nickjillings@1341 47 // Create playback start/stop points
nickjillings@1341 48 var playback = document.createElement("button");
nickjillings@1341 49 playback.innerHTML = 'Stop';
nickjillings@1341 50 playback.id = 'playback-button';
nickjillings@1341 51 playback.style.float = 'left';
nickjillings@1341 52 // onclick function. Check if it is playing or not, call the correct function in the
nickjillings@1341 53 // audioEngine, change the button text to reflect the next state.
nickjillings@1341 54 playback.onclick = function() {
nickjillings@1341 55 if (audioEngineContext.status == 1) {
nickjillings@1341 56 audioEngineContext.stop();
nickjillings@1341 57 this.innerHTML = 'Stop';
nickjillings@1341 58 var time = audioEngineContext.timer.getTestTime();
nickjillings@1341 59 console.log('Stopped at ' + time); // DEBUG/SAFETY
nickjillings@1341 60 }
nickjillings@1341 61 };
nickjillings@1341 62 // Create Submit (save) button
nickjillings@1341 63 var submit = document.createElement("button");
nickjillings@1341 64 submit.innerHTML = 'Submit';
nickjillings@1341 65 submit.onclick = buttonSubmitClick;
nickjillings@1341 66 submit.id = 'submit-button';
nickjillings@1341 67 submit.style.float = 'left';
nickjillings@1341 68 // Append the interface buttons into the interfaceButtons object.
nickjillings@1341 69 interfaceButtons.appendChild(playback);
nickjillings@1341 70 interfaceButtons.appendChild(submit);
nickjillings@1341 71
nickjillings@1341 72 // Create a slider box
nickjillings@1341 73 var sliderBox = document.createElement('div');
nickjillings@1341 74 sliderBox.style.width = "100%";
nickjillings@1341 75 sliderBox.style.height = window.innerHeight - 200+12 + 'px';
nickjillings@1341 76 sliderBox.style.marginBottom = '10px';
nickjillings@1341 77 sliderBox.id = 'slider';
nickjillings@1341 78 var scaleHolder = document.createElement('div');
nickjillings@1341 79 scaleHolder.id = "scale-holder";
nickjillings@1341 80 sliderBox.appendChild(scaleHolder);
nickjillings@1341 81 var scaleText = document.createElement('div');
nickjillings@1341 82 scaleText.id = "scale-text-holder";
nickjillings@1341 83 scaleHolder.appendChild(scaleText);
nickjillings@1341 84 var scaleCanvas = document.createElement('canvas');
nickjillings@1341 85 scaleCanvas.id = "scale-canvas";
nickjillings@1341 86 scaleHolder.appendChild(scaleCanvas);
nickjillings@1341 87 var sliderObjectHolder = document.createElement('div');
nickjillings@1341 88 sliderObjectHolder.id = 'slider-holder';
nickjillings@1341 89 sliderObjectHolder.align = "center";
nickjillings@1341 90 sliderBox.appendChild(sliderObjectHolder);
nickjillings@1341 91
nickjillings@1341 92 // Global parent for the comment boxes on the page
nickjillings@1341 93 var feedbackHolder = document.createElement('div');
nickjillings@1341 94 feedbackHolder.id = 'feedbackHolder';
nickjillings@1341 95
nickjillings@1341 96 testContent.style.zIndex = 1;
nickjillings@1341 97 interfaceContext.insertPoint.innerHTML = null; // Clear the current schema
nickjillings@1341 98
nickjillings@1341 99 // Inject into HTML
nickjillings@1341 100 testContent.appendChild(title); // Insert the title
nickjillings@1341 101 testContent.appendChild(pagetitle);
nickjillings@1341 102 testContent.appendChild(interfaceButtons);
nickjillings@1341 103 testContent.appendChild(sliderBox);
nickjillings@1341 104 testContent.appendChild(feedbackHolder);
nickjillings@1341 105 interfaceContext.insertPoint.appendChild(testContent);
nickjillings@1341 106
nickjillings@1341 107 // Load the full interface
nickjillings@1341 108 testState.initialise();
nickjillings@1341 109 testState.advanceState();
nickjillings@1341 110 }
nickjillings@1341 111
nickjillings@1341 112 function loadTest(audioHolderObject)
nickjillings@1341 113 {
nickjillings@1341 114 var id = audioHolderObject.id;
nickjillings@1341 115
nickjillings@1341 116 var feedbackHolder = document.getElementById('feedbackHolder');
nickjillings@1356 117 feedbackHolder.innerHTML = null;
nickjillings@1341 118 var interfaceObj = audioHolderObject.interfaces;
nickjillings@1341 119 if (interfaceObj.length > 1)
nickjillings@1341 120 {
nickjillings@1341 121 console.log("WARNING - This interface only supports one <interface> node per page. Using first interface node");
nickjillings@1341 122 }
nickjillings@1341 123 interfaceObj = interfaceObj[0];
nickjillings@1341 124 if(interfaceObj.title != null)
nickjillings@1341 125 {
nickjillings@1341 126 document.getElementById("pageTitle").textContent = interfaceObj.title;
nickjillings@1341 127 }
nickjillings@1356 128 var interfaceOptions = specification.interfaces.options.concat(interfaceObj.options);
nickjillings@1356 129 for (var option of interfaceOptions)
nickjillings@1356 130 {
nickjillings@1356 131 if (option.type == "show")
nickjillings@1356 132 {
nickjillings@1356 133 switch(option.name) {
nickjillings@1356 134 case "playhead":
nickjillings@1356 135 var playbackHolder = document.getElementById('playback-holder');
nickjillings@1356 136 if (playbackHolder == null)
nickjillings@1356 137 {
nickjillings@1356 138 playbackHolder = document.createElement('div');
nickjillings@1356 139 playbackHolder.style.width = "100%";
nickjillings@1356 140 playbackHolder.align = 'center';
nickjillings@1356 141 playbackHolder.appendChild(interfaceContext.playhead.object);
nickjillings@1356 142 feedbackHolder.appendChild(playbackHolder);
nickjillings@1356 143 }
nickjillings@1356 144 break;
nickjillings@1356 145 case "page-count":
nickjillings@1356 146 var pagecountHolder = document.getElementById('page-count');
nickjillings@1356 147 if (pagecountHolder == null)
nickjillings@1356 148 {
nickjillings@1356 149 pagecountHolder = document.createElement('div');
nickjillings@1356 150 pagecountHolder.id = 'page-count';
nickjillings@1356 151 }
nickjillings@1356 152 pagecountHolder.innerHTML = '<span>Page '+(audioHolderObject.presentedId+1)+' of '+specification.pages.length+'</span>';
nickjillings@1356 153 var inject = document.getElementById('interface-buttons');
nickjillings@1356 154 inject.appendChild(pagecountHolder);
nickjillings@1356 155 break;
nickjillings@1356 156 case "volume":
nickjillings@1356 157 if (document.getElementById('master-volume-holder') == null)
nickjillings@1356 158 {
nickjillings@1356 159 feedbackHolder.appendChild(interfaceContext.volume.object);
nickjillings@1356 160 }
nickjillings@1356 161 break;
nickjillings@1356 162 }
nickjillings@1356 163 }
nickjillings@1356 164 }
nickjillings@1341 165
nickjillings@1341 166 // Delete outside reference
nickjillings@1341 167 var outsideReferenceHolder = document.getElementById('outside-reference');
nickjillings@1341 168 if (outsideReferenceHolder != null) {
nickjillings@1341 169 document.getElementById('interface-buttons').removeChild(outsideReferenceHolder);
nickjillings@1341 170 }
nickjillings@1341 171
nickjillings@1341 172 var sliderBox = document.getElementById('slider-holder');
nickjillings@1341 173 sliderBox.innerHTML = null;
nickjillings@1341 174
nickjillings@1341 175 var commentBoxPrefix = "Comment on track";
nickjillings@1341 176 if (interfaceObj.commentBoxPrefix != undefined) {
nickjillings@1341 177 commentBoxPrefix = interfaceObj.commentBoxPrefix;
nickjillings@1341 178 }
nickjillings@1341 179 var loopPlayback = audioHolderObject.loop;
nickjillings@1341 180
nickjillings@1341 181 currentTestHolder = document.createElement('audioHolder');
nickjillings@1341 182 currentTestHolder.id = audioHolderObject.id;
nickjillings@1341 183 currentTestHolder.repeatCount = audioHolderObject.repeatCount;
nickjillings@1341 184
nickjillings@1341 185 $(audioHolderObject.commentQuestions).each(function(index,element) {
nickjillings@1341 186 var node = interfaceContext.createCommentQuestion(element);
nickjillings@1341 187 feedbackHolder.appendChild(node.holder);
nickjillings@1341 188 });
nickjillings@1341 189
nickjillings@1341 190 // Find all the audioElements from the audioHolder
nickjillings@1341 191 var label = 0;
nickjillings@1341 192 $(audioHolderObject.audioElements).each(function(index,element){
nickjillings@1341 193 // Find URL of track
nickjillings@1341 194 // In this jQuery loop, variable 'this' holds the current audioElement.
nickjillings@1341 195
nickjillings@1341 196 var audioObject = audioEngineContext.newTrack(element);
nickjillings@1341 197 if (element.type == 'outside-reference')
nickjillings@1341 198 {
nickjillings@1341 199 // Construct outside reference;
nickjillings@1341 200 var orNode = new outsideReferenceDOM(audioObject,index,document.getElementById('interface-buttons'));
nickjillings@1341 201 audioObject.bindInterface(orNode);
nickjillings@1341 202 } else {
nickjillings@1341 203 // Create a slider per track
nickjillings@1342 204 var sliderObj = new sliderObject(audioObject,label);
nickjillings@1341 205
nickjillings@1341 206 if (typeof audioHolderObject.initialPosition === "number")
nickjillings@1341 207 {
nickjillings@1341 208 // Set the values
nickjillings@1342 209 sliderObj.slider.value = audioHolderObject.initalPosition;
nickjillings@1341 210 } else {
nickjillings@1341 211 // Distribute it randomnly
nickjillings@1342 212 sliderObj.slider.value = Math.random();
nickjillings@1341 213 }
nickjillings@1342 214 sliderBox.appendChild(sliderObj.holder);
nickjillings@1342 215 audioObject.bindInterface(sliderObj);
nickjillings@1316 216 interfaceContext.createCommentBox(audioObject);
nickjillings@1341 217 label += 1;
nickjillings@1341 218 }
nickjillings@1341 219
nickjillings@1341 220 });
nickjillings@1341 221
nickjillings@1341 222 // Auto-align
nickjillings@1341 223 resizeWindow(null);
nickjillings@1341 224 }
nickjillings@1341 225
nickjillings@1341 226 function sliderObject(audioObject,label)
nickjillings@1341 227 {
nickjillings@1341 228 // Constructs the slider object. We use the HTML5 slider object
nickjillings@1341 229 this.parent = audioObject;
nickjillings@1341 230 this.holder = document.createElement('div');
nickjillings@1341 231 this.title = document.createElement('span');
nickjillings@1341 232 this.slider = document.createElement('input');
nickjillings@1341 233 this.play = document.createElement('button');
nickjillings@1341 234
nickjillings@1341 235 this.holder.className = 'track-slider';
nickjillings@1341 236 this.holder.style.height = window.innerHeight-200 + 'px';
nickjillings@1341 237 this.holder.appendChild(this.title);
nickjillings@1341 238 this.holder.appendChild(this.slider);
nickjillings@1341 239 this.holder.appendChild(this.play);
nickjillings@1341 240 this.holder.align = "center";
nickjillings@1343 241 if (label == 0)
nickjillings@1341 242 {
nickjillings@1341 243 this.holder.style.marginLeft = '0px';
nickjillings@1341 244 }
nickjillings@1341 245 this.holder.setAttribute('trackIndex',audioObject.id);
nickjillings@1341 246
nickjillings@1341 247 this.title.textContent = label;
nickjillings@1341 248 this.title.style.width = "100%";
nickjillings@1341 249 this.title.style.float = "left";
nickjillings@1341 250
nickjillings@1341 251 this.slider.type = "range";
nickjillings@1341 252 this.slider.className = "track-slider-range track-slider-not-moved";
nickjillings@1341 253 this.slider.min = "0";
nickjillings@1341 254 this.slider.max = "1";
nickjillings@1341 255 this.slider.step = "0.01";
nickjillings@1341 256 this.slider.setAttribute('orient','vertical');
nickjillings@1341 257 this.slider.style.height = window.innerHeight-250 + 'px';
nickjillings@1341 258 this.slider.onchange = function()
nickjillings@1341 259 {
nickjillings@1341 260 var time = audioEngineContext.timer.getTestTime();
nickjillings@1341 261 var id = Number(this.parentNode.getAttribute('trackIndex'));
nickjillings@1341 262 audioEngineContext.audioObjects[id].metric.moved(time,this.value);
nickjillings@1341 263 console.log('slider '+id+' moved to '+this.value+' ('+time+')');
nickjillings@1341 264 $(this).removeClass('track-slider-not-moved');
nickjillings@1341 265 };
nickjillings@1341 266
nickjillings@1341 267 this.play.textContent = "Loading...";
nickjillings@1341 268 this.play.value = audioObject.id;
nickjillings@1341 269 this.play.style.float = "left";
nickjillings@1341 270 this.play.style.width = "100%";
nickjillings@1341 271 this.play.disabled = true;
nickjillings@1377 272 this.play.setAttribute("playstate","ready");
nickjillings@1341 273 this.play.onclick = function(event)
nickjillings@1341 274 {
nickjillings@1341 275 var id = Number(event.currentTarget.value);
nickjillings@1341 276 //audioEngineContext.metric.sliderPlayed(id);
nickjillings@1377 277 if (event.currentTarget.getAttribute("playstate") == "ready")
nickjillings@1377 278 {audioEngineContext.play(id);}
nickjillings@1377 279 else if (event.currentTarget.getAttribute("playstate") == "playing")
nickjillings@1377 280 {audioEngineContext.stop();}
nickjillings@1341 281 };
nickjillings@1341 282
nickjillings@1341 283 this.enable = function() {
nickjillings@1341 284 this.play.disabled = false;
nickjillings@1341 285 this.play.textContent = "Play";
nickjillings@1341 286 $(this.slider).removeClass('track-slider-disabled');
nickjillings@1341 287 };
nickjillings@1341 288
nickjillings@1341 289 this.exportXMLDOM = function(audioObject) {
nickjillings@1341 290 // Called by the audioObject holding this element. Must be present
nickjillings@1341 291 var node = storage.document.createElement('value');
nickjillings@1341 292 node.textContent = this.slider.value;
nickjillings@1341 293 return node;
nickjillings@1341 294 };
nickjillings@1360 295 this.startPlayback = function()
nickjillings@1360 296 {
nickjillings@1360 297 // Called when playback has begun
nickjillings@1377 298 this.play.setAttribute("playstate","playing");
nickjillings@1360 299 $(".track-slider").removeClass('track-slider-playing');
nickjillings@1360 300 $(this.holder).addClass('track-slider-playing');
nickjillings@1360 301 var outsideReference = document.getElementById('outside-reference');
nickjillings@1360 302 if (outsideReference != null) {
nickjillings@1360 303 $(outsideReference).removeClass('track-slider-playing');
nickjillings@1360 304 }
nickjillings@1383 305 this.play.textContent = "Stop";
nickjillings@1360 306 };
nickjillings@1360 307 this.stopPlayback = function()
nickjillings@1360 308 {
nickjillings@1360 309 // Called when playback has stopped. This gets called even if playback never started!
nickjillings@1377 310 this.play.setAttribute("playstate","ready");
nickjillings@1360 311 $(this.holder).removeClass('track-slider-playing');
nickjillings@1383 312 this.play.textContent = "Play";
nickjillings@1360 313 };
nickjillings@1341 314 this.getValue = function() {
nickjillings@1341 315 return this.slider.value;
nickjillings@1341 316 };
nickjillings@1341 317
nickjillings@1341 318 this.resize = function(event)
nickjillings@1341 319 {
nickjillings@1341 320 this.holder.style.height = window.innerHeight-200 + 'px';
nickjillings@1341 321 this.slider.style.height = window.innerHeight-250 + 'px';
nickjillings@1341 322 };
nickjillings@1341 323 this.updateLoading = function(progress)
nickjillings@1341 324 {
nickjillings@1341 325 progress = String(progress);
nickjillings@1341 326 progress = progress.substr(0,5);
nickjillings@1341 327 this.play.textContent = "Loading: "+progress+"%";
nickjillings@1341 328 };
nickjillings@1341 329
nickjillings@1341 330 if (this.parent.state == 1)
nickjillings@1341 331 {
nickjillings@1341 332 this.enable();
nickjillings@1341 333 }
nickjillings@1341 334 this.getPresentedId = function()
nickjillings@1341 335 {
nickjillings@1341 336 return this.title.textContent;
nickjillings@1341 337 };
nickjillings@1341 338 this.canMove = function()
nickjillings@1341 339 {
nickjillings@1341 340 return true;
nickjillings@1341 341 };
nickjillings@1341 342 }
nickjillings@1341 343
nickjillings@1341 344 function outsideReferenceDOM(audioObject,index,inject)
nickjillings@1341 345 {
nickjillings@1341 346 this.parent = audioObject;
nickjillings@1341 347 this.outsideReferenceHolder = document.createElement('button');
nickjillings@1341 348 this.outsideReferenceHolder.id = 'outside-reference';
nickjillings@1341 349 this.outsideReferenceHolder.className = 'outside-reference';
nickjillings@1341 350 this.outsideReferenceHolder.setAttribute('track-id',index);
nickjillings@1341 351 this.outsideReferenceHolder.textContent = "Play Reference";
nickjillings@1341 352 this.outsideReferenceHolder.disabled = true;
nickjillings@1341 353
nickjillings@1341 354 this.outsideReferenceHolder.onclick = function(event)
nickjillings@1341 355 {
nickjillings@1341 356 audioEngineContext.play(event.currentTarget.getAttribute('track-id'));
nickjillings@1341 357 };
nickjillings@1341 358 inject.appendChild(this.outsideReferenceHolder);
nickjillings@1341 359 this.enable = function()
nickjillings@1341 360 {
nickjillings@1341 361 if (this.parent.state == 1)
nickjillings@1341 362 {
nickjillings@1341 363 this.outsideReferenceHolder.disabled = false;
nickjillings@1341 364 }
nickjillings@1341 365 };
nickjillings@1341 366 this.updateLoading = function(progress)
nickjillings@1341 367 {
nickjillings@1341 368 if (progress != 100)
nickjillings@1341 369 {
nickjillings@1341 370 progress = String(progress);
nickjillings@1341 371 progress = progress.split('.')[0];
nickjillings@1341 372 this.outsideReferenceHolder[0].children[0].textContent = progress+'%';
nickjillings@1341 373 } else {
nickjillings@1341 374 this.outsideReferenceHolder[0].children[0].textContent = "Play Reference";
nickjillings@1341 375 }
nickjillings@1341 376 };
nickjillings@1360 377 this.startPlayback = function()
nickjillings@1360 378 {
nickjillings@1360 379 // Called when playback has begun
nickjillings@1360 380 $('.track-slider').removeClass('track-slider-playing');
nickjillings@1360 381 $('.comment-div').removeClass('comment-box-playing');
nickjillings@1360 382 $(this.outsideReferenceHolder).addClass('track-slider-playing');
nickjillings@1360 383 };
nickjillings@1360 384 this.stopPlayback = function()
nickjillings@1360 385 {
nickjillings@1360 386 // Called when playback has stopped. This gets called even if playback never started!
nickjillings@1360 387 $(this.outsideReferenceHolder).removeClass('track-slider-playing');
nickjillings@1360 388 };
nickjillings@1341 389 this.exportXMLDOM = function(audioObject)
nickjillings@1341 390 {
nickjillings@1341 391 return null;
nickjillings@1341 392 };
nickjillings@1341 393 this.getValue = function()
nickjillings@1341 394 {
nickjillings@1341 395 return 0;
nickjillings@1341 396 };
nickjillings@1341 397 this.getPresentedId = function()
nickjillings@1341 398 {
nickjillings@1341 399 return 'reference';
nickjillings@1341 400 };
nickjillings@1341 401 this.canMove = function()
nickjillings@1341 402 {
nickjillings@1341 403 return false;
nickjillings@1341 404 };
nickjillings@1341 405 }
nickjillings@1341 406
nickjillings@1341 407 function resizeWindow(event)
nickjillings@1341 408 {
nickjillings@1341 409 // Function called when the window has been resized.
nickjillings@1341 410 // MANDATORY FUNCTION
nickjillings@1341 411
nickjillings@1341 412 var outsideRef = document.getElementById('outside-reference');
nickjillings@1341 413 if(outsideRef != null)
nickjillings@1341 414 {
nickjillings@1341 415 outsideRef.style.left = (window.innerWidth-120)/2 + 'px';
nickjillings@1341 416 }
nickjillings@1341 417
nickjillings@1341 418 // Auto-align
nickjillings@1341 419 var numObj = document.getElementsByClassName('track-slider').length;
nickjillings@1341 420 var totalWidth = (numObj-1)*150+100;
nickjillings@1341 421 var diff = (window.innerWidth - totalWidth)/2;
nickjillings@1341 422 document.getElementById('slider').style.height = window.innerHeight - 180 + 'px';
nickjillings@1341 423 if (diff <= 0){diff = 0;}
nickjillings@1341 424 document.getElementById('slider-holder').style.marginLeft = diff + 'px';
nickjillings@1341 425 for (var i in audioEngineContext.audioObjects)
nickjillings@1341 426 {
nickjillings@1341 427 if (audioEngineContext.audioObjects[i].specification.type != 'outside-reference'){
nickjillings@1341 428 audioEngineContext.audioObjects[i].interfaceDOM.resize(event);
nickjillings@1341 429 }
nickjillings@1341 430 }
nickjillings@1341 431 document.getElementById('scale-holder').style.marginLeft = (diff-100) + 'px';
nickjillings@1341 432 document.getElementById('scale-text-holder').style.height = window.innerHeight-194 + 'px';
nickjillings@1341 433 var canvas = document.getElementById('scale-canvas');
nickjillings@1341 434 canvas.width = totalWidth;
nickjillings@1341 435 canvas.height = window.innerHeight-194;
nickjillings@1341 436 drawScale();
nickjillings@1341 437 }
nickjillings@1341 438
nickjillings@1341 439 function drawScale()
nickjillings@1341 440 {
nickjillings@1341 441 var interfaceObj = testState.currentStateMap.interfaces[0];
nickjillings@1341 442 var scales = testState.currentStateMap.interfaces[0].scales;
nickjillings@1341 443 scales = scales.sort(function(a,b) {
nickjillings@1341 444 return a.position - b.position;
nickjillings@1341 445 });
nickjillings@1341 446 var canvas = document.getElementById('scale-canvas');
nickjillings@1341 447 var ctx = canvas.getContext("2d");
nickjillings@1341 448 var height = canvas.height;
nickjillings@1341 449 var width = canvas.width;
nickjillings@1341 450 var draw_heights = [24, height-34];
nickjillings@1341 451 var textHolder = document.getElementById('scale-text-holder');
nickjillings@1341 452 textHolder.innerHTML = null;
nickjillings@1341 453 var lastHeight = 0;
nickjillings@1341 454 for (var scale of scales)
nickjillings@1341 455 {
nickjillings@1341 456 var posPercent = scale.position / 100.0;
nickjillings@1341 457 var posPix = (1-posPercent)*(draw_heights[1]-draw_heights[0])+draw_heights[0];
nickjillings@1341 458 ctx.fillStyle = "#000000";
nickjillings@1341 459 ctx.setLineDash([1,2]);
nickjillings@1341 460 ctx.moveTo(0,posPix);
nickjillings@1341 461 ctx.lineTo(width,posPix);
nickjillings@1341 462 ctx.stroke();
nickjillings@1341 463 var text = document.createElement('div');
nickjillings@1341 464 text.align = "right";
nickjillings@1341 465 var textC = document.createElement('span');
nickjillings@1341 466 textC.textContent = scale.text;
nickjillings@1341 467 text.appendChild(textC);
nickjillings@1341 468 text.className = "scale-text";
nickjillings@1341 469 textHolder.appendChild(text);
nickjillings@1341 470 text.style.top = (posPix-9) + 'px';
nickjillings@1341 471 text.style.left = 100 - ($(text).width()+3) + 'px';
nickjillings@1341 472 lastHeight = posPix;
nickjillings@1341 473 }
nickjillings@1341 474 }
nickjillings@1341 475
nickjillings@1341 476 function buttonSubmitClick() // TODO: Only when all songs have been played!
nickjillings@1341 477 {
nickjillings@1341 478 var checks = [];
nickjillings@1341 479 checks = checks.concat(testState.currentStateMap.interfaces[0].options);
nickjillings@1341 480 checks = checks.concat(specification.interfaces.options);
nickjillings@1341 481 var canContinue = true;
nickjillings@1341 482
nickjillings@1341 483 // Check that the anchor and reference objects are correctly placed
nickjillings@1341 484 if (interfaceContext.checkHiddenAnchor() == false) {return;}
nickjillings@1341 485 if (interfaceContext.checkHiddenReference() == false) {return;}
nickjillings@1341 486
nickjillings@1341 487 for (var i=0; i<checks.length; i++) {
nickjillings@1341 488 if (checks[i].type == 'check')
nickjillings@1341 489 {
nickjillings@1341 490 switch(checks[i].name) {
nickjillings@1341 491 case 'fragmentPlayed':
nickjillings@1341 492 // Check if all fragments have been played
nickjillings@1341 493 var checkState = interfaceContext.checkAllPlayed();
nickjillings@1341 494 if (checkState == false) {canContinue = false;}
nickjillings@1341 495 break;
nickjillings@1341 496 case 'fragmentFullPlayback':
nickjillings@1341 497 // Check all fragments have been played to their full length
nickjillings@1341 498 var checkState = interfaceContext.checkAllPlayed();
nickjillings@1341 499 if (checkState == false) {canContinue = false;}
nickjillings@1341 500 console.log('NOTE: fragmentFullPlayback not currently implemented, performing check fragmentPlayed instead');
nickjillings@1341 501 break;
nickjillings@1341 502 case 'fragmentMoved':
nickjillings@1341 503 // Check all fragment sliders have been moved.
nickjillings@1341 504 var checkState = interfaceContext.checkAllMoved();
nickjillings@1341 505 if (checkState == false) {canContinue = false;}
nickjillings@1341 506 break;
nickjillings@1341 507 case 'fragmentComments':
nickjillings@1341 508 // Check all fragment sliders have been moved.
nickjillings@1341 509 var checkState = interfaceContext.checkAllCommented();
nickjillings@1341 510 if (checkState == false) {canContinue = false;}
nickjillings@1341 511 break;
nickjillings@1341 512 //case 'scalerange':
nickjillings@1341 513 // Check the scale is used to its full width outlined by the node
nickjillings@1341 514 //var checkState = interfaceContext.checkScaleRange();
nickjillings@1341 515 //if (checkState == false) {canContinue = false;}
nickjillings@1341 516 // break;
nickjillings@1341 517 default:
nickjillings@1341 518 console.log("WARNING - Check option "+checks[i].check+" is not supported on this interface");
nickjillings@1341 519 break;
nickjillings@1341 520 }
nickjillings@1341 521
nickjillings@1341 522 }
nickjillings@1341 523 if (!canContinue) {break;}
nickjillings@1341 524 }
nickjillings@1341 525
nickjillings@1341 526 if (canContinue) {
nickjillings@1341 527 if (audioEngineContext.status == 1) {
nickjillings@1341 528 var playback = document.getElementById('playback-button');
nickjillings@1341 529 playback.click();
nickjillings@1341 530 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
nickjillings@1341 531 } else
nickjillings@1341 532 {
nickjillings@1341 533 if (audioEngineContext.timer.testStarted == false)
nickjillings@1341 534 {
nickjillings@1341 535 alert('You have not started the test! Please press start to begin the test!');
nickjillings@1341 536 return;
nickjillings@1341 537 }
nickjillings@1341 538 }
nickjillings@1341 539 testState.advanceState();
nickjillings@1341 540 }
nickjillings@1341 541 }
nickjillings@1341 542
nickjillings@1341 543 function pageXMLSave(store, pageSpecification)
nickjillings@1341 544 {
nickjillings@1341 545 // MANDATORY
nickjillings@1341 546 // Saves a specific test page
nickjillings@1341 547 // You can use this space to add any extra nodes to your XML <audioHolder> saves
nickjillings@1341 548 // Get the current <page> information in store (remember to appendChild your data to it)
nickjillings@1341 549 // pageSpecification is the current page node configuration
nickjillings@1341 550 // To create new XML nodes, use storage.document.createElement();
nickjillings@1341 551 }