To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / _segmentation / parts2mirex.m
History | View | Annotate | Download (1000 Bytes)
| 1 |
function parts2mirex(song, filename, varargin) |
|---|---|
| 2 |
if nargin > 2 && strcmp(varargin{1}, 'integrated')
|
| 3 |
parts = song.integratedparts; |
| 4 |
else |
| 5 |
parts = song.parts; |
| 6 |
end |
| 7 |
|
| 8 |
beattimes = song.beattimes; |
| 9 |
% beattimes = [0; beattimes]; |
| 10 |
startIndex = []; |
| 11 |
letters = {};
|
| 12 |
|
| 13 |
for iPart = 1:length(parts) |
| 14 |
for iInstance = 1:length(parts(iPart).indices) |
| 15 |
startIndex = [startIndex parts(iPart).indices(iInstance)]; |
| 16 |
letters = [letters parts(iPart).letter]; |
| 17 |
end |
| 18 |
end |
| 19 |
|
| 20 |
[sorted, sortind] = sort(startIndex); |
| 21 |
endIndex = zeros(length(sorted),1); |
| 22 |
for iIndex = 1:length(sorted)-1; |
| 23 |
endIndex(iIndex) = sorted(iIndex+1); |
| 24 |
end |
| 25 |
endIndex(end) = length(beattimes); |
| 26 |
|
| 27 |
f = fopen(filename,'w'); |
| 28 |
|
| 29 |
fprintf(f,'0.000 %1.3f "%s"\n',beattimes(endIndex(1)),letters{sortind(1)});
|
| 30 |
for iSeg = 2:length(sorted)-1 |
| 31 |
fprintf(f,'%1.3f %1.3f "%s"\n',beattimes(sorted(iSeg)),beattimes(endIndex(iSeg)),letters{sortind(iSeg)});
|
| 32 |
end |
| 33 |
fprintf(f,'%1.3f %1.3f "%s"\n',beattimes(sorted(end)),song.t(end),letters{sortind(end)});
|
| 34 |
|
| 35 |
fclose(f); |
| 36 |
|