comparison core.js @ 701:c76205be5fc1

Added comments. Variable name changes to match specification document during ape.js loading.
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Tue, 07 Apr 2015 11:32:46 +0100
parents a6364db4c2ea
children 6ff6de6a0fa2 375410a5571d
comparison
equal deleted inserted replaced
700:47d868d4716e 701:c76205be5fc1
19 // NORE: Currently this will only work with webkit browsers (Chrome/Safari)! 19 // NORE: Currently this will only work with webkit browsers (Chrome/Safari)!
20 audioContext = new AudioContext; 20 audioContext = new AudioContext;
21 21
22 // Create the audio engine object 22 // Create the audio engine object
23 audioEngineContext = new AudioEngine(); 23 audioEngineContext = new AudioEngine();
24 } 24 };
25 25
26 function loadProjectSpec(url) { 26 function loadProjectSpec(url) {
27 // Load the project document from the given URL, decode the XML and instruct audioEngine to get audio data 27 // Load the project document from the given URL, decode the XML and instruct audioEngine to get audio data
28 // If url is null, request client to upload project XML document 28 // If url is null, request client to upload project XML document
29 var r = new XMLHttpRequest(); 29 var r = new XMLHttpRequest();
30 r.open('GET',url,true); 30 r.open('GET',url,true);
31 r.onload = function() { 31 r.onload = function() {
32 loadProjectSpecCallback(r.response); 32 loadProjectSpecCallback(r.response);
33 } 33 };
34 r.send(); 34 r.send();
35 } 35 };
36 36
37 function loadProjectSpecCallback(response) { 37 function loadProjectSpecCallback(response) {
38 // Function called after asynchronous download of XML project specification 38 // Function called after asynchronous download of XML project specification
39 var decode = $.parseXML(response); 39 var decode = $.parseXML(response);
40 projectXML = $(decode); 40 projectXML = $(decode);
41 41
42 // Now extract the setup tag 42 // Now extract the setup tag
43 var xmlSetup = projectXML.find('setup'); 43 var xmlSetup = projectXML.find('setup');
44 // Detect the interface to use and load the relevant javascripts.
44 var interfaceType = xmlSetup[0].attributes['interface']; 45 var interfaceType = xmlSetup[0].attributes['interface'];
45 var interfaceJS = document.createElement('script'); 46 var interfaceJS = document.createElement('script');
46 interfaceJS.setAttribute("type","text/javascript"); 47 interfaceJS.setAttribute("type","text/javascript");
47 if (interfaceType.value == 'APE') { 48 if (interfaceType.value == 'APE') {
48 interfaceJS.setAttribute("src","ape.js"); 49 interfaceJS.setAttribute("src","ape.js");
106 { 107 {
107 this.audioObjects[i].play(timer); 108 this.audioObjects[i].play(timer);
108 } 109 }
109 this.status = 1; 110 this.status = 1;
110 } 111 }
111 } 112 };
112 113
113 this.stop = function() { 114 this.stop = function() {
114 // Send stop and reset command to all playback buffers 115 // Send stop and reset command to all playback buffers
115 if (this.status == 1) { 116 if (this.status == 1) {
116 for (var i=0; i<this.audioObjects.length; i++) 117 for (var i=0; i<this.audioObjects.length; i++)
117 { 118 {
118 this.audioObjects[i].stop(); 119 this.audioObjects[i].stop();
119 } 120 }
120 this.status = 0; 121 this.status = 0;
121 } 122 }
122 } 123 };
123 124
124 this.selectedTrack = function(id) { 125 this.selectedTrack = function(id) {
125 for (var i=0; i<this.audioObjects.length; i++) 126 for (var i=0; i<this.audioObjects.length; i++)
126 { 127 {
127 if (id == i) { 128 if (id == i) {
128 this.audioObjects[i].outputGain.gain.value = 1.0; 129 this.audioObjects[i].outputGain.gain.value = 1.0;
129 } else { 130 } else {
130 this.audioObjects[i].outputGain.gain.value = 0.0; 131 this.audioObjects[i].outputGain.gain.value = 0.0;
131 } 132 }
132 } 133 }
133 } 134 };
134 135
135 136
136 this.newTrack = function(url) { 137 this.newTrack = function(url) {
137 // Pull data from given URL into new audio buffer 138 // Pull data from given URL into new audio buffer
138 // URLs must either be from the same source OR be setup to 'Access-Control-Allow-Origin' 139 // URLs must either be from the same source OR be setup to 'Access-Control-Allow-Origin'
141 audioObjectId = this.audioObjects.length 142 audioObjectId = this.audioObjects.length
142 this.audioObjects[audioObjectId] = new audioObject(audioObjectId); 143 this.audioObjects[audioObjectId] = new audioObject(audioObjectId);
143 144
144 // AudioObject will get track itself. 145 // AudioObject will get track itself.
145 this.audioObjects[audioObjectId].constructTrack(url); 146 this.audioObjects[audioObjectId].constructTrack(url);
146 } 147 };
147 148
148 } 149 }
149 150
150 function audioObject(id) { 151 function audioObject(id) {
151 // The main buffer object with common control nodes to the AudioEngine 152 // The main buffer object with common control nodes to the AudioEngine
168 // When stopeed, the buffer node is deleted and recreated with the stored buffer. 169 // When stopeed, the buffer node is deleted and recreated with the stored buffer.
169 this.buffer; 170 this.buffer;
170 171
171 this.play = function(startTime) { 172 this.play = function(startTime) {
172 this.bufferNode.start(startTime); 173 this.bufferNode.start(startTime);
173 } 174 };
174 175
175 this.stop = function() { 176 this.stop = function() {
176 this.bufferNode.stop(0); 177 this.bufferNode.stop(0);
177 this.bufferNode = audioContext.createBufferSource(); 178 this.bufferNode = audioContext.createBufferSource();
178 this.bufferNode.connect(this.outputGain); 179 this.bufferNode.connect(this.outputGain);
179 this.bufferNode.buffer = this.buffer; 180 this.bufferNode.buffer = this.buffer;
180 this.bufferNode.loop = true; 181 this.bufferNode.loop = true;
181 } 182 };
182 183
183 this.constructTrack = function(url) { 184 this.constructTrack = function(url) {
184 var request = new XMLHttpRequest(); 185 var request = new XMLHttpRequest();
185 request.open('GET',url,true); 186 request.open('GET',url,true);
186 request.responseType = 'arraybuffer'; 187 request.responseType = 'arraybuffer';
200 if (audioObj.state == 0 || audioObj.buffer == undefined) { 201 if (audioObj.state == 0 || audioObj.buffer == undefined) {
201 // Genuine error 202 // Genuine error
202 console.log('FATAL - Error loading buffer on '+audioObj.id); 203 console.log('FATAL - Error loading buffer on '+audioObj.id);
203 } 204 }
204 }); 205 });
205 } 206 };
206 request.send(); 207 request.send();
207 } 208 };
208 209
209 } 210 }