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