Debian Codegraph @

fon/praat_TimeTier.cpp

raw
1 /* praat_TimeTier.cpp
2 *
3 * Copyright (C) 1992-2012,2013,2014,2015,2016 Paul Boersma
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "praat_TimeTier.h"
20
21 // MARK: TIMETIER
22
23 // MARK: Query
24
25 DIRECT (INTEGER_TimeTier_getNumberOfPoints) {
26 QUERY_ONE_FOR_REAL (AnyTier)
27 const integer result = my points.size;
28 QUERY_ONE_FOR_REAL_END (U" points")
29 }
30
31 FORM (INTEGER_TimeTier_getLowIndexFromTime, U"Get low index", U"AnyTier: Get low index from time...") {
32 REAL (time, U"Time (s)", U"0.5")
33 OK
34 DO
35 QUERY_ONE_FOR_REAL (AnyTier)
36 const double result =
37 my points.size == 0 ? undefined : AnyTier_timeToLowIndex (me, time);
38 QUERY_ONE_FOR_REAL_END (U"")
39 }
40
41 FORM (INTEGER_TimeTier_getHighIndexFromTime, U"Get high index", U"AnyTier: Get high index from time...") {
42 REAL (time, U"Time (s)", U"0.5")
43 OK
44 DO
45 QUERY_ONE_FOR_REAL (AnyTier)
46 const double result =
47 my points.size == 0 ? undefined : AnyTier_timeToHighIndex (me, time);
48 QUERY_ONE_FOR_REAL_END (U"")
49 }
50
51 FORM (INTEGER_TimeTier_getNearestIndexFromTime, U"Get nearest index", U"AnyTier: Get nearest index from time...") {
52 REAL (time, U"Time (s)", U"0.5")
53 OK
54 DO
55 QUERY_ONE_FOR_REAL (AnyTier) // TODO: make it more general that we don't return an integer, because we should be able to return undefined, as here
56 const double result =
57 my points.size == 0 ? undefined : AnyTier_timeToNearestIndex (me, time);
58 QUERY_ONE_FOR_REAL_END (U"")
59 }
60
61 FORM (REAL_TimeTier_getTimeFromIndex, U"Get time", nullptr /*"AnyTier: Get time from index..."*/) {
62 NATURAL (pointNumber, U"Point number", U"10")
63 OK
64 DO
65 QUERY_ONE_FOR_REAL (AnyTier)
66 const double result =
67 pointNumber > my points.size ? undefined : my points.at [pointNumber] -> number;
68 QUERY_ONE_FOR_REAL_END (U" seconds")
69 }
70
71 // MARK: Modify
72
73 FORM (MODIFY_TimeTier_removePoint, U"Remove one point", U"AnyTier: Remove point...") {
74 NATURAL (pointNumber, U"Point number", U"1")
75 OK
76 DO
77 MODIFY_EACH (AnyTier)
78 AnyTier_removePoint (me, pointNumber);
79 MODIFY_EACH_END
80 }
81
82 FORM (MODIFY_TimeTier_removePointNear, U"Remove one point", U"AnyTier: Remove point near...") {
83 REAL (time, U"Time (s)", U"0.5")
84 OK
85 DO
86 MODIFY_EACH (AnyTier)
87 AnyTier_removePointNear (me, time);
88 MODIFY_EACH_END
89 }
90
91 FORM (MODIFY_TimeTier_removePointsBetween, U"Remove points", U"AnyTier: Remove points between...") {
92 REAL (fromTime, U"left Time range (s)", U"0.0")
93 REAL (toTime, U"right Time range (s)", U"1.0")
94 OK
95 DO
96 MODIFY_EACH (AnyTier)
97 AnyTier_removePointsBetween (me, fromTime, toTime);
98 MODIFY_EACH_END
99 }
100
101 // MARK: - buttons
102
103 void praat_TimeTier_query_init (ClassInfo klas) {
104 praat_TimeFunction_query_init (klas);
105 praat_addAction1 (klas, 1, U"Get number of points", nullptr, 1, INTEGER_TimeTier_getNumberOfPoints);
106 praat_addAction1 (klas, 1, U"Get low index from time...", nullptr, 1, INTEGER_TimeTier_getLowIndexFromTime);
107 praat_addAction1 (klas, 1, U"Get high index from time...", nullptr, 1, INTEGER_TimeTier_getHighIndexFromTime);
108 praat_addAction1 (klas, 1, U"Get nearest index from time...", nullptr, 1, INTEGER_TimeTier_getNearestIndexFromTime);
109 praat_addAction1 (klas, 1, U"Get time from index...", nullptr, 1, REAL_TimeTier_getTimeFromIndex);
110 }
111
112 void praat_TimeTier_modify_init (ClassInfo klas) {
113 praat_TimeFunction_modify_init (klas);
114 praat_addAction1 (klas, 0, U"Remove point...", nullptr, 1, MODIFY_TimeTier_removePoint);
115 praat_addAction1 (klas, 0, U"Remove point near...", nullptr, 1, MODIFY_TimeTier_removePointNear);
116 praat_addAction1 (klas, 0, U"Remove points between...", nullptr, 1, MODIFY_TimeTier_removePointsBetween);
117 }
118
119 /* End of file praat_TimeTier.cpp */