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