nicholas@2
|
1 /**
|
nicholas@2
|
2 * ape.js
|
nicholas@2
|
3 * Create the APE interface
|
nicholas@2
|
4 */
|
nicholas@2
|
5
|
n@38
|
6 // preTest - In preTest state
|
n@38
|
7 // testRun-ID - In test running, test Id number at the end 'testRun-2'
|
n@38
|
8 // testRunPost-ID - Post test of test ID
|
n@38
|
9 // testRunPre-ID - Pre-test of test ID
|
n@38
|
10 // postTest - End of test, final submission!
|
n@38
|
11
|
n@32
|
12
|
nicholas@2
|
13 // Once this is loaded and parsed, begin execution
|
n@181
|
14 loadInterface();
|
nicholas@2
|
15
|
n@181
|
16 function loadInterface() {
|
nicholas@2
|
17
|
n@16
|
18 // Get the dimensions of the screen available to the page
|
nicholas@2
|
19 var width = window.innerWidth;
|
nicholas@2
|
20 var height = window.innerHeight;
|
nicholas@2
|
21
|
nicholas@2
|
22 // The injection point into the HTML page
|
n@182
|
23 interfaceContext.insertPoint = document.getElementById("topLevelBody");
|
n@22
|
24 var testContent = document.createElement('div');
|
nicholas@135
|
25
|
n@22
|
26 testContent.id = 'testContent';
|
n@176
|
27
|
n@34
|
28
|
n@52
|
29 // Create APE specific metric functions
|
n@52
|
30 audioEngineContext.metric.initialiseTest = function()
|
n@52
|
31 {
|
n@52
|
32 };
|
n@52
|
33
|
n@52
|
34 audioEngineContext.metric.sliderMoved = function()
|
n@52
|
35 {
|
n@183
|
36
|
n@52
|
37 var id = this.data;
|
n@52
|
38 this.data = -1;
|
n@52
|
39 var position = convSliderPosToRate(id);
|
b@115
|
40 console.log('slider ' + id + ': '+ position + ' (' + time + ')'); // DEBUG/SAFETY: show position and slider id
|
n@52
|
41 if (audioEngineContext.timer.testStarted)
|
n@52
|
42 {
|
n@52
|
43 audioEngineContext.audioObjects[id].metric.moved(time,position);
|
n@52
|
44 }
|
n@52
|
45 };
|
n@52
|
46
|
n@52
|
47 audioEngineContext.metric.sliderPlayed = function(id)
|
n@52
|
48 {
|
n@52
|
49 var time = audioEngineContext.timer.getTestTime();
|
n@52
|
50 if (audioEngineContext.timer.testStarted)
|
n@52
|
51 {
|
n@52
|
52 if (this.lastClicked >= 0)
|
n@52
|
53 {
|
n@52
|
54 audioEngineContext.audioObjects[this.lastClicked].metric.listening(time);
|
n@52
|
55 }
|
n@52
|
56 this.lastClicked = id;
|
n@52
|
57 audioEngineContext.audioObjects[id].metric.listening(time);
|
n@52
|
58 }
|
b@115
|
59 console.log('slider ' + id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id
|
n@52
|
60 };
|
n@52
|
61
|
nicholas@214
|
62 // Bindings for interfaceContext
|
nicholas@214
|
63 Interface.prototype.checkAllPlayed = function()
|
nicholas@214
|
64 {
|
nicholas@214
|
65 hasBeenPlayed = audioEngineContext.checkAllPlayed();
|
nicholas@214
|
66 if (hasBeenPlayed.length > 0) // if a fragment has not been played yet
|
nicholas@214
|
67 {
|
nicholas@214
|
68 str = "";
|
nicholas@214
|
69 if (hasBeenPlayed.length > 1) {
|
nicholas@214
|
70 for (var i=0; i<hasBeenPlayed.length; i++) {
|
nicholas@214
|
71 str = str + hasBeenPlayed[i];
|
nicholas@214
|
72 if (i < hasBeenPlayed.length-2){
|
nicholas@214
|
73 str += ", ";
|
nicholas@214
|
74 } else if (i == hasBeenPlayed.length-2) {
|
nicholas@214
|
75 str += " or ";
|
nicholas@214
|
76 }
|
nicholas@214
|
77 }
|
nicholas@214
|
78 alert('You have not played fragments ' + str + ' yet. Please listen, rate and comment all samples before submitting.');
|
nicholas@214
|
79 } else {
|
nicholas@214
|
80 alert('You have not played fragment ' + hasBeenPlayed[0] + ' yet. Please listen, rate and comment all samples before submitting.');
|
nicholas@214
|
81 }
|
nicholas@214
|
82 return false;
|
nicholas@214
|
83 }
|
nicholas@214
|
84 return true;
|
nicholas@219
|
85 };
|
nicholas@214
|
86
|
nicholas@214
|
87 Interface.prototype.checkAllMoved = function() {
|
nicholas@214
|
88 var audioObjs = audioEngineContext.audioObjects;
|
nicholas@214
|
89 var state = true;
|
nicholas@214
|
90 var strNums = [];
|
nicholas@214
|
91 for (var i=0; i<audioObjs.length; i++)
|
nicholas@214
|
92 {
|
nicholas@214
|
93 if (audioObjs[i].metric.wasMoved == false) {
|
nicholas@214
|
94 state = false;
|
nicholas@214
|
95 strNums.push(i);
|
nicholas@214
|
96 }
|
nicholas@214
|
97 }
|
nicholas@214
|
98 if (state == false) {
|
nicholas@214
|
99 if (strNums.length > 1) {
|
nicholas@214
|
100 var str = "";
|
nicholas@214
|
101 for (var i=0; i<strNums.length; i++) {
|
nicholas@214
|
102 str = str + strNums[i];
|
nicholas@214
|
103 if (i < strNums.length-2){
|
nicholas@214
|
104 str += ", ";
|
nicholas@214
|
105 } else if (i == strNums.length-2) {
|
nicholas@214
|
106 str += " or ";
|
nicholas@214
|
107 }
|
nicholas@214
|
108 }
|
nicholas@214
|
109 alert('You have not moved fragments ' + str + ' yet. Please listen, rate and comment all samples before submitting.');
|
nicholas@214
|
110 } else {
|
nicholas@214
|
111 alert('You have not moved fragment ' + strNums[0] + ' yet. Please listen, rate and comment all samples before submitting.');
|
nicholas@214
|
112 }
|
nicholas@214
|
113 }
|
nicholas@214
|
114 return state;
|
nicholas@219
|
115 };
|
nicholas@214
|
116
|
nicholas@214
|
117 Interface.prototype.checkAllCommented = function() {
|
nicholas@214
|
118 var audioObjs = audioEngineContext.audioObjects;
|
nicholas@214
|
119 var audioHolder = testState.stateMap[testState.stateIndex];
|
nicholas@214
|
120 var state = true;
|
nicholas@214
|
121 if (audioHolder.elementComments) {
|
nicholas@214
|
122 var strNums = [];
|
nicholas@214
|
123 for (var i=0; i<audioObjs.length; i++)
|
nicholas@214
|
124 {
|
nicholas@214
|
125 if (audioObjs[i].commentDOM.trackCommentBox.value.length == 0) {
|
nicholas@214
|
126 state = false;
|
nicholas@214
|
127 strNums.push(i);
|
nicholas@214
|
128 }
|
nicholas@214
|
129 }
|
nicholas@214
|
130 if (state == false) {
|
nicholas@214
|
131 if (strNums.length > 1) {
|
nicholas@214
|
132 var str = "";
|
nicholas@214
|
133 for (var i=0; i<strNums.length; i++) {
|
nicholas@214
|
134 str = str + strNums[i];
|
nicholas@214
|
135 if (i < strNums.length-2){
|
nicholas@214
|
136 str += ", ";
|
nicholas@214
|
137 } else if (i == strNums.length-2) {
|
nicholas@214
|
138 str += " or ";
|
nicholas@214
|
139 }
|
nicholas@214
|
140 }
|
nicholas@214
|
141 alert('You have not commented on fragments ' + str + ' yet. Please listen, rate and comment all samples before submitting.');
|
nicholas@214
|
142 } else {
|
nicholas@214
|
143 alert('You have not commented on fragment ' + strNums[0] + ' yet. Please listen, rate and comment all samples before submitting.');
|
nicholas@214
|
144 }
|
nicholas@214
|
145 }
|
nicholas@214
|
146 }
|
nicholas@214
|
147 return state;
|
nicholas@219
|
148 };
|
nicholas@214
|
149
|
nicholas@231
|
150 Interface.prototype.checkScaleRange = function()
|
nicholas@231
|
151 {
|
nicholas@231
|
152 var audioObjs = audioEngineContext.audioObjects;
|
nicholas@231
|
153 var audioHolder = testState.stateMap[testState.stateIndex];
|
nicholas@231
|
154 var interfaces = audioHolder.interfaces;
|
nicholas@231
|
155
|
nicholas@231
|
156 var minRanking = audioObjs[0].interfaceDOM.getValue();
|
nicholas@231
|
157 var maxRanking = minRanking;
|
nicholas@231
|
158
|
nicholas@231
|
159 var minScale;
|
nicholas@231
|
160 var maxScale;
|
nicholas@231
|
161 for (var i=0; i<interfaces[0].options.length; i++)
|
nicholas@231
|
162 {
|
nicholas@231
|
163 if (interfaces[0].options[i].check == "scalerange") {
|
nicholas@231
|
164 minScale = interfaces[0].options[i].min;
|
nicholas@231
|
165 maxScale = interfaces[0].options[i].max;
|
nicholas@231
|
166 }
|
nicholas@231
|
167 }
|
nicholas@231
|
168
|
nicholas@231
|
169 for (var i=1; i<audioObjs.length; i++){
|
nicholas@231
|
170 var ranking = audioObjs[i].interfaceDOM.getValue();
|
nicholas@231
|
171 if (ranking < minRanking) { minRanking = ranking;}
|
nicholas@231
|
172 if (ranking > maxRanking) { maxRanking = ranking;}
|
nicholas@231
|
173 }
|
nicholas@231
|
174 if (minRanking > minScale || maxRanking < maxScale) {
|
nicholas@231
|
175 alert('Please use the full width of the scale');
|
nicholas@231
|
176 return false;
|
nicholas@231
|
177 } else {
|
nicholas@231
|
178 return true;
|
nicholas@231
|
179 }
|
nicholas@231
|
180 };
|
nicholas@231
|
181
|
n@177
|
182 // Bindings for audioObjects
|
n@177
|
183
|
nicholas@2
|
184 // Create the top div for the Title element
|
n@181
|
185 var titleAttr = specification.title;
|
nicholas@2
|
186 var title = document.createElement('div');
|
nicholas@2
|
187 title.className = "title";
|
nicholas@2
|
188 title.align = "center";
|
nicholas@2
|
189 var titleSpan = document.createElement('span');
|
nicholas@2
|
190
|
nicholas@2
|
191 // Set title to that defined in XML, else set to default
|
nicholas@2
|
192 if (titleAttr != undefined) {
|
n@181
|
193 titleSpan.textContent = titleAttr;
|
nicholas@2
|
194 } else {
|
n@181
|
195 titleSpan.textContent = 'Listening test';
|
nicholas@2
|
196 }
|
nicholas@2
|
197 // Insert the titleSpan element into the title div element.
|
nicholas@2
|
198 title.appendChild(titleSpan);
|
nicholas@2
|
199
|
n@47
|
200 var pagetitle = document.createElement('div');
|
n@47
|
201 pagetitle.className = "pageTitle";
|
n@47
|
202 pagetitle.align = "center";
|
n@47
|
203 var titleSpan = document.createElement('span');
|
n@47
|
204 titleSpan.id = "pageTitle";
|
n@47
|
205 pagetitle.appendChild(titleSpan);
|
n@47
|
206
|
nicholas@7
|
207 // Create Interface buttons!
|
nicholas@7
|
208 var interfaceButtons = document.createElement('div');
|
nicholas@7
|
209 interfaceButtons.id = 'interface-buttons';
|
nicholas@7
|
210
|
nicholas@7
|
211 // Create playback start/stop points
|
nicholas@7
|
212 var playback = document.createElement("button");
|
b@101
|
213 playback.innerHTML = 'Stop';
|
n@49
|
214 playback.id = 'playback-button';
|
n@16
|
215 // onclick function. Check if it is playing or not, call the correct function in the
|
n@16
|
216 // audioEngine, change the button text to reflect the next state.
|
nicholas@7
|
217 playback.onclick = function() {
|
b@101
|
218 if (audioEngineContext.status == 1) {
|
b@101
|
219 audioEngineContext.stop();
|
n@25
|
220 this.innerHTML = 'Stop';
|
b@115
|
221 var time = audioEngineContext.timer.getTestTime();
|
b@115
|
222 console.log('Stopped at ' + time); // DEBUG/SAFETY
|
nicholas@7
|
223 }
|
n@16
|
224 };
|
nicholas@7
|
225 // Create Submit (save) button
|
nicholas@7
|
226 var submit = document.createElement("button");
|
n@25
|
227 submit.innerHTML = 'Submit';
|
n@43
|
228 submit.onclick = buttonSubmitClick;
|
n@49
|
229 submit.id = 'submit-button';
|
n@16
|
230 // Append the interface buttons into the interfaceButtons object.
|
nicholas@7
|
231 interfaceButtons.appendChild(playback);
|
nicholas@7
|
232 interfaceButtons.appendChild(submit);
|
nicholas@7
|
233
|
nicholas@2
|
234 // Now create the slider and HTML5 canvas boxes
|
nicholas@2
|
235
|
n@16
|
236 // Create the div box to center align
|
nicholas@2
|
237 var sliderBox = document.createElement('div');
|
nicholas@2
|
238 sliderBox.className = 'sliderCanvasDiv';
|
n@16
|
239 sliderBox.id = 'sliderCanvasHolder';
|
nicholas@2
|
240
|
n@16
|
241 // Create the slider box to hold the slider elements
|
nicholas@5
|
242 var canvas = document.createElement('div');
|
nicholas@2
|
243 canvas.id = 'slider';
|
n@127
|
244 canvas.align = "left";
|
n@127
|
245 canvas.addEventListener('dragover',function(event){
|
n@127
|
246 event.preventDefault();
|
n@127
|
247 return false;
|
n@127
|
248 },false);
|
n@127
|
249 var sliderMargin = document.createAttribute('marginsize');
|
n@127
|
250 sliderMargin.nodeValue = 42; // Set default margins to 42px either side
|
n@16
|
251 // Must have a known EXACT width, as this is used later to determine the ratings
|
n@127
|
252 var w = (Number(sliderMargin.nodeValue)+8)*2;
|
n@127
|
253 canvas.style.width = width - w +"px";
|
n@127
|
254 canvas.style.marginLeft = sliderMargin.nodeValue +'px';
|
n@127
|
255 canvas.setAttributeNode(sliderMargin);
|
nicholas@2
|
256 sliderBox.appendChild(canvas);
|
n@16
|
257
|
n@47
|
258 // Create the div to hold any scale objects
|
n@47
|
259 var scale = document.createElement('div');
|
n@47
|
260 scale.className = 'sliderScale';
|
n@47
|
261 scale.id = 'sliderScaleHolder';
|
n@47
|
262 scale.align = 'left';
|
n@47
|
263 sliderBox.appendChild(scale);
|
n@47
|
264
|
n@16
|
265 // Global parent for the comment boxes on the page
|
nicholas@3
|
266 var feedbackHolder = document.createElement('div');
|
n@34
|
267 feedbackHolder.id = 'feedbackHolder';
|
nicholas@2
|
268
|
n@38
|
269 testContent.style.zIndex = 1;
|
n@182
|
270 interfaceContext.insertPoint.innerHTML = null; // Clear the current schema
|
n@38
|
271
|
n@38
|
272 // Inject into HTML
|
n@38
|
273 testContent.appendChild(title); // Insert the title
|
n@47
|
274 testContent.appendChild(pagetitle);
|
n@38
|
275 testContent.appendChild(interfaceButtons);
|
n@38
|
276 testContent.appendChild(sliderBox);
|
n@38
|
277 testContent.appendChild(feedbackHolder);
|
n@182
|
278 interfaceContext.insertPoint.appendChild(testContent);
|
n@22
|
279
|
n@36
|
280 // Load the full interface
|
nicholas@129
|
281 testState.initialise();
|
nicholas@129
|
282 testState.advanceState();
|
nicholas@135
|
283
|
nicholas@2
|
284 }
|
nicholas@5
|
285
|
n@181
|
286 function loadTest(audioHolderObject)
|
n@34
|
287 {
|
nicholas@110
|
288
|
nicholas@110
|
289 // Reset audioEngineContext.Metric globals for new test
|
n@113
|
290 audioEngineContext.newTestPage();
|
nicholas@110
|
291
|
n@181
|
292 var id = audioHolderObject.id;
|
n@34
|
293
|
n@34
|
294 var feedbackHolder = document.getElementById('feedbackHolder');
|
n@34
|
295 var canvas = document.getElementById('slider');
|
n@34
|
296 feedbackHolder.innerHTML = null;
|
n@34
|
297 canvas.innerHTML = null;
|
n@47
|
298
|
nicholas@220
|
299 //var playbackHolder = document.createElement('div');
|
nicholas@220
|
300 //playbackHolder.style.width = "100%";
|
nicholas@220
|
301 //playbackHolder.align = 'center';
|
nicholas@220
|
302 //playbackHolder.appendChild(interfaceContext.playhead.object);
|
nicholas@220
|
303 //feedbackHolder.appendChild(playbackHolder);
|
n@47
|
304 // Setup question title
|
n@184
|
305 var interfaceObj = audioHolderObject.interfaces;
|
n@184
|
306 var commentBoxPrefix = "Comment on track";
|
n@184
|
307 if (interfaceObj.length != 0) {
|
n@184
|
308 interfaceObj = interfaceObj[0];
|
n@184
|
309 var titleNode = interfaceObj.title;
|
n@184
|
310 if (titleNode != undefined)
|
n@184
|
311 {
|
n@184
|
312 document.getElementById('pageTitle').textContent = titleNode;
|
n@184
|
313 }
|
n@184
|
314 var positionScale = canvas.style.width.substr(0,canvas.style.width.length-2);
|
n@184
|
315 var offset = Number(document.getElementById('slider').attributes['marginsize'].value);
|
n@184
|
316 var scale = document.getElementById('sliderScaleHolder');
|
n@184
|
317 scale.innerHTML = null;
|
n@184
|
318 $(interfaceObj.scale).each(function(index,scaleObj){
|
n@184
|
319 var value = document.createAttribute('value');
|
n@184
|
320 var position = Number(scaleObj[0])*0.01;
|
n@184
|
321 value.nodeValue = position;
|
n@184
|
322 var pixelPosition = (position*positionScale)+offset;
|
n@184
|
323 var scaleDOM = document.createElement('span');
|
n@184
|
324 scaleDOM.textContent = scaleObj[1];
|
n@184
|
325 scale.appendChild(scaleDOM);
|
n@184
|
326 scaleDOM.style.left = Math.floor((pixelPosition-($(scaleDOM).width()/2)))+'px';
|
n@184
|
327 scaleDOM.setAttributeNode(value);
|
n@184
|
328 });
|
n@184
|
329
|
n@184
|
330 if (interfaceObj.commentBoxPrefix != undefined) {
|
n@184
|
331 commentBoxPrefix = interfaceObj.commentBoxPrefix;
|
n@184
|
332 }
|
n@174
|
333 }
|
n@34
|
334
|
n@34
|
335 /// CHECK FOR SAMPLE RATE COMPATIBILITY
|
n@181
|
336 if (audioHolderObject.sampleRate != undefined) {
|
n@181
|
337 if (Number(audioHolderObject.sampleRate) != audioContext.sampleRate) {
|
n@184
|
338 var errStr = 'Sample rates do not match! Requested '+Number(audioHolderObject.sampleRate)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.';
|
n@34
|
339 alert(errStr);
|
n@34
|
340 return;
|
n@34
|
341 }
|
n@34
|
342 }
|
n@45
|
343
|
n@181
|
344 var commentShow = audioHolderObject.elementComments;
|
nicholas@66
|
345
|
n@181
|
346 var loopPlayback = audioHolderObject.loop;
|
n@181
|
347
|
n@57
|
348 audioEngineContext.loopPlayback = loopPlayback;
|
n@57
|
349 // Create AudioEngine bindings for playback
|
n@202
|
350 audioEngineContext.selectedTrack = function(id) {
|
n@202
|
351 console.log('Deprecated');
|
n@202
|
352 };
|
n@57
|
353
|
n@46
|
354 currentTestHolder = document.createElement('audioHolder');
|
n@181
|
355 currentTestHolder.id = audioHolderObject.id;
|
n@181
|
356 currentTestHolder.repeatCount = audioHolderObject.repeatCount;
|
n@46
|
357
|
n@181
|
358 var randomise = audioHolderObject.randomiseOrder;
|
n@45
|
359
|
n@181
|
360 var audioElements = audioHolderObject.audioElements;
|
nicholas@58
|
361 currentTrackOrder = [];
|
n@45
|
362 if (randomise) {
|
n@181
|
363 audioHolderObject.audioElements = randomiseOrder(audioHolderObject.audioElements);
|
n@45
|
364 }
|
n@45
|
365
|
nicholas@58
|
366 // Delete any previous audioObjects associated with the audioEngine
|
nicholas@58
|
367 audioEngineContext.audioObjects = [];
|
nicholas@211
|
368 interfaceContext.deleteCommentBoxes();
|
nicholas@58
|
369
|
n@45
|
370 // Find all the audioElements from the audioHolder
|
n@181
|
371 $(audioHolderObject.audioElements).each(function(index,element){
|
n@34
|
372 // Find URL of track
|
n@34
|
373 // In this jQuery loop, variable 'this' holds the current audioElement.
|
n@34
|
374
|
n@34
|
375 // Now load each audio sample. First create the new track by passing the full URL
|
n@181
|
376 var trackURL = audioHolderObject.hostURL + element.url;
|
n@182
|
377 var audioObject = audioEngineContext.newTrack(element);
|
nicholas@66
|
378
|
n@205
|
379 var node = interfaceContext.createCommentBox(audioObject);
|
n@34
|
380
|
n@34
|
381 // Create a slider per track
|
n@183
|
382 audioObject.interfaceDOM = new sliderObject(audioObject);
|
n@154
|
383
|
n@34
|
384 // Distribute it randomnly
|
n@138
|
385 var w = window.innerWidth - (offset+8)*2;
|
n@34
|
386 w = Math.random()*w;
|
n@138
|
387 w = Math.floor(w+(offset+8));
|
n@183
|
388 audioObject.interfaceDOM.trackSliderObj.style.left = w+'px';
|
n@34
|
389
|
n@183
|
390 canvas.appendChild(audioObject.interfaceDOM.trackSliderObj);
|
n@183
|
391 audioObject.metric.initialised(convSliderPosToRate(audioObject.interfaceDOM.trackSliderObj));
|
b@102
|
392
|
n@34
|
393 });
|
n@182
|
394 if (commentShow) {
|
n@182
|
395 interfaceContext.showCommentBoxes(feedbackHolder,true);
|
n@182
|
396 }
|
n@39
|
397
|
n@181
|
398 $(audioHolderObject.commentQuestions).each(function(index,element) {
|
n@193
|
399 var node = interfaceContext.createCommentQuestion(element);
|
n@193
|
400 feedbackHolder.appendChild(node.holder);
|
nicholas@65
|
401 });
|
n@153
|
402
|
n@153
|
403
|
n@153
|
404 testWaitIndicator();
|
n@39
|
405 }
|
n@39
|
406
|
n@183
|
407 function sliderObject(audioObject) {
|
n@183
|
408 // Create a new slider object;
|
n@183
|
409 this.parent = audioObject;
|
n@183
|
410 this.trackSliderObj = document.createElement('div');
|
n@183
|
411 this.trackSliderObj.className = 'track-slider';
|
n@183
|
412 this.trackSliderObj.id = 'track-slider-'+audioObject.id;
|
n@183
|
413
|
n@183
|
414 this.trackSliderObj.setAttribute('trackIndex',audioObject.id);
|
n@183
|
415 this.trackSliderObj.innerHTML = '<span>'+audioObject.id+'</span>';
|
n@183
|
416 this.trackSliderObj.draggable = true;
|
n@183
|
417 this.trackSliderObj.ondragend = dragEnd;
|
n@183
|
418
|
n@183
|
419 // Onclick, switch playback to that track
|
n@183
|
420 this.trackSliderObj.onclick = function() {
|
n@183
|
421 // Start the test on first click, that way timings are more accurate.
|
n@183
|
422 audioEngineContext.play();
|
n@183
|
423 if (audioEngineContext.audioObjectsReady) {
|
n@183
|
424 // Cannot continue to issue play command until audioObjects reported as ready!
|
n@183
|
425 // Get the track ID from the object ID
|
nicholas@210
|
426 var element;
|
nicholas@210
|
427 if (event.srcElement.nodeName == "SPAN") {
|
nicholas@210
|
428 element = event.srcElement.parentNode;
|
nicholas@210
|
429 } else {
|
nicholas@210
|
430 element = event.srcElement;
|
nicholas@210
|
431 }
|
nicholas@210
|
432 var id = Number(element.attributes['trackIndex'].value);
|
n@183
|
433 //audioEngineContext.metric.sliderPlayed(id);
|
n@202
|
434 audioEngineContext.play(id);
|
n@183
|
435 // Currently playing track red, rest green
|
n@183
|
436
|
n@183
|
437 //document.getElementById('track-slider-'+index).style.backgroundColor = "#FF0000";
|
n@183
|
438 $('.track-slider').removeClass('track-slider-playing');
|
nicholas@210
|
439 $(element).addClass('track-slider-playing');
|
n@183
|
440 $('.comment-div').removeClass('comment-box-playing');
|
n@183
|
441 $('#comment-div-'+id).addClass('comment-box-playing');
|
n@183
|
442 }
|
n@183
|
443 };
|
n@183
|
444
|
nicholas@219
|
445 this.exportXMLDOM = function(audioObject) {
|
n@183
|
446 // Called by the audioObject holding this element. Must be present
|
n@183
|
447 var node = document.createElement('value');
|
n@183
|
448 node.textContent = convSliderPosToRate(this.trackSliderObj);
|
n@183
|
449 return node;
|
n@183
|
450 };
|
nicholas@219
|
451 this.getValue = function() {
|
nicholas@219
|
452 return convSliderPosToRate(this.trackSliderObj);
|
nicholas@220
|
453 };
|
n@183
|
454 }
|
nicholas@119
|
455
|
nicholas@5
|
456 function dragEnd(ev) {
|
nicholas@5
|
457 // Function call when a div has been dropped
|
n@33
|
458 var slider = document.getElementById('slider');
|
n@127
|
459 var marginSize = Number(slider.attributes['marginsize'].value);
|
n@51
|
460 var w = slider.style.width;
|
n@51
|
461 w = Number(w.substr(0,w.length-2));
|
nicholas@133
|
462 var x = ev.x;
|
n@127
|
463 if (x >= marginSize && x < w+marginSize) {
|
n@51
|
464 this.style.left = (x)+'px';
|
nicholas@5
|
465 } else {
|
n@127
|
466 if (x<marginSize) {
|
n@127
|
467 this.style.left = marginSize+'px';
|
nicholas@5
|
468 } else {
|
n@127
|
469 this.style.left = (w+marginSize) + 'px';
|
nicholas@5
|
470 }
|
nicholas@5
|
471 }
|
n@183
|
472 var time = audioEngineContext.timer.getTestTime();
|
n@183
|
473 var id = Number(ev.srcElement.getAttribute('trackindex'));
|
n@183
|
474 audioEngineContext.audioObjects[id].metric.moved(time,convSliderPosToRate(ev.srcElement));
|
nicholas@5
|
475 }
|
nicholas@7
|
476
|
b@101
|
477 function buttonSubmitClick() // TODO: Only when all songs have been played!
|
n@40
|
478 {
|
nicholas@232
|
479 var checks = testState.currentStateMap[testState.currentIndex].interfaces[0].options;
|
nicholas@214
|
480 var canContinue = true;
|
nicholas@219
|
481
|
nicholas@219
|
482 // Check that the anchor and reference objects are correctly placed
|
nicholas@219
|
483 var audioObjs = audioEngineContext.audioObjects;
|
nicholas@219
|
484 var audioHolder = testState.stateMap[testState.stateIndex];
|
nicholas@219
|
485 var anchorId = null;
|
nicholas@219
|
486 var referenceId = null;
|
nicholas@219
|
487 for (var i=0; i<audioObjs.length; i++) {
|
nicholas@219
|
488 if (audioObjs[i].specification.anchor == true && anchorId == null) {anchorId = i;}
|
nicholas@219
|
489 if (audioObjs[i].specification.reference == true && referenceId == null) {referenceId = i;}
|
nicholas@219
|
490 }
|
nicholas@219
|
491 if (anchorId != null) {
|
nicholas@219
|
492 if (audioObjs[anchorId].specification.marker != null) {
|
nicholas@219
|
493 if (audioObjs[anchorId].interfaceDOM.getValue() > audioObjs[anchorId].specification.marker)
|
nicholas@219
|
494 {
|
nicholas@219
|
495 // Anchor is not set below
|
nicholas@219
|
496 console.log('Anchor node not below marker value');
|
nicholas@219
|
497 alert('Please keep listening');
|
nicholas@219
|
498 return;
|
nicholas@219
|
499 }
|
nicholas@219
|
500 } else {
|
nicholas@219
|
501 // No marker value given, ensure it is the minimum value
|
nicholas@219
|
502 var anchorVal = audioObjs[anchorId].interfaceDOM.getValue();
|
nicholas@219
|
503 for (var i=0; i<audioObjs.length; i++) {
|
nicholas@219
|
504 if (i != anchorId) {
|
nicholas@219
|
505 if (anchorVal > audioObjs[i].interfaceDOM.getValue()) {
|
nicholas@219
|
506 // Anchor not the minimum
|
nicholas@219
|
507 console.log('No marker set, anchor node not the minimum');
|
nicholas@219
|
508 alert('Please keep listening');
|
nicholas@219
|
509 return;
|
nicholas@219
|
510 }
|
nicholas@219
|
511 }
|
nicholas@219
|
512 }
|
nicholas@219
|
513 }
|
nicholas@219
|
514 }
|
nicholas@219
|
515 if (referenceId != null) {
|
nicholas@219
|
516 if (audioObjs[referenceId].specification.marker != null) {
|
nicholas@219
|
517 if (audioObjs[referenceId].interfaceDOM.getValue() < audioObjs[referenceId].specification.marker)
|
nicholas@219
|
518 {
|
nicholas@219
|
519 // Anchor is not set below
|
nicholas@219
|
520 console.log('Reference node not above marker value');
|
nicholas@219
|
521 alert('Please keep listening');
|
nicholas@219
|
522 return;
|
nicholas@219
|
523 }
|
nicholas@219
|
524 } else {
|
nicholas@219
|
525 // No marker value given, ensure it is the minimum value
|
nicholas@219
|
526 var referenceVal = audioObjs[referenceId].interfaceDOM.getValue();
|
nicholas@219
|
527 for (var i=0; i<audioObjs.length; i++) {
|
nicholas@219
|
528 if (i != referenceId) {
|
nicholas@219
|
529 if (referenceVal > audioObjs[i].interfaceDOM.getValue()) {
|
nicholas@219
|
530 // Anchor not the minimum
|
nicholas@219
|
531 console.log('No marker set, reference node not the maximum');
|
nicholas@219
|
532 alert('Please keep listening');
|
nicholas@219
|
533 return;
|
nicholas@219
|
534 }
|
nicholas@219
|
535 }
|
nicholas@219
|
536 }
|
nicholas@219
|
537 }
|
nicholas@219
|
538 }
|
nicholas@219
|
539
|
nicholas@214
|
540 for (var i=0; i<checks.length; i++) {
|
nicholas@214
|
541 if (checks[i].type == 'check')
|
nicholas@214
|
542 {
|
nicholas@214
|
543 switch(checks[i].check) {
|
nicholas@214
|
544 case 'fragmentPlayed':
|
nicholas@214
|
545 // Check if all fragments have been played
|
nicholas@214
|
546 var checkState = interfaceContext.checkAllPlayed();
|
nicholas@214
|
547 if (checkState == false) {canContinue = false;}
|
nicholas@214
|
548 break;
|
nicholas@214
|
549 case 'fragmentFullPlayback':
|
nicholas@214
|
550 // Check all fragments have been played to their full length
|
nicholas@214
|
551 var checkState = interfaceContext.checkAllPlayed();
|
nicholas@214
|
552 if (checkState == false) {canContinue = false;}
|
nicholas@214
|
553 console.log('NOTE: fragmentFullPlayback not currently implemented, performing check fragmentPlayed instead');
|
nicholas@214
|
554 break;
|
nicholas@214
|
555 case 'fragmentMoved':
|
nicholas@214
|
556 // Check all fragment sliders have been moved.
|
nicholas@214
|
557 var checkState = interfaceContext.checkAllMoved();
|
nicholas@214
|
558 if (checkState == false) {canContinue = false;}
|
nicholas@214
|
559 break;
|
nicholas@214
|
560 case 'fragmentComments':
|
nicholas@214
|
561 // Check all fragment sliders have been moved.
|
nicholas@214
|
562 var checkState = interfaceContext.checkAllCommented();
|
nicholas@214
|
563 if (checkState == false) {canContinue = false;}
|
nicholas@214
|
564 break;
|
nicholas@231
|
565 case 'scalerange':
|
nicholas@231
|
566 // Check the scale is used to its full width outlined by the node
|
nicholas@231
|
567 var checkState = interfaceContext.checkScaleRange();
|
nicholas@231
|
568 if (checkState == false) {canContinue = false;}
|
nicholas@231
|
569 break;
|
nicholas@214
|
570 }
|
nicholas@214
|
571
|
nicholas@214
|
572 }
|
nicholas@231
|
573 if (!canContinue) {break;}
|
nicholas@214
|
574 }
|
nicholas@214
|
575
|
nicholas@214
|
576 if (canContinue) {
|
nicholas@107
|
577 if (audioEngineContext.status == 1) {
|
nicholas@107
|
578 var playback = document.getElementById('playback-button');
|
nicholas@107
|
579 playback.click();
|
nicholas@107
|
580 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
|
nicholas@107
|
581 } else
|
nicholas@107
|
582 {
|
nicholas@107
|
583 if (audioEngineContext.timer.testStarted == false)
|
nicholas@107
|
584 {
|
nicholas@107
|
585 alert('You have not started the test! Please press start to begin the test!');
|
nicholas@107
|
586 return;
|
nicholas@107
|
587 }
|
nicholas@107
|
588 }
|
nicholas@129
|
589 testState.advanceState();
|
nicholas@214
|
590 }
|
n@40
|
591 }
|
n@40
|
592
|
n@183
|
593 function convSliderPosToRate(slider)
|
n@51
|
594 {
|
n@51
|
595 var w = document.getElementById('slider').style.width;
|
n@127
|
596 var marginsize = Number(document.getElementById('slider').attributes['marginsize'].value);
|
n@51
|
597 var maxPix = w.substr(0,w.length-2);
|
n@51
|
598 var pix = slider.style.left;
|
n@51
|
599 pix = pix.substr(0,pix.length-2);
|
n@127
|
600 var rate = (pix-marginsize)/maxPix;
|
n@51
|
601 return rate;
|
n@51
|
602 }
|
n@51
|
603
|
n@127
|
604 function resizeWindow(event){
|
n@127
|
605 // Function called when the window has been resized.
|
n@127
|
606 // MANDATORY FUNCTION
|
n@127
|
607
|
n@127
|
608 // Store the slider marker values
|
n@127
|
609 var holdValues = [];
|
n@127
|
610 $(".track-slider").each(function(index,sliderObj){
|
n@127
|
611 holdValues.push(convSliderPosToRate(index));
|
n@127
|
612 });
|
n@127
|
613
|
n@127
|
614 var width = event.target.innerWidth;
|
n@127
|
615 var canvas = document.getElementById('sliderCanvasHolder');
|
n@127
|
616 var sliderDiv = canvas.children[0];
|
n@127
|
617 var sliderScaleDiv = canvas.children[1];
|
n@127
|
618 var marginsize = Number(sliderDiv.attributes['marginsize'].value);
|
n@127
|
619 var w = (marginsize+8)*2;
|
n@127
|
620 sliderDiv.style.width = width - w + 'px';
|
n@127
|
621 var width = width - w;
|
n@127
|
622 // Move sliders into new position
|
n@127
|
623 $(".track-slider").each(function(index,sliderObj){
|
n@127
|
624 var pos = holdValues[index];
|
n@127
|
625 var pix = pos * width;
|
n@127
|
626 sliderObj.style.left = pix+marginsize+'px';
|
n@127
|
627 });
|
n@127
|
628
|
n@127
|
629 // Move scale labels
|
n@127
|
630 $(sliderScaleDiv.children).each(function(index,scaleObj){
|
n@127
|
631 var position = Number(scaleObj.attributes['value'].value);
|
n@127
|
632 var pixelPosition = (position*width)+marginsize;
|
n@127
|
633 scaleObj.style.left = Math.floor((pixelPosition-($(scaleObj).width()/2)))+'px';
|
n@127
|
634 });
|
n@127
|
635 }
|
n@127
|
636
|
n@181
|
637 function pageXMLSave(store, testXML)
|
n@44
|
638 {
|
n@44
|
639 // Saves a specific test page
|
nicholas@129
|
640 var xmlDoc = store;
|
n@50
|
641 // Check if any session wide metrics are enabled
|
nicholas@67
|
642
|
n@181
|
643 var commentShow = testXML.elementComments;
|
nicholas@67
|
644
|
n@50
|
645 var metric = document.createElement('metric');
|
n@50
|
646 if (audioEngineContext.metric.enableTestTimer)
|
n@50
|
647 {
|
n@50
|
648 var testTime = document.createElement('metricResult');
|
n@50
|
649 testTime.id = 'testTime';
|
n@50
|
650 testTime.textContent = audioEngineContext.timer.testDuration;
|
n@50
|
651 metric.appendChild(testTime);
|
n@50
|
652 }
|
n@50
|
653 xmlDoc.appendChild(metric);
|
n@178
|
654 var audioObjects = audioEngineContext.audioObjects;
|
n@178
|
655 for (var i=0; i<audioObjects.length; i++)
|
n@45
|
656 {
|
n@183
|
657 var audioElement = audioEngineContext.audioObjects[i].exportXMLDOM();
|
n@45
|
658 xmlDoc.appendChild(audioElement);
|
n@45
|
659 }
|
n@193
|
660
|
n@193
|
661 $(interfaceContext.commentQuestions).each(function(index,element){
|
n@193
|
662 var node = element.exportXMLDOM();
|
n@193
|
663 xmlDoc.appendChild(node);
|
n@193
|
664 });
|
nicholas@129
|
665 store = xmlDoc;
|
nicholas@67
|
666 } |