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