Mercurial > hg > webaudioevaluationtool
comparison interfaces/timeline.js @ 2480:713a2d059a16
Completed waveform/timeline interface. Need to add in checks
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Thu, 04 Aug 2016 11:34:29 +0100 |
parents | dbe43b4ab7aa |
children | 3c92c732fb05 |
comparison
equal
deleted
inserted
replaced
2479:dbe43b4ab7aa | 2480:713a2d059a16 |
---|---|
175 list: [], | 175 list: [], |
176 Comment: function(parent,time, str) { | 176 Comment: function(parent,time, str) { |
177 this.parent = parent; | 177 this.parent = parent; |
178 this.time = time; | 178 this.time = time; |
179 this.DOM = document.createElement("div"); | 179 this.DOM = document.createElement("div"); |
180 this.DOM.className = "comment-div"; | 180 this.DOM.className = "comment-entry"; |
181 var titleHolder = document.createElement("div"); | |
182 titleHolder.className = "comment-entry-header"; | |
181 this.title = document.createElement("span"); | 183 this.title = document.createElement("span"); |
182 if (str != undefined) { | 184 if (str != undefined) { |
183 this.title.textContent = str; | 185 this.title.textContent = str; |
184 } else { | 186 } else { |
185 this.title.textContent = "Time: "+time.toFixed(2)+"s"; | 187 this.title.textContent = "Time: "+time.toFixed(2)+"s"; |
186 } | 188 } |
189 titleHolder.appendChild(this.title); | |
187 this.textarea = document.createElement("textarea"); | 190 this.textarea = document.createElement("textarea"); |
188 this.textarea.className = "trackComment"; | 191 this.textarea.className = "comment-entry-text"; |
189 this.DOM.appendChild(this.title); | 192 this.DOM.appendChild(titleHolder); |
190 this.DOM.appendChild(document.createElement("br")); | |
191 this.DOM.appendChild(this.textarea); | 193 this.DOM.appendChild(this.textarea); |
194 | |
195 this.clear = { | |
196 DOM: document.createElement("button"), | |
197 parent: this, | |
198 handleEvent: function() { | |
199 this.parent.parent.deleteComment(this.parent); | |
200 } | |
201 } | |
202 this.clear.DOM.textContent = "Delete"; | |
203 this.clear.DOM.addEventListener("click",this.clear); | |
204 titleHolder.appendChild(this.clear.DOM); | |
205 | |
192 this.resize = function() { | 206 this.resize = function() { |
193 var w = window.innerWidth; | 207 var w = window.innerWidth; |
194 w = Math.min(w,800); | 208 w = Math.min(w,800); |
195 w = Math.max(w,200); | 209 w = Math.max(w,200); |
196 var elem_w = w / 2.5; | 210 var elem_w = w / 2.5; |
197 elem_w = Math.max(elem_w,190); | 211 elem_w = Math.max(elem_w,190); |
198 this.DOM.style.width = elem_w+"px"; | 212 this.DOM.style.width = elem_w+"px"; |
199 this.textarea.style.width = (elem_w-5)+"px"; | 213 this.textarea.style.width = (elem_w-5)+"px"; |
200 } | 214 } |
215 this.buildXML = function(root) { | |
216 //storage.document.createElement(); | |
217 var node = storage.document.createElement("comment"); | |
218 var question = storage.document.createElement("question"); | |
219 var comment = storage.document.createElement("response"); | |
220 node.setAttribute("time",this.time); | |
221 question.textContent = this.title.textContent; | |
222 comment.textContent = this.textarea.value; | |
223 node.appendChild(question); | |
224 node.appendChild(comment); | |
225 root.appendChild(node); | |
226 } | |
201 this.resize(); | 227 this.resize(); |
202 }, | 228 }, |
203 newComment: function(time) { | 229 newComment: function(time) { |
204 var node = new this.Comment(this,time); | 230 var node = new this.Comment(this,time); |
205 this.list.push(node); | 231 this.list.push(node); |
206 commentHolder.appendChild(node.DOM); | 232 commentHolder.appendChild(node.DOM); |
207 return node; | 233 return node; |
208 }, | 234 }, |
209 deleteComment: function(comment) { | 235 deleteComment: function(comment) { |
210 | 236 var index = this.list.findIndex(function(element,index,array){ |
237 if (element == comment) {return true;} return false; | |
238 },comment); | |
239 if (index == -1) { | |
240 return false; | |
241 } | |
242 var node = this.list.splice(index,1); | |
243 comment.DOM.remove(); | |
244 this.parent.canvas.drawMarkers(); | |
245 return true; | |
211 }, | 246 }, |
212 clearList: function() { | 247 clearList: function() { |
213 | 248 while(this.list.length > 0) { |
249 this.deleteComment(this.list[0]); | |
250 } | |
214 } | 251 } |
215 } | 252 } |
216 | 253 |
217 this.canvas = { | 254 this.canvas = { |
218 parent: this, | 255 parent: this, |
228 this.layer4.width = w; | 265 this.layer4.width = w; |
229 this.layer1.style.width = w+"px"; | 266 this.layer1.style.width = w+"px"; |
230 this.layer2.style.width = w+"px"; | 267 this.layer2.style.width = w+"px"; |
231 this.layer3.style.width = w+"px"; | 268 this.layer3.style.width = w+"px"; |
232 this.layer4.style.width = w+"px"; | 269 this.layer4.style.width = w+"px"; |
270 this.drawWaveform(); | |
271 this.drawMarkers(); | |
233 }, | 272 }, |
234 handleEvent: function(event) { | 273 handleEvent: function(event) { |
235 switch(event.currentTarget) { | 274 switch(event.currentTarget) { |
236 case this.layer1: | 275 case this.layer1: |
237 switch(event.type) { | 276 switch(event.type) { |
251 } | 290 } |
252 break; | 291 break; |
253 } | 292 } |
254 }, | 293 }, |
255 drawWaveform: function() { | 294 drawWaveform: function() { |
295 if (this.parent.parent == undefined || this.parent.parent.buffer == undefined) { | |
296 return; | |
297 } | |
256 var buffer = this.parent.parent.buffer.buffer; | 298 var buffer = this.parent.parent.buffer.buffer; |
257 var context = this.layer4.getContext("2d"); | 299 var context = this.layer4.getContext("2d"); |
258 context.lineWidth = 1; | 300 context.lineWidth = 1; |
259 context.strokeStyle = "#888"; | 301 context.strokeStyle = "#888"; |
260 context.clearRect(0,0,this.layer4.width, this.layer4.height); | 302 context.clearRect(0,0,this.layer4.width, this.layer4.height); |
303 context.moveTo(pixX,0); | 345 context.moveTo(pixX,0); |
304 context.lineTo(pixX,this.layer2.height); | 346 context.lineTo(pixX,this.layer2.height); |
305 context.stroke(); | 347 context.stroke(); |
306 }, | 348 }, |
307 drawMarkers: function() { | 349 drawMarkers: function() { |
350 if (this.parent.parent == undefined || this.parent.parent.buffer == undefined) { | |
351 return; | |
352 } | |
308 var context = this.layer3.getContext("2d"); | 353 var context = this.layer3.getContext("2d"); |
309 context.clearRect(0,0,this.layer3.width, this.layer3.height); | 354 context.clearRect(0,0,this.layer3.width, this.layer3.height); |
310 context.strokeStyle = "#008"; | 355 context.strokeStyle = "#008"; |
311 var tpp = this.parent.parent.buffer.buffer.duration/this.layer1.width; | 356 var tpp = this.parent.parent.buffer.buffer.duration/this.layer1.width; |
312 for (var i=0; i<this.comments.list.length; i++) { | 357 for (var i=0; i<this.comments.list.length; i++) { |
357 this.playButton.DOM.addEventListener("click",this.playButton); | 402 this.playButton.DOM.addEventListener("click",this.playButton); |
358 this.playButton.DOM.className = "timeline-button timeline-button-disabled"; | 403 this.playButton.DOM.className = "timeline-button timeline-button-disabled"; |
359 this.playButton.DOM.disabled = true; | 404 this.playButton.DOM.disabled = true; |
360 this.playButton.DOM.textContent = "Wait"; | 405 this.playButton.DOM.textContent = "Wait"; |
361 | 406 |
362 this.clearButton = { | |
363 parent: this, | |
364 DOM: document.createElement("button"), | |
365 handleEvent: function(event) { | |
366 this.parent.comments.clearList(); | |
367 } | |
368 } | |
369 this.clearButton.DOM.addEventListener("click",this.clearButton); | |
370 this.clearButton.DOM.className = "timeline-button"; | |
371 this.clearButton.DOM.textContent = "Clear"; | |
372 | |
373 | |
374 buttonHolder.appendChild(this.playButton.DOM); | 407 buttonHolder.appendChild(this.playButton.DOM); |
375 buttonHolder.appendChild(this.clearButton.DOM); | |
376 | 408 |
377 this.resize = function() { | 409 this.resize = function() { |
378 var w = window.innerWidth; | 410 var w = window.innerWidth; |
379 w = Math.min(w,800); | 411 w = Math.min(w,800); |
380 w = Math.max(w,200); | 412 w = Math.max(w,200); |
450 } | 482 } |
451 } | 483 } |
452 | 484 |
453 function buttonSubmitClick() | 485 function buttonSubmitClick() |
454 { | 486 { |
487 testState.advanceState(); | |
455 } | 488 } |
456 | 489 |
457 function pageXMLSave(store, pageSpecification) | 490 function pageXMLSave(store, pageSpecification) |
458 { | 491 { |
459 // MANDATORY | 492 // MANDATORY |
460 // Saves a specific test page | 493 // Saves a specific test page |
461 // You can use this space to add any extra nodes to your XML <audioHolder> saves | 494 // You can use this space to add any extra nodes to your XML <audioHolder> saves |
462 // Get the current <page> information in store (remember to appendChild your data to it) | 495 // Get the current <page> information in store (remember to appendChild your data to it) |
463 // pageSpecification is the current page node configuration | 496 // pageSpecification is the current page node configuration |
464 // To create new XML nodes, use storage.document.createElement(); | 497 // To create new XML nodes, use storage.document.createElement(); |
498 | |
499 for (var i=0; i<audioEngineContext.audioObjects.length; i++) { | |
500 var id = audioEngineContext.audioObjects[i].specification.id; | |
501 var commentsList = audioEngineContext.audioObjects[i].interfaceDOM.comments.list; | |
502 var root = audioEngineContext.audioObjects[i].storeDOM; | |
503 for (var j=0; j<commentsList.length; j++) { | |
504 commentsList[j].buildXML(root); | |
505 } | |
506 } | |
465 } | 507 } |