comparison ape.js @ 214:7c93a516b748 Dev_main

Implemeted Features #1267, #1268 and started #1266. Standardised fragment checking.
author Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk>
date Tue, 16 Jun 2015 16:59:08 +0100
parents 5d251b4aabd6
children e5c565c19493
comparison
equal deleted inserted replaced
213:28525223b3c0 214:7c93a516b748
56 this.lastClicked = id; 56 this.lastClicked = id;
57 audioEngineContext.audioObjects[id].metric.listening(time); 57 audioEngineContext.audioObjects[id].metric.listening(time);
58 } 58 }
59 console.log('slider ' + id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id 59 console.log('slider ' + id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id
60 }; 60 };
61
62 // Bindings for interfaceContext
63 Interface.prototype.checkAllPlayed = function()
64 {
65 hasBeenPlayed = audioEngineContext.checkAllPlayed();
66 if (hasBeenPlayed.length > 0) // if a fragment has not been played yet
67 {
68 str = "";
69 if (hasBeenPlayed.length > 1) {
70 for (var i=0; i<hasBeenPlayed.length; i++) {
71 str = str + hasBeenPlayed[i];
72 if (i < hasBeenPlayed.length-2){
73 str += ", ";
74 } else if (i == hasBeenPlayed.length-2) {
75 str += " or ";
76 }
77 }
78 alert('You have not played fragments ' + str + ' yet. Please listen, rate and comment all samples before submitting.');
79 } else {
80 alert('You have not played fragment ' + hasBeenPlayed[0] + ' yet. Please listen, rate and comment all samples before submitting.');
81 }
82 return false;
83 }
84 return true;
85 }
86
87 Interface.prototype.checkAllMoved = function() {
88 var audioObjs = audioEngineContext.audioObjects;
89 var state = true;
90 var strNums = [];
91 for (var i=0; i<audioObjs.length; i++)
92 {
93 if (audioObjs[i].metric.wasMoved == false) {
94 state = false;
95 strNums.push(i);
96 }
97 }
98 if (state == false) {
99 if (strNums.length > 1) {
100 var str = "";
101 for (var i=0; i<strNums.length; i++) {
102 str = str + strNums[i];
103 if (i < strNums.length-2){
104 str += ", ";
105 } else if (i == strNums.length-2) {
106 str += " or ";
107 }
108 }
109 alert('You have not moved fragments ' + str + ' yet. Please listen, rate and comment all samples before submitting.');
110 } else {
111 alert('You have not moved fragment ' + strNums[0] + ' yet. Please listen, rate and comment all samples before submitting.');
112 }
113 }
114 return state;
115 }
116
117 Interface.prototype.checkAllCommented = function() {
118 var audioObjs = audioEngineContext.audioObjects;
119 var audioHolder = testState.stateMap[testState.stateIndex];
120 var state = true;
121 if (audioHolder.elementComments) {
122 var strNums = [];
123 for (var i=0; i<audioObjs.length; i++)
124 {
125 if (audioObjs[i].commentDOM.trackCommentBox.value.length == 0) {
126 state = false;
127 strNums.push(i);
128 }
129 }
130 if (state == false) {
131 if (strNums.length > 1) {
132 var str = "";
133 for (var i=0; i<strNums.length; i++) {
134 str = str + strNums[i];
135 if (i < strNums.length-2){
136 str += ", ";
137 } else if (i == strNums.length-2) {
138 str += " or ";
139 }
140 }
141 alert('You have not commented on fragments ' + str + ' yet. Please listen, rate and comment all samples before submitting.');
142 } else {
143 alert('You have not commented on fragment ' + strNums[0] + ' yet. Please listen, rate and comment all samples before submitting.');
144 }
145 }
146 }
147 return state;
148 }
61 149
62 // Bindings for audioObjects 150 // Bindings for audioObjects
63 151
64 // Create the top div for the Title element 152 // Create the top div for the Title element
65 var titleAttr = specification.title; 153 var titleAttr = specification.title;
351 audioEngineContext.audioObjects[id].metric.moved(time,convSliderPosToRate(ev.srcElement)); 439 audioEngineContext.audioObjects[id].metric.moved(time,convSliderPosToRate(ev.srcElement));
352 } 440 }
353 441
354 function buttonSubmitClick() // TODO: Only when all songs have been played! 442 function buttonSubmitClick() // TODO: Only when all songs have been played!
355 { 443 {
356 hasBeenPlayed = audioEngineContext.checkAllPlayed(); 444 var checks = specification.commonInterface.options;
357 if (hasBeenPlayed.length == 0) { 445 var canContinue = true;
446 for (var i=0; i<checks.length; i++) {
447 if (checks[i].type == 'check')
448 {
449 switch(checks[i].check) {
450 case 'fragmentPlayed':
451 // Check if all fragments have been played
452 var checkState = interfaceContext.checkAllPlayed();
453 if (checkState == false) {canContinue = false;}
454 break;
455 case 'fragmentFullPlayback':
456 // Check all fragments have been played to their full length
457 var checkState = interfaceContext.checkAllPlayed();
458 if (checkState == false) {canContinue = false;}
459 console.log('NOTE: fragmentFullPlayback not currently implemented, performing check fragmentPlayed instead');
460 break;
461 case 'fragmentMoved':
462 // Check all fragment sliders have been moved.
463 var checkState = interfaceContext.checkAllMoved();
464 if (checkState == false) {canContinue = false;}
465 break;
466 case 'fragmentComments':
467 // Check all fragment sliders have been moved.
468 var checkState = interfaceContext.checkAllCommented();
469 if (checkState == false) {canContinue = false;}
470 break;
471 }
472
473 }
474 }
475
476 if (canContinue) {
358 if (audioEngineContext.status == 1) { 477 if (audioEngineContext.status == 1) {
359 var playback = document.getElementById('playback-button'); 478 var playback = document.getElementById('playback-button');
360 playback.click(); 479 playback.click();
361 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options 480 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
362 } else 481 } else
366 alert('You have not started the test! Please press start to begin the test!'); 485 alert('You have not started the test! Please press start to begin the test!');
367 return; 486 return;
368 } 487 }
369 } 488 }
370 testState.advanceState(); 489 testState.advanceState();
371 } else // if a fragment has not been played yet 490 }
372 {
373 str = "";
374 if (hasBeenPlayed.length > 1) {
375 for (var i=0; i<hasBeenPlayed.length; i++) {
376 str = str + hasBeenPlayed[i];
377 if (i < hasBeenPlayed.length-2){
378 str += ", ";
379 } else if (i == hasBeenPlayed.length-2) {
380 str += " or ";
381 }
382 }
383 alert('You have not played fragments ' + str + ' yet. Please listen, rate and comment all samples before submitting.');
384 } else {
385 alert('You have not played fragment ' + hasBeenPlayed[0] + ' yet. Please listen, rate and comment all samples before submitting.');
386 }
387 return;
388 }
389 } 491 }
390 492
391 function convSliderPosToRate(slider) 493 function convSliderPosToRate(slider)
392 { 494 {
393 var w = document.getElementById('slider').style.width; 495 var w = document.getElementById('slider').style.width;