b@0
|
1 function launch(sesScript,noTst)
|
b@0
|
2 % launch a session script composed of a succession of single tests
|
b@0
|
3 % sesScript: session script name if recalling old script (optional)
|
b@0
|
4 % noTst: start from specified test (optional)
|
b@0
|
5 %
|
b@0
|
6 % by Brecht De Man at Centre for Digital Music, 12 January 2014
|
b@0
|
7
|
b@0
|
8 % make sure you are in listening test folder
|
b@0
|
9 cdFolder = which('launch');
|
b@0
|
10 cdFolder = cdFolder(1:end-8); % remove 'launch.m' from string
|
b@0
|
11 cd(cdFolder);
|
b@0
|
12
|
b@0
|
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
b@0
|
14 % Interface
|
b@0
|
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
b@0
|
16 cd0=cd; % save path
|
b@0
|
17
|
b@0
|
18 % Choose Session
|
b@0
|
19 if ~exist('sesScript', 'file') % if sesScript was not provided or doesn't exist
|
b@0
|
20 [sesScript,cdScript]=uigetfile('*.txt','Please enter a session script');
|
b@0
|
21 if ~sesScript % if still not provided
|
b@0
|
22 return % exit
|
b@0
|
23 end
|
b@0
|
24 else
|
b@0
|
25 cdScript=cd0; % folder of script is same as folder of listening test
|
b@0
|
26 end
|
b@0
|
27
|
b@0
|
28
|
b@0
|
29 % Enter name and check ID is not already used...
|
b@0
|
30 ASK=1;
|
b@0
|
31 reREAD=0;
|
b@0
|
32 while ASK
|
b@0
|
33 prompt={'Please enter your name or any ID : '};
|
b@0
|
34 def={'myID'};
|
b@0
|
35 title='ID';
|
b@0
|
36 lineNo=1;
|
b@0
|
37 answer=inputdlg(prompt,title,lineNo,def);
|
b@0
|
38 if isempty(answer)
|
b@0
|
39 return
|
b@0
|
40 end
|
b@0
|
41 id=answer{1}; % from cell to string
|
b@0
|
42
|
b@0
|
43 % if name already present, return to former test
|
b@0
|
44 d=dir('responses');
|
b@0
|
45 ASK=0;
|
b@0
|
46 for noF=1:length(d)
|
b@0
|
47 name=strtok(d(noF).name,'.');
|
b@0
|
48 if strcmp(name,answer)
|
b@0
|
49 switch lower(questdlg('This ID is already used. Do you wish to re-use it?'))
|
b@0
|
50 case 'yes'
|
b@0
|
51 cd('responses');
|
b@0
|
52 ASK=0;
|
b@0
|
53 expre=sprintf('load %s',id);
|
b@0
|
54 eval(expre);
|
b@0
|
55 expre=sprintf('tstDat=%s.tstDat;',id); % read mat-file
|
b@0
|
56 eval(expre);
|
b@0
|
57 reREAD=1;
|
b@0
|
58 cd('../');
|
b@0
|
59 break;
|
b@0
|
60 case {'no','cancel'}
|
b@0
|
61 ASK=1;
|
b@0
|
62 break;
|
b@0
|
63 end
|
b@0
|
64 end
|
b@0
|
65 end
|
b@0
|
66 end
|
b@0
|
67
|
b@0
|
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
b@0
|
69 % Read the script and create tstdat
|
b@0
|
70 % IF THE TEST WAS DONE ALREADY ONCE, THE .MAT FILE IS USED INSTEAD (see above)
|
b@0
|
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
b@0
|
72 if ~reREAD
|
b@0
|
73 cd(cdScript);
|
b@0
|
74 tstDat=[];
|
b@0
|
75 fid=fopen(sesScript,'r');
|
b@0
|
76 while ~feof(fid) % read until end of session file
|
b@0
|
77 lin=fgetl(fid);
|
b@0
|
78 [fil1,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1);
|
b@0
|
79 if COUNT
|
b@0
|
80 if ~strcmp(fil1(1),'%') % if not a comment
|
b@0
|
81 [fil2,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin(NEXTINDEX:end),'%s',1);
|
b@0
|
82 tstDat{end+1}.tstType=fil1; % what type of test?
|
b@0
|
83 tstDat{end}.tstFile=fil2; % test file?
|
b@0
|
84 end
|
b@0
|
85 end
|
b@0
|
86 end
|
b@0
|
87 fclose(fid);
|
b@0
|
88
|
b@0
|
89 % ensure even length (sound list for every test)
|
b@0
|
90 if mod(length(tstDat),2)
|
b@0
|
91 warning('Uneven number of lines in session script. ');
|
b@0
|
92 % randomise order of tests
|
b@0
|
93 else
|
b@0
|
94 testPerm = randperm(length(tstDat)/2);
|
b@0
|
95 tstDatCopy = tstDat;
|
b@0
|
96 for t = 1:length(tstDat)/2
|
b@0
|
97 tstDat{2*t-1} = tstDatCopy{2*testPerm(t)-1};
|
b@0
|
98 tstDat{2*t} = tstDatCopy{2*testPerm(t)};
|
b@0
|
99 end
|
b@0
|
100 end
|
b@0
|
101 end
|
b@0
|
102
|
b@0
|
103 cd(cd0); % back to listening test folder
|
b@0
|
104
|
b@0
|
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
b@0
|
106 % Set session variables
|
b@0
|
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
b@0
|
108
|
b@0
|
109 sesDat.sesScript=sesScript;
|
b@0
|
110 sesDat.id=id;
|
b@0
|
111 sesDat.tstDat=tstDat;
|
b@0
|
112 sesDat.reREAD=reREAD;
|
b@0
|
113 sesDat.noTst=1;
|
b@0
|
114 sesDat.nbTst=length(tstDat);
|
b@0
|
115 sesDat.date=datestr(now);
|
b@0
|
116 sesDat.cuSndListFile=[];
|
b@0
|
117 sesDat.cuSndList=[];
|
b@0
|
118
|
b@0
|
119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
b@0
|
120 % Start test
|
b@0
|
121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
b@0
|
122 % load the sndlist
|
b@0
|
123 if sesDat.noTst>1 % where were we?
|
b@0
|
124 sesDat.noTst=noTst-1; % IS THIS RIGHT?
|
b@0
|
125 sndList(sesDat);
|
b@0
|
126 else % always start with first test (allow changing earlier stuff if desired)
|
b@0
|
127 expr=sprintf('%s(sesDat);',tstDat{1}.tstType);
|
b@0
|
128 eval(expr);
|
b@0
|
129 end |