annotate testdata/scripts/matlab/convertMIDIToPianoRoll.m @ 250:ec296f783a6f
Add current trios output results for non-normalised input on default branch
author |
Chris Cannam |
date |
Tue, 22 Jul 2014 18:32:00 +0100 |
parents |
51c18a17404a |
children |
|
rev |
line source |
emmanouil@71
|
1 function [pianoRoll,newnmat] = convertMIDIToPianoRoll(filename,timeResolution,dur)
|
emmanouil@71
|
2
|
emmanouil@71
|
3 % Time resolution is in msec
|
emmanouil@71
|
4 % eg. pianoRoll = convertMIDIToPianoRoll('bach_847MINp_align.mid',10);
|
emmanouil@71
|
5
|
emmanouil@71
|
6 % Read MIDI file
|
emmanouil@71
|
7 nmat = readmidi(filename);
|
emmanouil@71
|
8
|
emmanouil@71
|
9
|
emmanouil@71
|
10 % Gather MIDI information
|
emmanouil@71
|
11 [n1 n2] = size(nmat);
|
emmanouil@71
|
12 lenthInSec = nmat(n1,6) + nmat(n1,7);
|
emmanouil@71
|
13 pianoRoll = zeros(88,round(lenthInSec*(1000/timeResolution)));
|
emmanouil@71
|
14
|
emmanouil@71
|
15
|
emmanouil@71
|
16 % Fill piano roll
|
emmanouil@71
|
17 for i=1:n1
|
emmanouil@71
|
18 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;
|
emmanouil@71
|
19 end;
|
emmanouil@71
|
20
|
emmanouil@71
|
21 pianoRoll = pianoRoll';
|
emmanouil@71
|
22
|
emmanouil@71
|
23 % Plot piano roll
|
emmanouil@71
|
24 %figure; imagesc(imrotate(pianoRoll,0)); axis xy
|
emmanouil@71
|
25 %colormap('gray'); xlabel('time frame'); ylabel('Pitch');
|
emmanouil@71
|
26
|
emmanouil@71
|
27
|
emmanouil@71
|
28 % Convert to non-MIDI nmat
|
emmanouil@71
|
29 newnmat(:,1) = nmat(:,6);
|
emmanouil@71
|
30 newnmat(:,2) = nmat(:,6)+nmat(:,7);
|
emmanouil@71
|
31 newnmat(:,3) = nmat(:,4)-20; |