changeset 496:cb348f6208b2 Dev_main

All interfaces support comment boxes. Comment box identification matches presented tag (for instance, AB will be Comment on fragment A, rather than 1). Tighter buffer loading protocol, audioObjects register with the buffer rather than checking for buffer existence (which can be buggy depending on the buffer state). Buffers now have a state to ensure exact location in loading chain (downloading, decoding, LUFS, ready).
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Fri, 29 Jan 2016 11:11:57 +0000
parents 305742b40ddc
children da8b22838465
files core.js interfaces/AB.js interfaces/ape.js interfaces/discrete.js interfaces/horizontal-sliders.js interfaces/mushra.js
diffstat 6 files changed, 69 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/core.js	Wed Jan 27 14:51:38 2016 +0000
+++ b/core.js	Fri Jan 29 11:11:57 2016 +0000
@@ -950,8 +950,14 @@
 		this.xmlRequest = new XMLHttpRequest();
 		this.xmlRequest.parent = this;
 		this.users = [];
+        this.progress = 0;
+        this.status = 0;
 		this.ready = function()
 		{
+            if (this.status >= 2)
+            {
+                this.status = 3;
+            }
 			for (var i=0; i<this.users.length; i++)
 			{
 				this.users[i].state = 1;
@@ -983,6 +989,7 @@
                             buffer_ptr[n] = waveObj.decoded_data[c][n];
                         }
                     }
+                    
                     delete waveObj;
                 } else {
                     audioContext.decodeAudioData(bufferObj.xmlRequest.response, function(decodedData) {
@@ -999,11 +1006,13 @@
                                 console.log('URL: '+audioObj.url);
                                 errorSessionDump('Fragment '+audioObj.id+' 404 error');
                             }
+                            this.status = -1;
                         }
                     });
                 }
                 if (bufferObj.buffer != undefined)
                 {
+                    bufferObj.status = 2;
                     calculateLoudness(bufferObj,"I");
                 }
 			};
@@ -1025,8 +1034,25 @@
 				}
 			};
 			this.xmlRequest.addEventListener("progress", this.progressCallback);
+            this.status = 1;
 			this.xmlRequest.send();
 		};
+        
+        this.registerAudioObject = function(audioObject)
+        {
+            // Called by an audioObject to register to the buffer for use
+            // First check if already in the register pool
+            for (var objects of this.users)
+            {
+                if (audioObject.id == objects.id){return 0;}
+            }
+            this.users.push(audioObject);
+            if (this.status == 3)
+            {
+                // The buffer is already ready, trigger bufferLoaded
+                audioObject.bufferLoaded(this);
+            }
+        }
 	};
 	
 	this.play = function(id) {
@@ -1114,12 +1140,11 @@
 		{
 			console.log("[WARN]: Buffer was not loaded in pre-test! "+URL);
 			buffer = new this.bufferObj();
+            this.buffers.push(buffer);
 			buffer.getMedia(URL);
-			this.buffers.push(buffer);
 		}
 		this.audioObjects[audioObjectId].specification = element;
 		this.audioObjects[audioObjectId].url = URL;
-		buffer.users.push(this.audioObjects[audioObjectId]);
 		// Obtain store node
 		var aeNodes = this.pageStore.XMLDOM.getElementsByTagName('audioelement');
 		for (var i=0; i<aeNodes.length; i++)
@@ -1130,10 +1155,7 @@
 				break;
 			}
 		}
-		if (buffer.buffer.lufs != undefined)
-		{
-			this.audioObjects[audioObjectId].bufferLoaded(buffer);
-		}
+        buffer.registerAudioObject(this.audioObjects[audioObjectId]);
 		return this.audioObjects[audioObjectId];
 	};
 	
@@ -2351,7 +2373,7 @@
 		this.trackComment.id = 'comment-div-'+audioObject.id;
 		// Create a string next to each comment asking for a comment
 		this.trackString = document.createElement('span');
-		this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.id;
+		this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.interfaceDOM.getPresentedId();
 		// Create the HTML5 comment box 'textarea'
 		this.trackCommentBox = document.createElement('textarea');
 		this.trackCommentBox.rows = '4';
--- a/interfaces/AB.js	Wed Jan 27 14:51:38 2016 +0000
+++ b/interfaces/AB.js	Fri Jan 29 11:11:57 2016 +0000
@@ -150,6 +150,18 @@
 	
 	// Populate the comparitor object
 	interfaceContext.comparitor = new Comparitor(audioHolderObject);
+    if (audioHolderObject.showElementComments)
+    {
+        var commentHolder = document.createElement('div');
+        commentHolder.id = 'commentHolder';
+        document.getElementById('testContent').appendChild(commentHolder);
+        // Generate one comment box per presented page
+        for (var element of audioEngineContext.audioObjects)
+        {
+            interfaceContext.createCommentBox(element);
+        }
+        interfaceContext.showCommentBoxes(commentHolder,true);
+    }
 	resizeWindow(null);
 }
 
--- a/interfaces/ape.js	Wed Jan 27 14:51:38 2016 +0000
+++ b/interfaces/ape.js	Fri Jan 29 11:11:57 2016 +0000
@@ -353,10 +353,10 @@
 			var orNode = new outsideReferenceDOM(audioObject,index,document.getElementById('interface-buttons'));
 			audioObject.bindInterface(orNode);
 		} else {
-			var node = interfaceContext.createCommentBox(audioObject);
 			// Create a slider per track
 			var sliderNode = new sliderObject(audioObject,interfaceObj);
 			audioObject.bindInterface(sliderNode);
+            interfaceContext.createCommentBox(audioObject);
 		}
 	});
 	
--- a/interfaces/discrete.js	Wed Jan 27 14:51:38 2016 +0000
+++ b/interfaces/discrete.js	Fri Jan 29 11:11:57 2016 +0000
@@ -197,17 +197,21 @@
 			var orNode = new outsideReferenceDOM(audioObject,index,document.getElementById('interface-buttons'));
 			audioObject.bindInterface(orNode);
 		} else {
-			var node = interfaceContext.createCommentBox(audioObject);
-		
 			// Create a slider per track
 			var sliderObj = new discreteObject(audioObject,label,interfaceScales);
 			sliderBox.appendChild(sliderObj.holder);
 			audioObject.bindInterface(sliderObj);
+            interfaceContext.createCommentBox(audioObject);
 			label += 1;
 		}
         
 	});
 	
+    if (page.showElementComments)
+    {
+        interfaceContext.showCommentBoxes(feedbackHolder,true);
+    }
+    
 	// Auto-align
 	resizeWindow(null);
 }
@@ -246,6 +250,7 @@
 		var node = document.createElement('input');
 		node.setAttribute('type','radio');
 		node.className = 'track-radio';
+        node.disabled = true;
 		node.setAttribute('position',interfaceScales[i].position);
 		node.setAttribute('name',audioObject.specification.id);
 		node.setAttribute('id',audioObject.specification.id+'-'+String(i));
@@ -297,10 +302,22 @@
 		this.play.disabled = false;
 		this.play.textContent = "Play";
 		$(this.slider).removeClass('track-slider-disabled');
+        for (var radio of this.discretes)
+        {
+            radio.disabled = false;
+        }
 	};
 	this.updateLoading = function(progress)
 	{
 		// progress is a value from 0 to 100 indicating the current download state of media files
+        if (progress != 100)
+        {
+            progress = String(progress);
+            progress = progress.split('.')[0];
+            this.play.textContent = progress+'%';
+        } else {
+            this.play.textContent = "Play";
+        }
 	};
     
     this.startPlayback = function()
@@ -309,6 +326,7 @@
         $(".track-slider").removeClass('track-slider-playing');
 		$(this.holder).addClass('track-slider-playing');
 		var outsideReference = document.getElementById('outside-reference');
+        this.play.textContent = "Listening";
 		if (outsideReference != null) {
 			$(outsideReference).removeClass('track-slider-playing');
 		}
@@ -317,6 +335,7 @@
     {
         // Called by audioObject when playback stops
         $(this.holder).removeClass('track-slider-playing');
+        this.play.textContent = "Play";
     }
     
 	this.getValue = function()
--- a/interfaces/horizontal-sliders.js	Wed Jan 27 14:51:38 2016 +0000
+++ b/interfaces/horizontal-sliders.js	Fri Jan 29 11:11:57 2016 +0000
@@ -197,8 +197,6 @@
 			var orNode = new outsideReferenceDOM(audioObject,index,document.getElementById('interface-buttons'));
 			audioObject.bindInterface(orNode);
 		} else {
-			var node = interfaceContext.createCommentBox(audioObject);
-		
 			// Create a slider per track
 			var sliderObj = new sliderObject(audioObject,label);
 			
@@ -212,11 +210,15 @@
 			}
 			sliderBox.appendChild(sliderObj.holder);
 			audioObject.bindInterface(sliderObj);
+            interfaceContext.createCommentBox(audioObject);
 			label += 1;
 		}
         
 	});
-	
+	if (page.showElementComments)
+    {
+        interfaceContext.showCommentBoxes(feedbackHolder,true);
+    }
 	// Auto-align
 	resizeWindow(null);
 }
--- a/interfaces/mushra.js	Wed Jan 27 14:51:38 2016 +0000
+++ b/interfaces/mushra.js	Fri Jan 29 11:11:57 2016 +0000
@@ -200,8 +200,6 @@
 			var orNode = new outsideReferenceDOM(audioObject,index,document.getElementById('interface-buttons'));
 			audioObject.bindInterface(orNode);
 		} else {
-			var node = interfaceContext.createCommentBox(audioObject);
-		
 			// Create a slider per track
 			var sliderObj = new sliderObject(audioObject,label);
 			
@@ -215,6 +213,7 @@
 			}
 			sliderBox.appendChild(sliderObj.holder);
 			audioObject.bindInterface(sliderObj);
+            interfaceContext.createCommentBox(audioObject);
 			label += 1;
 		}