changeset 2823:25027b8665a2

Implementation for #209
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Tue, 09 May 2017 14:52:00 +0100
parents 394b5e20d78f
children 8451aaf83c43 64a5603831e2 0228ab1777d9
files js/core.js xml/test-schema.xsd
diffstat 2 files changed, 26 insertions(+), 7 deletions(-) [+]
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() {
--- a/xml/test-schema.xsd	Tue May 09 13:21:34 2017 +0100
+++ b/xml/test-schema.xsd	Tue May 09 14:52:00 2017 +0100
@@ -28,7 +28,7 @@
         </xs:attribute>
 
         <xs:attribute name="minNumberPlays" type="xs:nonNegativeInteger" default="0" />
-        <xs:attribute name="maxNumberPlays" type="xs:nonNegativeInteger" use="optional" />
+        <xs:attribute name="maxNumberPlays" type="xs:nonNegativeInteger" />
 
         <xs:attribute name="playOne" type="xs:boolean" default="false" />
 
@@ -70,8 +70,8 @@
                 <xs:attribute ref="preSilence" />
                 <xs:attribute ref="postSilence" />
                 <xs:attribute ref="playOne" />
-                <xs:attribute ref="minNumberPlays" />
-                <xs:attribute ref="maxNumberPlays" />
+                <xs:attribute ref="minNumberPlays" use="optional" />
+                <xs:attribute ref="maxNumberPlays" use="optional" />
             </xs:complexType>
         </xs:element>
 
@@ -112,8 +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" />
-                <xs:attribute ref="maxNumberPlays" />
+                <xs:attribute ref="minNumberPlays" use="optional" />
+                <xs:attribute ref="maxNumberPlays" use="optional" />
             </xs:complexType>
         </xs:element>
 
@@ -245,8 +245,8 @@
                     </xs:simpleType>
                 </xs:attribute>
                 <xs:attribute name="image" type="xs:anyURI" use="optional" />
-                <xs:attribute ref="minNumberPlays" />
-                <xs:attribute ref="maxNumberPlays" />
+                <xs:attribute ref="minNumberPlays" use="optional" />
+                <xs:attribute ref="maxNumberPlays" use="optional" />
             </xs:complexType>
         </xs:element>