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

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