# HG changeset patch # User Nicholas Jillings # Date 1476802198 -3600 # Node ID 249a1152e525b5776a898984b85bf7853a4ad867 # Parent b6bc57a2a681dd83570a671168d200980a7b21a1# Parent 9b536838a962568bf5442fd16082db66f8e4d8be Merge branch 'master' into Dev_main # Conflicts: # interfaces/AB.js # js/core.js # js/specification.js diff -r b6bc57a2a681 -r 249a1152e525 interfaces/AB.js --- a/interfaces/AB.js Tue Oct 18 15:28:24 2016 +0100 +++ b/interfaces/AB.js Tue Oct 18 15:49:58 2016 +0100 @@ -2,15 +2,15 @@ loadInterface(); function loadInterface() { - // Get the dimensions of the screen available to the page - var width = window.innerWidth; - var height = window.innerHeight; - interfaceContext.insertPoint.innerHTML = ""; // Clear the current schema - - // Custom comparator Object - Interface.prototype.comparator = null; - - Interface.prototype.checkScaleRange = function (min, max) { + // Get the dimensions of the screen available to the page + var width = window.innerWidth; + var height = window.innerHeight; + interfaceContext.insertPoint.innerHTML = ""; // Clear the current schema + + // Custom comparator Object + Interface.prototype.comparator = null; + + Interface.prototype.checkScaleRange = function(min, max) { var page = testState.getCurrentTestPage(); var audioObjects = audioEngineContext.audioObjects; var state = true; @@ -19,170 +19,166 @@ var maxRanking = -Infinity; for (var ao of audioObjects) { var rank = ao.interfaceDOM.getValue(); - if (rank < minRanking) { - minRanking = rank; - } - if (rank > maxRanking) { - maxRanking = rank; - } + if (rank < minRanking) {minRanking = rank;} + if (rank > maxRanking) {maxRanking = rank;} } - if (maxRanking * 100 < max) { + if (maxRanking*100 < max) { str += "At least one fragment must be selected." state = false; } if (!state) { console.log(str); this.storeErrorNode(str); - interfaceContext.lightbox.post("Message", str); + interfaceContext.lightbox.post("Message",str); } return state; } - - // The injection point into the HTML page - interfaceContext.insertPoint = document.getElementById("topLevelBody"); - var testContent = document.createElement('div'); - testContent.id = 'testContent'; - - // Create the top div for the Title element - var titleAttr = specification.title; - var title = document.createElement('div'); - title.className = "title"; - title.align = "center"; - var titleSpan = document.createElement('span'); + + // The injection point into the HTML page + interfaceContext.insertPoint = document.getElementById("topLevelBody"); + var testContent = document.createElement('div'); + testContent.id = 'testContent'; + + // Create the top div for the Title element + var titleAttr = specification.title; + var title = document.createElement('div'); + title.className = "title"; + title.align = "center"; + var titleSpan = document.createElement('span'); titleSpan.id = "test-title"; - - // Set title to that defined in XML, else set to default - if (titleAttr != undefined) { - titleSpan.textContent = titleAttr; - } else { - titleSpan.textContent = 'Listening test'; - } - // Insert the titleSpan element into the title div element. - title.appendChild(titleSpan); - - var pagetitle = document.createElement('div'); - pagetitle.className = "pageTitle"; - pagetitle.align = "center"; - var titleSpan = document.createElement('span'); - titleSpan.id = "pageTitle"; - pagetitle.appendChild(titleSpan); - - // Create Interface buttons! - var interfaceButtons = document.createElement('div'); - interfaceButtons.id = 'interface-buttons'; - interfaceButtons.style.height = '25px'; - - // Create playback start/stop points - var playback = document.createElement("button"); - playback.innerHTML = 'Stop'; - playback.id = 'playback-button'; - playback.style.float = 'left'; - // onclick function. Check if it is playing or not, call the correct function in the - // audioEngine, change the button text to reflect the next state. - playback.onclick = function () { - if (audioEngineContext.status == 1) { - audioEngineContext.stop(); - this.innerHTML = 'Stop'; + + // Set title to that defined in XML, else set to default + if (titleAttr != undefined) { + titleSpan.textContent = titleAttr; + } else { + titleSpan.textContent = 'Listening test'; + } + // Insert the titleSpan element into the title div element. + title.appendChild(titleSpan); + + var pagetitle = document.createElement('div'); + pagetitle.className = "pageTitle"; + pagetitle.align = "center"; + var titleSpan = document.createElement('span'); + titleSpan.id = "pageTitle"; + pagetitle.appendChild(titleSpan); + + // Create Interface buttons! + var interfaceButtons = document.createElement('div'); + interfaceButtons.id = 'interface-buttons'; + interfaceButtons.style.height = '25px'; + + // Create playback start/stop points + var playback = document.createElement("button"); + playback.innerHTML = 'Stop'; + playback.id = 'playback-button'; + playback.style.float = 'left'; + // onclick function. Check if it is playing or not, call the correct function in the + // audioEngine, change the button text to reflect the next state. + playback.onclick = function() { + if (audioEngineContext.status == 1) { + audioEngineContext.stop(); + this.innerHTML = 'Stop'; var time = audioEngineContext.timer.getTestTime(); console.log('Stopped at ' + time); // DEBUG/SAFETY - } - }; - // Append the interface buttons into the interfaceButtons object. - interfaceButtons.appendChild(playback); - - // Global parent for the comment boxes on the page - var feedbackHolder = document.createElement('div'); - feedbackHolder.id = 'feedbackHolder'; - + } + }; + // Append the interface buttons into the interfaceButtons object. + interfaceButtons.appendChild(playback); + + // Global parent for the comment boxes on the page + var feedbackHolder = document.createElement('div'); + feedbackHolder.id = 'feedbackHolder'; + // Create outside reference holder var outsideRef = document.createElement("div"); outsideRef.id = "outside-reference-holder"; - - // Construct the AB Boxes - var boxes = document.createElement('div'); - boxes.align = "center"; - boxes.id = "box-holders"; + + // Construct the AB Boxes + var boxes = document.createElement('div'); + boxes.align = "center"; + boxes.id = "box-holders"; boxes.style.float = "left"; - - var submit = document.createElement('button'); - submit.id = "submit"; - submit.onclick = buttonSubmitClick; - submit.className = "big-button"; - submit.textContent = "submit"; - submit.style.position = "relative"; - submit.style.left = (window.innerWidth - 250) / 2 + 'px'; - - feedbackHolder.appendChild(boxes); - + + var submit = document.createElement('button'); + submit.id = "submit"; + submit.onclick = buttonSubmitClick; + submit.className = "big-button"; + submit.textContent = "submit"; + submit.style.position = "relative"; + submit.style.left = (window.innerWidth-250)/2 + 'px'; + + feedbackHolder.appendChild(boxes); + // Create holder for comment boxes var comments = document.createElement("div"); comments.id = "comment-box-holder"; + + // Inject into HTML + testContent.appendChild(title); // Insert the title + testContent.appendChild(pagetitle); + testContent.appendChild(interfaceButtons); + testContent.appendChild(outsideRef); + testContent.appendChild(feedbackHolder); + testContent.appendChild(submit); + testContent.appendChild(comments); + interfaceContext.insertPoint.appendChild(testContent); - // Inject into HTML - testContent.appendChild(title); // Insert the title - testContent.appendChild(pagetitle); - testContent.appendChild(interfaceButtons); - testContent.appendChild(outsideRef); - testContent.appendChild(feedbackHolder); - testContent.appendChild(submit); - testContent.appendChild(comments); - interfaceContext.insertPoint.appendChild(testContent); - - // Load the full interface - testState.initialise(); - testState.advanceState(); + // Load the full interface + testState.initialise(); + testState.advanceState(); } -function loadTest(audioHolderObject) { - var feedbackHolder = document.getElementById('feedbackHolder'); - var interfaceObj = audioHolderObject.interfaces; - if (interfaceObj.length > 1) { - console.log("WARNING - This interface only supports one node per page. Using first interface node"); - } - interfaceObj = interfaceObj[0]; - +function loadTest(audioHolderObject) +{ + var feedbackHolder = document.getElementById('feedbackHolder'); + var interfaceObj = audioHolderObject.interfaces; + if (interfaceObj.length > 1) + { + console.log("WARNING - This interface only supports one node per page. Using first interface node"); + } + interfaceObj = interfaceObj[0]; + var commentHolder = document.getElementById('comment-box-holder'); commentHolder.innerHTML = ""; - + // Delete outside reference - var outsideReferenceHolder = document.getElementById("outside-reference-holder"); + var outsideReferenceHolder = document.getElementById("outside-reference-holder"); outsideReferenceHolder.innerHTML = ""; - + // Set the page title if (typeof audioHolderObject.title == "string" && audioHolderObject.title.length > 0) { document.getElementById("test-title").textContent = audioHolderObject.title } - - if (interfaceObj.title != null) { - document.getElementById("pageTitle").textContent = interfaceObj.title; - } - + + if(interfaceObj.title != null) + { + document.getElementById("pageTitle").textContent = interfaceObj.title; + } + var interfaceOptions = specification.interfaces.options.concat(interfaceObj.options); // Clear the interfaceElements { var node = document.getElementById('playback-holder'); - if (node) { - feedbackHolder.removeChild(node); - } + if (node){feedbackHolder.removeChild(node);} node = document.getElementById('page-count'); - if (node) { - document.getElementById('interface-buttons').removeChild(node); - } + if (node){document.getElementById('interface-buttons').removeChild(node);} node = document.getElementById('master-volume-holder-float'); - if (node) { - feedbackHolder.removeChild(node); - } + if (node){feedbackHolder.removeChild(node);} } - + // Populate the comparator object - interfaceContext.comparator = new comparator(audioHolderObject); - - for (var option of interfaceOptions) { - if (option.type == "show") { - switch (option.name) { + interfaceContext.comparator = new comparator(audioHolderObject); + + for (var option of interfaceOptions) + { + if (option.type == "show") + { + switch(option.name) { case "playhead": var playbackHolder = document.getElementById('playback-holder'); - if (playbackHolder == null) { + if (playbackHolder == null) + { playbackHolder = document.createElement('div'); playbackHolder.id = 'playback-holder'; playbackHolder.style.width = "100%"; @@ -194,329 +190,309 @@ break; case "page-count": var pagecountHolder = document.getElementById('page-count'); - if (pagecountHolder == null) { + if (pagecountHolder == null) + { pagecountHolder = document.createElement('div'); pagecountHolder.id = 'page-count'; document.getElementById('interface-buttons').appendChild(pagecountHolder); } - pagecountHolder.innerHTML = 'Page ' + (testState.stateIndex + 1) + ' of ' + testState.stateMap.length + ''; + pagecountHolder.innerHTML = 'Page '+(testState.stateIndex+1)+' of '+testState.stateMap.length+''; break; case "volume": - if (document.getElementById('master-volume-holder-float') == null) { + if (document.getElementById('master-volume-holder-float') == null) + { feedbackHolder.appendChild(interfaceContext.volume.object); } break; case "comments": // Generate one comment box per presented page - for (var element of audioEngineContext.audioObjects) { + for (var element of audioEngineContext.audioObjects) + { interfaceContext.commentBoxes.createCommentBox(element); } - interfaceContext.commentBoxes.showCommentBoxes(commentHolder, true); + interfaceContext.commentBoxes.showCommentBoxes(commentHolder,true); break; } } } - - $(audioHolderObject.commentQuestions).each(function (index, element) { - var node = interfaceContext.createCommentQuestion(element); - commentHolder.appendChild(node.holder); - }); - - resizeWindow(null); + + $(audioHolderObject.commentQuestions).each(function(index,element) { + var node = interfaceContext.createCommentQuestion(element); + commentHolder.appendChild(node.holder); + }); + + resizeWindow(null); } -function comparator(audioHolderObject) { - this.comparatorBox = function (audioElement, id, text) { - this.parent = audioElement; - this.id = id; - this.value = 0; - this.disabled = true; - this.box = document.createElement('div'); - this.box.className = 'comparator-holder'; - this.box.setAttribute('track-id', audioElement.id); - this.box.id = 'comparator-' + text; - this.selector = document.createElement('div'); - this.selector.className = 'comparator-selector disabled'; - var selectorText = document.createElement('span'); - selectorText.textContent = text; - this.selector.appendChild(selectorText); - this.playback = document.createElement('button'); - this.playback.className = 'comparator-button'; - this.playback.disabled = true; - this.playback.textContent = "Listen"; - this.box.appendChild(this.selector); - this.box.appendChild(this.playback); - this.selector.onclick = function (event) { - var time = audioEngineContext.timer.getTestTime(); - if ($(event.currentTarget).hasClass('disabled')) { - console.log("Please wait until sample has loaded"); - return; +function comparator(audioHolderObject) +{ + this.comparatorBox = function(audioElement,id,text) + { + this.parent = audioElement; + this.id = id; + this.value = 0; + this.disabled = true; + this.box = document.createElement('div'); + this.box.className = 'comparator-holder'; + this.box.setAttribute('track-id',audioElement.id); + this.box.id = 'comparator-'+text; + this.selector = document.createElement('div'); + this.selector.className = 'comparator-selector disabled'; + var selectorText = document.createElement('span'); + selectorText.textContent = text; + this.selector.appendChild(selectorText); + this.playback = document.createElement('button'); + this.playback.className = 'comparator-button'; + this.playback.disabled = true; + this.playback.textContent = "Listen"; + this.box.appendChild(this.selector); + this.box.appendChild(this.playback); + this.selector.onclick = function(event) + { + var time = audioEngineContext.timer.getTestTime(); + if ($(event.currentTarget).hasClass('disabled')) + { + console.log("Please wait until sample has loaded"); + return; + } + if (audioEngineContext.status == 0) + { + interfaceContext.lightbox.post("Message","Please listen to the samples before making a selection"); + console.log("Please listen to the samples before making a selection"); + return; } - if (audioEngineContext.status == 0) { - interfaceContext.lightbox.post("Message", "Please listen to the samples before making a selection"); - console.log("Please listen to the samples before making a selection"); - return; - } - var id = event.currentTarget.parentElement.getAttribute('track-id'); - interfaceContext.comparator.selected = id; + var id = event.currentTarget.parentElement.getAttribute('track-id'); + interfaceContext.comparator.selected = id; if ($(event.currentTarget).hasClass("selected")) { $(".comparator-selector").removeClass('selected'); - for (var i = 0; i < interfaceContext.comparator.comparators.length; i++) { + for (var i=0; i 122) { - label = "a"; - } - break; - case "none": - label = ""; - break; - case "capital": - default: - if (label.charCodeAt(0) < 65 || label.charCodeAt(0) > 90) { - label = "A"; - } - break; - } - } - for (var index = 0; index < audioHolderObject.audioElements.length; index++) { - var element = audioHolderObject.audioElements[index]; + this.exportXMLDOM = function(audioObject) + { + var node = storage.document.createElement('value'); + node.textContent = this.value; + return node; + }; + this.getValue = function() { + return this.value; + }; + this.getPresentedId = function() + { + return this.selector.children[0].textContent; + }; + this.canMove = function() + { + return false; + }; + }; + + this.boxHolders = document.getElementById('box-holders'); + this.boxHolders.innerHTML = ""; + this.comparators = []; + this.selected = null; + + // First generate the Audio Objects for the Audio Engine + for (var index=0; index saves - // Get the current information in store (remember to appendChild your data to it) - // pageSpecification is the current page node configuration - // To create new XML nodes, use storage.document.createElement(); -} +function pageXMLSave(store, pageSpecification) +{ + // MANDATORY + // Saves a specific test page + // You can use this space to add any extra nodes to your XML saves + // Get the current information in store (remember to appendChild your data to it) + // pageSpecification is the current page node configuration + // To create new XML nodes, use storage.document.createElement(); +} \ No newline at end of file diff -r b6bc57a2a681 -r 249a1152e525 interfaces/ABX.js --- a/interfaces/ABX.js Tue Oct 18 15:28:24 2016 +0100 +++ b/interfaces/ABX.js Tue Oct 18 15:49:58 2016 +0100 @@ -323,7 +323,7 @@ if (this.parent.specification.parent.playOne || specification.playOne) { $('.comparator-button').text('Wait'); $('.comparator-button').attr("disabled","true"); - $(this.playback).css("disabled","false"); + $(this.playback).removeAttr("disabled"); } else { $('.comparator-button').text('Listen'); } diff -r b6bc57a2a681 -r 249a1152e525 js/core.js --- a/js/core.js Tue Oct 18 15:28:24 2016 +0100 +++ b/js/core.js Tue Oct 18 15:49:58 2016 +0100 @@ -1113,7 +1113,8 @@ this.postNode(); } else { // Reached the end of the popupOptions - this.popupContent.innerHTML = ""; + this.popupTitle.textContent = ""; + this.popupResponse.innerHTML = ""; this.hidePopup(); for (var node of this.popupOptions) { this.store.postResult(node); @@ -1387,7 +1388,7 @@ // because web audio will optimise and any route which does not go to the destination gets ignored. this.outputGain = audioContext.createGain(); this.fooGain = audioContext.createGain(); - this.fooGain.gain = 0; + this.fooGain.gain.value = 0; // Use this to detect playback state: 0 - stopped, 1 - playing this.status = 0; @@ -1407,6 +1408,14 @@ this.pageStore = null; + // Chrome 53+ Error solution + // Empty buffer for keep-alive + var nullBuffer = audioContext.createBuffer(1, audioContext.sampleRate, audioContext.sampleRate); + this.nullBufferSource = audioContext.createBufferSource(); + this.nullBufferSource.buffer = nullBuffer; + this.nullBufferSource.loop = true; + this.nullBufferSource.start(0); + // Create store for new audioObjects this.audioObjects = []; @@ -1559,7 +1568,7 @@ } else { var dst = copybuffer.getChannelData(c); for (var n = 0; n < newLength; n++) - dst[n] = src[n + start_sample]; + dst[n] = buffer[n + start_sample]; } } return copybuffer; @@ -1770,6 +1779,7 @@ // Connect buffer to the audio graph this.outputGain.connect(audioEngineContext.outputGain); + audioEngineContext.nullBufferSource.connect(this.outputGain); // the audiobuffer is not designed for multi-start playback // When stopeed, the buffer node is deleted and recreated with the stored buffer. @@ -1793,16 +1803,14 @@ var startTime = this.specification.startTime; var stopTime = this.specification.stopTime; var copybuffer = new callee.constructor(); - if (isFinite(startTime) || isFinite(stopTime)) { - copybuffer.buffer = callee.cropBuffer(startTime, stopTime); + + copybuffer.buffer = callee.cropBuffer(startTime || 0, stopTime || callee.buffer.duration); + if (preSilenceTime != 0 || postSilenceTime != 0) { + copybuffer.buffer = copybuffer.copyBuffer(preSilenceTime, postSilenceTime); } - if (preSilenceTime != 0 || postSilenceTime != 0) { - if (copybuffer.buffer == undefined) { - copybuffer.buffer = callee.copyBuffer(preSilenceTime, postSilenceTime); - } else { - copybuffer.buffer = copybuffer.copyBuffer(preSilenceTime, postSilenceTime); - } - } + + copybuffer.lufs = callee.buffer.lufs; + this.buffer = copybuffer; var targetLUFS = this.specification.parent.loudness || specification.loudness; if (typeof targetLUFS === "number" && isFinite(targetLUFS)) { @@ -1860,14 +1868,21 @@ event.currentTarget.owner.stop(audioContext.currentTime + 1); } }; + this.outputGain.gain.cancelScheduledValues(audioContext.currentTime); if (!audioEngineContext.loopPlayback || !audioEngineContext.synchPlayback) { this.metric.startListening(audioEngineContext.timer.getTestTime()); - this.outputGain.gain.setValueAtTime(this.onplayGain, 0.0); + this.outputGain.gain.setValueAtTime(this.onplayGain, startTime); this.interfaceDOM.startPlayback(); } else { this.outputGain.gain.setValueAtTime(0.0, startTime); } - this.bufferNode.start(startTime, this.specification.startTime || 0, this.specification.stopTime - this.specification.startTime || this.buffer.buffer.duration); + if (audioEngineContext.loopPlayback) { + this.bufferNode.loopStart = this.specification.startTime || 0; + this.bufferNode.loopEnd = this.specification.stopTime - this.specification.startTime || this.buffer.buffer.duration; + this.bufferNode.start(startTime); + } else { + this.bufferNode.start(startTime, this.specification.startTime || 0, this.specification.stopTime - this.specification.startTime || this.buffer.buffer.duration); + } this.bufferNode.playbackStartTime = audioEngineContext.timer.getTestTime(); } }; @@ -1879,7 +1894,7 @@ this.bufferNode.stop(stopTime); this.bufferNode = undefined; } - this.outputGain.gain.value = 0.0; + this.outputGain.gain.setValueAtTime(0.0, stopTime); this.interfaceDOM.stopPlayback(); }; diff -r b6bc57a2a681 -r 249a1152e525 js/specification.js --- a/js/specification.js Tue Oct 18 15:28:24 2016 +0100 +++ b/js/specification.js Tue Oct 18 15:49:58 2016 +0100 @@ -495,83 +495,88 @@ this.decode = function (parent, xml) { this.parent = parent; - var attributeMap = this.schema.getAllElementsByTagName('xs:attribute'); - for (var i = 0; i < attributeMap.length; i++) { - var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref'); - var projectAttr = xml.getAttribute(attributeName); - projectAttr = parent.processAttribute(projectAttr, attributeMap[i], parent.schema); - switch (typeof projectAttr) { - case "number": - case "boolean": - eval('this.' + attributeName + ' = ' + projectAttr); - break; - case "string": - eval('this.' + attributeName + ' = "' + projectAttr + '"'); - break; - } - } - + var attributeMap = this.schema.getAllElementsByTagName('xs:attribute'); + for (var i=0; i - + Please enter your name. diff -r b6bc57a2a681 -r 249a1152e525 tests/examples/AB_example.xml --- a/tests/examples/AB_example.xml Tue Oct 18 15:28:24 2016 +0100 +++ b/tests/examples/AB_example.xml Tue Oct 18 15:49:58 2016 +0100 @@ -1,6 +1,6 @@ - + Please enter your name. diff -r b6bc57a2a681 -r 249a1152e525 tests/examples/mushra_example.xml --- a/tests/examples/mushra_example.xml Tue Oct 18 15:28:24 2016 +0100 +++ b/tests/examples/mushra_example.xml Tue Oct 18 15:49:58 2016 +0100 @@ -1,6 +1,6 @@ - + Thank you for looking at WAET. You can modify the successful completion text as well! diff -r b6bc57a2a681 -r 249a1152e525 tests/examples/project.xml --- a/tests/examples/project.xml Tue Oct 18 15:28:24 2016 +0100 +++ b/tests/examples/project.xml Tue Oct 18 15:49:58 2016 +0100 @@ -94,7 +94,7 @@ - Comment on fragment + Comment on fragment Example Test Question