-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_midicsv.m
26 lines (24 loc) · 1.09 KB
/
write_midicsv.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
% Copyright (c) 2017 J.B. Peperkamp <[email protected]>
% released under GPL - see file COPYRIGHT
function [] = write_midicsv(midistruct,filen)
f = fopen(filen,'w');
fprintf(f,'0,0,Header,%u,%u,%u\n',midistruct.format,midistruct.ntracks,midistruct.division);
for i = 1:midistruct.ntracks
for j = 1:length(midistruct.tracks{i})
thisline = midistruct.tracks{i}(j);
if thisline.event == MidiMsg.key_signature
if thisline.parameters(2)
fprintf(f,'%u,%u,%s,%u,"minor"\n',thisline.track,thisline.time,thisline.event,thisline.parameters(1));
else
fprintf(f,'%u,%u,%s,%u,"major"\n',thisline.track,thisline.time,thisline.parameters(1));
end
else
if endsWith(thisline.event,'_t')
fprintf(f,'%u,%u,%s,"%s"\n',thisline.track,thisline.time,thisline.event,thisline.parameters);
else
fprintf(f,'%u,%u,%s%s\n',thisline.track,thisline.time,thisline.event,strrep(num2str(thisline.parameters,',%u'),' ',''));
end
end
end
end
fprintf(f,'0,0,End_of_file');