nickjillings@1683
|
1 /**
|
nickjillings@1683
|
2 * ape.js
|
nickjillings@1683
|
3 * Create the APE interface
|
nickjillings@1683
|
4 */
|
nickjillings@1683
|
5
|
nickjillings@1648
|
6 // preTest - In preTest state
|
nickjillings@1648
|
7 // testRun-ID - In test running, test Id number at the end 'testRun-2'
|
nickjillings@1648
|
8 // testRunPost-ID - Post test of test ID
|
nickjillings@1648
|
9 // testRunPre-ID - Pre-test of test ID
|
nickjillings@1648
|
10 // postTest - End of test, final submission!
|
nickjillings@1648
|
11
|
nickjillings@1642
|
12
|
nickjillings@1683
|
13 // Once this is loaded and parsed, begin execution
|
nickjillings@1581
|
14 loadInterface();
|
nickjillings@1683
|
15
|
nickjillings@1581
|
16 function loadInterface() {
|
nickjillings@1683
|
17
|
nickjillings@1697
|
18 // Get the dimensions of the screen available to the page
|
nickjillings@1683
|
19 var width = window.innerWidth;
|
nickjillings@1683
|
20 var height = window.innerHeight;
|
nickjillings@1683
|
21
|
nickjillings@1683
|
22 // The injection point into the HTML page
|
nickjillings@1582
|
23 interfaceContext.insertPoint = document.getElementById("topLevelBody");
|
nickjillings@1702
|
24 var testContent = document.createElement('div');
|
nickjillings@1604
|
25
|
nickjillings@1702
|
26 testContent.id = 'testContent';
|
nickjillings@1576
|
27
|
nickjillings@1644
|
28
|
nickjillings@1662
|
29 // Create APE specific metric functions
|
nickjillings@1662
|
30 audioEngineContext.metric.initialiseTest = function()
|
nickjillings@1662
|
31 {
|
nickjillings@1662
|
32 };
|
nickjillings@1662
|
33
|
nickjillings@1662
|
34 audioEngineContext.metric.sliderMoved = function()
|
nickjillings@1662
|
35 {
|
nickjillings@1583
|
36
|
nickjillings@1662
|
37 var id = this.data;
|
nickjillings@1662
|
38 this.data = -1;
|
nickjillings@1662
|
39 var position = convSliderPosToRate(id);
|
b@1606
|
40 console.log('slider ' + id + ': '+ position + ' (' + time + ')'); // DEBUG/SAFETY: show position and slider id
|
nickjillings@1662
|
41 if (audioEngineContext.timer.testStarted)
|
nickjillings@1662
|
42 {
|
nickjillings@1662
|
43 audioEngineContext.audioObjects[id].metric.moved(time,position);
|
nickjillings@1662
|
44 }
|
nickjillings@1662
|
45 };
|
nickjillings@1662
|
46
|
nickjillings@1662
|
47 audioEngineContext.metric.sliderPlayed = function(id)
|
nickjillings@1662
|
48 {
|
nickjillings@1662
|
49 var time = audioEngineContext.timer.getTestTime();
|
nickjillings@1662
|
50 if (audioEngineContext.timer.testStarted)
|
nickjillings@1662
|
51 {
|
nickjillings@1662
|
52 if (this.lastClicked >= 0)
|
nickjillings@1662
|
53 {
|
nickjillings@1662
|
54 audioEngineContext.audioObjects[this.lastClicked].metric.listening(time);
|
nickjillings@1662
|
55 }
|
nickjillings@1662
|
56 this.lastClicked = id;
|
nickjillings@1662
|
57 audioEngineContext.audioObjects[id].metric.listening(time);
|
nickjillings@1662
|
58 }
|
b@1606
|
59 console.log('slider ' + id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id
|
nickjillings@1662
|
60 };
|
nickjillings@1662
|
61
|
nickjillings@1577
|
62 // Bindings for audioObjects
|
nickjillings@1577
|
63
|
nickjillings@1683
|
64 // Create the top div for the Title element
|
nickjillings@1581
|
65 var titleAttr = specification.title;
|
nickjillings@1683
|
66 var title = document.createElement('div');
|
nickjillings@1683
|
67 title.className = "title";
|
nickjillings@1683
|
68 title.align = "center";
|
nickjillings@1683
|
69 var titleSpan = document.createElement('span');
|
nickjillings@1683
|
70
|
nickjillings@1683
|
71 // Set title to that defined in XML, else set to default
|
nickjillings@1683
|
72 if (titleAttr != undefined) {
|
nickjillings@1581
|
73 titleSpan.textContent = titleAttr;
|
nickjillings@1683
|
74 } else {
|
nickjillings@1581
|
75 titleSpan.textContent = 'Listening test';
|
nickjillings@1683
|
76 }
|
nickjillings@1683
|
77 // Insert the titleSpan element into the title div element.
|
nickjillings@1683
|
78 title.appendChild(titleSpan);
|
nickjillings@1683
|
79
|
nickjillings@1657
|
80 var pagetitle = document.createElement('div');
|
nickjillings@1657
|
81 pagetitle.className = "pageTitle";
|
nickjillings@1657
|
82 pagetitle.align = "center";
|
nickjillings@1657
|
83 var titleSpan = document.createElement('span');
|
nickjillings@1657
|
84 titleSpan.id = "pageTitle";
|
nickjillings@1657
|
85 pagetitle.appendChild(titleSpan);
|
nickjillings@1657
|
86
|
nickjillings@1688
|
87 // Create Interface buttons!
|
nickjillings@1688
|
88 var interfaceButtons = document.createElement('div');
|
nickjillings@1688
|
89 interfaceButtons.id = 'interface-buttons';
|
nickjillings@1688
|
90
|
nickjillings@1688
|
91 // Create playback start/stop points
|
nickjillings@1688
|
92 var playback = document.createElement("button");
|
b@1609
|
93 playback.innerHTML = 'Stop';
|
nickjillings@1659
|
94 playback.id = 'playback-button';
|
nickjillings@1697
|
95 // onclick function. Check if it is playing or not, call the correct function in the
|
nickjillings@1697
|
96 // audioEngine, change the button text to reflect the next state.
|
nickjillings@1688
|
97 playback.onclick = function() {
|
b@1609
|
98 if (audioEngineContext.status == 1) {
|
b@1609
|
99 audioEngineContext.stop();
|
nickjillings@1705
|
100 this.innerHTML = 'Stop';
|
b@1606
|
101 var time = audioEngineContext.timer.getTestTime();
|
b@1606
|
102 console.log('Stopped at ' + time); // DEBUG/SAFETY
|
nickjillings@1688
|
103 }
|
nickjillings@1697
|
104 };
|
nickjillings@1688
|
105 // Create Submit (save) button
|
nickjillings@1688
|
106 var submit = document.createElement("button");
|
nickjillings@1705
|
107 submit.innerHTML = 'Submit';
|
nickjillings@1653
|
108 submit.onclick = buttonSubmitClick;
|
nickjillings@1659
|
109 submit.id = 'submit-button';
|
nickjillings@1697
|
110 // Append the interface buttons into the interfaceButtons object.
|
nickjillings@1688
|
111 interfaceButtons.appendChild(playback);
|
nickjillings@1688
|
112 interfaceButtons.appendChild(submit);
|
nickjillings@1688
|
113
|
nickjillings@1683
|
114 // Now create the slider and HTML5 canvas boxes
|
nickjillings@1683
|
115
|
nickjillings@1697
|
116 // Create the div box to center align
|
nickjillings@1683
|
117 var sliderBox = document.createElement('div');
|
nickjillings@1683
|
118 sliderBox.className = 'sliderCanvasDiv';
|
nickjillings@1697
|
119 sliderBox.id = 'sliderCanvasHolder';
|
nickjillings@1683
|
120
|
nickjillings@1697
|
121 // Create the slider box to hold the slider elements
|
nickjillings@1686
|
122 var canvas = document.createElement('div');
|
nickjillings@1683
|
123 canvas.id = 'slider';
|
nickjillings@1633
|
124 canvas.align = "left";
|
nickjillings@1633
|
125 canvas.addEventListener('dragover',function(event){
|
nickjillings@1633
|
126 event.preventDefault();
|
nickjillings@1633
|
127 return false;
|
nickjillings@1633
|
128 },false);
|
nickjillings@1633
|
129 var sliderMargin = document.createAttribute('marginsize');
|
nickjillings@1633
|
130 sliderMargin.nodeValue = 42; // Set default margins to 42px either side
|
nickjillings@1697
|
131 // Must have a known EXACT width, as this is used later to determine the ratings
|
nickjillings@1633
|
132 var w = (Number(sliderMargin.nodeValue)+8)*2;
|
nickjillings@1633
|
133 canvas.style.width = width - w +"px";
|
nickjillings@1633
|
134 canvas.style.marginLeft = sliderMargin.nodeValue +'px';
|
nickjillings@1633
|
135 canvas.setAttributeNode(sliderMargin);
|
nickjillings@1683
|
136 sliderBox.appendChild(canvas);
|
nickjillings@1697
|
137
|
nickjillings@1657
|
138 // Create the div to hold any scale objects
|
nickjillings@1657
|
139 var scale = document.createElement('div');
|
nickjillings@1657
|
140 scale.className = 'sliderScale';
|
nickjillings@1657
|
141 scale.id = 'sliderScaleHolder';
|
nickjillings@1657
|
142 scale.align = 'left';
|
nickjillings@1657
|
143 sliderBox.appendChild(scale);
|
nickjillings@1657
|
144
|
nickjillings@1697
|
145 // Global parent for the comment boxes on the page
|
nickjillings@1684
|
146 var feedbackHolder = document.createElement('div');
|
nickjillings@1644
|
147 feedbackHolder.id = 'feedbackHolder';
|
nickjillings@1642
|
148
|
nickjillings@1648
|
149 testContent.style.zIndex = 1;
|
nickjillings@1582
|
150 interfaceContext.insertPoint.innerHTML = null; // Clear the current schema
|
nickjillings@1642
|
151
|
nickjillings@1648
|
152 // Inject into HTML
|
nickjillings@1648
|
153 testContent.appendChild(title); // Insert the title
|
nickjillings@1657
|
154 testContent.appendChild(pagetitle);
|
nickjillings@1648
|
155 testContent.appendChild(interfaceButtons);
|
nickjillings@1648
|
156 testContent.appendChild(sliderBox);
|
nickjillings@1648
|
157 testContent.appendChild(feedbackHolder);
|
nickjillings@1582
|
158 interfaceContext.insertPoint.appendChild(testContent);
|
nickjillings@1642
|
159
|
nickjillings@1646
|
160 // Load the full interface
|
nickjillings@1634
|
161 testState.initialise();
|
nickjillings@1634
|
162 testState.advanceState();
|
nickjillings@1649
|
163
|
nickjillings@1642
|
164 }
|
nickjillings@1642
|
165
|
nickjillings@1581
|
166 function loadTest(audioHolderObject)
|
nickjillings@1644
|
167 {
|
nickjillings@1617
|
168
|
nickjillings@1617
|
169 // Reset audioEngineContext.Metric globals for new test
|
nickjillings@1620
|
170 audioEngineContext.newTestPage();
|
nickjillings@1617
|
171
|
nickjillings@1581
|
172 var id = audioHolderObject.id;
|
nickjillings@1644
|
173
|
nickjillings@1644
|
174 var feedbackHolder = document.getElementById('feedbackHolder');
|
nickjillings@1644
|
175 var canvas = document.getElementById('slider');
|
nickjillings@1644
|
176 feedbackHolder.innerHTML = null;
|
nickjillings@1644
|
177 canvas.innerHTML = null;
|
nickjillings@1657
|
178
|
nickjillings@1657
|
179 // Setup question title
|
nickjillings@1584
|
180 var interfaceObj = audioHolderObject.interfaces;
|
nickjillings@1584
|
181 var commentBoxPrefix = "Comment on track";
|
nickjillings@1584
|
182 if (interfaceObj.length != 0) {
|
nickjillings@1584
|
183 interfaceObj = interfaceObj[0];
|
nickjillings@1584
|
184 var titleNode = interfaceObj.title;
|
nickjillings@1584
|
185 if (titleNode != undefined)
|
nickjillings@1584
|
186 {
|
nickjillings@1584
|
187 document.getElementById('pageTitle').textContent = titleNode;
|
nickjillings@1584
|
188 }
|
nickjillings@1584
|
189 var positionScale = canvas.style.width.substr(0,canvas.style.width.length-2);
|
nickjillings@1584
|
190 var offset = Number(document.getElementById('slider').attributes['marginsize'].value);
|
nickjillings@1584
|
191 var scale = document.getElementById('sliderScaleHolder');
|
nickjillings@1584
|
192 scale.innerHTML = null;
|
nickjillings@1584
|
193 $(interfaceObj.scale).each(function(index,scaleObj){
|
nickjillings@1584
|
194 var value = document.createAttribute('value');
|
nickjillings@1584
|
195 var position = Number(scaleObj[0])*0.01;
|
nickjillings@1584
|
196 value.nodeValue = position;
|
nickjillings@1584
|
197 var pixelPosition = (position*positionScale)+offset;
|
nickjillings@1584
|
198 var scaleDOM = document.createElement('span');
|
nickjillings@1584
|
199 scaleDOM.textContent = scaleObj[1];
|
nickjillings@1584
|
200 scale.appendChild(scaleDOM);
|
nickjillings@1584
|
201 scaleDOM.style.left = Math.floor((pixelPosition-($(scaleDOM).width()/2)))+'px';
|
nickjillings@1584
|
202 scaleDOM.setAttributeNode(value);
|
nickjillings@1584
|
203 });
|
nickjillings@1584
|
204
|
nickjillings@1584
|
205 if (interfaceObj.commentBoxPrefix != undefined) {
|
nickjillings@1584
|
206 commentBoxPrefix = interfaceObj.commentBoxPrefix;
|
nickjillings@1584
|
207 }
|
nickjillings@2028
|
208 }
|
nickjillings@1644
|
209
|
nickjillings@1688
|
210 /// CHECK FOR SAMPLE RATE COMPATIBILITY
|
nickjillings@1581
|
211 if (audioHolderObject.sampleRate != undefined) {
|
nickjillings@1581
|
212 if (Number(audioHolderObject.sampleRate) != audioContext.sampleRate) {
|
nickjillings@1584
|
213 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@1688
|
214 alert(errStr);
|
nickjillings@1688
|
215 return;
|
nickjillings@1688
|
216 }
|
nickjillings@1688
|
217 }
|
nickjillings@1655
|
218
|
nickjillings@1581
|
219 var commentShow = audioHolderObject.elementComments;
|
nickjillings@1675
|
220
|
nickjillings@1581
|
221 var loopPlayback = audioHolderObject.loop;
|
nickjillings@1581
|
222
|
nickjillings@1667
|
223 audioEngineContext.loopPlayback = loopPlayback;
|
nickjillings@1667
|
224 // Create AudioEngine bindings for playback
|
nickjillings@1667
|
225 if (loopPlayback) {
|
nickjillings@1667
|
226 audioEngineContext.selectedTrack = function(id) {
|
nickjillings@1667
|
227 for (var i=0; i<this.audioObjects.length; i++)
|
nickjillings@1667
|
228 {
|
nickjillings@1667
|
229 if (id == i) {
|
nickjillings@1637
|
230 this.audioObjects[i].loopStart();
|
nickjillings@1667
|
231 } else {
|
nickjillings@1637
|
232 this.audioObjects[i].loopStop();
|
nickjillings@1667
|
233 }
|
nickjillings@1667
|
234 }
|
nickjillings@1667
|
235 };
|
nickjillings@1667
|
236 } else {
|
nickjillings@1667
|
237 audioEngineContext.selectedTrack = function(id) {
|
nickjillings@1667
|
238 for (var i=0; i<this.audioObjects.length; i++)
|
nickjillings@1667
|
239 {
|
nickjillings@2002
|
240 this.audioObjects[i].outputGain.gain.value = 0.0;
|
nickjillings@2002
|
241 this.audioObjects[i].stop();
|
nickjillings@1667
|
242 }
|
nickjillings@2004
|
243 if (this.status == 1) {
|
nickjillings@2004
|
244 this.audioObjects[id].outputGain.gain.value = 1.0;
|
nickjillings@2004
|
245 this.audioObjects[id].play(audioContext.currentTime+0.01);
|
nickjillings@2004
|
246 }
|
nickjillings@1667
|
247 };
|
nickjillings@1667
|
248 }
|
nickjillings@1667
|
249
|
nickjillings@1656
|
250 currentTestHolder = document.createElement('audioHolder');
|
nickjillings@1581
|
251 currentTestHolder.id = audioHolderObject.id;
|
nickjillings@1581
|
252 currentTestHolder.repeatCount = audioHolderObject.repeatCount;
|
nickjillings@1656
|
253
|
nickjillings@1581
|
254 var randomise = audioHolderObject.randomiseOrder;
|
nickjillings@1655
|
255
|
nickjillings@1581
|
256 var audioElements = audioHolderObject.audioElements;
|
nickjillings@1668
|
257 currentTrackOrder = [];
|
nickjillings@1655
|
258 if (randomise) {
|
nickjillings@1581
|
259 audioHolderObject.audioElements = randomiseOrder(audioHolderObject.audioElements);
|
nickjillings@1655
|
260 }
|
nickjillings@1655
|
261
|
nickjillings@1668
|
262 // Delete any previous audioObjects associated with the audioEngine
|
nickjillings@1668
|
263 audioEngineContext.audioObjects = [];
|
nickjillings@1668
|
264
|
nickjillings@1697
|
265 // Find all the audioElements from the audioHolder
|
nickjillings@1581
|
266 $(audioHolderObject.audioElements).each(function(index,element){
|
nickjillings@1688
|
267 // Find URL of track
|
nickjillings@1697
|
268 // In this jQuery loop, variable 'this' holds the current audioElement.
|
nickjillings@1697
|
269
|
nickjillings@1697
|
270 // Now load each audio sample. First create the new track by passing the full URL
|
nickjillings@1581
|
271 var trackURL = audioHolderObject.hostURL + element.url;
|
nickjillings@1582
|
272 var audioObject = audioEngineContext.newTrack(element);
|
nickjillings@1675
|
273
|
nickjillings@2035
|
274 var node = interfaceContext.createCommentBox(audioObject);
|
nickjillings@1697
|
275
|
nickjillings@1686
|
276 // Create a slider per track
|
nickjillings@1583
|
277 audioObject.interfaceDOM = new sliderObject(audioObject);
|
nickjillings@2014
|
278
|
nickjillings@1686
|
279 // Distribute it randomnly
|
nickjillings@2006
|
280 var w = window.innerWidth - (offset+8)*2;
|
nickjillings@1686
|
281 w = Math.random()*w;
|
nickjillings@2006
|
282 w = Math.floor(w+(offset+8));
|
nickjillings@1583
|
283 audioObject.interfaceDOM.trackSliderObj.style.left = w+'px';
|
nickjillings@1689
|
284
|
nickjillings@1583
|
285 canvas.appendChild(audioObject.interfaceDOM.trackSliderObj);
|
nickjillings@1583
|
286 audioObject.metric.initialised(convSliderPosToRate(audioObject.interfaceDOM.trackSliderObj));
|
b@1610
|
287
|
nickjillings@1696
|
288 });
|
nickjillings@1582
|
289 if (commentShow) {
|
nickjillings@1582
|
290 interfaceContext.showCommentBoxes(feedbackHolder,true);
|
nickjillings@1582
|
291 }
|
nickjillings@1684
|
292
|
nickjillings@1581
|
293 $(audioHolderObject.commentQuestions).each(function(index,element) {
|
nickjillings@2032
|
294 var node = interfaceContext.createCommentQuestion(element);
|
nickjillings@2032
|
295 feedbackHolder.appendChild(node.holder);
|
nickjillings@1674
|
296 });
|
nickjillings@2013
|
297
|
nickjillings@2013
|
298
|
nickjillings@2013
|
299 testWaitIndicator();
|
nickjillings@1649
|
300 }
|
nickjillings@1649
|
301
|
nickjillings@1583
|
302 function sliderObject(audioObject) {
|
nickjillings@1583
|
303 // Create a new slider object;
|
nickjillings@1583
|
304 this.parent = audioObject;
|
nickjillings@1583
|
305 this.trackSliderObj = document.createElement('div');
|
nickjillings@1583
|
306 this.trackSliderObj.className = 'track-slider';
|
nickjillings@1583
|
307 this.trackSliderObj.id = 'track-slider-'+audioObject.id;
|
nickjillings@1583
|
308
|
nickjillings@1583
|
309 this.trackSliderObj.setAttribute('trackIndex',audioObject.id);
|
nickjillings@1583
|
310 this.trackSliderObj.innerHTML = '<span>'+audioObject.id+'</span>';
|
nickjillings@1583
|
311 this.trackSliderObj.draggable = true;
|
nickjillings@1583
|
312 this.trackSliderObj.ondragend = dragEnd;
|
nickjillings@1583
|
313
|
nickjillings@1583
|
314 // Onclick, switch playback to that track
|
nickjillings@1583
|
315 this.trackSliderObj.onclick = function() {
|
nickjillings@1583
|
316 // Start the test on first click, that way timings are more accurate.
|
nickjillings@1583
|
317 audioEngineContext.play();
|
nickjillings@1583
|
318 if (audioEngineContext.audioObjectsReady) {
|
nickjillings@1583
|
319 // Cannot continue to issue play command until audioObjects reported as ready!
|
nickjillings@1583
|
320 // Get the track ID from the object ID
|
nickjillings@1583
|
321 var id = Number(event.srcElement.attributes['trackIndex'].value);
|
nickjillings@1583
|
322 //audioEngineContext.metric.sliderPlayed(id);
|
nickjillings@1583
|
323 audioEngineContext.selectedTrack(id);
|
nickjillings@1583
|
324 // Currently playing track red, rest green
|
nickjillings@1583
|
325
|
nickjillings@1583
|
326 //document.getElementById('track-slider-'+index).style.backgroundColor = "#FF0000";
|
nickjillings@1583
|
327 $('.track-slider').removeClass('track-slider-playing');
|
nickjillings@1583
|
328 $(event.srcElement).addClass('track-slider-playing');
|
nickjillings@1583
|
329 $('.comment-div').removeClass('comment-box-playing');
|
nickjillings@1583
|
330 $('#comment-div-'+id).addClass('comment-box-playing');
|
nickjillings@1583
|
331 }
|
nickjillings@1583
|
332 };
|
nickjillings@1583
|
333
|
nickjillings@1583
|
334 this.exportXMLDOM = function() {
|
nickjillings@1583
|
335 // Called by the audioObject holding this element. Must be present
|
nickjillings@1583
|
336 var node = document.createElement('value');
|
nickjillings@1583
|
337 node.textContent = convSliderPosToRate(this.trackSliderObj);
|
nickjillings@1583
|
338 return node;
|
nickjillings@1583
|
339 };
|
nickjillings@1583
|
340 }
|
nickjillings@1686
|
341
|
nickjillings@1686
|
342 function dragEnd(ev) {
|
nickjillings@1686
|
343 // Function call when a div has been dropped
|
nickjillings@1643
|
344 var slider = document.getElementById('slider');
|
nickjillings@1633
|
345 var marginSize = Number(slider.attributes['marginsize'].value);
|
nickjillings@1661
|
346 var w = slider.style.width;
|
nickjillings@1661
|
347 w = Number(w.substr(0,w.length-2));
|
nickjillings@1661
|
348 var x = ev.x;
|
nickjillings@1633
|
349 if (x >= marginSize && x < w+marginSize) {
|
nickjillings@1661
|
350 this.style.left = (x)+'px';
|
nickjillings@1686
|
351 } else {
|
nickjillings@1633
|
352 if (x<marginSize) {
|
nickjillings@1633
|
353 this.style.left = marginSize+'px';
|
nickjillings@1686
|
354 } else {
|
nickjillings@1633
|
355 this.style.left = (w+marginSize) + 'px';
|
nickjillings@1686
|
356 }
|
nickjillings@1686
|
357 }
|
nickjillings@1583
|
358 var time = audioEngineContext.timer.getTestTime();
|
nickjillings@1583
|
359 var id = Number(ev.srcElement.getAttribute('trackindex'));
|
nickjillings@1583
|
360 audioEngineContext.audioObjects[id].metric.moved(time,convSliderPosToRate(ev.srcElement));
|
nickjillings@1642
|
361 }
|
nickjillings@1642
|
362
|
b@1609
|
363 function buttonSubmitClick() // TODO: Only when all songs have been played!
|
nickjillings@1649
|
364 {
|
nickjillings@1614
|
365 hasBeenPlayed = audioEngineContext.checkAllPlayed();
|
nickjillings@1614
|
366 if (hasBeenPlayed.length == 0) {
|
nickjillings@1614
|
367 if (audioEngineContext.status == 1) {
|
nickjillings@1614
|
368 var playback = document.getElementById('playback-button');
|
nickjillings@1614
|
369 playback.click();
|
nickjillings@1614
|
370 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
|
nickjillings@1614
|
371 } else
|
nickjillings@1614
|
372 {
|
nickjillings@1614
|
373 if (audioEngineContext.timer.testStarted == false)
|
nickjillings@1614
|
374 {
|
nickjillings@1614
|
375 alert('You have not started the test! Please press start to begin the test!');
|
nickjillings@1614
|
376 return;
|
nickjillings@1614
|
377 }
|
nickjillings@1614
|
378 }
|
nickjillings@1634
|
379 testState.advanceState();
|
b@1610
|
380 } else // if a fragment has not been played yet
|
b@1610
|
381 {
|
nickjillings@1614
|
382 str = "";
|
nickjillings@1614
|
383 if (hasBeenPlayed.length > 1) {
|
nickjillings@1614
|
384 for (var i=0; i<hasBeenPlayed.length; i++) {
|
nickjillings@1614
|
385 str = str + hasBeenPlayed[i];
|
nickjillings@1614
|
386 if (i < hasBeenPlayed.length-2){
|
nickjillings@1614
|
387 str += ", ";
|
nickjillings@1614
|
388 } else if (i == hasBeenPlayed.length-2) {
|
nickjillings@1614
|
389 str += " or ";
|
nickjillings@1614
|
390 }
|
nickjillings@1614
|
391 }
|
nickjillings@1614
|
392 alert('You have not played fragments ' + str + ' yet. Please listen, rate and comment all samples before submitting.');
|
nickjillings@1614
|
393 } else {
|
nickjillings@1614
|
394 alert('You have not played fragment ' + hasBeenPlayed[0] + ' yet. Please listen, rate and comment all samples before submitting.');
|
nickjillings@1614
|
395 }
|
b@1610
|
396 return;
|
b@1610
|
397 }
|
nickjillings@1650
|
398 }
|
nickjillings@1650
|
399
|
nickjillings@1583
|
400 function convSliderPosToRate(slider)
|
nickjillings@1661
|
401 {
|
nickjillings@1661
|
402 var w = document.getElementById('slider').style.width;
|
nickjillings@1633
|
403 var marginsize = Number(document.getElementById('slider').attributes['marginsize'].value);
|
nickjillings@1661
|
404 var maxPix = w.substr(0,w.length-2);
|
nickjillings@1661
|
405 var pix = slider.style.left;
|
nickjillings@1661
|
406 pix = pix.substr(0,pix.length-2);
|
nickjillings@1633
|
407 var rate = (pix-marginsize)/maxPix;
|
nickjillings@1661
|
408 return rate;
|
nickjillings@1661
|
409 }
|
nickjillings@1661
|
410
|
nickjillings@1633
|
411 function resizeWindow(event){
|
nickjillings@1633
|
412 // Function called when the window has been resized.
|
nickjillings@1633
|
413 // MANDATORY FUNCTION
|
nickjillings@1633
|
414
|
nickjillings@1633
|
415 // Store the slider marker values
|
nickjillings@1633
|
416 var holdValues = [];
|
nickjillings@1633
|
417 $(".track-slider").each(function(index,sliderObj){
|
nickjillings@1633
|
418 holdValues.push(convSliderPosToRate(index));
|
nickjillings@1633
|
419 });
|
nickjillings@1633
|
420
|
nickjillings@1633
|
421 var width = event.target.innerWidth;
|
nickjillings@1633
|
422 var canvas = document.getElementById('sliderCanvasHolder');
|
nickjillings@1633
|
423 var sliderDiv = canvas.children[0];
|
nickjillings@1633
|
424 var sliderScaleDiv = canvas.children[1];
|
nickjillings@1633
|
425 var marginsize = Number(sliderDiv.attributes['marginsize'].value);
|
nickjillings@1633
|
426 var w = (marginsize+8)*2;
|
nickjillings@1633
|
427 sliderDiv.style.width = width - w + 'px';
|
nickjillings@1633
|
428 var width = width - w;
|
nickjillings@1633
|
429 // Move sliders into new position
|
nickjillings@1633
|
430 $(".track-slider").each(function(index,sliderObj){
|
nickjillings@1633
|
431 var pos = holdValues[index];
|
nickjillings@1633
|
432 var pix = pos * width;
|
nickjillings@1633
|
433 sliderObj.style.left = pix+marginsize+'px';
|
nickjillings@1633
|
434 });
|
nickjillings@1633
|
435
|
nickjillings@1633
|
436 // Move scale labels
|
nickjillings@1633
|
437 $(sliderScaleDiv.children).each(function(index,scaleObj){
|
nickjillings@1633
|
438 var position = Number(scaleObj.attributes['value'].value);
|
nickjillings@1633
|
439 var pixelPosition = (position*width)+marginsize;
|
nickjillings@1633
|
440 scaleObj.style.left = Math.floor((pixelPosition-($(scaleObj).width()/2)))+'px';
|
nickjillings@1633
|
441 });
|
nickjillings@1633
|
442 }
|
nickjillings@1633
|
443
|
nickjillings@1581
|
444 function pageXMLSave(store, testXML)
|
nickjillings@1654
|
445 {
|
nickjillings@1654
|
446 // Saves a specific test page
|
nickjillings@1634
|
447 var xmlDoc = store;
|
nickjillings@1660
|
448 // Check if any session wide metrics are enabled
|
nickjillings@1676
|
449
|
nickjillings@1581
|
450 var commentShow = testXML.elementComments;
|
nickjillings@1676
|
451
|
nickjillings@1660
|
452 var metric = document.createElement('metric');
|
nickjillings@1660
|
453 if (audioEngineContext.metric.enableTestTimer)
|
nickjillings@1660
|
454 {
|
nickjillings@1660
|
455 var testTime = document.createElement('metricResult');
|
nickjillings@1660
|
456 testTime.id = 'testTime';
|
nickjillings@1660
|
457 testTime.textContent = audioEngineContext.timer.testDuration;
|
nickjillings@1660
|
458 metric.appendChild(testTime);
|
nickjillings@1660
|
459 }
|
nickjillings@1660
|
460 xmlDoc.appendChild(metric);
|
nickjillings@1578
|
461 var audioObjects = audioEngineContext.audioObjects;
|
nickjillings@1578
|
462 for (var i=0; i<audioObjects.length; i++)
|
nickjillings@1655
|
463 {
|
nickjillings@1583
|
464 var audioElement = audioEngineContext.audioObjects[i].exportXMLDOM();
|
nickjillings@1655
|
465 xmlDoc.appendChild(audioElement);
|
nickjillings@1655
|
466 }
|
nickjillings@2032
|
467
|
nickjillings@2032
|
468 $(interfaceContext.commentQuestions).each(function(index,element){
|
nickjillings@2032
|
469 var node = element.exportXMLDOM();
|
nickjillings@2032
|
470 xmlDoc.appendChild(node);
|
nickjillings@2032
|
471 });
|
nickjillings@1634
|
472 store = xmlDoc;
|
nickjillings@1676
|
473 } |