Mercurial > hg > webaudioevaluationtool
changeset 895:e2e39f867db3
Removed selected track. audioEngineContext.play(id) now controls audioObject playbacks
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Thu, 11 Jun 2015 09:38:09 +0100 |
parents | 1af8a548cab2 |
children | ce1f952a36f3 |
files | ape.js core.js example_eval/project.xml |
diffstat | 3 files changed, 44 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/ape.js Wed Jun 10 16:12:46 2015 +0100 +++ b/ape.js Thu Jun 11 09:38:09 2015 +0100 @@ -227,30 +227,9 @@ audioEngineContext.loopPlayback = loopPlayback; // Create AudioEngine bindings for playback - if (loopPlayback) { - audioEngineContext.selectedTrack = function(id) { - for (var i=0; i<this.audioObjects.length; i++) - { - if (id == i) { - this.audioObjects[i].loopStart(); - } else { - this.audioObjects[i].loopStop(); - } - } - }; - } else { - audioEngineContext.selectedTrack = function(id) { - for (var i=0; i<this.audioObjects.length; i++) - { - this.audioObjects[i].outputGain.gain.value = 0.0; - this.audioObjects[i].stop(); - } - if (this.status == 1) { - this.audioObjects[id].outputGain.gain.value = 1.0; - this.audioObjects[id].play(audioContext.currentTime+0.01); - } - }; - } + audioEngineContext.selectedTrack = function(id) { + console.log('Deprecated'); + }; currentTestHolder = document.createElement('audioHolder'); currentTestHolder.id = audioHolderObject.id; @@ -327,7 +306,7 @@ // Get the track ID from the object ID var id = Number(event.srcElement.attributes['trackIndex'].value); //audioEngineContext.metric.sliderPlayed(id); - audioEngineContext.selectedTrack(id); + audioEngineContext.play(id); // Currently playing track red, rest green //document.getElementById('track-slider-'+index).style.backgroundColor = "#FF0000";
--- a/core.js Wed Jun 10 16:12:46 2015 +0100 +++ b/core.js Thu Jun 11 09:38:09 2015 +0100 @@ -675,7 +675,7 @@ // Create store for new audioObjects this.audioObjects = []; - this.play = function() { + this.play = function(id) { // Start the timer and set the audioEngine state to playing (1) if (this.status == 0) { // Check if all audioObjects are ready @@ -684,12 +684,32 @@ } if (this.audioObjectsReady == true) { this.timer.startTest(); - if (this.loopPlayback) { - for(var i=0; i<this.audioObjects.length; i++) { - this.audioObjects[i].play(this.timer.getTestTime()+1); + this.status = 1; + } + } + if (this.status== 1) { + if (id == undefined) {id = -1;} + if (this.loopPlayback) { + for (var i=0; i<this.audioObjects.length; i++) + { + this.audioObjects[i].play(this.timer.getTestTime()+1); + if (id == i) { + this.audioObjects[i].loopStart(); + } else { + this.audioObjects[i].loopStop(); } } - this.status = 1; + } else { + for (var i=0; i<this.audioObjects.length; i++) + { + if (i != id) { + this.audioObjects[i].outputGain.gain.value = 0.0; + this.audioObjects[i].stop(); + } else if (i == id) { + this.audioObjects[id].outputGain.gain.value = 1.0; + this.audioObjects[id].play(audioContext.currentTime+0.01); + } + } } } }; @@ -705,7 +725,6 @@ } }; - this.newTrack = function(element) { // Pull data from given URL into new audio buffer // URLs must either be from the same source OR be setup to 'Access-Control-Allow-Origin' @@ -791,19 +810,21 @@ }; this.play = function(startTime) { - this.bufferNode = audioContext.createBufferSource(); - this.bufferNode.owner = this; - this.bufferNode.connect(this.outputGain); - this.bufferNode.buffer = this.buffer; - this.bufferNode.loop = audioEngineContext.loopPlayback; - this.bufferNode.onended = function() { - // Safari does not like using 'this' to reference the calling object! - event.srcElement.owner.metric.stopListening(audioEngineContext.timer.getTestTime()); - }; - if (this.bufferNode.loop == false) { - this.metric.startListening(audioEngineContext.timer.getTestTime()); + if (this.bufferNode == undefined) { + this.bufferNode = audioContext.createBufferSource(); + this.bufferNode.owner = this; + this.bufferNode.connect(this.outputGain); + this.bufferNode.buffer = this.buffer; + this.bufferNode.loop = audioEngineContext.loopPlayback; + this.bufferNode.onended = function() { + // Safari does not like using 'this' to reference the calling object! + event.srcElement.owner.metric.stopListening(audioEngineContext.timer.getTestTime()); + }; + if (this.bufferNode.loop == false) { + this.metric.startListening(audioEngineContext.timer.getTestTime()); + } + this.bufferNode.start(startTime); } - this.bufferNode.start(startTime); }; this.stop = function() {
--- a/example_eval/project.xml Wed Jun 10 16:12:46 2015 +0100 +++ b/example_eval/project.xml Thu Jun 11 09:38:09 2015 +0100 @@ -35,7 +35,7 @@ <metricEnable>elementListenTracker</metricEnable> </Metric> </setup> - <audioHolder id='0' hostURL="example_eval/" sampleRate="44100" randomiseOrder='true' repeatCount='0' loop='true' elementComments='true'> + <audioHolder id='0' hostURL="example_eval/" sampleRate="44100" randomiseOrder='true' repeatCount='0' loop='false' elementComments='true'> <interface> <title>Example Test Question</title> <scale position="0">Min</scale>