-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtgInsertNewIntervalTier.m
More file actions
69 lines (60 loc) · 2.01 KB
/
Copy pathtgInsertNewIntervalTier.m
File metadata and controls
69 lines (60 loc) · 2.01 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function tgNew = tgInsertNewIntervalTier(tg, tierInd, tierName, tStart, tEnd)
% function tgNew = tgInsertNewIntervalTier(tg, tierInd, tierName, tStart, tEnd)
%
% Inserts new interval tier to the specified index (existing tiers are
% shifted). The new tier contains one empty interval from beginning to end.
% Then, if we add new boundaries, this interval is divided to smaller
% pieces.
%
% tierInd ... new tier index (1 = the first, Inf = the last)
% tierName ... new tier name
% tStart ... [optional] start time of the new tier
% tEnd ... [optional] end time of the new tier
%
% v1.0, Tomas Boril, borilt@gmail.com
%
% tg = tgRead('demo/H.TextGrid');
% tg2 = tgInsertNewIntervalTier(tg, 1, 'INTERVALS');
% tg2 = tgInsertBoundary(tg2, 'INTERVALS', 0.8);
% tg2 = tgInsertBoundary(tg2, 'INTERVALS', 0.1, 'Interval A');
% tg2 = tgInsertInterval(tg2, 'INTERVALS', 1.2, 2.5, 'Interval B');
% tg2 = tgInsertNewIntervalTier(tg2, Inf, 'LastTier');
% tg2 = tgInsertInterval(tg2, 'LastTier', 1, 3, 'This is the last tier');
% tgPlot(tg2);
if nargin ~= 3 && nargin ~= 5
error('Wrong number of arguments.')
end
if ~isInt(tierInd)
error(['tierInd must be integer >= 1 or +Inf [' num2str(tierInd) ']']);
end
ntiers = tgGetNumberOfTiers(tg);
if isinf(tierInd)
if tierInd > 0
tierInd = ntiers+1;
else
error('tierInd must be integer >= 1 or +Inf')
end
end
if tierInd < 1 || tierInd>ntiers+1
error(['tierInd out of range [1; ntiers+1], tierInd = ' num2str(tierInd) ', ntiers = ' num2str(ntiers)]);
end
tgNew = tg;
tNew.name = tierName;
tNew.type = 'interval';
if nargin == 5
if tStart >= tEnd
error(['tStart [' num2str(tStart) '] must be lower than tEnd [' num2str(tEnd) ']']);
end
tNew.T1(1) = tStart;
tNew.T2(1) = tEnd;
tgNew.tmin = min(tg.tmin, tStart);
tgNew.tmax = max(tg.tmax, tEnd);
else
tNew.T1(1) = tg.tmin;
tNew.T2(1) = tg.tmax;
end
tNew.Label{1} = '';
for I = ntiers + 1: -1: tierInd+1
tgNew.tier{I} = tgNew.tier{I-1};
end
tgNew.tier{tierInd} = tNew;