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