1 /* praat_TimeFrameSampled.cpp
2  *
3  * Copyright (C) 2016,2017,2019 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_TimeFrameSampled.h"
20 
21 // MARK: - TIMEFRAMESAMPLED
22 
DIRECT(INTEGER_TimeFrameSampled_getNumberOfFrames)23 DIRECT (INTEGER_TimeFrameSampled_getNumberOfFrames) {
24 	QUERY_ONE_FOR_REAL (Sampled)
25 		integer result = my nx;
26 	QUERY_ONE_FOR_REAL_END (U" frames");
27 }
28 
29 FORM (REAL_TimeFrameSampled_getFrameFromTime, U"Get frame number from time", U"Get frame number from time...") {
30 	REAL (time, U"Time (s)", U"0.5")
31 	OK
32 DO
33 	QUERY_ONE_FOR_REAL (Sampled)
34 		double result = Sampled_xToIndex (me, time);
35 	QUERY_ONE_FOR_REAL_END (U" (frame as a real number)")
36 }
37 
DIRECT(REAL_TimeFrameSampled_getFrameLength)38 DIRECT (REAL_TimeFrameSampled_getFrameLength) {
39 	QUERY_ONE_FOR_REAL (Sampled)
40 		double result = my dx;
41 	QUERY_ONE_FOR_REAL_END (U" seconds")
42 }
43 
44 FORM (REAL_TimeFrameSampled_getTimeFromFrame, U"Get time from frame number", U"Get time from frame number...") {
45 	NATURAL (frameNumber, U"Frame number", U"1")
46 	OK
47 DO
48 	QUERY_ONE_FOR_REAL (Sampled)
49 		double result = Sampled_indexToX (me, frameNumber);
50 	QUERY_ONE_FOR_REAL_END (U" seconds")
51 }
52 
DIRECT(NUMVEC_TimeFrameSampled_listAllFrameTimes)53 DIRECT (NUMVEC_TimeFrameSampled_listAllFrameTimes) {
54 	QUERY_ONE_FOR_REAL_VECTOR (Sampled)
55 		autoVEC result = Sampled_listAllXValues (me);
56 	QUERY_ONE_FOR_REAL_VECTOR_END
57 }
58 
59 // MARK: - buttons
60 
praat_TimeFrameSampled_query_init(ClassInfo klas)61 void praat_TimeFrameSampled_query_init (ClassInfo klas) {
62 	praat_TimeFunction_query_init (klas);
63 	praat_addAction1 (klas, 1, U"Query time sampling", nullptr, 1, nullptr);
64 	praat_addAction1 (klas, 1, U"Get number of frames", nullptr, 2, INTEGER_TimeFrameSampled_getNumberOfFrames);
65 	praat_addAction1 (klas, 1, U"Get time step", nullptr, 2, REAL_TimeFrameSampled_getFrameLength);
66 	praat_addAction1 (klas, 1,   U"Get frame length", U"*Get time step", praat_DEPTH_2 | praat_DEPRECATED_2004, REAL_TimeFrameSampled_getFrameLength);
67 	praat_addAction1 (klas, 1,   U"Get frame duration", U"*Get time step", praat_DEPTH_2 | praat_DEPRECATED_2004, REAL_TimeFrameSampled_getFrameLength);
68 	praat_addAction1 (klas, 1, U"Get time from frame number...", nullptr, 2, REAL_TimeFrameSampled_getTimeFromFrame);
69 	praat_addAction1 (klas, 1,   U"Get time from frame...", U"*Get time from frame number...", praat_DEPTH_2 | praat_DEPRECATED_2004, REAL_TimeFrameSampled_getTimeFromFrame);
70 	praat_addAction1 (klas, 1, U"List all frame times", nullptr, 2, NUMVEC_TimeFrameSampled_listAllFrameTimes);
71 	praat_addAction1 (klas, 1, U"Get frame number from time...", nullptr, 2, REAL_TimeFrameSampled_getFrameFromTime);
72 	praat_addAction1 (klas, 1,   U"Get frame from time...", U"*Get frame number from time...", praat_DEPTH_2 | praat_DEPRECATED_2004, REAL_TimeFrameSampled_getFrameFromTime);
73 }
74 
75 /* End of file praat_TimeFrameSampled.cpp */
76