ivan@81
|
1 function [PR,t,nn] = piano_roll(Notes,vel,ts)
|
ivan@81
|
2 %
|
ivan@81
|
3 % Inputs:
|
ivan@81
|
4 % Notes: A 'notes' matrix as returned from midiInfo.m
|
ivan@81
|
5 % vel: (optional) if vel==1, set value to note velocity instead of 1. (default 0)
|
ivan@81
|
6 % ts: (optional) time step of one 'pixel' in seconds (default 0.01)
|
ivan@81
|
7 %
|
ivan@81
|
8 % Outputs:
|
ivan@81
|
9 % PR: PR(ni,ti): value at note index ni, time index ti
|
ivan@81
|
10 % t: t(ti): time value in seconds at time index ti
|
ivan@81
|
11 % nn: nn(ni): note number at note index ti
|
ivan@81
|
12 %
|
ivan@81
|
13 % (i.e. t and nn provide 'real-world units' for PR)
|
ivan@81
|
14 %
|
ivan@81
|
15
|
ivan@81
|
16 % Copyright (c) 2009 Ken Schutte
|
ivan@81
|
17 % more info at: http://www.kenschutte.com/midi
|
ivan@81
|
18
|
ivan@81
|
19 if nargin < 2
|
ivan@81
|
20 vel = 0;
|
ivan@81
|
21 end
|
ivan@81
|
22 if nargin < 3
|
ivan@81
|
23 ts = 0.01;
|
ivan@81
|
24 end
|
ivan@81
|
25
|
ivan@81
|
26 Nnotes = size(Notes,1);
|
ivan@81
|
27
|
ivan@81
|
28 n1 = round(Notes(:,5)/ts)+1;
|
ivan@81
|
29 n2 = round(Notes(:,6)/ts)+1;
|
ivan@81
|
30
|
ivan@81
|
31 if vel == 0
|
ivan@81
|
32 vals = ones(Nnotes,1);
|
ivan@81
|
33 else
|
ivan@81
|
34 vals = Notes(:,4); % velocity
|
ivan@81
|
35 end
|
ivan@81
|
36
|
ivan@81
|
37 for i=1:Nnotes
|
ivan@81
|
38 PR(Notes(i,3), n1(i):n2(i)) = vals(i);
|
ivan@81
|
39 end
|
ivan@81
|
40
|
ivan@81
|
41 % create quantized time axis:
|
ivan@81
|
42 t = linspace(0,max(Notes(:,6)),size(PR,2));
|
ivan@81
|
43 % note axis:
|
ivan@81
|
44 nn = min(Notes(:,3)):max(Notes(:,3));
|
ivan@81
|
45 % truncate to notes used:
|
ivan@81
|
46 PR = PR(nn,:);
|