Mercurial > hg > webaudioevaluationtool
changeset 2870:0228ab1777d9
Merge branch 'master' into vnext
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Tue, 09 May 2017 14:52:47 +0100 |
parents | 6fe4ab566afa (current diff) 25027b8665a2 (diff) |
children | 0981212c091f 97a52e326464 |
files | js/core.js |
diffstat | 3 files changed, 34 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/js/core.js Fri May 05 09:35:44 2017 +0100 +++ b/js/core.js Tue May 09 14:52:47 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() {
--- a/js/specification.js Fri May 05 09:35:44 2017 +0100 +++ b/js/specification.js Tue May 09 14:52:47 2017 +0100 @@ -17,6 +17,8 @@ this.preSilence = undefined; this.postSilence = undefined; this.playOne = undefined; + this.minNumberPlays = undefined; + this.maxNumberPlays = undefined; // nodes this.metrics = undefined; @@ -548,6 +550,8 @@ this.restrictMovement = undefined; this.position = undefined; this.commentBoxPrefix = "Comment on track"; + this.minNumberPlays = undefined; + this.maxNumberPlays = undefined; this.audioElements = []; this.commentQuestions = []; this.schema = schemaRoot.getAllElementsByName("page")[0]; @@ -809,6 +813,8 @@ this.stopTime = undefined; this.sampleRate = undefined; this.image = undefined; + this.minNumberPlays = undefined; + this.maxNumberPlays = undefined; this.alternatives = []; this.schema = schemaRoot.getAllElementsByName('audioelement')[0]; this.parent = undefined;
--- a/xml/test-schema.xsd Fri May 05 09:35:44 2017 +0100 +++ b/xml/test-schema.xsd Tue May 09 14:52:47 2017 +0100 @@ -27,6 +27,9 @@ </xs:simpleType> </xs:attribute> + <xs:attribute name="minNumberPlays" type="xs:nonNegativeInteger" default="0" /> + <xs:attribute name="maxNumberPlays" type="xs:nonNegativeInteger" /> + <xs:attribute name="playOne" type="xs:boolean" default="false" /> <xs:attribute name="minWait" type="xs:nonNegativeInteger" default="0" /> @@ -67,6 +70,8 @@ <xs:attribute ref="preSilence" /> <xs:attribute ref="postSilence" /> <xs:attribute ref="playOne" /> + <xs:attribute ref="minNumberPlays" use="optional" /> + <xs:attribute ref="maxNumberPlays" use="optional" /> </xs:complexType> </xs:element> @@ -107,6 +112,8 @@ <xs:attribute ref="postSilence" /> <xs:attribute ref="playOne" /> <xs:attribute name="restrictMovement" type="xs:boolean" default="false" use="optional" /> + <xs:attribute ref="minNumberPlays" use="optional" /> + <xs:attribute ref="maxNumberPlays" use="optional" /> </xs:complexType> </xs:element> @@ -238,6 +245,8 @@ </xs:simpleType> </xs:attribute> <xs:attribute name="image" type="xs:anyURI" use="optional" /> + <xs:attribute ref="minNumberPlays" use="optional" /> + <xs:attribute ref="maxNumberPlays" use="optional" /> </xs:complexType> </xs:element>