annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/@mirmidi/mirmidi.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function varargout = mirmidi(orig,varargin)
wolffd@0 2 % m = mirmidi(x) converts into a MIDI sequence.
wolffd@0 3 % Option associated to mirpitch function can be specified:
wolffd@0 4 % 'Contrast' with default value c = .3
wolffd@0 5
wolffd@0 6 thr.key = 'Contrast';
wolffd@0 7 thr.type = 'Integer';
wolffd@0 8 thr.default = .3;
wolffd@0 9 option.thr = thr;
wolffd@0 10
wolffd@0 11 mono.key = 'Mono';
wolffd@0 12 mono.type = 'Boolean';
wolffd@0 13 mono.default = 1;
wolffd@0 14 option.mono = mono;
wolffd@0 15
wolffd@0 16 release.key = {'Release','Releases'};
wolffd@0 17 release.type = 'String';
wolffd@0 18 release.choice = {'Olivier','Valeri',0,'no','off'};
wolffd@0 19 release.default = 'Valeri';
wolffd@0 20 option.release = release;
wolffd@0 21
wolffd@0 22 specif.option = option;
wolffd@0 23
wolffd@0 24 varargout = mirfunction(@mirmidi,orig,varargin,nargout,specif,@init,@main);
wolffd@0 25
wolffd@0 26
wolffd@0 27 function [x type] = init(x,option)
wolffd@0 28 try
wolffd@0 29 hz2midi(440);
wolffd@0 30 catch
wolffd@0 31 mirerror('MIRMIDI','MIDItoolbox does not seem to be installed.');
wolffd@0 32 end
wolffd@0 33 if not(isamir(x,'mirmidi')) && not(isamir(x,'mirpitch'))
wolffd@0 34 if isa(x,'mirdesign') && not(option.mono)
wolffd@0 35 x = set(x,'SeparateChannels',1);
wolffd@0 36 end
wolffd@0 37 o = mironsets(x,'Attacks','Releases',option.release);
wolffd@0 38 x = {o x};
wolffd@0 39 end
wolffd@0 40 type = 'mirmidi';
wolffd@0 41
wolffd@0 42
wolffd@0 43 function m = main(x,option,postoption)
wolffd@0 44 if iscell(x) %not(isamir(x,'mirmidi'))
wolffd@0 45 o = x{1};
wolffd@0 46 a = x{2};
wolffd@0 47 s = mirsegment(a,o);
wolffd@0 48 x = mirpitch(s,'Contrast',option.thr,'Sum',0);
wolffd@0 49 do = get(o,'PeakVal');
wolffd@0 50 da = get(o,'AttackPos');
wolffd@0 51 dr = get(o,'ReleasePos');
wolffd@0 52 df = get(o,'FramePos');
wolffd@0 53 else
wolffd@0 54 do = NaN;
wolffd@0 55 end
wolffd@0 56 dp = get(x,'Data');
wolffd@0 57 %fp = get(x,'FramePos');
wolffd@0 58 nmat = cell(1,length(dp));
wolffd@0 59 for i = 1:length(dp)
wolffd@0 60 nmat{i} = [];
wolffd@0 61 for j = 2:length(dp{i})
wolffd@0 62 tij = mean(df{i}{1}(:,da{i}{1}{1}(j-1)));
wolffd@0 63 dij = mean(df{i}{1}(:,dr{i}{1}{1}(j-1))) - tij;
wolffd@0 64 if not(iscell(do))
wolffd@0 65 vij = 120;
wolffd@0 66 else
wolffd@0 67 vij = round(do{i}{1}{1}(j-1)/max(do{i}{1}{1})*120);
wolffd@0 68 end
wolffd@0 69 for k = 1:size(dp{i}{j},3)
wolffd@0 70 for l = 1:size(dp{i}{j},2)
wolffd@0 71 for n = 1:length(dp{i}{j}{1,l,k})
wolffd@0 72 f = dp{i}{j}{1,l,k}(n);
wolffd@0 73 p = round(hz2midi(f));
wolffd@0 74 nmat{i} = [nmat{i}; tij dij 1 p vij tij dij];
wolffd@0 75 end
wolffd@0 76 end
wolffd@0 77 end
wolffd@0 78 end
wolffd@0 79 end
wolffd@0 80 m = class(struct,'mirmidi',mirdata(x));
wolffd@0 81 m = set(m,'Data',nmat);