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