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