function pitchvel3d(nmat) %This function plots the pitch, time, velocity. It read in a Midi file using nmat format from the MIDI Toolbox. Arrays are created from the velocity, pitch, and onsets/offsets from the midi structure and plotted on a 3-dimensional graph. The highest velocities are shown in the peaks of the graph, lower velocities are shown as smaller lumps. % Usage: pitchvel3d(nmat) % % Example: % nmat=readmidi('test.mid'); % pitchvel3d(nmat) % % The following non-standard files are required to run this function. % leastnonzero(array) provided at http://www-scf.usc.edu/~lidavid/ISE575/ % readmid(mid) from MIDI TOOLBOX % onset(nmat) from MIDI TOOLBOX % dur(nmat) from MIDI TOOLBOX % pitch(nmat) from MIDI TOOLBOX % velocity(nmat) from MIDI TOOLBOX % % Also see Pianoroll % % Author: David Li, USC % Email: gemste@yahoo.com % on=onset(nmat,'beat'); off=on+dur(nmat,'beat'); totaldur=max(onset(nmat))+ dur(nmat(end,:)); p=pitch(nmat); v=velocity(nmat); if (max(v) == min(v)) disp('ERROR: No velocity in nmat'); end % pianoroll(nmat) % figure t_int=leastnonzero(off-on)/4; %t_int=leastnonzero(on(2:end)-off(1:end-1))/4; %leastnonzero(dur(nmat))/4; %.25;%min(dur(nmat))/2; p_int=.25; p_dist=.25; pitch_space=leastnonzero(p):p_int/4:max(p); %minimi-2:maksimi+2; time_space=leastnonzero(on)-t_int:t_int/2:max(max(on),max(off))+t_int; [pi,ti]=meshgrid(pitch_space,time_space); t=[min(time_space);min(time_space);max(time_space);max(time_space); on;on;off;off; on-t_int;on-t_int;off+t_int;off+t_int]; pitch=[min(p)-p_int-1;max(p)+p_int+1;min(p)-p_int-1;max(p)+p_int+1; p;p+p_dist;p;p+p_dist; p-p_int;p+p_dist+p_int;p-p_int;p+p_dist+p_int]; v0=min(v)-(max(v)-min(v))/5; velocity=[v0;v0;v0;v0;v;v;v;v;v0*ones(4*length(p),1)]; zi=griddata(t,pitch,velocity,ti,pi); surf(ti,pi,zi,zi) zlabel('Velocity') ylabel('Pitch') xlabel('Time') SHADING flat map=COLORMAP; %map(1:3,1:3)=0; mapnew=map; %mapnew(2:end,:)=1; mapnew(33:end,:)=mapnew(32:-1:1,:); %map(1:end-1,:)=0; %map(end,:)=1; colormap(mapnew)