comparison test_create/test_create.html @ 401:17a2b99622c0 Dev_main

Synced Specification object. Test create decodes and encodes gain attributes (not implemented in HTML yet)
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Fri, 11 Dec 2015 18:03:54 +0000
parents 42cf69a134aa
children db353cc479b8
comparison
equal deleted inserted replaced
400:3fb85ae8fced 401:17a2b99622c0
1750 node.decode(this,audioHolders[i]); 1750 node.decode(this,audioHolders[i]);
1751 this.audioHolders.push(node); 1751 this.audioHolders.push(node);
1752 } 1752 }
1753 1753
1754 // New check if we need to randomise the test order 1754 // New check if we need to randomise the test order
1755 if (this.randomiseOrder) 1755 if (this.randomiseOrder && typeof randomiseOrder === "function")
1756 { 1756 {
1757 this.audioHolders = randomiseOrder(this.audioHolders); 1757 this.audioHolders = randomiseOrder(this.audioHolders);
1758 for (var i=0; i<this.audioHolders.length; i++) 1758 for (var i=0; i<this.audioHolders.length; i++)
1759 { 1759 {
1760 this.audioHolders[i].presentedId = i; 1760 this.audioHolders[i].presentedId = i;
2055 } else { 2055 } else {
2056 this.audioElements.push(node); 2056 this.audioElements.push(node);
2057 } 2057 }
2058 } 2058 }
2059 2059
2060 if (this.randomiseOrder == true) 2060 if (this.randomiseOrder == true && typeof randomiseOrder === "function")
2061 { 2061 {
2062 this.audioElements = randomiseOrder(this.audioElements); 2062 this.audioElements = randomiseOrder(this.audioElements);
2063 } 2063 }
2064 2064
2065 var commentQuestionsDOM = xml.getElementsByTagName('CommentQuestion'); 2065 var commentQuestionsDOM = xml.getElementsByTagName('CommentQuestion');
2114 2114
2115 this.interfaceNode = function() { 2115 this.interfaceNode = function() {
2116 this.title = undefined; 2116 this.title = undefined;
2117 this.options = []; 2117 this.options = [];
2118 this.scale = []; 2118 this.scale = [];
2119 this.name = undefined;
2119 this.decode = function(DOM) 2120 this.decode = function(DOM)
2120 { 2121 {
2121 var title = DOM.getElementsByTagName('title'); 2122 var title = DOM.getElementsByTagName('title');
2122 if (title.length == 0) {this.title = null;} 2123 if (title.length == 0) {this.title = null;}
2123 else {this.title = title[0].textContent;} 2124 else {this.title = title[0].textContent;}
2125 var name = DOM.getAttribute("name");
2126 if (name != undefined) {this.name = name;}
2124 this.options = parent.commonInterface.options; 2127 this.options = parent.commonInterface.options;
2125 var scale = DOM.getElementsByTagName('scale'); 2128 var scale = DOM.getElementsByTagName('scale');
2126 this.scale = []; 2129 this.scale = [];
2127 for (var i=0; i<scale.length; i++) { 2130 for (var i=0; i<scale.length; i++) {
2128 var arr = [null, null]; 2131 var arr = [null, null];
2169 this.id = null; 2172 this.id = null;
2170 this.parent = null; 2173 this.parent = null;
2171 this.type = "normal"; 2174 this.type = "normal";
2172 this.marker = false; 2175 this.marker = false;
2173 this.enforce = false; 2176 this.enforce = false;
2177 this.gain = 1.0;
2174 this.decode = function(parent,xml) 2178 this.decode = function(parent,xml)
2175 { 2179 {
2176 this.url = xml.getAttribute('url'); 2180 this.url = xml.getAttribute('url');
2177 this.id = xml.id; 2181 this.id = xml.id;
2178 this.parent = parent; 2182 this.parent = parent;
2179 this.type = xml.getAttribute('type'); 2183 this.type = xml.getAttribute('type');
2184 var gain = xml.getAttribute('gain');
2185 if (isNaN(gain) == false && gain != null)
2186 {
2187 this.gain = decibelToLinear(Number(gain));
2188 }
2180 if (this.type == null) {this.type = "normal";} 2189 if (this.type == null) {this.type = "normal";}
2181 if (this.type == 'anchor') {this.anchor = true;} 2190 if (this.type == 'anchor') {this.anchor = true;}
2182 else {this.anchor = false;} 2191 else {this.anchor = false;}
2183 if (this.type == 'reference') {this.reference = true;} 2192 if (this.type == 'reference') {this.reference = true;}
2184 else {this.reference = false;} 2193 else {this.reference = false;}
2185
2186 if (this.anchor == true || this.reference == true) 2194 if (this.anchor == true || this.reference == true)
2187 { 2195 {
2188 this.marker = xml.getAttribute('marker'); 2196 this.marker = xml.getAttribute('marker');
2189 if (this.marker != undefined) 2197 if (this.marker != undefined)
2190 { 2198 {
2212 { 2220 {
2213 var AENode = root.createElement("audioElements"); 2221 var AENode = root.createElement("audioElements");
2214 AENode.id = this.id; 2222 AENode.id = this.id;
2215 AENode.setAttribute("url",this.url); 2223 AENode.setAttribute("url",this.url);
2216 AENode.setAttribute("type",this.type); 2224 AENode.setAttribute("type",this.type);
2225 AENode.setAttribute("gain",linearToDecibel(this.gain));
2217 if (this.marker != false) 2226 if (this.marker != false)
2218 { 2227 {
2219 AENode.setAttribute("marker",this.marker*100); 2228 AENode.setAttribute("marker",this.marker*100);
2220 } 2229 }
2221 return AENode; 2230 return AENode;
2313 break; 2322 break;
2314 } 2323 }
2315 }; 2324 };
2316 }; 2325 };
2317 }; 2326 };
2327 }
2328
2329 function linearToDecibel(gain)
2330 {
2331 return 20.0*Math.log10(gain);
2332 }
2333
2334 function decibelToLinear(gain)
2335 {
2336 return Math.pow(10,gain/20.0);
2318 } 2337 }
2319 2338
2320 function createDeleteNodeButton(node) 2339 function createDeleteNodeButton(node)
2321 { 2340 {
2322 var button = document.createElement("button"); 2341 var button = document.createElement("button");