n@1170
|
1 <html>
|
n@1170
|
2 <head>
|
n@1170
|
3 <!-- This defines the test creator tool for the Web Audio Evaluation Toolbox -->
|
n@1170
|
4 <link rel='stylesheet' type="text/css" href="style.css"/>
|
n@1170
|
5 <script type="text/javascript">
|
n@1170
|
6 // Copy of Specifiation node from Core.js
|
n@1170
|
7 function Specification() {
|
n@1170
|
8 // Handles the decoding of the project specification XML into a simple JavaScript Object.
|
n@1170
|
9
|
n@1170
|
10 this.interface = null;
|
n@1170
|
11 this.projectReturn = null;
|
n@1170
|
12 this.randomiseOrder = null;
|
n@1170
|
13 this.testPages = null;
|
n@1170
|
14 this.pages = [];
|
n@1170
|
15 this.metrics = null;
|
n@1170
|
16 this.interfaces = null;
|
n@1170
|
17 this.loudness = null;
|
n@1170
|
18 this.errors = [];
|
n@1170
|
19 this.schema = null;
|
n@1170
|
20
|
n@1170
|
21 this.randomiseOrder = function(input)
|
n@1170
|
22 {
|
n@1170
|
23 // This takes an array of information and randomises the order
|
n@1170
|
24 var N = input.length;
|
n@1170
|
25
|
n@1170
|
26 var inputSequence = []; // For safety purposes: keep track of randomisation
|
n@1170
|
27 for (var counter = 0; counter < N; ++counter)
|
n@1170
|
28 inputSequence.push(counter) // Fill array
|
n@1170
|
29 var inputSequenceClone = inputSequence.slice(0);
|
n@1170
|
30
|
n@1170
|
31 var holdArr = [];
|
n@1170
|
32 var outputSequence = [];
|
n@1170
|
33 for (var n=0; n<N; n++)
|
n@1170
|
34 {
|
n@1170
|
35 // First pick a random number
|
n@1170
|
36 var r = Math.random();
|
n@1170
|
37 // Multiply and floor by the number of elements left
|
n@1170
|
38 r = Math.floor(r*input.length);
|
n@1170
|
39 // Pick out that element and delete from the array
|
n@1170
|
40 holdArr.push(input.splice(r,1)[0]);
|
n@1170
|
41 // Do the same with sequence
|
n@1170
|
42 outputSequence.push(inputSequence.splice(r,1)[0]);
|
n@1170
|
43 }
|
n@1170
|
44 console.log(inputSequenceClone.toString()); // print original array to console
|
n@1170
|
45 console.log(outputSequence.toString()); // print randomised array to console
|
n@1170
|
46 return holdArr;
|
n@1170
|
47 };
|
n@1170
|
48
|
n@1170
|
49 this.processAttribute = function(attribute,schema)
|
n@1170
|
50 {
|
n@1170
|
51 // attribute is the string returned from getAttribute on the XML
|
n@1170
|
52 // schema is the <xs:attribute> node
|
n@1170
|
53 if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined)
|
n@1170
|
54 {
|
n@1170
|
55 schema = this.schema.getAllElementsByName(schema.getAttribute('ref'))[0];
|
n@1170
|
56 }
|
n@1170
|
57 var defaultOpt = schema.getAttribute('default');
|
n@1170
|
58 if (attribute == null) {
|
n@1170
|
59 attribute = defaultOpt;
|
n@1170
|
60 }
|
n@1170
|
61 var dataType = schema.getAttribute('type');
|
n@1170
|
62 if (typeof dataType == "string") { dataType = dataType.substr(3);}
|
n@1170
|
63 else {dataType = "string";}
|
n@1170
|
64 if (attribute == null)
|
n@1170
|
65 {
|
n@1170
|
66 return attribute;
|
n@1170
|
67 }
|
n@1170
|
68 switch(dataType)
|
n@1170
|
69 {
|
n@1170
|
70 case "boolean":
|
n@1170
|
71 if (attribute == 'true'){attribute = true;}else{attribute=false;}
|
n@1170
|
72 break;
|
n@1170
|
73 case "negativeInteger":
|
n@1170
|
74 case "positiveInteger":
|
n@1170
|
75 case "nonNegativeInteger":
|
n@1170
|
76 case "nonPositiveInteger":
|
n@1170
|
77 case "integer":
|
n@1170
|
78 case "decimal":
|
n@1170
|
79 case "short":
|
n@1170
|
80 attribute = Number(attribute);
|
n@1170
|
81 break;
|
n@1170
|
82 case "string":
|
n@1170
|
83 default:
|
n@1170
|
84 attribute = String(attribute);
|
n@1170
|
85 break;
|
n@1170
|
86 }
|
n@1170
|
87 return attribute;
|
n@1170
|
88 };
|
n@1170
|
89
|
n@1170
|
90 this.decode = function(projectXML) {
|
n@1170
|
91 this.errors = [];
|
n@1170
|
92 // projectXML - DOM Parsed document
|
n@1170
|
93 this.projectXML = projectXML.childNodes[0];
|
n@1170
|
94 var setupNode = projectXML.getElementsByTagName('setup')[0];
|
n@1170
|
95 var schemaSetup = this.schema.getAllElementsByName('setup')[0];
|
n@1170
|
96 // First decode the attributes
|
n@1170
|
97 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute');
|
n@1170
|
98 for (var i in attributes)
|
n@1170
|
99 {
|
n@1170
|
100 if (isNaN(Number(i)) == true){break;}
|
n@1170
|
101 var attributeName = attributes[i].getAttribute('name');
|
n@1170
|
102 var projectAttr = setupNode.getAttribute(attributeName);
|
n@1170
|
103 projectAttr = this.processAttribute(projectAttr,attributes[i]);
|
n@1170
|
104 switch(typeof projectAttr)
|
n@1170
|
105 {
|
n@1170
|
106 case "number":
|
n@1170
|
107 case "boolean":
|
n@1170
|
108 eval('this.'+attributeName+' = '+projectAttr);
|
n@1170
|
109 break;
|
n@1170
|
110 case "string":
|
n@1170
|
111 eval('this.'+attributeName+' = "'+projectAttr+'"');
|
n@1170
|
112 break;
|
n@1170
|
113 }
|
n@1170
|
114
|
n@1170
|
115 }
|
n@1170
|
116
|
n@1170
|
117 this.metrics = new this.metricNode();
|
n@1170
|
118
|
n@1170
|
119 this.metrics.decode(this,setupNode.getElementsByTagName('metric')[0]);
|
n@1170
|
120
|
n@1170
|
121 // Now process the survey node options
|
n@1170
|
122 var survey = setupNode.getElementsByTagName('survey');
|
n@1170
|
123 for (var i in survey) {
|
n@1170
|
124 if (isNaN(Number(i)) == true){break;}
|
n@1170
|
125 var location = survey[i].getAttribute('location');
|
n@1170
|
126 if (location == 'pre' || location == 'before')
|
n@1170
|
127 {
|
n@1170
|
128 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");}
|
n@1170
|
129 else {
|
n@1170
|
130 this.preTest = new this.surveyNode();
|
n@1170
|
131 this.preTest.decode(this,survey[i]);
|
n@1170
|
132 }
|
n@1170
|
133 } else if (location == 'post' || location == 'after') {
|
n@1170
|
134 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");}
|
n@1170
|
135 else {
|
n@1170
|
136 this.postTest = new this.surveyNode();
|
n@1170
|
137 this.postTest.decode(this,survey[i]);
|
n@1170
|
138 }
|
n@1170
|
139 }
|
n@1170
|
140 }
|
n@1170
|
141
|
n@1170
|
142 var interfaceNode = setupNode.getElementsByTagName('interface');
|
n@1170
|
143 if (interfaceNode.length > 1)
|
n@1170
|
144 {
|
n@1170
|
145 this.errors.push("Only one <interface> node in the <setup> node allowed! Others except first ingnored!");
|
n@1170
|
146 }
|
n@1170
|
147 this.interfaces = new this.interfaceNode();
|
n@1170
|
148 if (interfaceNode.length != 0)
|
n@1170
|
149 {
|
n@1170
|
150 interfaceNode = interfaceNode[0];
|
n@1170
|
151 this.interfaces.decode(this,interfaceNode,this.schema.getAllElementsByName('interface')[1]);
|
n@1170
|
152 }
|
n@1170
|
153
|
n@1170
|
154 // Page tags
|
n@1170
|
155 var pageTags = projectXML.getElementsByTagName('page');
|
n@1170
|
156 var pageSchema = this.schema.getAllElementsByName('page')[0];
|
n@1170
|
157 for (var i=0; i<pageTags.length; i++)
|
n@1170
|
158 {
|
n@1170
|
159 var node = new this.page();
|
n@1170
|
160 node.decode(this,pageTags[i],pageSchema);
|
n@1170
|
161 this.pages.push(node);
|
n@1170
|
162 }
|
n@1170
|
163 };
|
n@1170
|
164
|
n@1170
|
165 this.encode = function()
|
n@1170
|
166 {
|
n@1170
|
167 var root = document.implementation.createDocument(null,"waet");
|
n@1170
|
168
|
n@1170
|
169 // Build setup node
|
n@1170
|
170
|
n@1170
|
171 return root;
|
n@1170
|
172 };
|
n@1170
|
173
|
n@1170
|
174 this.surveyNode = function() {
|
n@1170
|
175 this.location = null;
|
n@1170
|
176 this.options = [];
|
n@1170
|
177 this.schema = specification.schema.getAllElementsByName('survey')[0];
|
n@1170
|
178
|
n@1170
|
179 this.OptionNode = function() {
|
n@1170
|
180 this.type = undefined;
|
n@1170
|
181 this.schema = specification.schema.getAllElementsByName('surveyentry')[0];
|
n@1170
|
182 this.id = undefined;
|
n@1170
|
183 this.mandatory = undefined;
|
n@1170
|
184 this.statement = undefined;
|
n@1170
|
185 this.boxsize = undefined;
|
n@1170
|
186 this.options = [];
|
n@1170
|
187 this.min = undefined;
|
n@1170
|
188 this.max = undefined;
|
n@1170
|
189 this.step = undefined;
|
n@1170
|
190
|
n@1170
|
191 this.decode = function(parent,child)
|
n@1170
|
192 {
|
n@1170
|
193 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
|
n@1170
|
194 for (var i in attributeMap){
|
n@1170
|
195 if(isNaN(Number(i)) == true){break;}
|
n@1170
|
196 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
|
n@1170
|
197 var projectAttr = child.getAttribute(attributeName);
|
n@1170
|
198 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]);
|
n@1170
|
199 switch(typeof projectAttr)
|
n@1170
|
200 {
|
n@1170
|
201 case "number":
|
n@1170
|
202 case "boolean":
|
n@1170
|
203 eval('this.'+attributeName+' = '+projectAttr);
|
n@1170
|
204 break;
|
n@1170
|
205 case "string":
|
n@1170
|
206 eval('this.'+attributeName+' = "'+projectAttr+'"');
|
n@1170
|
207 break;
|
n@1170
|
208 }
|
n@1170
|
209 }
|
n@1170
|
210 this.statement = child.getElementsByTagName('statement')[0].textContent;
|
n@1170
|
211 if (this.type == "checkbox" || this.type == "radio") {
|
n@1170
|
212 var children = child.getElementsByTagName('option');
|
n@1170
|
213 if (children.length == null) {
|
n@1170
|
214 console.log('Malformed' +child.nodeName+ 'entry');
|
n@1170
|
215 this.statement = 'Malformed' +child.nodeName+ 'entry';
|
n@1170
|
216 this.type = 'statement';
|
n@1170
|
217 } else {
|
n@1170
|
218 this.options = [];
|
n@1170
|
219 for (var i in children)
|
n@1170
|
220 {
|
n@1170
|
221 if (isNaN(Number(i))==true){break;}
|
n@1170
|
222 this.options.push({
|
n@1170
|
223 name: children[i].getAttribute('name'),
|
n@1170
|
224 text: children[i].textContent
|
n@1170
|
225 });
|
n@1170
|
226 }
|
n@1170
|
227 }
|
n@1170
|
228 }
|
n@1170
|
229 };
|
n@1170
|
230
|
n@1170
|
231 this.exportXML = function(root)
|
n@1170
|
232 {
|
n@1170
|
233 var node = root.createElement('surveyelement');
|
n@1170
|
234 node.setAttribute('type',this.type);
|
n@1170
|
235 var statement = root.createElement('statement');
|
n@1170
|
236 statement.textContent = this.statement;
|
n@1170
|
237 node.appendChild(statement);
|
n@1170
|
238 switch(this.type)
|
n@1170
|
239 {
|
n@1170
|
240 case "statement":
|
n@1170
|
241 break;
|
n@1170
|
242 case "question":
|
n@1170
|
243 node.id = this.id;
|
n@1170
|
244 node.setAttribute("mandatory",this.mandatory);
|
n@1170
|
245 node.setAttribute("boxsize",this.boxsize);
|
n@1170
|
246 break;
|
n@1170
|
247 case "number":
|
n@1170
|
248 node.id = this.id;
|
n@1170
|
249 node.setAttribute("mandatory",this.mandatory);
|
n@1170
|
250 node.setAttribute("min", this.min);
|
n@1170
|
251 node.setAttribute("max", this.max);
|
n@1170
|
252 node.setAttribute("step", this.step);
|
n@1170
|
253 break;
|
n@1170
|
254 case "checkbox":
|
n@1170
|
255 case "radio":
|
n@1170
|
256 node.id = this.id;
|
n@1170
|
257 for (var i=0; i<this.options.length; i++)
|
n@1170
|
258 {
|
n@1170
|
259 var option = this.options[i];
|
n@1170
|
260 var optionNode = root.createElement("option");
|
n@1170
|
261 optionNode.setAttribute("name",option.name);
|
n@1170
|
262 optionNode.textContent = option.text;
|
n@1170
|
263 node.appendChild(optionNode);
|
n@1170
|
264 }
|
n@1170
|
265 break;
|
n@1170
|
266 }
|
n@1170
|
267 return node;
|
n@1170
|
268 };
|
n@1170
|
269 };
|
n@1170
|
270 this.decode = function(parent,xml) {
|
n@1170
|
271 this.location = xml.getAttribute('location');
|
n@1170
|
272 if (this.location == 'before'){this.location = 'pre';}
|
n@1170
|
273 else if (this.location == 'after'){this.location = 'post';}
|
n@1170
|
274 for (var i in xml.children)
|
n@1170
|
275 {
|
n@1170
|
276 if(isNaN(Number(i))==true){break;}
|
n@1170
|
277 var node = new this.OptionNode();
|
n@1170
|
278 node.decode(parent,xml.children[i]);
|
n@1170
|
279 this.options.push(node);
|
n@1170
|
280 }
|
n@1170
|
281 };
|
n@1170
|
282 this.encode = function(root) {
|
n@1170
|
283 var node = root.createElement('survey');
|
n@1170
|
284 node.setAttribute('location',this.location);
|
n@1170
|
285 for (var i=0; i<this.options.length; i++)
|
n@1170
|
286 {
|
n@1170
|
287 node.appendChild(this.options[i].exportXML());
|
n@1170
|
288 }
|
n@1170
|
289 return node;
|
n@1170
|
290 };
|
n@1170
|
291 };
|
n@1170
|
292
|
n@1170
|
293 this.interfaceNode = function()
|
n@1170
|
294 {
|
n@1170
|
295 this.title = null;
|
n@1170
|
296 this.name = null;
|
n@1170
|
297 this.options = [];
|
n@1170
|
298 this.scales = [];
|
n@1170
|
299 this.schema = specification.schema.getAllElementsByName('interface')[1];
|
n@1170
|
300
|
n@1170
|
301 this.decode = function(parent,xml) {
|
n@1170
|
302 this.name = xml.getAttribute('name');
|
n@1170
|
303 var titleNode = xml.getElementsByTagName('title');
|
n@1170
|
304 if (titleNode.length == 1)
|
n@1170
|
305 {
|
n@1170
|
306 this.title = titleNode[0].textContent;
|
n@1170
|
307 }
|
n@1170
|
308 var interfaceOptionNodes = xml.getElementsByTagName('interfaceoption');
|
n@1170
|
309 // Extract interfaceoption node schema
|
n@1170
|
310 var interfaceOptionNodeSchema = this.schema.getAllElementsByName('interfaceoption')[0];
|
n@1170
|
311 var attributeMap = interfaceOptionNodeSchema.getAllElementsByTagName('xs:attribute');
|
n@1170
|
312 for (var i=0; i<interfaceOptionNodes.length; i++)
|
n@1170
|
313 {
|
n@1170
|
314 var ioNode = interfaceOptionNodes[i];
|
n@1170
|
315 var option = {};
|
n@1170
|
316 for (var j=0; j<attributeMap.length; j++)
|
n@1170
|
317 {
|
n@1170
|
318 var attributeName = attributeMap[j].getAttribute('name') || attributeMap[j].getAttribute('ref');
|
n@1170
|
319 var projectAttr = ioNode.getAttribute(attributeName);
|
n@1170
|
320 projectAttr = parent.processAttribute(projectAttr,attributeMap[j]);
|
n@1170
|
321 switch(typeof projectAttr)
|
n@1170
|
322 {
|
n@1170
|
323 case "number":
|
n@1170
|
324 case "boolean":
|
n@1170
|
325 eval('option.'+attributeName+' = '+projectAttr);
|
n@1170
|
326 break;
|
n@1170
|
327 case "string":
|
n@1170
|
328 eval('option.'+attributeName+' = "'+projectAttr+'"');
|
n@1170
|
329 break;
|
n@1170
|
330 }
|
n@1170
|
331 }
|
n@1170
|
332 this.options.push(option);
|
n@1170
|
333 }
|
n@1170
|
334
|
n@1170
|
335 // Now the scales nodes
|
n@1170
|
336 var scaleParent = xml.getElementsByTagName('scales');
|
n@1170
|
337 if (scaleParent.length == 1) {
|
n@1170
|
338 scaleParent = scaleParent[0];
|
n@1170
|
339 for (var i=0; i<scaleParent.children.length; i++) {
|
n@1170
|
340 var child = scaleParent.children[i];
|
n@1170
|
341 this.scales.push({
|
n@1170
|
342 text: child.textContent,
|
n@1170
|
343 position: Number(child.getAttribute('position'))
|
n@1170
|
344 });
|
n@1170
|
345 }
|
n@1170
|
346 }
|
n@1170
|
347 };
|
n@1170
|
348
|
n@1170
|
349 this.encode = function(root) {
|
n@1170
|
350
|
n@1170
|
351 };
|
n@1170
|
352 };
|
n@1170
|
353
|
n@1170
|
354 this.metricNode = function() {
|
n@1170
|
355 this.enabled = [];
|
n@1170
|
356 this.decode = function(parent, xml) {
|
n@1170
|
357 var children = xml.getElementsByTagName('metricenable');
|
n@1170
|
358 for (var i in children) {
|
n@1170
|
359 if (isNaN(Number(i)) == true){break;}
|
n@1170
|
360 this.enabled.push(children[i].textContent);
|
n@1170
|
361 }
|
n@1170
|
362 }
|
n@1170
|
363 this.encode = function(root) {
|
n@1170
|
364 var node = root.createElement('metric');
|
n@1170
|
365 for (var i in this.enabled)
|
n@1170
|
366 {
|
n@1170
|
367 if (isNaN(Number(i)) == true){break;}
|
n@1170
|
368 var child = root.createElement('metricenable');
|
n@1170
|
369 child.textContent = this.enabled[i];
|
n@1170
|
370 node.appendChild(child);
|
n@1170
|
371 }
|
n@1170
|
372 return node;
|
n@1170
|
373 }
|
n@1170
|
374 }
|
n@1170
|
375
|
n@1170
|
376 this.page = function() {
|
n@1170
|
377 this.presentedId = undefined;
|
n@1170
|
378 this.id = undefined;
|
n@1170
|
379 this.hostURL = undefined;
|
n@1170
|
380 this.randomiseOrder = undefined;
|
n@1170
|
381 this.loop = undefined;
|
n@1170
|
382 this.showElementComments = undefined;
|
n@1170
|
383 this.outsideReference = null;
|
n@1170
|
384 this.loudness = null;
|
n@1170
|
385 this.preTest = null;
|
n@1170
|
386 this.postTest = null;
|
n@1170
|
387 this.interfaces = [];
|
n@1170
|
388 this.commentBoxPrefix = "Comment on track";
|
n@1170
|
389 this.audioElements = [];
|
n@1170
|
390 this.commentQuestions = [];
|
n@1170
|
391 this.schema = specification.schema.getAllElementsByName("page")[0];
|
n@1170
|
392
|
n@1170
|
393 this.decode = function(parent,xml)
|
n@1170
|
394 {
|
n@1170
|
395 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
|
n@1170
|
396 for (var i=0; i<attributeMap.length; i++)
|
n@1170
|
397 {
|
n@1170
|
398 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
|
n@1170
|
399 var projectAttr = xml.getAttribute(attributeName);
|
n@1170
|
400 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]);
|
n@1170
|
401 switch(typeof projectAttr)
|
n@1170
|
402 {
|
n@1170
|
403 case "number":
|
n@1170
|
404 case "boolean":
|
n@1170
|
405 eval('this.'+attributeName+' = '+projectAttr);
|
n@1170
|
406 break;
|
n@1170
|
407 case "string":
|
n@1170
|
408 eval('this.'+attributeName+' = "'+projectAttr+'"');
|
n@1170
|
409 break;
|
n@1170
|
410 }
|
n@1170
|
411 }
|
n@1170
|
412
|
n@1170
|
413 // Get the Comment Box Prefix
|
n@1170
|
414 var CBP = xml.getElementsByTagName('commentboxprefix');
|
n@1170
|
415 if (CBP.length != 0) {
|
n@1170
|
416 this.commentBoxPrefix = CBP[0].textContent;
|
n@1170
|
417 }
|
n@1170
|
418
|
n@1170
|
419 // Now decode the interfaces
|
n@1170
|
420 var interfaceNode = xml.getElementsByTagName('interface');
|
n@1170
|
421 for (var i=0; i<interfaceNode.length; i++)
|
n@1170
|
422 {
|
n@1170
|
423 var node = new parent.interfaceNode();
|
n@1170
|
424 node.decode(this,interfaceNode[i],parent.schema.getAllElementsByName('interface')[1]);
|
n@1170
|
425 this.interfaces.push(node);
|
n@1170
|
426 }
|
n@1170
|
427
|
n@1170
|
428 // Now process the survey node options
|
n@1170
|
429 var survey = xml.getElementsByTagName('survey');
|
n@1170
|
430 var surveySchema = parent.schema.getAllElementsByName('survey')[0];
|
n@1170
|
431 for (var i in survey) {
|
n@1170
|
432 if (isNaN(Number(i)) == true){break;}
|
n@1170
|
433 var location = survey[i].getAttribute('location');
|
n@1170
|
434 if (location == 'pre' || location == 'before')
|
n@1170
|
435 {
|
n@1170
|
436 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");}
|
n@1170
|
437 else {
|
n@1170
|
438 this.preTest = new parent.surveyNode();
|
n@1170
|
439 this.preTest.decode(parent,survey[i],surveySchema);
|
n@1170
|
440 }
|
n@1170
|
441 } else if (location == 'post' || location == 'after') {
|
n@1170
|
442 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");}
|
n@1170
|
443 else {
|
n@1170
|
444 this.postTest = new parent.surveyNode();
|
n@1170
|
445 this.postTest.decode(parent,survey[i],surveySchema);
|
n@1170
|
446 }
|
n@1170
|
447 }
|
n@1170
|
448 }
|
n@1170
|
449
|
n@1170
|
450 // Now process the audioelement tags
|
n@1170
|
451 var audioElements = xml.getElementsByTagName('audioelement');
|
n@1170
|
452 for (var i=0; i<audioElements.length; i++)
|
n@1170
|
453 {
|
n@1170
|
454 var node = new this.audioElementNode();
|
n@1170
|
455 node.decode(this,audioElements[i]);
|
n@1170
|
456 this.audioElements.push(node);
|
n@1170
|
457 }
|
n@1170
|
458
|
n@1170
|
459 // Now decode the commentquestions
|
n@1170
|
460 var commentQuestions = xml.getElementsByTagName('commentquestion');
|
n@1170
|
461 for (var i=0; i<commentQuestions.length; i++)
|
n@1170
|
462 {
|
n@1170
|
463 var node = new this.commentQuestionNode();
|
n@1170
|
464 node.decode(parent,commentQuestions[i]);
|
n@1170
|
465 this.commentQuestions.push(node);
|
n@1170
|
466 }
|
n@1170
|
467 };
|
n@1170
|
468
|
n@1170
|
469 this.encode = function(root)
|
n@1170
|
470 {
|
n@1170
|
471 var AHNode = root.createElement("audioHolder");
|
n@1170
|
472 AHNode.id = this.id;
|
n@1170
|
473 AHNode.setAttribute("hostURL",this.hostURL);
|
n@1170
|
474 AHNode.setAttribute("sampleRate",this.sampleRate);
|
n@1170
|
475 AHNode.setAttribute("randomiseOrder",this.randomiseOrder);
|
n@1170
|
476 AHNode.setAttribute("repeatCount",this.repeatCount);
|
n@1170
|
477 AHNode.setAttribute("loop",this.loop);
|
n@1170
|
478 AHNode.setAttribute("elementComments",this.elementComments);
|
n@1170
|
479 if(this.loudness != null) {AHNode.setAttribute("loudness",this.loudness);}
|
n@1170
|
480 if(this.initialPosition != null) {
|
n@1170
|
481 AHNode.setAttribute("loudness",this.initialPosition*100);
|
n@1170
|
482 }
|
n@1170
|
483 for (var i=0; i<this.interfaces.length; i++)
|
n@1170
|
484 {
|
n@1170
|
485 AHNode.appendChild(this.interfaces[i].encode(root));
|
n@1170
|
486 }
|
n@1170
|
487
|
n@1170
|
488 for (var i=0; i<this.audioElements.length; i++) {
|
n@1170
|
489 AHNode.appendChild(this.audioElements[i].encode(root));
|
n@1170
|
490 }
|
n@1170
|
491 // Create <CommentQuestion>
|
n@1170
|
492 for (var i=0; i<this.commentQuestions.length; i++)
|
n@1170
|
493 {
|
n@1170
|
494 AHNode.appendChild(this.commentQuestions[i].exportXML(root));
|
n@1170
|
495 }
|
n@1170
|
496
|
n@1170
|
497 // Create <PreTest>
|
n@1170
|
498 var AHPreTest = root.createElement("PreTest");
|
n@1170
|
499 for (var i=0; i<this.preTest.options.length; i++)
|
n@1170
|
500 {
|
n@1170
|
501 AHPreTest.appendChild(this.preTest.options[i].exportXML(root));
|
n@1170
|
502 }
|
n@1170
|
503
|
n@1170
|
504 var AHPostTest = root.createElement("PostTest");
|
n@1170
|
505 for (var i=0; i<this.postTest.options.length; i++)
|
n@1170
|
506 {
|
n@1170
|
507 AHPostTest.appendChild(this.postTest.options[i].exportXML(root));
|
n@1170
|
508 }
|
n@1170
|
509 AHNode.appendChild(AHPreTest);
|
n@1170
|
510 AHNode.appendChild(AHPostTest);
|
n@1170
|
511 return AHNode;
|
n@1170
|
512 };
|
n@1170
|
513
|
n@1170
|
514 this.commentQuestionNode = function() {
|
n@1170
|
515 this.id = null;
|
n@1170
|
516 this.type = undefined;
|
n@1170
|
517 this.options = [];
|
n@1170
|
518 this.statement = undefined;
|
n@1170
|
519 this.schema = specification.schema.getAllElementsByName('commentquestion')[0];
|
n@1170
|
520 this.decode = function(parent,xml)
|
n@1170
|
521 {
|
n@1170
|
522 this.id = xml.id;
|
n@1170
|
523 this.type = xml.getAttribute('type');
|
n@1170
|
524 this.statement = xml.getElementsByTagName('statement')[0].textContent;
|
n@1170
|
525 var optNodes = xml.getElementsByTagName('option');
|
n@1170
|
526 for (var i=0; i<optNodes.length; i++)
|
n@1170
|
527 {
|
n@1170
|
528 var optNode = optNodes[i];
|
n@1170
|
529 this.options.push({
|
n@1170
|
530 name: optNode.getAttribute('name'),
|
n@1170
|
531 text: optNode.textContent
|
n@1170
|
532 });
|
n@1170
|
533 }
|
n@1170
|
534 };
|
n@1170
|
535
|
n@1170
|
536 this.encode = function(root)
|
n@1170
|
537 {
|
n@1170
|
538
|
n@1170
|
539 };
|
n@1170
|
540 };
|
n@1170
|
541
|
n@1170
|
542 this.audioElementNode = function() {
|
n@1170
|
543 this.url = null;
|
n@1170
|
544 this.id = null;
|
n@1170
|
545 this.parent = null;
|
n@1170
|
546 this.type = null;
|
n@1170
|
547 this.marker = false;
|
n@1170
|
548 this.enforce = false;
|
n@1170
|
549 this.gain = 1.0;
|
n@1170
|
550 this.schema = specification.schema.getAllElementsByName('audioelement')[0];;
|
n@1170
|
551 this.parent = null;
|
n@1170
|
552 this.decode = function(parent,xml)
|
n@1170
|
553 {
|
n@1170
|
554 this.parent = parent;
|
n@1170
|
555 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
|
n@1170
|
556 for (var i=0; i<attributeMap.length; i++)
|
n@1170
|
557 {
|
n@1170
|
558 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
|
n@1170
|
559 var projectAttr = xml.getAttribute(attributeName);
|
n@1170
|
560 projectAttr = specification.processAttribute(projectAttr,attributeMap[i]);
|
n@1170
|
561 switch(typeof projectAttr)
|
n@1170
|
562 {
|
n@1170
|
563 case "number":
|
n@1170
|
564 case "boolean":
|
n@1170
|
565 eval('this.'+attributeName+' = '+projectAttr);
|
n@1170
|
566 break;
|
n@1170
|
567 case "string":
|
n@1170
|
568 eval('this.'+attributeName+' = "'+projectAttr+'"');
|
n@1170
|
569 break;
|
n@1170
|
570 }
|
n@1170
|
571 }
|
n@1170
|
572
|
n@1170
|
573 };
|
n@1170
|
574 this.encode = function(root)
|
n@1170
|
575 {
|
n@1170
|
576 var AENode = root.createElement("audioElements");
|
n@1170
|
577 AENode.id = this.id;
|
n@1170
|
578 AENode.setAttribute("url",this.url);
|
n@1170
|
579 AENode.setAttribute("type",this.type);
|
n@1170
|
580 AENode.setAttribute("gain",linearToDecibel(this.gain));
|
n@1170
|
581 if (this.marker != false)
|
n@1170
|
582 {
|
n@1170
|
583 AENode.setAttribute("marker",this.marker*100);
|
n@1170
|
584 }
|
n@1170
|
585 return AENode;
|
n@1170
|
586 };
|
n@1170
|
587 };
|
n@1170
|
588 };
|
n@1170
|
589 }
|
n@1170
|
590 </script>
|
n@1170
|
591 <script type="text/javascript" src="test_core.js"/>
|
n@1170
|
592 <script type="text/javascript">
|
n@1170
|
593
|
n@1170
|
594 </script>
|
n@1170
|
595 </head>
|
n@1170
|
596 <body>
|
n@1170
|
597 <div id="popupHolder"></div>
|
n@1170
|
598 <div id="blanket"></div>
|
n@1170
|
599 <div id="content"></div>
|
n@1170
|
600 </body>
|
n@1170
|
601 </html> |