Mercurial > hg > webaudioevaluationtool
comparison core.js @ 1582:d4b626a4bc76
Comment Boxes handled by Interface object.
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Thu, 04 Jun 2015 16:48:04 +0100 |
parents | 284251e3a6a3 |
children | 62e755ce8d34 |
comparison
equal
deleted
inserted
replaced
1581:284251e3a6a3 | 1582:d4b626a4bc76 |
---|---|
7 | 7 |
8 /* create the web audio API context and store in audioContext*/ | 8 /* create the web audio API context and store in audioContext*/ |
9 var audioContext; // Hold the browser web audio API | 9 var audioContext; // Hold the browser web audio API |
10 var projectXML; // Hold the parsed setup XML | 10 var projectXML; // Hold the parsed setup XML |
11 var specification; | 11 var specification; |
12 var interfaceContext; | |
12 var popup; // Hold the interfacePopup object | 13 var popup; // Hold the interfacePopup object |
13 var testState; | 14 var testState; |
14 var currentTrackOrder = []; // Hold the current XML tracks in their (randomised) order | 15 var currentTrackOrder = []; // Hold the current XML tracks in their (randomised) order |
15 var audioEngineContext; // The custome AudioEngine object | 16 var audioEngineContext; // The custome AudioEngine object |
16 var projectReturn; // Hold the URL for the return | 17 var projectReturn; // Hold the URL for the return |
37 // Create the popup interface object | 38 // Create the popup interface object |
38 popup = new interfacePopup(); | 39 popup = new interfacePopup(); |
39 | 40 |
40 // Create the specification object | 41 // Create the specification object |
41 specification = new Specification(); | 42 specification = new Specification(); |
43 | |
44 // Create the interface object | |
45 interfaceContext = new Interface(specification); | |
42 }; | 46 }; |
43 | 47 |
44 function interfacePopup() { | 48 function interfacePopup() { |
45 // Creates an object to manage the popup | 49 // Creates an object to manage the popup |
46 this.popup = null; | 50 this.popup = null; |
223 this.currentTestId++; | 227 this.currentTestId++; |
224 } | 228 } |
225 this.stateIndex++; | 229 this.stateIndex++; |
226 if (this.stateIndex >= this.stateMap.length) { | 230 if (this.stateIndex >= this.stateMap.length) { |
227 console.log('Test Completed'); | 231 console.log('Test Completed'); |
228 createProjectSave(projectReturn); | 232 createProjectSave(specification.projectReturn); |
229 } else { | 233 } else { |
230 this.currentStateMap = this.stateMap[this.stateIndex]; | 234 this.currentStateMap = this.stateMap[this.stateIndex]; |
231 if (this.currentStateMap.type == "audioHolder") { | 235 if (this.currentStateMap.type == "audioHolder") { |
232 console.log('Loading test page'); | 236 console.log('Loading test page'); |
233 loadTest(this.currentStateMap); | 237 loadTest(this.currentStateMap); |
416 a.download = "save.xml"; | 420 a.download = "save.xml"; |
417 a.textContent = "Save File"; | 421 a.textContent = "Save File"; |
418 | 422 |
419 popup.showPopup(); | 423 popup.showPopup(); |
420 popup.popupContent.innerHTML = null; | 424 popup.popupContent.innerHTML = null; |
421 popup.popupContent.appendChild(a) | 425 popup.popupContent.appendChild(a); |
422 } else { | 426 } else { |
423 var xmlhttp = new XMLHttpRequest; | 427 var xmlhttp = new XMLHttpRequest; |
424 xmlhttp.open("POST",destURL,true); | 428 xmlhttp.open("POST",destURL,true); |
425 xmlhttp.setRequestHeader('Content-Type', 'text/xml'); | 429 xmlhttp.setRequestHeader('Content-Type', 'text/xml'); |
426 xmlhttp.onerror = function(){ | 430 xmlhttp.onerror = function(){ |
433 createProjectSave(null); | 437 createProjectSave(null); |
434 } | 438 } |
435 }; | 439 }; |
436 xmlhttp.send(file); | 440 xmlhttp.send(file); |
437 } | 441 } |
438 return submitDiv; | |
439 } | 442 } |
440 | 443 |
441 // Only other global function which must be defined in the interface class. Determines how to create the XML document. | 444 // Only other global function which must be defined in the interface class. Determines how to create the XML document. |
442 function interfaceXMLSave(){ | 445 function interfaceXMLSave(){ |
443 // Create the XML string to be exported with results | 446 // Create the XML string to be exported with results |
508 this.status = 0; | 511 this.status = 0; |
509 } | 512 } |
510 }; | 513 }; |
511 | 514 |
512 | 515 |
513 this.newTrack = function(url) { | 516 this.newTrack = function(element) { |
514 // Pull data from given URL into new audio buffer | 517 // Pull data from given URL into new audio buffer |
515 // URLs must either be from the same source OR be setup to 'Access-Control-Allow-Origin' | 518 // URLs must either be from the same source OR be setup to 'Access-Control-Allow-Origin' |
516 | 519 |
517 // Create the audioObject with ID of the new track length; | 520 // Create the audioObject with ID of the new track length; |
518 audioObjectId = this.audioObjects.length; | 521 audioObjectId = this.audioObjects.length; |
519 this.audioObjects[audioObjectId] = new audioObject(audioObjectId); | 522 this.audioObjects[audioObjectId] = new audioObject(audioObjectId); |
520 | 523 |
521 // AudioObject will get track itself. | 524 // AudioObject will get track itself. |
522 this.audioObjects[audioObjectId].constructTrack(url); | 525 this.audioObjects[audioObjectId].specification = element; |
526 this.audioObjects[audioObjectId].constructTrack(element.parent.hostURL + element.url); | |
523 return this.audioObjects[audioObjectId]; | 527 return this.audioObjects[audioObjectId]; |
524 }; | 528 }; |
525 | 529 |
526 this.newTestPage = function() { | 530 this.newTestPage = function() { |
527 this.state = 0; | 531 this.state = 0; |
555 } | 559 } |
556 | 560 |
557 function audioObject(id) { | 561 function audioObject(id) { |
558 // The main buffer object with common control nodes to the AudioEngine | 562 // The main buffer object with common control nodes to the AudioEngine |
559 | 563 |
564 this.specification; | |
560 this.id = id; | 565 this.id = id; |
561 this.state = 0; // 0 - no data, 1 - ready | 566 this.state = 0; // 0 - no data, 1 - ready |
562 this.url = null; // Hold the URL given for the output back to the results. | 567 this.url = null; // Hold the URL given for the output back to the results. |
563 this.metric = new metricTracker(this); | 568 this.metric = new metricTracker(this); |
564 | 569 |
1030 arr[1] = scale[i].textContent; | 1035 arr[1] = scale[i].textContent; |
1031 this.scale.push(arr); | 1036 this.scale.push(arr); |
1032 } | 1037 } |
1033 }; | 1038 }; |
1034 | 1039 |
1035 this.audioElementNode = function(xml) { | 1040 this.audioElementNode = function(parent,xml) { |
1036 this.url = xml.getAttribute('url'); | 1041 this.url = xml.getAttribute('url'); |
1037 this.id = xml.id; | 1042 this.id = xml.id; |
1043 this.parent = parent; | |
1038 }; | 1044 }; |
1039 | 1045 |
1040 this.commentQuestionNode = function(xml) { | 1046 this.commentQuestionNode = function(xml) { |
1041 this.id = xml.id; | 1047 this.id = xml.id; |
1042 if (xml.getAttribute('mandatory') == 'true') {this.mandatory = true;} | 1048 if (xml.getAttribute('mandatory') == 'true') {this.mandatory = true;} |
1072 } | 1078 } |
1073 | 1079 |
1074 this.audioElements =[]; | 1080 this.audioElements =[]; |
1075 var audioElementsDOM = xml.getElementsByTagName('audioElements'); | 1081 var audioElementsDOM = xml.getElementsByTagName('audioElements'); |
1076 for (var i=0; i<audioElementsDOM.length; i++) { | 1082 for (var i=0; i<audioElementsDOM.length; i++) { |
1077 this.audioElements.push(new this.audioElementNode(audioElementsDOM[i])); | 1083 this.audioElements.push(new this.audioElementNode(this,audioElementsDOM[i])); |
1078 } | 1084 } |
1079 | 1085 |
1080 this.commentQuestions = []; | 1086 this.commentQuestions = []; |
1081 var commentQuestionsDOM = xml.getElementsByTagName('CommentQuestion'); | 1087 var commentQuestionsDOM = xml.getElementsByTagName('CommentQuestion'); |
1082 for (var i=0; i<commentQuestionsDOM.length; i++) { | 1088 for (var i=0; i<commentQuestionsDOM.length; i++) { |
1083 this.commentQuestions.push(new this.commentQuestionNode(commentQuestionsDOM[i])); | 1089 this.commentQuestions.push(new this.commentQuestionNode(commentQuestionsDOM[i])); |
1084 } | 1090 } |
1085 }; | 1091 }; |
1086 } | 1092 } |
1087 | 1093 |
1088 function Interface() { | 1094 function Interface(specificationObject) { |
1089 // This handles the bindings between the interface and the audioEngineContext; | 1095 // This handles the bindings between the interface and the audioEngineContext; |
1090 | 1096 this.specification = specificationObject; |
1091 } | 1097 this.insertPoint = document.getElementById("topLevelBody"); |
1092 | 1098 |
1099 // Bounded by interface!! | |
1100 // Interface object MUST have an exportXMLDOM method which returns the various DOM levels | |
1101 // For example, APE returns the slider position normalised in a <value> tag. | |
1102 this.interfaceObjects = []; | |
1103 this.interfaceObject = function(){}; | |
1104 | |
1105 this.commentBoxes = []; | |
1106 this.commentBox = function(audioObject) { | |
1107 var element = audioObject.specification; | |
1108 this.id = audioObject.id; | |
1109 var audioHolderObject = audioObject.specification.parent; | |
1110 // Create document objects to hold the comment boxes | |
1111 this.trackComment = document.createElement('div'); | |
1112 this.trackComment.className = 'comment-div'; | |
1113 this.trackComment.id = 'comment-div-'+audioObject.id; | |
1114 // Create a string next to each comment asking for a comment | |
1115 var trackString = document.createElement('span'); | |
1116 trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.id; | |
1117 // Create the HTML5 comment box 'textarea' | |
1118 var trackCommentBox = document.createElement('textarea'); | |
1119 trackCommentBox.rows = '4'; | |
1120 trackCommentBox.cols = '100'; | |
1121 trackCommentBox.name = 'trackComment'+audioObject.id; | |
1122 trackCommentBox.className = 'trackComment'; | |
1123 var br = document.createElement('br'); | |
1124 // Add to the holder. | |
1125 this.trackComment.appendChild(trackString); | |
1126 this.trackComment.appendChild(br); | |
1127 this.trackComment.appendChild(trackCommentBox); | |
1128 }; | |
1129 | |
1130 this.createCommentBox = function(audioObject) { | |
1131 var node = new this.commentBox(audioObject); | |
1132 this.commentBoxes.push(node); | |
1133 audioObject.commentDOM = node; | |
1134 return node; | |
1135 }; | |
1136 | |
1137 this.sortCommentBoxes = function() { | |
1138 var holder = []; | |
1139 while (this.commentBoxes.length > 0) { | |
1140 var node = this.commentBoxes.pop(0); | |
1141 holder[node.id] = node; | |
1142 } | |
1143 this.commentBoxes = holder; | |
1144 }; | |
1145 | |
1146 this.showCommentBoxes = function(inject, sort) { | |
1147 if (sort) {interfaceContext.sortCommentBoxes();} | |
1148 for (var i=0; i<interfaceContext.commentBoxes.length; i++) { | |
1149 inject.appendChild(this.commentBoxes[i].trackComment); | |
1150 } | |
1151 }; | |
1152 } | |
1153 |