changeset 8:a6364db4c2ea

All tracks start muted. Clicking on sliders un-mutes that track. All tracks loop until stopped
author Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk>
date Wed, 25 Mar 2015 12:56:42 +0000
parents 6a6272b06d34
children 8343b2ba7ce7
files ape.js core.js
diffstat 2 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ape.js	Wed Mar 25 12:48:29 2015 +0000
+++ b/ape.js	Wed Mar 25 12:56:42 2015 +0000
@@ -155,6 +155,14 @@
 		trackSliderObj.style.float = "left";
 		trackSliderObj.draggable = true;
 		trackSliderObj.ondragend = dragEnd;
+		
+		// Onclick, switch playback to that track
+		trackSliderObj.onclick = function() {
+			// Get the track ID from the object ID
+			var id = Number(this.id.substr(13,2)); // Maximum theoretical tracks is 99!
+			audioEngineContext.selectedTrack(id);
+		}
+		
 		canvas.appendChild(trackSliderObj);
 	})
 	
--- a/core.js	Wed Mar 25 12:48:29 2015 +0000
+++ b/core.js	Wed Mar 25 12:56:42 2015 +0000
@@ -121,6 +121,18 @@
 		}
 	}
 	
+	this.selectedTrack = function(id) {
+		for (var i=0; i<this.audioObjects.length; i++)
+		{
+			if (id == i) {
+				this.audioObjects[i].outputGain.gain.value = 1.0;
+			} else {
+				this.audioObjects[i].outputGain.gain.value = 0.0;
+			}
+		}
+	}
+	
+	
 	this.newTrack = function(url) {
 		// Pull data from given URL into new audio buffer
 		// URLs must either be from the same source OR be setup to 'Access-Control-Allow-Origin'
@@ -145,6 +157,9 @@
 	this.bufferNode = audioContext.createBufferSource();
 	this.outputGain = audioContext.createGain();
 	
+	// Default output gain to be zero
+	this.outputGain.gain.value = 0.0;
+	
 	// Connect buffer to the audio graph
 	this.bufferNode.connect(this.outputGain);
 	this.outputGain.connect(audioEngineContext.outputGain);
@@ -164,7 +179,7 @@
 		this.bufferNode.buffer = this.buffer;
 		this.bufferNode.loop = true;
 	}
-	
+
 	this.constructTrack = function(url) {
 		var request = new XMLHttpRequest();
 		request.open('GET',url,true);