Debian Codegraph @

fon/praat_TimeFunction.cpp

raw
1 /* praat_TimeFunction.cpp
2 *
3 * Copyright (C) 1992-2017,2022,2023 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_TimeFunction.h"
20
21 // MARK: - TIMEFUNCTION
22
23 // MARK: Query
24
25 DIRECT (REAL_TimeFunction_getStartTime) {
26 QUERY_ONE_FOR_REAL (Function)
27 double result = my xmin;
28 QUERY_ONE_FOR_REAL_END (U" seconds")
29 }
30
31 DIRECT (REAL_TimeFunction_getEndTime) {
32 QUERY_ONE_FOR_REAL (Function)
33 double result = my xmax;
34 QUERY_ONE_FOR_REAL_END (U" seconds")
35 }
36
37 DIRECT (REAL_TimeFunction_getTotalDuration) {
38 QUERY_ONE_FOR_REAL (Function)
39 double result = my xmax - my xmin;
40 QUERY_ONE_FOR_REAL_END (U" seconds")
41 }
42
43 // MARK: Modify
44
45 FORM (MODIFY_TimeFunction_shiftTimesBy, U"Shift times by", nullptr) {
46 REAL (shift, U"Shift (s)", U"0.5")
47 OK
48 DO
49 MODIFY_EACH (Function)
50 Function_shiftXBy (me, shift);
51 MODIFY_EACH_END
52 }
53
54 FORM (MODIFY_TimeFunction_shiftTimesTo, U"Shift times to", nullptr) {
55 CHOICE (shift, U"Shift", 1)
56 OPTION (U"start time")
57 OPTION (U"centre time")
58 OPTION (U"end time")
59 REAL (toTime, U"To time (s)", U"0.0")
60 OK
61 DO
62 MODIFY_EACH (Function)
63 Function_shiftXTo (me, shift == 1 ? my xmin : shift == 2 ? 0.5 * (my xmin + my xmax) : my xmax, toTime);
64 MODIFY_EACH_END
65 }
66
67 DIRECT (MODIFY_TimeFunction_shiftToZero) {
68 MODIFY_EACH (Function)
69 Function_shiftXTo (me, my xmin, 0.0);
70 MODIFY_EACH_END
71 }
72
73 FORM (MODIFY_TimeFunction_scaleTimesBy, U"Scale times by", nullptr) {
74 POSITIVE (factor, U"Factor", U"2.0")
75 OK
76 DO
77 MODIFY_EACH (Function)
78 Function_scaleXBy (me, factor);
79 MODIFY_EACH_END
80 }
81
82 FORM (MODIFY_TimeFunction_scaleTimesTo, U"Scale times to", nullptr) {
83 REAL (newStartTime, U"New start time (s)", U"0.0")
84 REAL (newEndTime, U"New end time (s)", U"1.0")
85 OK
86 DO
87 if (newStartTime >= newEndTime) Melder_throw (U"New end time should be greater than new start time.");
88 MODIFY_EACH (Function)
89 Function_scaleXTo (me, newStartTime, newEndTime);
90 MODIFY_EACH_END
91 }
92
93 // MARK: - buttons
94
95 void praat_TimeFunction_query_init (ClassInfo klas) {
96 praat_addAction1 (klas, 1, U"Query time domain", nullptr, 1, nullptr);
97 praat_addAction1 (klas, 1, U"Get start time || Get starting time", nullptr, 2, REAL_TimeFunction_getStartTime);
98 // alternatives COMPATIBILITY <= 2006
99 praat_addAction1 (klas, 1, U"Get end time || Get finishing time", nullptr, 2, REAL_TimeFunction_getEndTime);
100 // alternatives COMPATIBILITY <= 2006
101 praat_addAction1 (klas, 1, U"Get total duration || Get duration", nullptr, 2, REAL_TimeFunction_getTotalDuration);
102 // alternatives COMPATIBILITY <= 2004
103 }
104
105 void praat_TimeFunction_modify_init (ClassInfo klas) {
106 praat_addAction1 (klas, 0, U"Modify times", nullptr, 1, nullptr);
107 praat_addAction1 (klas, 0, U"Shift times by...", nullptr, 2, MODIFY_TimeFunction_shiftTimesBy);
108 praat_addAction1 (klas, 0, U"Shift times to...", nullptr, 2, MODIFY_TimeFunction_shiftTimesTo);
109 praat_addAction1 (klas, 0, U"Shift to zero", nullptr, GuiMenu_DEPTH_2 | GuiMenu_DEPRECATED_2008, MODIFY_TimeFunction_shiftToZero);
110 // replace with "Shift times to..."
111 praat_addAction1 (klas, 0, U"Scale times by...", nullptr, 2, MODIFY_TimeFunction_scaleTimesBy);
112 praat_addAction1 (klas, 0, U"Scale times to... || Scale times...", nullptr, 2, MODIFY_TimeFunction_scaleTimesTo);
113 // alternatives COMPATIBILITY <= 2008
114 }
115
116 /* End of file praat_TimeFunction.cpp */