nickjillings@1556: /** nickjillings@1556: * ape.js nickjillings@1556: * Create the APE interface nickjillings@1556: */ nickjillings@1556: nickjillings@1556: // preTest - In preTest state nickjillings@1556: // testRun-ID - In test running, test Id number at the end 'testRun-2' nickjillings@1556: // testRunPost-ID - Post test of test ID nickjillings@1556: // testRunPre-ID - Pre-test of test ID nickjillings@1556: // postTest - End of test, final submission! nickjillings@1556: nickjillings@1556: nickjillings@1556: // Once this is loaded and parsed, begin execution nickjillings@1556: loadInterface(); nickjillings@1556: nickjillings@1556: function loadInterface() { nickjillings@1556: nickjillings@1556: // Get the dimensions of the screen available to the page nickjillings@1556: var width = window.innerWidth; nickjillings@1556: var height = window.innerHeight; nickjillings@1556: nickjillings@1556: // The injection point into the HTML page nickjillings@1556: interfaceContext.insertPoint = document.getElementById("topLevelBody"); nickjillings@1556: var testContent = document.createElement('div'); nickjillings@1556: nickjillings@1556: testContent.id = 'testContent'; nickjillings@1556: nickjillings@1556: nickjillings@1556: // Create APE specific metric functions nickjillings@1556: audioEngineContext.metric.initialiseTest = function() nickjillings@1556: { nickjillings@1556: }; nickjillings@1556: nickjillings@1556: audioEngineContext.metric.sliderMoved = function() nickjillings@1556: { nickjillings@1556: nickjillings@1556: var id = this.data; nickjillings@1556: this.data = -1; nickjillings@1556: var position = convSliderPosToRate(id); nickjillings@1556: console.log('slider ' + id + ': '+ position + ' (' + time + ')'); // DEBUG/SAFETY: show position and slider id nickjillings@1556: if (audioEngineContext.timer.testStarted) nickjillings@1556: { nickjillings@1556: audioEngineContext.audioObjects[id].metric.moved(time,position); nickjillings@1556: } nickjillings@1556: }; nickjillings@1556: nickjillings@1556: audioEngineContext.metric.sliderPlayed = function(id) nickjillings@1556: { nickjillings@1556: var time = audioEngineContext.timer.getTestTime(); nickjillings@1556: if (audioEngineContext.timer.testStarted) nickjillings@1556: { nickjillings@1556: if (this.lastClicked >= 0) nickjillings@1556: { nickjillings@1556: audioEngineContext.audioObjects[this.lastClicked].metric.listening(time); nickjillings@1556: } nickjillings@1556: this.lastClicked = id; nickjillings@1556: audioEngineContext.audioObjects[id].metric.listening(time); nickjillings@1556: } nickjillings@1556: console.log('slider ' + id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id nickjillings@1556: }; nickjillings@1556: nickjillings@1557: // Bindings for interfaceContext nickjillings@1557: Interface.prototype.checkAllPlayed = function() nickjillings@1557: { nickjillings@1557: hasBeenPlayed = audioEngineContext.checkAllPlayed(); nickjillings@1557: if (hasBeenPlayed.length > 0) // if a fragment has not been played yet nickjillings@1557: { nickjillings@1557: str = ""; nickjillings@1557: if (hasBeenPlayed.length > 1) { nickjillings@1557: for (var i=0; i 1) { nickjillings@1557: var str = ""; nickjillings@1557: for (var i=0; i 1) { nickjillings@1557: var str = ""; nickjillings@1557: for (var i=0; i'; nickjillings@1556: this.trackSliderObj.draggable = true; nickjillings@1556: this.trackSliderObj.ondragend = dragEnd; nickjillings@1556: nickjillings@1556: // Onclick, switch playback to that track nickjillings@1556: this.trackSliderObj.onclick = function() { nickjillings@1556: // Start the test on first click, that way timings are more accurate. nickjillings@1556: audioEngineContext.play(); nickjillings@1556: if (audioEngineContext.audioObjectsReady) { nickjillings@1556: // Cannot continue to issue play command until audioObjects reported as ready! nickjillings@1556: // Get the track ID from the object ID nickjillings@1556: var element; nickjillings@1556: if (event.srcElement.nodeName == "SPAN") { nickjillings@1556: element = event.srcElement.parentNode; nickjillings@1556: } else { nickjillings@1556: element = event.srcElement; nickjillings@1556: } nickjillings@1556: var id = Number(element.attributes['trackIndex'].value); nickjillings@1556: //audioEngineContext.metric.sliderPlayed(id); nickjillings@1556: audioEngineContext.play(id); nickjillings@1556: // Currently playing track red, rest green nickjillings@1556: nickjillings@1556: //document.getElementById('track-slider-'+index).style.backgroundColor = "#FF0000"; nickjillings@1556: $('.track-slider').removeClass('track-slider-playing'); nickjillings@1556: $(element).addClass('track-slider-playing'); nickjillings@1556: $('.comment-div').removeClass('comment-box-playing'); nickjillings@1556: $('#comment-div-'+id).addClass('comment-box-playing'); nickjillings@1556: } nickjillings@1556: }; nickjillings@1556: nickjillings@1561: this.exportXMLDOM = function(audioObject) { nickjillings@1556: // Called by the audioObject holding this element. Must be present nickjillings@1556: var node = document.createElement('value'); nickjillings@1556: node.textContent = convSliderPosToRate(this.trackSliderObj); nickjillings@1556: return node; nickjillings@1556: }; nickjillings@1561: this.getValue = function() { nickjillings@1561: return convSliderPosToRate(this.trackSliderObj); nickjillings@1561: } nickjillings@1556: } nickjillings@1556: nickjillings@1556: function dragEnd(ev) { nickjillings@1556: // Function call when a div has been dropped nickjillings@1556: var slider = document.getElementById('slider'); nickjillings@1556: var marginSize = Number(slider.attributes['marginsize'].value); nickjillings@1556: var w = slider.style.width; nickjillings@1556: w = Number(w.substr(0,w.length-2)); nickjillings@1556: var x = ev.x; nickjillings@1556: if (x >= marginSize && x < w+marginSize) { nickjillings@1556: this.style.left = (x)+'px'; nickjillings@1556: } else { nickjillings@1556: if (x audioObjs[anchorId].specification.marker) nickjillings@1561: { nickjillings@1561: // Anchor is not set below nickjillings@1561: console.log('Anchor node not below marker value'); nickjillings@1561: alert('Please keep listening'); nickjillings@1561: return; nickjillings@1561: } nickjillings@1561: } else { nickjillings@1561: // No marker value given, ensure it is the minimum value nickjillings@1561: var anchorVal = audioObjs[anchorId].interfaceDOM.getValue(); nickjillings@1561: for (var i=0; i audioObjs[i].interfaceDOM.getValue()) { nickjillings@1561: // Anchor not the minimum nickjillings@1561: console.log('No marker set, anchor node not the minimum'); nickjillings@1561: alert('Please keep listening'); nickjillings@1561: return; nickjillings@1561: } nickjillings@1561: } nickjillings@1561: } nickjillings@1561: } nickjillings@1561: } nickjillings@1561: if (referenceId != null) { nickjillings@1561: if (audioObjs[referenceId].specification.marker != null) { nickjillings@1561: if (audioObjs[referenceId].interfaceDOM.getValue() < audioObjs[referenceId].specification.marker) nickjillings@1561: { nickjillings@1561: // Anchor is not set below nickjillings@1561: console.log('Reference node not above marker value'); nickjillings@1561: alert('Please keep listening'); nickjillings@1561: return; nickjillings@1561: } nickjillings@1561: } else { nickjillings@1561: // No marker value given, ensure it is the minimum value nickjillings@1561: var referenceVal = audioObjs[referenceId].interfaceDOM.getValue(); nickjillings@1561: for (var i=0; i audioObjs[i].interfaceDOM.getValue()) { nickjillings@1561: // Anchor not the minimum nickjillings@1561: console.log('No marker set, reference node not the maximum'); nickjillings@1561: alert('Please keep listening'); nickjillings@1561: return; nickjillings@1561: } nickjillings@1561: } nickjillings@1561: } nickjillings@1561: } nickjillings@1561: } nickjillings@1561: nickjillings@1557: for (var i=0; i