annotate listeningTest/launch.m @ 15:24be5e9ce25b tip

Update README
author Brecht De Man <brecht.deman@bcu.ac.uk>
date Thu, 20 Sep 2018 12:23:20 +0200
parents 3c26ad251043
children
rev   line source
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@9 43 % make robust
b@9 44 % if first character is a number:
b@9 45 if id(1) >= '0' && id(1) <= '9'
b@9 46 id = strcat('NUM', id);
b@9 47 end
b@9 48 % if it contains spaces or special characters:
b@9 49 id = strrep(id, ' ', '_');
b@9 50 id = strrep(id, '/', 'SLASH');
b@9 51 id = strrep(id, '\', 'BACKSLASH');
b@9 52 id = strrep(id, ':', 'COLON');
b@9 53 id = strrep(id, '.', 'DOT');
b@9 54 id = strrep(id, ',', 'COMMA');
b@9 55 id = strrep(id, '?', 'QMARK');
b@9 56 id = strrep(id, ';', 'SEMICOLON');
b@9 57 id = strrep(id, '!', 'EXCLMARK');
b@9 58 id = strrep(id, '(', 'OBRACKET');
b@9 59 id = strrep(id, ')', 'CBRACKET');
b@9 60
b@0 61 % if name already present, return to former test
b@0 62 d=dir('responses');
b@0 63 ASK=0;
b@0 64 for noF=1:length(d)
b@0 65 name=strtok(d(noF).name,'.');
b@0 66 if strcmp(name,answer)
b@0 67 switch lower(questdlg('This ID is already used. Do you wish to re-use it?'))
b@0 68 case 'yes'
b@0 69 cd('responses');
b@0 70 ASK=0;
b@0 71 expre=sprintf('load %s',id);
b@0 72 eval(expre);
b@0 73 expre=sprintf('tstDat=%s.tstDat;',id); % read mat-file
b@0 74 eval(expre);
b@0 75 reREAD=1;
b@0 76 cd('../');
b@0 77 break;
b@0 78 case {'no','cancel'}
b@0 79 ASK=1;
b@0 80 break;
b@0 81 end
b@0 82 end
b@0 83 end
b@0 84 end
b@0 85
b@0 86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b@0 87 % Read the script and create tstdat
b@0 88 % IF THE TEST WAS DONE ALREADY ONCE, THE .MAT FILE IS USED INSTEAD (see above)
b@0 89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b@10 90 RANDOMORDER = 0;
b@0 91 if ~reREAD
b@0 92 cd(cdScript);
b@0 93 tstDat=[];
b@0 94 fid=fopen(sesScript,'r');
b@0 95 while ~feof(fid) % read until end of session file
b@0 96 lin=fgetl(fid);
b@0 97 [fil1,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1);
b@0 98 if COUNT
b@0 99 if ~strcmp(fil1(1),'%') % if not a comment
b@10 100 if ~sum(strfind(lower(fil1), 'random'))
b@10 101 [fil2,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin(NEXTINDEX:end),'%s',1);
b@10 102 tstDat{end+1}.tstType=fil1; % what type of test?
b@10 103 tstDat{end}.tstFile=fil2; % test file?
b@10 104 else
b@10 105 RANDOMORDER = 1;
b@10 106 end
b@0 107 end
b@0 108 end
b@0 109 end
b@0 110 fclose(fid);
b@0 111
b@0 112 % ensure even length (sound list for every test)
b@0 113 if mod(length(tstDat),2)
b@0 114 warning('Uneven number of lines in session script. ');
b@0 115 % randomise order of tests
b@0 116 else
b@10 117 if RANDOMORDER
b@10 118 testPerm = randperm(length(tstDat)/2);
b@10 119 tstDatCopy = tstDat;
b@10 120 for t = 1:length(tstDat)/2
b@10 121 tstDat{2*t-1} = tstDatCopy{2*testPerm(t)-1};
b@10 122 tstDat{2*t} = tstDatCopy{2*testPerm(t)};
b@10 123 end
b@0 124 end
b@0 125 end
b@0 126 end
b@0 127
b@0 128 cd(cd0); % back to listening test folder
b@0 129
b@0 130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b@0 131 % Set session variables
b@0 132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b@0 133
b@0 134 sesDat.sesScript=sesScript;
b@0 135 sesDat.id=id;
b@0 136 sesDat.tstDat=tstDat;
b@0 137 sesDat.reREAD=reREAD;
b@0 138 sesDat.noTst=1;
b@0 139 sesDat.nbTst=length(tstDat);
b@0 140 sesDat.date=datestr(now);
b@0 141 sesDat.cuSndListFile=[];
b@0 142 sesDat.cuSndList=[];
b@0 143
b@0 144 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b@0 145 % Start test
b@0 146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b@0 147 % load the sndlist
b@0 148 if sesDat.noTst>1 % where were we?
b@0 149 sesDat.noTst=noTst-1; % IS THIS RIGHT?
b@0 150 sndList(sesDat);
b@0 151 else % always start with first test (allow changing earlier stuff if desired)
b@0 152 expr=sprintf('%s(sesDat);',tstDat{1}.tstType);
b@0 153 eval(expr);
b@0 154 end