Mercurial > hg > webaudioevaluationtool
comparison interfaces/discrete.js @ 1346:c6fd5f897fa2
discrete.js interface built with correct styling. Example discrete is DCR
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Thu, 14 Jan 2016 11:22:31 +0000 |
parents | 36bbc9972852 |
children | a275f9689af6 |
comparison
equal
deleted
inserted
replaced
1345:36bbc9972852 | 1346:c6fd5f897fa2 |
---|---|
78 scaleText.style.height = "25px"; | 78 scaleText.style.height = "25px"; |
79 scaleText.style.width = "100%"; | 79 scaleText.style.width = "100%"; |
80 scaleHolder.appendChild(scaleText); | 80 scaleHolder.appendChild(scaleText); |
81 var scaleCanvas = document.createElement('canvas'); | 81 var scaleCanvas = document.createElement('canvas'); |
82 scaleCanvas.id = "scale-canvas"; | 82 scaleCanvas.id = "scale-canvas"; |
83 scaleCanvas.style.marginLeft = "100px"; | 83 scaleCanvas.style.marginLeft = "150px"; |
84 scaleHolder.appendChild(scaleCanvas); | 84 scaleHolder.appendChild(scaleCanvas); |
85 var sliderObjectHolder = document.createElement('div'); | 85 var sliderObjectHolder = document.createElement('div'); |
86 sliderObjectHolder.id = 'slider-holder'; | 86 sliderObjectHolder.id = 'slider-holder'; |
87 sliderObjectHolder.align = "center"; | 87 sliderObjectHolder.align = "center"; |
88 sliderBox.appendChild(sliderObjectHolder); | 88 sliderBox.appendChild(sliderObjectHolder); |
145 feedbackHolder.appendChild(node.holder); | 145 feedbackHolder.appendChild(node.holder); |
146 }); | 146 }); |
147 | 147 |
148 // Find all the audioElements from the audioHolder | 148 // Find all the audioElements from the audioHolder |
149 var label = 0; | 149 var label = 0; |
150 var numScales = testState.currentStateMap.interfaces[0].scales.length; | 150 var interfaceScales = testState.currentStateMap.interfaces[0].scales; |
151 $(page.audioElements).each(function(index,element){ | 151 $(page.audioElements).each(function(index,element){ |
152 // Find URL of track | 152 // Find URL of track |
153 // In this jQuery loop, variable 'this' holds the current audioElement. | 153 // In this jQuery loop, variable 'this' holds the current audioElement. |
154 | 154 |
155 var audioObject = audioEngineContext.newTrack(element); | 155 var audioObject = audioEngineContext.newTrack(element); |
160 audioObject.bindInterface(orNode); | 160 audioObject.bindInterface(orNode); |
161 } else { | 161 } else { |
162 var node = interfaceContext.createCommentBox(audioObject); | 162 var node = interfaceContext.createCommentBox(audioObject); |
163 | 163 |
164 // Create a slider per track | 164 // Create a slider per track |
165 var sliderObj = new discreteObject(audioObject,label,numScales); | 165 var sliderObj = new discreteObject(audioObject,label,interfaceScales); |
166 sliderBox.appendChild(sliderObj.holder); | 166 sliderBox.appendChild(sliderObj.holder); |
167 audioObject.bindInterface(sliderObj); | 167 audioObject.bindInterface(sliderObj); |
168 label += 1; | 168 label += 1; |
169 } | 169 } |
170 | 170 |
172 | 172 |
173 // Auto-align | 173 // Auto-align |
174 resizeWindow(null); | 174 resizeWindow(null); |
175 } | 175 } |
176 | 176 |
177 function discreteObject(audioObject,label,numOptions) | 177 function discreteObject(audioObject,label,interfaceScales) |
178 { | 178 { |
179 // An example node, you can make this however you want for each audioElement. | 179 // An example node, you can make this however you want for each audioElement. |
180 // However, every audioObject (audioEngineContext.audioObject) MUST have an interface object with the following | 180 // However, every audioObject (audioEngineContext.audioObject) MUST have an interface object with the following |
181 // You attach them by calling audioObject.bindInterface( ) | 181 // You attach them by calling audioObject.bindInterface( ) |
182 if (numOptions == null || numOptions == 0) | 182 if (interfaceScales == null || interfaceScales.length == 0) |
183 { | 183 { |
184 console.log("WARNING: The discrete radio's are built depending on the number of scale points specified! Ensure you have some specified. Defaulting to 5 for now!"); | 184 console.log("WARNING: The discrete radio's are built depending on the number of scale points specified! Ensure you have some specified. Defaulting to 5 for now!"); |
185 numOptions = 5; | 185 numOptions = 5; |
186 } | 186 } |
187 this.parent = audioObject; | 187 this.parent = audioObject; |
200 this.holder.setAttribute('trackIndex',audioObject.id); | 200 this.holder.setAttribute('trackIndex',audioObject.id); |
201 this.title.textContent = label; | 201 this.title.textContent = label; |
202 this.title.className = 'track-slider-title'; | 202 this.title.className = 'track-slider-title'; |
203 | 203 |
204 this.discreteHolder.className = "track-slider-range"; | 204 this.discreteHolder.className = "track-slider-range"; |
205 this.discreteHolder.style.width = window.innerWidth-420 + 'px'; | 205 this.discreteHolder.style.width = window.innerWidth-500 + 'px'; |
206 for (var i=0; i<numOptions; i++) | 206 for (var i=0; i<interfaceScales.length; i++) |
207 { | 207 { |
208 var node = document.createElement('input'); | 208 var node = document.createElement('input'); |
209 node.setAttribute('type','radio'); | 209 node.setAttribute('type','radio'); |
210 node.className = 'track-radio'; | |
211 node.setAttribute('position',interfaceScales[i].position); | |
210 node.setAttribute('name',audioObject.specification.id); | 212 node.setAttribute('name',audioObject.specification.id); |
211 node.setAttribute('id',audioObject.specification.id+'-'+String(i)); | 213 node.setAttribute('id',audioObject.specification.id+'-'+String(i)); |
212 this.discretes.push(node); | 214 this.discretes.push(node); |
213 this.discreteHolder.appendChild(node); | 215 this.discreteHolder.appendChild(node); |
214 node.onchange = function(event) | 216 node.onclick = function(event) |
215 { | 217 { |
218 if (audioEngineContext.status == 0) | |
219 { | |
220 event.currentTarget.checked = false; | |
221 return; | |
222 } | |
216 var time = audioEngineContext.timer.getTestTime(); | 223 var time = audioEngineContext.timer.getTestTime(); |
217 var id = Number(event.currentTarget.parentNode.parentNode.getAttribute('trackIndex')); | 224 var id = Number(event.currentTarget.parentNode.parentNode.getAttribute('trackIndex')); |
218 audioEngineContext.audioObjects[id].metric.moved(time,this.value); | 225 var value = event.currentTarget.getAttribute('position') / 100.0; |
219 console.log('slider '+id+' moved to '+this.value+' ('+time+')'); | 226 audioEngineContext.audioObjects[id].metric.moved(time,value); |
227 console.log('slider '+id+' moved to '+value+' ('+time+')'); | |
220 }; | 228 }; |
221 } | 229 } |
222 | 230 |
223 this.play.className = 'track-slider-button'; | 231 this.play.className = 'track-slider-button'; |
224 this.play.textContent = "Loading..."; | 232 this.play.textContent = "Loading..."; |
237 } | 245 } |
238 }; | 246 }; |
239 this.resize = function(event) | 247 this.resize = function(event) |
240 { | 248 { |
241 this.holder.style.width = window.innerWidth-200 + 'px'; | 249 this.holder.style.width = window.innerWidth-200 + 'px'; |
242 this.discreteHolder.style.width = window.innerWidth-420 + 'px'; | 250 this.discreteHolder.style.width = window.innerWidth-500 + 'px'; |
243 | 251 //text.style.left = (posPix+150-($(text).width()/2)) +'px'; |
252 for (var i=0; i<this.discretes.length; i++) | |
253 { | |
254 var width = $(this.discreteHolder).width() - 20; | |
255 var node = this.discretes[i]; | |
256 var nodeW = $(node).width(); | |
257 var position = node.getAttribute('position'); | |
258 var posPix = Math.round(width * (position / 100.0)); | |
259 node.style.left = (posPix+10 - (nodeW/2)) + 'px'; | |
260 } | |
244 }; | 261 }; |
245 this.enable = function() | 262 this.enable = function() |
246 { | 263 { |
247 // This is used to tell the interface object that playback of this node is ready | 264 // This is used to tell the interface object that playback of this node is ready |
248 this.play.disabled = false; | 265 this.play.disabled = false; |
253 { | 270 { |
254 // progress is a value from 0 to 100 indicating the current download state of media files | 271 // progress is a value from 0 to 100 indicating the current download state of media files |
255 }; | 272 }; |
256 this.getValue = function() | 273 this.getValue = function() |
257 { | 274 { |
258 // Return the current value of the object. If there is no value, return 0 | 275 // Return the current value of the object. If there is no value, return -1 |
259 return 0; | 276 var value = -1; |
277 for (var i=0; i<this.discretes.length; i++) | |
278 { | |
279 if (this.discretes[i].checked == true) | |
280 { | |
281 value = this.discretes[i].getAttribute('position') / 100.0; | |
282 break; | |
283 } | |
284 } | |
285 return value; | |
260 }; | 286 }; |
261 this.getPresentedId = function() | 287 this.getPresentedId = function() |
262 { | 288 { |
263 // Return the presented ID of the object. For instance, the APE has sliders starting from 0. Whilst AB has alphabetical scale | 289 // Return the presented ID of the object. For instance, the APE has sliders starting from 0. Whilst AB has alphabetical scale |
264 return this.title.textContent; | 290 return this.title.textContent; |
272 this.exportXMLDOM = function(audioObject) { | 298 this.exportXMLDOM = function(audioObject) { |
273 // Called by the audioObject holding this element to export the interface <value> node. | 299 // Called by the audioObject holding this element to export the interface <value> node. |
274 // If there is no value node (such as outside reference), return null | 300 // If there is no value node (such as outside reference), return null |
275 // If there are multiple value nodes (such as multiple scale / 2D scales), return an array of nodes with each value node having an 'interfaceName' attribute | 301 // If there are multiple value nodes (such as multiple scale / 2D scales), return an array of nodes with each value node having an 'interfaceName' attribute |
276 // Use storage.document.createElement('value'); to generate the XML node. | 302 // Use storage.document.createElement('value'); to generate the XML node. |
277 | 303 var node = storage.document.createElement('value'); |
304 node.textContent = this.getValue(); | |
305 return node; | |
278 }; | 306 }; |
279 }; | 307 }; |
280 | 308 |
281 function resizeWindow(event) | 309 function resizeWindow(event) |
282 { | 310 { |
284 | 312 |
285 var numObj = document.getElementsByClassName('track-slider').length; | 313 var numObj = document.getElementsByClassName('track-slider').length; |
286 var totalHeight = (numObj * 66)-30; | 314 var totalHeight = (numObj * 66)-30; |
287 document.getElementById('scale-holder').style.width = window.innerWidth-220 + 'px'; | 315 document.getElementById('scale-holder').style.width = window.innerWidth-220 + 'px'; |
288 var canvas = document.getElementById('scale-canvas'); | 316 var canvas = document.getElementById('scale-canvas'); |
289 canvas.width = window.innerWidth-420; | 317 canvas.width = window.innerWidth-520; |
290 canvas.height = totalHeight; | 318 canvas.height = totalHeight; |
291 for (var i in audioEngineContext.audioObjects) | 319 for (var i in audioEngineContext.audioObjects) |
292 { | 320 { |
293 if (audioEngineContext.audioObjects[i].specification.type != 'outside-reference'){ | 321 if (audioEngineContext.audioObjects[i].specification.type != 'outside-reference'){ |
294 audioEngineContext.audioObjects[i].interfaceDOM.resize(event); | 322 audioEngineContext.audioObjects[i].interfaceDOM.resize(event); |
327 var textC = document.createElement('span'); | 355 var textC = document.createElement('span'); |
328 textC.textContent = scale.text; | 356 textC.textContent = scale.text; |
329 text.appendChild(textC); | 357 text.appendChild(textC); |
330 text.className = "scale-text"; | 358 text.className = "scale-text"; |
331 textHolder.appendChild(text); | 359 textHolder.appendChild(text); |
332 text.style.width = Math.ceil($(text).width())+'px'; | 360 text.style.width = $(text.children[0]).width()+'px'; |
333 text.style.left = (posPix+100-($(text).width()/2)) +'px'; | 361 text.style.left = (posPix+150-($(text).width()/2)) +'px'; |
334 } | 362 } |
335 } | 363 } |
336 | 364 |
337 function buttonSubmitClick() // TODO: Only when all songs have been played! | 365 function buttonSubmitClick() // TODO: Only when all songs have been played! |
338 { | 366 { |