b@0: function launch(sesScript,noTst) b@0: % launch a session script composed of a succession of single tests b@0: % sesScript: session script name if recalling old script (optional) b@0: % noTst: start from specified test (optional) b@0: % b@0: % by Brecht De Man at Centre for Digital Music, 12 January 2014 b@0: b@0: % make sure you are in listening test folder b@0: cdFolder = which('launch'); b@0: cdFolder = cdFolder(1:end-8); % remove 'launch.m' from string b@0: cd(cdFolder); b@0: b@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% b@0: % Interface b@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% b@0: cd0=cd; % save path b@0: b@0: % Choose Session b@0: if ~exist('sesScript', 'file') % if sesScript was not provided or doesn't exist b@0: [sesScript,cdScript]=uigetfile('*.txt','Please enter a session script'); b@0: if ~sesScript % if still not provided b@0: return % exit b@0: end b@0: else b@0: cdScript=cd0; % folder of script is same as folder of listening test b@0: end b@0: b@0: b@0: % Enter name and check ID is not already used... b@0: ASK=1; b@0: reREAD=0; b@0: while ASK b@0: prompt={'Please enter your name or any ID : '}; b@0: def={'myID'}; b@0: title='ID'; b@0: lineNo=1; b@0: answer=inputdlg(prompt,title,lineNo,def); b@0: if isempty(answer) b@0: return b@0: end b@0: id=answer{1}; % from cell to string b@0: b@9: % make robust b@9: % if first character is a number: b@9: if id(1) >= '0' && id(1) <= '9' b@9: id = strcat('NUM', id); b@9: end b@9: % if it contains spaces or special characters: b@9: id = strrep(id, ' ', '_'); b@9: id = strrep(id, '/', 'SLASH'); b@9: id = strrep(id, '\', 'BACKSLASH'); b@9: id = strrep(id, ':', 'COLON'); b@9: id = strrep(id, '.', 'DOT'); b@9: id = strrep(id, ',', 'COMMA'); b@9: id = strrep(id, '?', 'QMARK'); b@9: id = strrep(id, ';', 'SEMICOLON'); b@9: id = strrep(id, '!', 'EXCLMARK'); b@9: id = strrep(id, '(', 'OBRACKET'); b@9: id = strrep(id, ')', 'CBRACKET'); b@9: b@0: % if name already present, return to former test b@0: d=dir('responses'); b@0: ASK=0; b@0: for noF=1:length(d) b@0: name=strtok(d(noF).name,'.'); b@0: if strcmp(name,answer) b@0: switch lower(questdlg('This ID is already used. Do you wish to re-use it?')) b@0: case 'yes' b@0: cd('responses'); b@0: ASK=0; b@0: expre=sprintf('load %s',id); b@0: eval(expre); b@0: expre=sprintf('tstDat=%s.tstDat;',id); % read mat-file b@0: eval(expre); b@0: reREAD=1; b@0: cd('../'); b@0: break; b@0: case {'no','cancel'} b@0: ASK=1; b@0: break; b@0: end b@0: end b@0: end b@0: end b@0: b@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% b@0: % Read the script and create tstdat b@0: % IF THE TEST WAS DONE ALREADY ONCE, THE .MAT FILE IS USED INSTEAD (see above) b@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% b@10: RANDOMORDER = 0; b@0: if ~reREAD b@0: cd(cdScript); b@0: tstDat=[]; b@0: fid=fopen(sesScript,'r'); b@0: while ~feof(fid) % read until end of session file b@0: lin=fgetl(fid); b@0: [fil1,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1); b@0: if COUNT b@0: if ~strcmp(fil1(1),'%') % if not a comment b@10: if ~sum(strfind(lower(fil1), 'random')) b@10: [fil2,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin(NEXTINDEX:end),'%s',1); b@10: tstDat{end+1}.tstType=fil1; % what type of test? b@10: tstDat{end}.tstFile=fil2; % test file? b@10: else b@10: RANDOMORDER = 1; b@10: end b@0: end b@0: end b@0: end b@0: fclose(fid); b@0: b@0: % ensure even length (sound list for every test) b@0: if mod(length(tstDat),2) b@0: warning('Uneven number of lines in session script. '); b@0: % randomise order of tests b@0: else b@10: if RANDOMORDER b@10: testPerm = randperm(length(tstDat)/2); b@10: tstDatCopy = tstDat; b@10: for t = 1:length(tstDat)/2 b@10: tstDat{2*t-1} = tstDatCopy{2*testPerm(t)-1}; b@10: tstDat{2*t} = tstDatCopy{2*testPerm(t)}; b@10: end b@0: end b@0: end b@0: end b@0: b@0: cd(cd0); % back to listening test folder b@0: b@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% b@0: % Set session variables b@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% b@0: b@0: sesDat.sesScript=sesScript; b@0: sesDat.id=id; b@0: sesDat.tstDat=tstDat; b@0: sesDat.reREAD=reREAD; b@0: sesDat.noTst=1; b@0: sesDat.nbTst=length(tstDat); b@0: sesDat.date=datestr(now); b@0: sesDat.cuSndListFile=[]; b@0: sesDat.cuSndList=[]; b@0: b@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% b@0: % Start test b@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% b@0: % load the sndlist b@0: if sesDat.noTst>1 % where were we? b@0: sesDat.noTst=noTst-1; % IS THIS RIGHT? b@0: sndList(sesDat); b@0: else % always start with first test (allow changing earlier stuff if desired) b@0: expr=sprintf('%s(sesDat);',tstDat{1}.tstType); b@0: eval(expr); b@0: end