Mercurial > hg > webaudioevaluationtool
diff js/core.js @ 2909:e2b241c88b74
ITU-R BS.1116 compliant template
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Tue, 01 Aug 2017 10:09:26 +0100 |
parents | 033027759cf7 |
children | fc41c3d909b7 |
line wrap: on
line diff
--- a/js/core.js Tue Aug 01 09:13:57 2017 +0100 +++ b/js/core.js Tue Aug 01 10:09:26 2017 +0100 @@ -1216,6 +1216,39 @@ this.currentStore = null; this.initialise = function () { + function randomiseElements(page) { + // Get the elements which are fixed / labelled + var fixed = [], + or = [], + remainder = []; + page.audioElements.forEach(function (a) { + if (a.label.length > 0 || a.postion !== undefined) { + fixed.push(a); + } else if (a.type === "outside-reference") { + or.push(a); + } else { + remainder.push(a); + } + }) + if (page.poolSize > 0 || page.randomiseOrder) { + page.randomiseOrder = true; + if (page.poolSize === 0) { + page.poolSize = page.audioElements.length; + } + page.poolSize -= fixed.length; + remainder = pickSubPool(remainder, page.poolSize); + } + // Randomise the remainders + if (page.randomiseOrder) { + remainder = randomiseOrder(remainder); + } + fixed = fixed.concat(remainder); + page.audioElements = fixed.concat(or); + page.audioElements.forEach(function (a, i) { + a.position = i; + }); + } + // Get the data from Specification var pagePool = []; specification.pages.forEach(function (page) { @@ -1253,17 +1286,7 @@ page.presentedId = i; this.stateMap.push(page); var elements = page.audioElements; - if (page.poolSize > 0 || page.randomiseOrder) { - page.randomiseOrder = true; - if (page.poolSize === 0) { - page.poolSize = elements.length; - } - elements = pickSubPool(elements, page.poolSize); - } - if (page.randomiseOrder) { - elements = randomiseOrder(elements); - } - page.audioElements = elements; + randomiseElements(page); storage.createTestPageStore(page); audioEngineContext.loadPageData(page); }, this); @@ -1325,23 +1348,6 @@ popup.hidePopup(); if (this.currentStateMap === null) { this.currentStateMap = this.stateMap[this.stateIndex]; - // Find and extract the outside reference - var elements = [], - ref = []; - var elem = this.currentStateMap.audioElements.pop(); - while (elem) { - if (elem.type == "outside-reference") { - ref.push(elem); - } else { - elements.push(elem); - } - elem = this.currentStateMap.audioElements.pop(); - } - elements = elements.reverse(); - if (this.currentStateMap.randomiseOrder) { - elements = randomiseOrder(elements); - } - this.currentStateMap.audioElements = elements.concat(ref); this.currentStore = storage.testPages[this.stateIndex]; if (this.currentStateMap.preTest !== undefined) {