Mercurial > hg > webaudioevaluationtool
comparison interfaces/AB.js @ 1102:b5bf2f57187c
Merge
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Tue, 08 Mar 2016 14:44:14 +0000 |
parents | 0a15fa67bda1 |
children | 83b439322229 |
comparison
equal
deleted
inserted
replaced
1101:a497058ae2ae | 1102:b5bf2f57187c |
---|---|
5 // Get the dimensions of the screen available to the page | 5 // Get the dimensions of the screen available to the page |
6 var width = window.innerWidth; | 6 var width = window.innerWidth; |
7 var height = window.innerHeight; | 7 var height = window.innerHeight; |
8 interfaceContext.insertPoint.innerHTML = null; // Clear the current schema | 8 interfaceContext.insertPoint.innerHTML = null; // Clear the current schema |
9 | 9 |
10 // Custom Comparitor Object | 10 // Custom comparator Object |
11 Interface.prototype.comparitor = null; | 11 Interface.prototype.comparator = null; |
12 | 12 |
13 // The injection point into the HTML page | 13 // The injection point into the HTML page |
14 interfaceContext.insertPoint = document.getElementById("topLevelBody"); | 14 interfaceContext.insertPoint = document.getElementById("topLevelBody"); |
15 var testContent = document.createElement('div'); | 15 var testContent = document.createElement('div'); |
16 testContent.id = 'testContent'; | 16 testContent.id = 'testContent'; |
132 if (pagecountHolder == null) | 132 if (pagecountHolder == null) |
133 { | 133 { |
134 pagecountHolder = document.createElement('div'); | 134 pagecountHolder = document.createElement('div'); |
135 pagecountHolder.id = 'page-count'; | 135 pagecountHolder.id = 'page-count'; |
136 } | 136 } |
137 pagecountHolder.innerHTML = '<span>Page '+(audioHolderObject.presentedId+1)+' of '+specification.pages.length+'</span>'; | 137 pagecountHolder.innerHTML = '<span>Page '+(testState.stateIndex+1)+' of '+testState.stateMap.length+'</span>'; |
138 var inject = document.getElementById('interface-buttons'); | 138 var inject = document.getElementById('interface-buttons'); |
139 inject.appendChild(pagecountHolder); | 139 inject.appendChild(pagecountHolder); |
140 break; | 140 break; |
141 case "volume": | 141 case "volume": |
142 if (document.getElementById('master-volume-holder') == null) | 142 if (document.getElementById('master-volume-holder') == null) |
146 break; | 146 break; |
147 } | 147 } |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 // Populate the comparitor object | 151 // Populate the comparator object |
152 interfaceContext.comparitor = new Comparitor(audioHolderObject); | 152 interfaceContext.comparator = new comparator(audioHolderObject); |
153 if (audioHolderObject.showElementComments) | 153 if (audioHolderObject.showElementComments) |
154 { | 154 { |
155 var commentHolder = document.createElement('div'); | 155 var commentHolder = document.createElement('div'); |
156 commentHolder.id = 'commentHolder'; | 156 commentHolder.id = 'commentHolder'; |
157 document.getElementById('testContent').appendChild(commentHolder); | 157 document.getElementById('testContent').appendChild(commentHolder); |
158 // Generate one comment box per presented page | 158 // Generate one comment box per presented page |
159 for (var element of audioEngineContext.audioObjects) | 159 for (var element of audioEngineContext.audioObjects) |
160 { | 160 { |
161 interfaceContext.createCommentBox(element); | 161 interfaceContext.commentBoxes.createCommentBox(element); |
162 } | 162 } |
163 interfaceContext.showCommentBoxes(commentHolder,true); | 163 interfaceContext.commentBoxes.showCommentBoxes(commentHolder,true); |
164 } | 164 } |
165 resizeWindow(null); | 165 resizeWindow(null); |
166 } | 166 } |
167 | 167 |
168 function Comparitor(audioHolderObject) | 168 function comparator(audioHolderObject) |
169 { | 169 { |
170 this.comparitorBox = function(audioElement,id,text) | 170 this.comparatorBox = function(audioElement,id,text) |
171 { | 171 { |
172 this.parent = audioElement; | 172 this.parent = audioElement; |
173 this.id = id; | 173 this.id = id; |
174 this.value = 0; | 174 this.value = 0; |
175 this.disabled = true; | 175 this.disabled = true; |
176 this.box = document.createElement('div'); | 176 this.box = document.createElement('div'); |
177 this.box.className = 'comparitor-holder'; | 177 this.box.className = 'comparator-holder'; |
178 this.box.setAttribute('track-id',audioElement.id); | 178 this.box.setAttribute('track-id',audioElement.id); |
179 this.box.id = 'comparitor-'+text; | 179 this.box.id = 'comparator-'+text; |
180 this.selector = document.createElement('div'); | 180 this.selector = document.createElement('div'); |
181 this.selector.className = 'comparitor-selector disabled'; | 181 this.selector.className = 'comparator-selector disabled'; |
182 var selectorText = document.createElement('span'); | 182 var selectorText = document.createElement('span'); |
183 selectorText.textContent = text; | 183 selectorText.textContent = text; |
184 this.selector.appendChild(selectorText); | 184 this.selector.appendChild(selectorText); |
185 this.playback = document.createElement('button'); | 185 this.playback = document.createElement('button'); |
186 this.playback.className = 'comparitor-button'; | 186 this.playback.className = 'comparator-button'; |
187 this.playback.disabled = true; | 187 this.playback.disabled = true; |
188 this.playback.textContent = "Listen"; | 188 this.playback.textContent = "Listen"; |
189 this.box.appendChild(this.selector); | 189 this.box.appendChild(this.selector); |
190 this.box.appendChild(this.playback); | 190 this.box.appendChild(this.playback); |
191 this.selector.onclick = function(event) | 191 this.selector.onclick = function(event) |
199 if (audioEngineContext.status == 0) | 199 if (audioEngineContext.status == 0) |
200 { | 200 { |
201 alert("Please listen to the samples before making a selection"); | 201 alert("Please listen to the samples before making a selection"); |
202 console.log("Please listen to the samples before making a selection"); | 202 console.log("Please listen to the samples before making a selection"); |
203 return; | 203 return; |
204 } | 204 } |
205 $(".comparitor-selector").removeClass('selected'); | |
206 var id = event.currentTarget.parentElement.getAttribute('track-id'); | 205 var id = event.currentTarget.parentElement.getAttribute('track-id'); |
207 interfaceContext.comparitor.selected = id; | 206 interfaceContext.comparator.selected = id; |
208 $(event.currentTarget).addClass('selected'); | 207 if ($(event.currentTarget).hasClass("selected")) { |
209 for (var i=0; i<interfaceContext.comparitor.comparitors.length; i++) | 208 $(".comparator-selector").removeClass('selected'); |
210 { | 209 for (var i=0; i<interfaceContext.comparator.comparators.length; i++) |
211 var obj = interfaceContext.comparitor.comparitors[i]; | 210 { |
212 if (i == id) { | 211 var obj = interfaceContext.comparator.comparators[i]; |
213 obj.value = 1; | 212 obj.parent.metric.moved(time,0); |
214 } else { | 213 } |
215 obj.value = 0; | 214 } else { |
216 } | 215 $(".comparator-selector").removeClass('selected'); |
217 obj.parent.metric.moved(time,obj.value); | 216 $(event.currentTarget).addClass('selected'); |
218 } | 217 for (var i=0; i<interfaceContext.comparator.comparators.length; i++) |
219 console.log("Selected "+id+' ('+time+')'); | 218 { |
219 var obj = interfaceContext.comparator.comparators[i]; | |
220 if (i == id) { | |
221 obj.value = 1; | |
222 } else { | |
223 obj.value = 0; | |
224 } | |
225 obj.parent.metric.moved(time,obj.value); | |
226 } | |
227 console.log("Selected "+id+' ('+time+')'); | |
228 } | |
220 }; | 229 }; |
221 this.playback.setAttribute("playstate","ready"); | 230 this.playback.setAttribute("playstate","ready"); |
222 this.playback.onclick = function(event) | 231 this.playback.onclick = function(event) |
223 { | 232 { |
224 var id = event.currentTarget.parentElement.getAttribute('track-id'); | 233 var id = event.currentTarget.parentElement.getAttribute('track-id'); |
248 this.playback.textContent = progress+'%'; | 257 this.playback.textContent = progress+'%'; |
249 } else { | 258 } else { |
250 this.playback.textContent = "Play"; | 259 this.playback.textContent = "Play"; |
251 } | 260 } |
252 }; | 261 }; |
262 this.error = function() { | |
263 // audioObject has an error!! | |
264 this.playback.textContent = "Error"; | |
265 $(this.playback).addClass("error-colour"); | |
266 } | |
253 this.startPlayback = function() | 267 this.startPlayback = function() |
254 { | 268 { |
255 $('.comparitor-button').text('Listen'); | 269 $('.comparator-button').text('Listen'); |
256 $(this.playback).text('Stop'); | 270 $(this.playback).text('Stop'); |
257 this.playback.setAttribute("playstate","playing"); | 271 this.playback.setAttribute("playstate","playing"); |
258 }; | 272 }; |
259 this.stopPlayback = function() | 273 this.stopPlayback = function() |
260 { | 274 { |
280 }; | 294 }; |
281 }; | 295 }; |
282 | 296 |
283 this.boxHolders = document.getElementById('box-holders'); | 297 this.boxHolders = document.getElementById('box-holders'); |
284 this.boxHolders.innerHTML = null; | 298 this.boxHolders.innerHTML = null; |
285 this.comparitors = []; | 299 this.comparators = []; |
286 this.selected = null; | 300 this.selected = null; |
287 | 301 |
288 // First generate the Audio Objects for the Audio Engine | 302 // First generate the Audio Objects for the Audio Engine |
289 for (var index=0; index<audioHolderObject.audioElements.length; index++) | 303 for (var index=0; index<audioHolderObject.audioElements.length; index++) |
290 { | 304 { |
292 if (index == audioHolderObject.outsideReference || element.type == 'outside-reference') | 306 if (index == audioHolderObject.outsideReference || element.type == 'outside-reference') |
293 { | 307 { |
294 console.log("WARNING - AB cannot have fixed reference"); | 308 console.log("WARNING - AB cannot have fixed reference"); |
295 } | 309 } |
296 var audioObject = audioEngineContext.newTrack(element); | 310 var audioObject = audioEngineContext.newTrack(element); |
297 var node = new this.comparitorBox(audioObject,index,String.fromCharCode(65 + index)); | 311 var node = new this.comparatorBox(audioObject,index,String.fromCharCode(65 + index)); |
298 audioObject.bindInterface(node); | 312 audioObject.bindInterface(node); |
299 this.comparitors.push(node); | 313 this.comparators.push(node); |
300 this.boxHolders.appendChild(node.box); | 314 this.boxHolders.appendChild(node.box); |
301 } | 315 } |
302 return this; | 316 return this; |
303 } | 317 } |
304 | 318 |
305 function resizeWindow(event) | 319 function resizeWindow(event) |
306 { | 320 { |
307 document.getElementById('submit').style.left = (window.innerWidth-250)/2 + 'px'; | 321 document.getElementById('submit').style.left = (window.innerWidth-250)/2 + 'px'; |
308 var numObj = interfaceContext.comparitor.comparitors.length; | 322 var numObj = interfaceContext.comparator.comparators.length; |
309 var boxW = numObj*312; | 323 var boxW = numObj*312; |
310 var diff = window.innerWidth - boxW; | 324 var diff = window.innerWidth - boxW; |
311 while (diff < 0) | 325 while (diff < 0) |
312 { | 326 { |
313 numObj = Math.ceil(numObj/2); | 327 numObj = Math.ceil(numObj/2); |