nickjillings@1683: /** nickjillings@1683: * ape.js nickjillings@1683: * Create the APE interface nickjillings@1683: */ nickjillings@1683: nickjillings@1648: // preTest - In preTest state nickjillings@1648: // testRun-ID - In test running, test Id number at the end 'testRun-2' nickjillings@1648: // testRunPost-ID - Post test of test ID nickjillings@1648: // testRunPre-ID - Pre-test of test ID nickjillings@1648: // postTest - End of test, final submission! nickjillings@1648: nickjillings@1642: nickjillings@1683: // Once this is loaded and parsed, begin execution nickjillings@1581: loadInterface(); nickjillings@1683: nickjillings@1581: function loadInterface() { nickjillings@1683: nickjillings@1697: // Get the dimensions of the screen available to the page nickjillings@1683: var width = window.innerWidth; nickjillings@1683: var height = window.innerHeight; nickjillings@1683: nickjillings@1683: // The injection point into the HTML page nickjillings@1582: interfaceContext.insertPoint = document.getElementById("topLevelBody"); nickjillings@1702: var testContent = document.createElement('div'); nickjillings@1604: nickjillings@1702: testContent.id = 'testContent'; nickjillings@1576: nickjillings@1644: nickjillings@1662: // Create APE specific metric functions nickjillings@1662: audioEngineContext.metric.initialiseTest = function() nickjillings@1662: { nickjillings@1662: }; nickjillings@1662: nickjillings@1662: audioEngineContext.metric.sliderMoved = function() nickjillings@1662: { nickjillings@1583: nickjillings@1662: var id = this.data; nickjillings@1662: this.data = -1; nickjillings@1662: var position = convSliderPosToRate(id); b@1606: console.log('slider ' + id + ': '+ position + ' (' + time + ')'); // DEBUG/SAFETY: show position and slider id nickjillings@1662: if (audioEngineContext.timer.testStarted) nickjillings@1662: { nickjillings@1662: audioEngineContext.audioObjects[id].metric.moved(time,position); nickjillings@1662: } nickjillings@1662: }; nickjillings@1662: nickjillings@1662: audioEngineContext.metric.sliderPlayed = function(id) nickjillings@1662: { nickjillings@1662: var time = audioEngineContext.timer.getTestTime(); nickjillings@1662: if (audioEngineContext.timer.testStarted) nickjillings@1662: { nickjillings@1662: if (this.lastClicked >= 0) nickjillings@1662: { nickjillings@1662: audioEngineContext.audioObjects[this.lastClicked].metric.listening(time); nickjillings@1662: } nickjillings@1662: this.lastClicked = id; nickjillings@1662: audioEngineContext.audioObjects[id].metric.listening(time); nickjillings@1662: } b@1606: console.log('slider ' + id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id nickjillings@1662: }; nickjillings@1662: 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@1583: this.trackSliderObj.draggable = true; nickjillings@1583: this.trackSliderObj.ondragend = dragEnd; nickjillings@1583: nickjillings@1583: // Onclick, switch playback to that track nickjillings@1583: this.trackSliderObj.onclick = function() { nickjillings@1583: // Start the test on first click, that way timings are more accurate. nickjillings@1583: audioEngineContext.play(); nickjillings@1583: if (audioEngineContext.audioObjectsReady) { nickjillings@1583: // Cannot continue to issue play command until audioObjects reported as ready! nickjillings@1583: // Get the track ID from the object ID nickjillings@1569: var element; nickjillings@1569: if (event.srcElement.nodeName == "SPAN") { nickjillings@1569: element = event.srcElement.parentNode; nickjillings@1569: } else { nickjillings@1569: element = event.srcElement; nickjillings@1569: } nickjillings@1569: var id = Number(element.attributes['trackIndex'].value); nickjillings@1583: //audioEngineContext.metric.sliderPlayed(id); nickjillings@1565: audioEngineContext.play(id); nickjillings@1583: // Currently playing track red, rest green nickjillings@1583: nickjillings@1583: //document.getElementById('track-slider-'+index).style.backgroundColor = "#FF0000"; nickjillings@1583: $('.track-slider').removeClass('track-slider-playing'); nickjillings@1569: $(element).addClass('track-slider-playing'); nickjillings@1583: $('.comment-div').removeClass('comment-box-playing'); nickjillings@1583: $('#comment-div-'+id).addClass('comment-box-playing'); nickjillings@1583: } nickjillings@1583: }; nickjillings@1583: nickjillings@1561: this.exportXMLDOM = function(audioObject) { nickjillings@1583: // Called by the audioObject holding this element. Must be present nickjillings@1583: var node = document.createElement('value'); nickjillings@1583: node.textContent = convSliderPosToRate(this.trackSliderObj); nickjillings@1583: return node; nickjillings@1583: }; nickjillings@1561: this.getValue = function() { nickjillings@1561: return convSliderPosToRate(this.trackSliderObj); nickjillings@1562: }; nickjillings@1583: } nickjillings@1686: nickjillings@1686: function dragEnd(ev) { nickjillings@1686: // Function call when a div has been dropped nickjillings@1643: var slider = document.getElementById('slider'); nickjillings@1633: var marginSize = Number(slider.attributes['marginsize'].value); nickjillings@1661: var w = slider.style.width; nickjillings@1661: w = Number(w.substr(0,w.length-2)); nickjillings@1661: var x = ev.x; nickjillings@1633: if (x >= marginSize && x < w+marginSize) { nickjillings@1661: this.style.left = (x)+'px'; nickjillings@1686: } else { nickjillings@1633: 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