# HG changeset patch # User Nicholas Jillings # Date 1494337967 -3600 # Node ID 0228ab1777d9c3a6f0feab0ac90588c5962ee19b # Parent 6fe4ab566afabb92ccde927f719edc2e452393a7# Parent 25027b8665a205cf1946dedc1db6b808e9d8f746 Merge branch 'master' into vnext diff -r 6fe4ab566afa -r 0228ab1777d9 js/core.js --- 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() { diff -r 6fe4ab566afa -r 0228ab1777d9 js/specification.js --- 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; diff -r 6fe4ab566afa -r 0228ab1777d9 xml/test-schema.xsd --- 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 @@ + + + @@ -67,6 +70,8 @@ + + @@ -107,6 +112,8 @@ + + @@ -238,6 +245,8 @@ + +