Mercurial > hg > webaudioevaluationtool
comparison ape.js @ 7:6a6272b06d34
Standalone version.
Movable sliders with rating
Comment boxes
Submission to XML file
TODO:
Click track to listen
author | Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk> |
---|---|
date | Wed, 25 Mar 2015 12:48:29 +0000 |
parents | 4766f485a1b0 |
children | a6364db4c2ea |
comparison
equal
deleted
inserted
replaced
6:8d9fd0ba13e3 | 7:6a6272b06d34 |
---|---|
14 // Set background to grey #ddd | 14 // Set background to grey #ddd |
15 document.getElementsByTagName('body')[0].style.backgroundColor = '#ddd'; | 15 document.getElementsByTagName('body')[0].style.backgroundColor = '#ddd'; |
16 | 16 |
17 // The injection point into the HTML page | 17 // The injection point into the HTML page |
18 var insertPoint = document.getElementById("topLevelBody"); | 18 var insertPoint = document.getElementById("topLevelBody"); |
19 | |
19 | 20 |
20 // Decode parts of the xmlDoc that are needed | 21 // Decode parts of the xmlDoc that are needed |
21 // xmlDoc MUST already be parsed by jQuery! | 22 // xmlDoc MUST already be parsed by jQuery! |
22 var xmlSetup = xmlDoc.find('setup'); | 23 var xmlSetup = xmlDoc.find('setup'); |
23 // Should put in an error function here incase of malprocessed or malformed XML | 24 // Should put in an error function here incase of malprocessed or malformed XML |
35 } else { | 36 } else { |
36 titleSpan.innerText = 'APE Tool'; | 37 titleSpan.innerText = 'APE Tool'; |
37 } | 38 } |
38 // Insert the titleSpan element into the title div element. | 39 // Insert the titleSpan element into the title div element. |
39 title.appendChild(titleSpan); | 40 title.appendChild(titleSpan); |
41 | |
42 // Store the return URL path in global projectReturn | |
43 projectReturn = xmlSetup[0].attributes['projectReturn'].value; | |
44 | |
45 // Create Interface buttons! | |
46 var interfaceButtons = document.createElement('div'); | |
47 interfaceButtons.id = 'interface-buttons'; | |
48 | |
49 // MANUAL DOWNLOAD POINT | |
50 // If project return is null, this MUST be specified as the location to create the download link | |
51 var downloadPoint = document.createElement('div'); | |
52 downloadPoint.id = 'download-point'; | |
53 | |
54 // Create playback start/stop points | |
55 var playback = document.createElement("button"); | |
56 playback.innerText = 'Start'; | |
57 playback.onclick = function() { | |
58 if (audioEngineContext.status == 0) { | |
59 audioEngineContext.play(); | |
60 this.innerText = 'Stop'; | |
61 } else { | |
62 audioEngineContext.stop(); | |
63 this.innerText = 'Start'; | |
64 } | |
65 } | |
66 // Create Submit (save) button | |
67 var submit = document.createElement("button"); | |
68 submit.innerText = 'Submit'; | |
69 submit.onclick = function() { | |
70 createProjectSave(projectReturn) | |
71 } | |
72 | |
73 interfaceButtons.appendChild(playback); | |
74 interfaceButtons.appendChild(submit); | |
75 interfaceButtons.appendChild(downloadPoint); | |
40 | 76 |
41 // Now create the slider and HTML5 canvas boxes | 77 // Now create the slider and HTML5 canvas boxes |
42 | 78 |
43 var sliderBox = document.createElement('div'); | 79 var sliderBox = document.createElement('div'); |
44 sliderBox.className = 'sliderCanvasDiv'; | 80 sliderBox.className = 'sliderCanvasDiv'; |
54 canvas.align = "left"; | 90 canvas.align = "left"; |
55 sliderBox.appendChild(canvas); | 91 sliderBox.appendChild(canvas); |
56 | 92 |
57 var feedbackHolder = document.createElement('div'); | 93 var feedbackHolder = document.createElement('div'); |
58 | 94 |
95 var tracks = xmlDoc.find('tracks'); | |
96 tracks = tracks[0]; | |
97 var hostURL = tracks.attributes['hostURL']; | |
98 if (hostURL == undefined) { | |
99 hostURL = ""; | |
100 } else { | |
101 hostURL = hostURL.value; | |
102 } | |
103 | |
104 var hostFs = tracks.attributes['sampleRate']; | |
105 var hostFsExplicit = tracks.attributes['sampleRateExplicit']; | |
106 if (hostFs == undefined) { | |
107 hostFsExplicit = false; | |
108 } else { | |
109 hostFs = hostFs.value; | |
110 if (hostFsExplicit != undefined) { | |
111 hostFsExplicit = hostFsExplicit.value; | |
112 } | |
113 } | |
114 | |
115 /// CHECK FOR SAMPLE RATE COMPATIBILITY | |
116 if (hostFsExplicit == true) { | |
117 if (Number(hostFs) != audioContext.sampleRate) { | |
118 var errStr = 'Sample rates do not match! Requested '+Number(hostFs)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.'; | |
119 alert(errStr); | |
120 return; | |
121 } | |
122 } | |
123 | |
59 var tracksXML = xmlDoc.find('track'); | 124 var tracksXML = xmlDoc.find('track'); |
60 tracksXML.each(function(index,element){ | 125 tracksXML.each(function(index,element){ |
126 // Find URL of track | |
127 var trackURL = hostURL + this.attributes['url'].value; | |
128 // Now load each track in | |
129 audioEngineContext.newTrack(trackURL); | |
61 var trackObj = document.createElement('div'); | 130 var trackObj = document.createElement('div'); |
62 var trackTitle = document.createElement('span'); | 131 var trackTitle = document.createElement('span'); |
63 trackTitle.innerText = 'Comment on track '+index; | 132 trackTitle.innerText = 'Comment on track '+index; |
64 var trackComment = document.createElement('textarea'); | 133 var trackComment = document.createElement('textarea'); |
65 trackComment.rows = '4'; | 134 trackComment.rows = '4'; |
91 | 160 |
92 | 161 |
93 // Inject into HTML | 162 // Inject into HTML |
94 insertPoint.innerHTML = null; // Clear the current schema | 163 insertPoint.innerHTML = null; // Clear the current schema |
95 insertPoint.appendChild(title); // Insert the title | 164 insertPoint.appendChild(title); // Insert the title |
165 insertPoint.appendChild(interfaceButtons); | |
96 insertPoint.appendChild(sliderBox); | 166 insertPoint.appendChild(sliderBox); |
97 insertPoint.appendChild(feedbackHolder); | 167 insertPoint.appendChild(feedbackHolder); |
98 } | 168 } |
99 | 169 |
100 function dragEnd(ev) { | 170 function dragEnd(ev) { |
107 } else { | 177 } else { |
108 this.style.left = window.innerWidth-50 + 'px'; | 178 this.style.left = window.innerWidth-50 + 'px'; |
109 } | 179 } |
110 } | 180 } |
111 } | 181 } |
182 | |
183 // Only other global function which must be defined in the interface class. Determines how to create the XML document. | |
184 function interfaceXMLSave(){ | |
185 // Create the XML string to be exported with results | |
186 var xmlDoc = document.createElement("BrowserEvaluationResult"); | |
187 var trackSliderObjects = document.getElementsByClassName('track-slider'); | |
188 var commentObjects = document.getElementsByClassName('trackComment'); | |
189 var rateMin = 50; | |
190 var rateMax = window.innerWidth-50; | |
191 for (var i=0; i<trackSliderObjects.length; i++) | |
192 { | |
193 var trackObj = document.createElement("Track"); | |
194 trackObj.id = i; | |
195 var slider = document.createElement("Rating"); | |
196 var rate = Number(trackSliderObjects[i].style.left.substr(0,trackSliderObjects[i].style.left.length-2)); | |
197 rate = (rate-rateMin)/rateMax; | |
198 slider.innerText = Math.floor(rate*100); | |
199 var comment = document.createElement("Comment"); | |
200 comment.innerText = commentObjects[i].value; | |
201 trackObj.appendChild(slider); | |
202 trackObj.appendChild(comment); | |
203 xmlDoc.appendChild(trackObj); | |
204 } | |
205 | |
206 return xmlDoc; | |
207 } | |
208 |