changeset 3012:3342bc1f3256

Merge branch 'master' into vnext # Conflicts: # js/core.js
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Wed, 06 Sep 2017 14:50:00 +0100
parents f57581f20068 (current diff) 151fae569ce9 (diff)
children 5acdaf4c14c3 cae294cb0242
files js/core.js
diffstat 5 files changed, 55 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/css/core.css	Thu Aug 03 14:51:01 2017 +0200
+++ b/css/core.css	Wed Sep 06 14:50:00 2017 +0100
@@ -88,14 +88,14 @@
     border-style: solid;
     background-color: #fff;
 }
-div.popup-option-checbox {
+div.popup-option-checkbox {
     /* Popup window checkbox */
     padding: 5px;
     width: fit-content;
     width: -moz-fit-content;
     width: -webkit-fit-content;
 }
-div.popup-option-checbox input {
+div.popup-option-checkbox input {
     /* Popup window checkbox */
     margin-right: 15px;
 }
--- a/js/core.js	Thu Aug 03 14:51:01 2017 +0200
+++ b/js/core.js	Wed Sep 06 14:50:00 2017 +0100
@@ -677,9 +677,10 @@
         var table = document.createElement("table");
         table.className = "popup-option-list";
         table.border = "0";
+        var nodelist = [];
         node.specification.options.forEach(function (option, index) {
             var tr = document.createElement("tr");
-            table.appendChild(tr);
+            nodelist.push(tr);
             var td = document.createElement("td");
             tr.appendChild(td);
             var input = document.createElement('input');
@@ -695,20 +696,37 @@
             tr = document.createElement('div');
             tr.setAttribute('name', 'option');
             tr.className = "popup-option-checbox";
-            if (node.response[index] !== undefined) {
-                if (node.response[index].checked === true) {
+            var resp = undefined;
+            if (node.response.length > 0) {
+                resp = node.response.find(function (a) {
+                    return a.name == option.name;
+                });
+            }
+            if (resp !== undefined) {
+                if (resp.checked === true) {
                     input.checked = "true";
                 }
+            } else {
+                node.response.push({
+                    "name": option.name,
+                    "text": option.text,
+                    "checked": false
+                });
             }
             index++;
         });
+        if (node.specification.randomise) {
+            nodelist = randomiseOrder(nodelist);
+        }
+        nodelist.forEach(function (e) {
+            table.appendChild(e);
+        });
         this.popupResponse.appendChild(table);
     }
 
     function processCheckbox(node) {
         console.log("Checkbox: " + node.specification.statement);
         var inputs = this.popupResponse.getElementsByTagName('input');
-        node.response = [];
         var numChecked = 0,
             i;
         for (i = 0; i < node.specification.options.length; i++) {
@@ -738,10 +756,9 @@
             }
         }
         for (i = 0; i < node.specification.options.length; i++) {
-            node.response.push({
-                name: node.specification.options[i].name,
-                text: node.specification.options[i].text,
-                checked: inputs[i].checked
+            node.response.forEach(function (a) {
+                var input = this.popupResponse.querySelector("#" + a.name);
+                a.checked = input.checked;
             });
             console.log(node.specification.options[i].name + ": " + inputs[i].checked);
         }
@@ -781,12 +798,10 @@
         var table = document.createElement("table");
         table.className = "popup-option-list";
         table.border = "0";
-        if (node.response === null || node.response.length === 0) {
-            node.response = [];
-        }
+        var nodelist = [];
         node.specification.options.forEach(function (option, index) {
             var tr = document.createElement("tr");
-            table.appendChild(tr);
+            nodelist.push(tr);
             var td = document.createElement("td");
             tr.appendChild(td);
             var input = document.createElement('input');
@@ -802,8 +817,16 @@
             td.appendChild(span);
             tr = document.createElement('div');
             tr.setAttribute('name', 'option');
-            tr.className = "popup-option-checbox";
-            table.appendChild(tr);
+            tr.className = "popup-option-checkbox";
+            if (node.response.name === option.name) {
+                input.checked = true;
+            }
+        });
+        if (node.specification.randomise) {
+            nodelist = randomiseOrder(nodelist);
+        }
+        nodelist.forEach(function (e) {
+            table.appendChild(e);
         });
         this.popupResponse.appendChild(table);
     }
@@ -1968,13 +1991,15 @@
                 // Safari does not like using 'this' to reference the calling object!
                 //event.currentTarget.owner.metric.stopListening(audioEngineContext.timer.getTestTime(),event.currentTarget.owner.getCurrentPosition());
                 if (event.currentTarget !== null) {
-                    event.currentTarget.owner.stop(audioContext.currentTime + 1);
+                    event.currentTarget.owner.stop(audioContext.currentTime + 0.1);
                 }
             };
             this.outputGain.gain.cancelScheduledValues(audioContext.currentTime);
             if (!audioEngineContext.loopPlayback || !audioEngineContext.synchPlayback) {
                 this.metric.startListening(audioEngineContext.timer.getTestTime());
-                this.outputGain.gain.linearRampToValueAtTime(this.onplayGain, startTime + specification.crossFade);
+                if (this.outputGain.gain.value !== this.onplayGain) {
+                    this.outputGain.gain.linearRampToValueAtTime(this.onplayGain, startTime + Number(specification.crossFade));
+                }
                 this.interfaceDOM.startPlayback();
             } else {
                 this.outputGain.gain.linearRampToValueAtTime(0.0, startTime);
--- a/js/loudness.js	Thu Aug 03 14:51:01 2017 +0200
+++ b/js/loudness.js	Wed Sep 06 14:50:00 2017 +0100
@@ -31,7 +31,7 @@
         target = -23;
     }
     if (offlineContext === undefined) {
-        offlineContext = new OfflineAudioContext(audioContext.destination.channelCount, buffer.buffer.duration * audioContext.sampleRate, audioContext.sampleRate);
+        offlineContext = new OfflineAudioContext(audioContext.destination.channelCount, Math.max(0.4, buffer.buffer.duration) * audioContext.sampleRate, audioContext.sampleRate);
     }
     // Create the required filters
     var KFilter = offlineContext.createBiquadFilter();
@@ -80,7 +80,7 @@
     var frame_size = Math.floor(buffer.sampleRate * frame_dur);
     var step_size = Math.floor(frame_size * (1.0 - frame_overlap));
     var num_frames = Math.floor((buffer.length - frame_size) / step_size);
-    num_frames = Math.max(num_frames, 0);
+    num_frames = Math.max(num_frames, 1);
 
     var MS = Array(buffer.numberOfChannels);
     for (var c = 0; c < buffer.numberOfChannels; c++) {
--- a/tests/examples/APE_example.xml	Thu Aug 03 14:51:01 2017 +0200
+++ b/tests/examples/APE_example.xml	Wed Sep 06 14:50:00 2017 +0100
@@ -2,24 +2,24 @@
     <waet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test-schema.xsd">
         <setup interface="APE" projectReturn="save.php" randomiseOrder='true' poolSize="2" loudness="-23" calibration="true">
             <survey location="before">
-                <surveyentry type="question" id="sessionId" mandatory="true">
+                <surveyquestion id="sessionId" mandatory="true">
                     <statement>Please enter your name.</statement>
                     <conditional check="equals" value="John" jumpToOnPass="test-intro" jumpToOnFail="checkboxtest" />
-                </surveyentry>
-                <surveyentry type="checkbox" id="checkboxtest" mandatory="true" min="2" max="4">
+                </surveyquestion>
+                <surveycheckbox id="checkboxtest" mandatory="true" min="2" max="4" randomise="true">
                     <statement>Please select with which activities you have any experience (example checkbox question)</statement>
                     <option name="musician">Playing a musical instrument</option>
                     <option name="soundengineer">Recording or mixing audio</option>
                     <option name="developer">Developing audio software</option>
                     <option name="hwdesigner">Designing or building audio hardware</option>
                     <option name="researcher">Research in the field of audio</option>
-                </surveyentry>
-                <surveyentry type="question" id="instrument" mandatory="false">
+                </surveycheckbox>
+                <surveyquestion id="instrument" mandatory="false">
                     <statement>What instrument did you play</statement>
-                </surveyentry>
-                <surveyentry type="statement" id="test-intro">
+                </surveyquestion>
+                <surveystatement id="test-intro">
                     <statement>This is an example of an 'APE'-style test, with two pages, using the test stimuli in 'example_eval/'.</statement>
-                </surveyentry>
+                </surveystatement>
             </survey>
             <survey location="after">
                 <surveyentry type="question" id="location" mandatory="true" boxsize="large">
--- a/xml/test-schema.xsd	Thu Aug 03 14:51:01 2017 +0200
+++ b/xml/test-schema.xsd	Wed Sep 06 14:50:00 2017 +0100
@@ -386,6 +386,7 @@
                 <xs:attribute ref="mandatory" />
                 <xs:attribute name="min" type="xs:decimal" />
                 <xs:attribute name="max" type="xs:decimal" />
+                <xs:attribute name="randomise" type="xs:boolean" default="false" />
                 <xs:attribute ref="minWait" />
             </xs:complexType>
         </xs:element>
@@ -411,6 +412,7 @@
                 <xs:attribute ref="minWait" />
                 <xs:attribute name="min" type="xs:decimal" />
                 <xs:attribute name="max" type="xs:decimal" />
+                <xs:attribute name="randomise" type="xs:boolean" default="false" />
             </xs:complexType>
         </xs:element>