Daniel@0: function varargout = mirmidi(orig,varargin) Daniel@0: % m = mirmidi(x) converts into a MIDI sequence. Daniel@0: % Option associated to mirpitch function can be specified: Daniel@0: % 'Contrast' with default value c = .3 Daniel@0: Daniel@0: thr.key = 'Contrast'; Daniel@0: thr.type = 'Integer'; Daniel@0: thr.default = .3; Daniel@0: option.thr = thr; Daniel@0: Daniel@0: mono.key = 'Mono'; Daniel@0: mono.type = 'Boolean'; Daniel@0: mono.default = 1; Daniel@0: option.mono = mono; Daniel@0: Daniel@0: release.key = {'Release','Releases'}; Daniel@0: release.type = 'String'; Daniel@0: release.choice = {'Olivier','Valeri',0,'no','off'}; Daniel@0: release.default = 'Valeri'; Daniel@0: option.release = release; Daniel@0: Daniel@0: specif.option = option; Daniel@0: Daniel@0: varargout = mirfunction(@mirmidi,orig,varargin,nargout,specif,@init,@main); Daniel@0: Daniel@0: Daniel@0: function [x type] = init(x,option) Daniel@0: try Daniel@0: hz2midi(440); Daniel@0: catch Daniel@0: mirerror('MIRMIDI','MIDItoolbox does not seem to be installed.'); Daniel@0: end Daniel@0: if not(isamir(x,'mirmidi')) && not(isamir(x,'mirpitch')) Daniel@0: if isa(x,'mirdesign') && not(option.mono) Daniel@0: x = set(x,'SeparateChannels',1); Daniel@0: end Daniel@0: o = mironsets(x,'Attacks','Releases',option.release); Daniel@0: x = {o x}; Daniel@0: end Daniel@0: type = 'mirmidi'; Daniel@0: Daniel@0: Daniel@0: function m = main(x,option,postoption) Daniel@0: if iscell(x) %not(isamir(x,'mirmidi')) Daniel@0: o = x{1}; Daniel@0: a = x{2}; Daniel@0: s = mirsegment(a,o); Daniel@0: x = mirpitch(s,'Contrast',option.thr,'Sum',0); Daniel@0: do = get(o,'PeakVal'); Daniel@0: da = get(o,'AttackPos'); Daniel@0: dr = get(o,'ReleasePos'); Daniel@0: df = get(o,'FramePos'); Daniel@0: else Daniel@0: do = NaN; Daniel@0: end Daniel@0: dp = get(x,'Data'); Daniel@0: %fp = get(x,'FramePos'); Daniel@0: nmat = cell(1,length(dp)); Daniel@0: for i = 1:length(dp) Daniel@0: nmat{i} = []; Daniel@0: for j = 2:length(dp{i}) Daniel@0: tij = mean(df{i}{1}(:,da{i}{1}{1}(j-1))); Daniel@0: dij = mean(df{i}{1}(:,dr{i}{1}{1}(j-1))) - tij; Daniel@0: if not(iscell(do)) Daniel@0: vij = 120; Daniel@0: else Daniel@0: vij = round(do{i}{1}{1}(j-1)/max(do{i}{1}{1})*120); Daniel@0: end Daniel@0: for k = 1:size(dp{i}{j},3) Daniel@0: for l = 1:size(dp{i}{j},2) Daniel@0: for n = 1:length(dp{i}{j}{1,l,k}) Daniel@0: f = dp{i}{j}{1,l,k}(n); Daniel@0: p = round(hz2midi(f)); Daniel@0: nmat{i} = [nmat{i}; tij dij 1 p vij tij dij]; Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: m = class(struct,'mirmidi',mirdata(x)); Daniel@0: m = set(m,'Data',nmat);