Mercurial > hg > webaudioevaluationtool
comparison interfaces/timeline.js @ 2702:28e179d4fb9a
JSHinted timeline.js
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Mon, 13 Mar 2017 11:48:44 +0000 |
parents | 22efb2d04bc9 |
children | a684dc7a5327 |
comparison
equal
deleted
inserted
replaced
2701:d29471d114cf | 2702:28e179d4fb9a |
---|---|
1 /** | 1 /** |
2 * WAET Timeline | 2 * WAET Timeline |
3 * This interface plots a waveform timeline per audio fragment on a page. Clicking on the fragment will generate a comment box for processing. | 3 * This interface plots a waveform timeline per audio fragment on a page. Clicking on the fragment will generate a comment box for processing. |
4 */ | 4 */ |
5 | 5 /*globals interfaceContext, window, document, console, audioEngineContext, testState, $, storage */ |
6 // Once this is loaded and parsed, begin execution | 6 // Once this is loaded and parsed, begin execution |
7 loadInterface(); | 7 loadInterface(); |
8 | 8 |
9 function loadInterface() { | 9 function loadInterface() { |
10 // Use this to do any one-time page / element construction. For instance, placing any stationary text objects, | 10 // Use this to do any one-time page / element construction. For instance, placing any stationary text objects, |
75 interfaceContext.insertPoint.appendChild(testContent); | 75 interfaceContext.insertPoint.appendChild(testContent); |
76 | 76 |
77 // Load the full interface | 77 // Load the full interface |
78 testState.initialise(); | 78 testState.initialise(); |
79 testState.advanceState(); | 79 testState.advanceState(); |
80 }; | 80 } |
81 | 81 |
82 function loadTest(page) { | 82 function loadTest(page) { |
83 // Called each time a new test page is to be build. The page specification node is the only item passed in | 83 // Called each time a new test page is to be build. The page specification node is the only item passed in |
84 var content = document.getElementById("timeline-test-content"); | 84 var content = document.getElementById("timeline-test-content"); |
85 content.innerHTML = ""; | 85 content.innerHTML = ""; |
92 //Set the page title | 92 //Set the page title |
93 if (typeof page.title == "string" && page.title.length > 0) { | 93 if (typeof page.title == "string" && page.title.length > 0) { |
94 document.getElementById("test-title").textContent = page.title; | 94 document.getElementById("test-title").textContent = page.title; |
95 } | 95 } |
96 | 96 |
97 if (interfaceObj.title != null) { | 97 if (interfaceObj.title !== null) { |
98 document.getElementById("page-title").textContent = interfaceObj.title; | 98 document.getElementById("page-title").textContent = interfaceObj.title; |
99 } | 99 } |
100 | 100 |
101 // Delete outside reference | 101 // Delete outside reference |
102 var outsideReferenceHolder = document.getElementById("outside-reference-holder"); | 102 var outsideReferenceHolder = document.getElementById("outside-reference-holder"); |
103 outsideReferenceHolder.innerHTML = ""; | 103 outsideReferenceHolder.innerHTML = ""; |
104 | 104 |
105 var commentBoxPrefix = "Comment on track"; | 105 var commentBoxPrefix = "Comment on track"; |
106 if (interfaceObj.commentBoxPrefix != undefined) { | 106 if (interfaceObj.commentBoxPrefix !== undefined) { |
107 commentBoxPrefix = interfaceObj.commentBoxPrefix; | 107 commentBoxPrefix = interfaceObj.commentBoxPrefix; |
108 } | 108 } |
109 var index = 0; | 109 var index = 0; |
110 var interfaceScales = testState.currentStateMap.interfaces[0].scales; | 110 var interfaceScales = testState.currentStateMap.interfaces[0].scales; |
111 var labelType = page.label; | 111 var labelType = page.label; |
114 } | 114 } |
115 $(page.audioElements).each(function (pageIndex, element) { | 115 $(page.audioElements).each(function (pageIndex, element) { |
116 var audioObject = audioEngineContext.newTrack(element); | 116 var audioObject = audioEngineContext.newTrack(element); |
117 if (page.audioElements.type == 'outside-reference') { | 117 if (page.audioElements.type == 'outside-reference') { |
118 var refNode = interfaceContext.outsideReferenceDOM(audioObject, index, outsideReferenceHolder); | 118 var refNode = interfaceContext.outsideReferenceDOM(audioObject, index, outsideReferenceHolder); |
119 audioObject.bindInterface(orNode); | 119 audioObject.bindInterface(refNode); |
120 } else { | 120 } else { |
121 var label = interfaceContext.getLabel(labelType, index, page.labelStart); | 121 var label = interfaceContext.getLabel(labelType, index, page.labelStart); |
122 var node = new interfaceObject(audioObject, label); | 122 var node = new interfaceObject(audioObject, label); |
123 | 123 |
124 content.appendChild(node.DOM); | 124 content.appendChild(node.DOM); |
167 this.DOM = document.createElement("div"); | 167 this.DOM = document.createElement("div"); |
168 this.DOM.className = "comment-entry"; | 168 this.DOM.className = "comment-entry"; |
169 var titleHolder = document.createElement("div"); | 169 var titleHolder = document.createElement("div"); |
170 titleHolder.className = "comment-entry-header"; | 170 titleHolder.className = "comment-entry-header"; |
171 this.title = document.createElement("span"); | 171 this.title = document.createElement("span"); |
172 if (str != undefined) { | 172 if (str !== undefined) { |
173 this.title.textContent = str; | 173 this.title.textContent = str; |
174 } else { | 174 } else { |
175 this.title.textContent = "Time: " + time.toFixed(2) + "s"; | 175 this.title.textContent = "Time: " + time.toFixed(2) + "s"; |
176 } | 176 } |
177 titleHolder.appendChild(this.title); | 177 titleHolder.appendChild(this.title); |
184 DOM: document.createElement("button"), | 184 DOM: document.createElement("button"), |
185 parent: this, | 185 parent: this, |
186 handleEvent: function () { | 186 handleEvent: function () { |
187 this.parent.parent.deleteComment(this.parent); | 187 this.parent.parent.deleteComment(this.parent); |
188 } | 188 } |
189 } | 189 }; |
190 this.clear.DOM.textContent = "Delete"; | 190 this.clear.DOM.textContent = "Delete"; |
191 this.clear.DOM.addEventListener("click", this.clear); | 191 this.clear.DOM.addEventListener("click", this.clear); |
192 titleHolder.appendChild(this.clear.DOM); | 192 titleHolder.appendChild(this.clear.DOM); |
193 | 193 |
194 this.resize = function () { | 194 this.resize = function () { |
197 w = Math.max(w, 200); | 197 w = Math.max(w, 200); |
198 var elem_w = w / 2.5; | 198 var elem_w = w / 2.5; |
199 elem_w = Math.max(elem_w, 190); | 199 elem_w = Math.max(elem_w, 190); |
200 this.DOM.style.width = elem_w + "px"; | 200 this.DOM.style.width = elem_w + "px"; |
201 this.textarea.style.width = (elem_w - 5) + "px"; | 201 this.textarea.style.width = (elem_w - 5) + "px"; |
202 } | 202 }; |
203 this.buildXML = function (root) { | 203 this.buildXML = function (root) { |
204 //storage.document.createElement(); | 204 //storage.document.createElement(); |
205 var node = storage.document.createElement("comment"); | 205 var node = storage.document.createElement("comment"); |
206 var question = storage.document.createElement("question"); | 206 var question = storage.document.createElement("question"); |
207 var comment = storage.document.createElement("response"); | 207 var comment = storage.document.createElement("response"); |
209 question.textContent = this.title.textContent; | 209 question.textContent = this.title.textContent; |
210 comment.textContent = this.textarea.value; | 210 comment.textContent = this.textarea.value; |
211 node.appendChild(question); | 211 node.appendChild(question); |
212 node.appendChild(comment); | 212 node.appendChild(comment); |
213 root.appendChild(node); | 213 root.appendChild(node); |
214 } | 214 }; |
215 this.resize(); | 215 this.resize(); |
216 }, | 216 }, |
217 newComment: function (time) { | 217 newComment: function (time) { |
218 var node = new this.Comment(this, time); | 218 var node = new this.Comment(this, time); |
219 this.list.push(node); | 219 this.list.push(node); |
238 clearList: function () { | 238 clearList: function () { |
239 while (this.list.length > 0) { | 239 while (this.list.length > 0) { |
240 this.deleteComment(this.list[0]); | 240 this.deleteComment(this.list[0]); |
241 } | 241 } |
242 } | 242 } |
243 } | 243 }; |
244 | 244 |
245 this.canvas = { | 245 this.canvas = { |
246 parent: this, | 246 parent: this, |
247 comments: this.comments, | 247 comments: this.comments, |
248 layer1: document.createElement("canvas"), | 248 layer1: document.createElement("canvas"), |
281 } | 281 } |
282 break; | 282 break; |
283 } | 283 } |
284 }, | 284 }, |
285 drawWaveform: function () { | 285 drawWaveform: function () { |
286 if (this.parent.parent == undefined || this.parent.parent.buffer == undefined) { | 286 if (this.parent.parent === undefined || this.parent.parent.buffer === undefined) { |
287 return; | 287 return; |
288 } | 288 } |
289 var buffer = this.parent.parent.buffer.buffer; | 289 var buffer = this.parent.parent.buffer.buffer; |
290 var context = this.layer4.getContext("2d"); | 290 var context = this.layer4.getContext("2d"); |
291 context.lineWidth = 1; | 291 context.lineWidth = 1; |
340 context.moveTo(pixX, 0); | 340 context.moveTo(pixX, 0); |
341 context.lineTo(pixX, this.layer2.height); | 341 context.lineTo(pixX, this.layer2.height); |
342 context.stroke(); | 342 context.stroke(); |
343 }, | 343 }, |
344 drawMarkers: function () { | 344 drawMarkers: function () { |
345 if (this.parent.parent == undefined || this.parent.parent.buffer == undefined) { | 345 if (this.parent.parent === undefined || this.parent.parent.buffer === undefined) { |
346 return; | 346 return; |
347 } | 347 } |
348 var context = this.layer3.getContext("2d"); | 348 var context = this.layer3.getContext("2d"); |
349 context.clearRect(0, 0, this.layer3.width, this.layer3.height); | 349 context.clearRect(0, 0, this.layer3.width, this.layer3.height); |
350 context.strokeStyle = "#008"; | 350 context.strokeStyle = "#008"; |
360 }, | 360 }, |
361 clearCanvas: function (canvas) { | 361 clearCanvas: function (canvas) { |
362 var context = canvas.getContext("2d"); | 362 var context = canvas.getContext("2d"); |
363 context.clearRect(0, 0, canvas.width, canvas.height); | 363 context.clearRect(0, 0, canvas.width, canvas.height); |
364 } | 364 } |
365 } | 365 }; |
366 this.canvas.layer1.className = "timeline-element-canvas canvas-layer1 canvas-disabled"; | 366 this.canvas.layer1.className = "timeline-element-canvas canvas-layer1 canvas-disabled"; |
367 this.canvas.layer2.className = "timeline-element-canvas canvas-layer2"; | 367 this.canvas.layer2.className = "timeline-element-canvas canvas-layer2"; |
368 this.canvas.layer3.className = "timeline-element-canvas canvas-layer3"; | 368 this.canvas.layer3.className = "timeline-element-canvas canvas-layer3"; |
369 this.canvas.layer4.className = "timeline-element-canvas canvas-layer3"; | 369 this.canvas.layer4.className = "timeline-element-canvas canvas-layer3"; |
370 this.canvas.layer1.height = "150"; | 370 this.canvas.layer1.height = "150"; |
391 audioEngineContext.play(id); | 391 audioEngineContext.play(id); |
392 } else if (str == "Stop") { | 392 } else if (str == "Stop") { |
393 audioEngineContext.stop(); | 393 audioEngineContext.stop(); |
394 } | 394 } |
395 } | 395 } |
396 } | 396 }; |
397 this.playButton.DOM.addEventListener("click", this.playButton); | 397 this.playButton.DOM.addEventListener("click", this.playButton); |
398 this.playButton.DOM.className = "timeline-button timeline-button-disabled"; | 398 this.playButton.DOM.className = "timeline-button timeline-button-disabled"; |
399 this.playButton.DOM.disabled = true; | 399 this.playButton.DOM.disabled = true; |
400 this.playButton.DOM.textContent = "Wait"; | 400 this.playButton.DOM.textContent = "Wait"; |
401 | 401 |
406 w = Math.min(w, 800); | 406 w = Math.min(w, 800); |
407 w = Math.max(w, 200); | 407 w = Math.max(w, 200); |
408 root.style.width = w + "px"; | 408 root.style.width = w + "px"; |
409 var c_w = w - 100; | 409 var c_w = w - 100; |
410 this.canvas.resize(c_w); | 410 this.canvas.resize(c_w); |
411 } | 411 }; |
412 | 412 |
413 this.enable = function () { | 413 this.enable = function () { |
414 // This is used to tell the interface object that playback of this node is ready | 414 // This is used to tell the interface object that playback of this node is ready |
415 this.canvas.layer1.addEventListener("click", this.canvas); | 415 this.canvas.layer1.addEventListener("click", this.canvas); |
416 this.canvas.layer1.className = "timeline-element-canvas canvas-layer1"; | 416 this.canvas.layer1.className = "timeline-element-canvas canvas-layer1"; |
457 // Use storage.document.createElement('value'); to generate the XML node. | 457 // Use storage.document.createElement('value'); to generate the XML node. |
458 return null; | 458 return null; |
459 }; | 459 }; |
460 this.error = function () { | 460 this.error = function () { |
461 // If there is an error with the audioObject, this will be called to indicate a failure | 461 // If there is an error with the audioObject, this will be called to indicate a failure |
462 } | 462 }; |
463 }; | 463 } |
464 | 464 |
465 function resizeWindow(event) { | 465 function resizeWindow(event) { |
466 // Called on every window resize event, use this to scale your page properly | 466 // Called on every window resize event, use this to scale your page properly |
467 for (var i = 0; i < audioEngineContext.audioObjects.length; i++) { | 467 for (var i = 0; i < audioEngineContext.audioObjects.length; i++) { |
468 audioEngineContext.audioObjects[i].interfaceDOM.resize(); | 468 audioEngineContext.audioObjects[i].interfaceDOM.resize(); |
469 } | 469 } |
470 } | 470 } |
471 | 471 |
472 function buttonSubmitClick() { | 472 function buttonSubmitClick() { |
473 if (audioEngineContext.timer.testStarted == false) { | 473 if (audioEngineContext.timer.testStarted === false) { |
474 interfaceContext.lightbox.post("Warning", 'You have not started the test! Please click play on a sample to begin the test!'); | 474 interfaceContext.lightbox.post("Warning", 'You have not started the test! Please click play on a sample to begin the test!'); |
475 return; | 475 return; |
476 } | 476 } |
477 var checks = testState.currentStateMap.interfaces[0], | 477 var checks = testState.currentStateMap.interfaces[0], |
478 canContinue = true; | 478 canContinue = true; |
493 break; | 493 break; |
494 default: | 494 default: |
495 console.log("WARNING - Check option " + checks[i].check + " is not supported on this interface"); | 495 console.log("WARNING - Check option " + checks[i].check + " is not supported on this interface"); |
496 break; | 496 break; |
497 } | 497 } |
498 if (checkState == false) { | 498 if (checkState === false) { |
499 canContinue = false; | 499 canContinue = false; |
500 } | 500 } |
501 } | 501 } |
502 if (!canContinue) { | 502 if (!canContinue) { |
503 return; | 503 return; |