Mercurial > hg > cip2012
comparison matlab/fileplay.m @ 20:6464cf684717
Added drum analysis functions and archive of plots
author | samer |
---|---|
date | Mon, 12 Mar 2012 15:51:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
19:14708527e1a2 | 20:6464cf684717 |
---|---|
1 % fileplay - Do plots for given file and play over MIDI channel 9 | |
2 % Data is played on kick and snare (note numbers 36 and 38). | |
3 % Metrical grid can be played on hi-hat, cowbell etc. | |
4 function player=fileplay(MO,file,varargin) | |
5 opts=prefs('vel',80,'dur',0.1,'shift',file{2},'metre',[],varargin{:}); | |
6 | |
7 disp(file{1}); | |
8 BDT=shift_beat(opts.shift,read(file{1})); | |
9 drumplot(BDT,'bar',4,'pause',0,varargin{:}); | |
10 player=playdrums(MO,[36,38,42,44,51,56,49,53],addmetre(opts.metre,BDT(:,[2,1,4])),opts); | |
11 end | |
12 | |
13 function player=playdrums(MO,PercMap,Evs,opts) | |
14 NN=map(PercMap,Evs(:,1)); | |
15 Times=(Evs(:,2)-Evs(1,2))/1000; | |
16 player=rendermidi(MO,window(zipmidi_abs(Times,opts.dur,9,NN,opts.vel)'),nows(MO)+1); | |
17 end | |
18 | |
19 function Evs=addmetre(metre,Evs) | |
20 for i=1:size(metre,1) | |
21 Evs=add_periodic(metre(i,1),metre(i,2),Evs); | |
22 end | |
23 end | |
24 | |
25 function X=add_periodic(m,type,Y) | |
26 [UMetPos,K]=unique(Y(:,3)); | |
27 Bars=(0:m:max(UMetPos))'; | |
28 BarTimes=interp1(UMetPos,Y(K,2),Bars); | |
29 Types=repmat(type,size(BarTimes)); | |
30 X=sort_by(2,vertcat(Y,[Types,BarTimes,Bars])); | |
31 end | |
32 | |
33 function X=sort_by(col,Y) | |
34 [dummy,K]=sort(Y(:,col)); | |
35 X=Y(K,:); | |
36 end |