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