To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Revision:

root / _segmentation / integratesmallparts.m

History | View | Annotate | Download (1.06 KB)

1
function song = integratesmallparts(song)
2

    
3
parts = song.parts;
4
nParts = numel(parts);
5

    
6

    
7

    
8
%% break up parts (every part will have one instance)
9
iNewpart = 0;
10
partindices = [];
11
for iPart = 1:nParts
12
    parts(iPart).nInd = length(parts(iPart).indices);
13
    for iInstance = 1:parts(iPart).nInd
14
        iNewpart = iNewpart + 1;
15
        newparts(iNewpart) = parts(iPart);
16
        newparts(iNewpart).indices = parts(iPart).indices(iInstance);
17
        newparts(iNewpart).nInd = 1;
18
        partindices = [partindices; parts(iPart).indices(iInstance)];
19
    end
20
end
21
nNewparts = numel(newparts);
22

    
23
%% sort the parts in order of occurrence
24
[sortind, sortind] = sort(partindices);
25
for iNewpart = 1:nNewparts 
26
    sortednewparts(iNewpart) = newparts(sortind(iNewpart));
27
end
28

    
29
%%
30
eraselist = [];
31
for iNewpart = 2:nNewparts
32
    if sortednewparts(iNewpart).n < 12
33
        eraselist = [eraselist; iNewpart];
34
        sortednewparts(iNewpart-1).n = ...
35
            sortednewparts(iNewpart-1).n + sortednewparts(iNewpart).n;
36
    end
37
end
38

    
39
sortednewparts(eraselist) = [];
40
song.integratedparts = sortednewparts;