Mercurial > hg > webaudioevaluationtool
diff js/core.js @ 2823:25027b8665a2
Implementation for #209
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Tue, 09 May 2017 14:52:00 +0100 |
parents | 6b38dc641812 |
children | 28a5504db337 0228ab1777d9 |
line wrap: on
line diff
--- a/js/core.js Tue May 09 13:21:34 2017 +0100 +++ b/js/core.js Tue May 09 14:52:00 2017 +0100 @@ -1717,6 +1717,11 @@ if (typeof id !== "number" || id < 0 || id > this.audioObjects.length) { throw ('FATAL - Passed id was undefined - AudioEngineContext.play(id)'); } + var maxPlays = this.audioObjects[id].specification.maxNumberPlays || this.audioObjects[id].specification.parent.maxNumberPlays || specification.maxNumberPlays; + if (maxPlays !== undefined && this.audioObjects[id].numberOfPlays >= maxPlays) { + interfaceContext.lightbox.post("Error", "Cannot play this fragment more than " + maxPlays + " times"); + return; + } if (this.status === 1) { this.timer.startTest(); interfaceContext.playhead.setTimePerPixel(this.audioObjects[id]); @@ -1850,6 +1855,8 @@ function audioObject(id) { // The main buffer object with common control nodes to the AudioEngine + var playCounter = 0; + this.specification = undefined; this.id = id; this.state = 0; // 0 - no data, 1 - ready @@ -1946,6 +1953,7 @@ this.play = function (startTime) { if (this.bufferNode === undefined && this.buffer.buffer !== undefined) { + playCounter++; this.bufferNode = audioContext.createBufferSource(); this.bufferNode.owner = this; this.bufferNode.connect(this.outputGain); @@ -2025,6 +2033,17 @@ } this.metric.exportXMLDOM(this.storeDOM.getElementsByTagName('metric')[0]); }; + + Object.defineProperties(this, { + "numberOfPlays": { + 'get': function () { + return playCounter; + }, + 'set': function () { + return playCounter; + } + } + }); } function timer() {