wolffd@0: function o = mirfunction(method,x,varg,nout,specif,init,main) wolffd@0: % Meta function called by all MIRtoolbox functions. wolffd@0: % Integrates the function into the general flowchart wolffd@0: % and eventually launches the "mireval" evaluation process. wolffd@0: % Here are the successive steps in the following code: wolffd@0: % - If the input is an audio filename, instantiates a new design flowchart. wolffd@0: % - Reads all the options specified by the user. wolffd@0: % - Performs the 'init' part of the MIRtoolbox function: wolffd@0: % - If the input is a design flowchart, wolffd@0: % add the 'init' part in the flowchart. wolffd@0: % - If the input is some MIRtoolbox data, wolffd@0: % execute the 'init' part on that data. wolffd@0: % - Performs the 'main' part of the MIRtoolbox function. wolffd@0: wolffd@0: if isempty(x) wolffd@0: o = {{},{},{}}; wolffd@0: return wolffd@0: end wolffd@0: wolffd@0: if ischar(x) % The input is a file name. wolffd@0: % Starting point of the design process wolffd@0: design_init = 1; wolffd@0: filename = x; wolffd@0: if strcmpi(func2str(method),'miraudio') wolffd@0: postoption = {}; wolffd@0: else wolffd@0: postoption.mono = 1; wolffd@0: end wolffd@0: orig = mirdesign(@miraudio,'Design',{varg},postoption,struct,'miraudio'); wolffd@0: % Implicitly, the audio file needs to be loaded first. wolffd@0: elseif isnumeric(x) wolffd@0: mirerror(func2str(method),'The input should be a file name or a MIRtoolbox object.'); wolffd@0: else wolffd@0: design_init = 0; wolffd@0: orig = x; wolffd@0: end wolffd@0: wolffd@0: % Reads all the options specified by the user. wolffd@0: [orig during after] = miroptions(method,orig,specif,varg); wolffd@0: wolffd@0: % Performs the 'init' part of the MIRtoolbox function. wolffd@0: if isa(orig,'mirdesign') wolffd@0: if not(get(orig,'Eval')) wolffd@0: % Top-down construction of the general design flowchart wolffd@0: wolffd@0: if isstruct(during) && isfield(during,'frame') && ... wolffd@0: isstruct(during.frame) && during.frame.auto wolffd@0: % 'Frame' option: wolffd@0: % Automatic insertion of the mirframe step in the design wolffd@0: orig = mirframe(orig,during.frame.length.val,... wolffd@0: during.frame.length.unit,... wolffd@0: during.frame.hop.val,... wolffd@0: during.frame.hop.unit); wolffd@0: end wolffd@0: wolffd@0: % The 'init' part of the function can be integrated into the design wolffd@0: % flowchart. This leads to a top-down construction of the wolffd@0: % flowchart. wolffd@0: % Automatic development of the implicit prerequisites, wolffd@0: % with management of the data types throughout the design process. wolffd@0: [orig type] = init(orig,during); wolffd@0: wolffd@0: o = mirdesign(method,orig,during,after,specif,type); wolffd@0: wolffd@0: if design_init && not(strcmpi(filename,'Design')) wolffd@0: % Now the design flowchart has been completed created. wolffd@0: % If the 'Design' keyword not used, wolffd@0: % the function is immediately evaluated wolffd@0: o = mireval(o,filename,nout); wolffd@0: else wolffd@0: o = returndesign(o,nout); wolffd@0: end wolffd@0: if not(iscell(o)) wolffd@0: o = {o}; wolffd@0: end wolffd@0: return wolffd@0: else wolffd@0: % During the top-down traversal of the flowchart (evaleach), at the wolffd@0: % beginning of the evaluation process. wolffd@0: wolffd@0: if not(isempty(get(orig,'TmpFile'))) && get(orig,'ChunkDecomposed') wolffd@0: orig = evaleach(orig); wolffd@0: if iscell(orig) wolffd@0: orig = orig{1}; wolffd@0: end wolffd@0: x = orig; wolffd@0: else wolffd@0: [orig x] = evaleach(orig); wolffd@0: end wolffd@0: wolffd@0: if not(isequal(method,@nthoutput)) wolffd@0: if iscell(orig) wolffd@0: orig = orig{1}; wolffd@0: end wolffd@0: if isempty(get(orig,'InterChunk')) wolffd@0: orig = set(orig,'InterChunk',get(x,'InterChunk')); wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: else wolffd@0: design = 0; wolffd@0: if iscell(orig) wolffd@0: i = 0; wolffd@0: while i1) || (isa(x,'mirdesign') && get(x,'Eval')) wolffd@0: o = {o x}; wolffd@0: elseif iscell(x) && isa(x{1},'mirdesign') && get(x{1},'Eval') wolffd@0: o = {o x{1}}; wolffd@0: elseif not(isempty(varg)) && isstruct(varg{1}) ... wolffd@0: && not(iscell(o) && iscell(o{1})) wolffd@0: % When the function was called by mireval, the output should be packed wolffd@0: % into one single cell array (in order to be send back to calling wolffd@0: % routines). wolffd@0: o = {o}; wolffd@0: end wolffd@0: wolffd@0: wolffd@0: function o = returndesign(i,nout) wolffd@0: o = cell(1,nout); wolffd@0: o{1} = i; wolffd@0: for k = 2:nout wolffd@0: o{k} = nthoutput(i,k); wolffd@0: end