nicholas@2: /** nicholas@2: * ape.js nicholas@2: * Create the APE interface nicholas@2: */ nicholas@2: n@38: // preTest - In preTest state n@38: // testRun-ID - In test running, test Id number at the end 'testRun-2' n@38: // testRunPost-ID - Post test of test ID n@38: // testRunPre-ID - Pre-test of test ID n@38: // postTest - End of test, final submission! n@38: n@32: nicholas@2: // Once this is loaded and parsed, begin execution n@181: loadInterface(); nicholas@2: n@181: function loadInterface() { nicholas@2: n@16: // Get the dimensions of the screen available to the page nicholas@2: var width = window.innerWidth; nicholas@2: var height = window.innerHeight; nicholas@2: nicholas@2: // The injection point into the HTML page n@182: interfaceContext.insertPoint = document.getElementById("topLevelBody"); n@22: var testContent = document.createElement('div'); nicholas@135: n@22: testContent.id = 'testContent'; n@176: n@34: n@52: // Create APE specific metric functions n@52: audioEngineContext.metric.initialiseTest = function() n@52: { n@52: }; n@52: n@52: audioEngineContext.metric.sliderMoved = function() n@52: { n@183: n@52: var id = this.data; n@52: this.data = -1; n@52: var position = convSliderPosToRate(id); b@115: console.log('slider ' + id + ': '+ position + ' (' + time + ')'); // DEBUG/SAFETY: show position and slider id n@52: if (audioEngineContext.timer.testStarted) n@52: { n@52: audioEngineContext.audioObjects[id].metric.moved(time,position); n@52: } n@52: }; n@52: n@52: audioEngineContext.metric.sliderPlayed = function(id) n@52: { n@52: var time = audioEngineContext.timer.getTestTime(); n@52: if (audioEngineContext.timer.testStarted) n@52: { n@52: if (this.lastClicked >= 0) n@52: { n@52: audioEngineContext.audioObjects[this.lastClicked].metric.listening(time); n@52: } n@52: this.lastClicked = id; n@52: audioEngineContext.audioObjects[id].metric.listening(time); n@52: } b@115: console.log('slider ' + id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id n@52: }; n@52: nicholas@214: // Bindings for interfaceContext nicholas@214: Interface.prototype.checkAllPlayed = function() nicholas@214: { nicholas@214: hasBeenPlayed = audioEngineContext.checkAllPlayed(); nicholas@214: if (hasBeenPlayed.length > 0) // if a fragment has not been played yet nicholas@214: { nicholas@214: str = ""; nicholas@214: if (hasBeenPlayed.length > 1) { nicholas@214: for (var i=0; i 1) { nicholas@214: var str = ""; nicholas@214: for (var i=0; i 1) { nicholas@214: var str = ""; nicholas@214: for (var i=0; i'; n@183: this.trackSliderObj.draggable = true; n@183: this.trackSliderObj.ondragend = dragEnd; n@183: n@183: // Onclick, switch playback to that track n@183: this.trackSliderObj.onclick = function() { n@183: // Start the test on first click, that way timings are more accurate. n@183: audioEngineContext.play(); n@183: if (audioEngineContext.audioObjectsReady) { n@183: // Cannot continue to issue play command until audioObjects reported as ready! n@183: // Get the track ID from the object ID nicholas@210: var element; nicholas@210: if (event.srcElement.nodeName == "SPAN") { nicholas@210: element = event.srcElement.parentNode; nicholas@210: } else { nicholas@210: element = event.srcElement; nicholas@210: } nicholas@210: var id = Number(element.attributes['trackIndex'].value); n@183: //audioEngineContext.metric.sliderPlayed(id); n@202: audioEngineContext.play(id); n@183: // Currently playing track red, rest green n@183: n@183: //document.getElementById('track-slider-'+index).style.backgroundColor = "#FF0000"; n@183: $('.track-slider').removeClass('track-slider-playing'); nicholas@210: $(element).addClass('track-slider-playing'); n@183: $('.comment-div').removeClass('comment-box-playing'); n@183: $('#comment-div-'+id).addClass('comment-box-playing'); n@183: } n@183: }; n@183: n@183: this.exportXMLDOM = function() { n@183: // Called by the audioObject holding this element. Must be present n@183: var node = document.createElement('value'); n@183: node.textContent = convSliderPosToRate(this.trackSliderObj); n@183: return node; n@183: }; n@183: } nicholas@119: nicholas@5: function dragEnd(ev) { nicholas@5: // Function call when a div has been dropped n@33: var slider = document.getElementById('slider'); n@127: var marginSize = Number(slider.attributes['marginsize'].value); n@51: var w = slider.style.width; n@51: w = Number(w.substr(0,w.length-2)); nicholas@133: var x = ev.x; n@127: if (x >= marginSize && x < w+marginSize) { n@51: this.style.left = (x)+'px'; nicholas@5: } else { n@127: if (x