Mercurial > hg > silvet
diff testdata/scripts/matlab/convertMIDIToPianoRoll.m @ 231:d9b688700819 norm eval-norm-todate
Merge from default branch
author | Chris Cannam |
---|---|
date | Wed, 16 Jul 2014 17:46:15 +0100 |
parents | 51c18a17404a |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testdata/scripts/matlab/convertMIDIToPianoRoll.m Wed Jul 16 17:46:15 2014 +0100 @@ -0,0 +1,31 @@ +function [pianoRoll,newnmat] = convertMIDIToPianoRoll(filename,timeResolution,dur) + +% Time resolution is in msec +% eg. pianoRoll = convertMIDIToPianoRoll('bach_847MINp_align.mid',10); + +% Read MIDI file +nmat = readmidi(filename); + + +% Gather MIDI information +[n1 n2] = size(nmat); +lenthInSec = nmat(n1,6) + nmat(n1,7); +pianoRoll = zeros(88,round(lenthInSec*(1000/timeResolution))); + + +% Fill piano roll +for i=1:n1 + pianoRoll(round(nmat(i,4)-20),round(nmat(i,6)*(1000/timeResolution))+1:round(nmat(i,6)*(1000/timeResolution)+dur*nmat(i,7)*(1000/timeResolution))+1) = 1; +end; + +pianoRoll = pianoRoll'; + +% Plot piano roll +%figure; imagesc(imrotate(pianoRoll,0)); axis xy +%colormap('gray'); xlabel('time frame'); ylabel('Pitch'); + + +% Convert to non-MIDI nmat +newnmat(:,1) = nmat(:,6); +newnmat(:,2) = nmat(:,6)+nmat(:,7); +newnmat(:,3) = nmat(:,4)-20; \ No newline at end of file