praat_TimeFunction.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* praat_TimeFunction.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. #include "praat_TimeFunction.h"
  19. // MARK: - TIMEFUNCTION
  20. // MARK: Query
  21. DIRECT (REAL_TimeFunction_getStartTime) {
  22. NUMBER_ONE (Function)
  23. double result = my xmin;
  24. NUMBER_ONE_END (U" seconds")
  25. }
  26. DIRECT (REAL_TimeFunction_getEndTime) {
  27. NUMBER_ONE (Function)
  28. double result = my xmax;
  29. NUMBER_ONE_END (U" seconds")
  30. }
  31. DIRECT (REAL_TimeFunction_getTotalDuration) {
  32. NUMBER_ONE (Function)
  33. double result = my xmax - my xmin;
  34. NUMBER_ONE_END (U" seconds")
  35. }
  36. // MARK: Modify
  37. FORM (MODIFY_TimeFunction_shiftTimesBy, U"Shift times by", nullptr) {
  38. REAL (shift, U"Shift (s)", U"0.5")
  39. OK
  40. DO
  41. MODIFY_EACH (Function)
  42. Function_shiftXBy (me, shift);
  43. MODIFY_EACH_END
  44. }
  45. FORM (MODIFY_TimeFunction_shiftTimesTo, U"Shift times to", nullptr) {
  46. RADIO (shift, U"Shift", 1)
  47. OPTION (U"start time")
  48. OPTION (U"centre time")
  49. OPTION (U"end time")
  50. REAL (toTime, U"To time (s)", U"0.0")
  51. OK
  52. DO
  53. MODIFY_EACH (Function)
  54. Function_shiftXTo (me, shift == 1 ? my xmin : shift == 2 ? 0.5 * (my xmin + my xmax) : my xmax, toTime);
  55. MODIFY_EACH_END
  56. }
  57. DIRECT (MODIFY_TimeFunction_shiftToZero) {
  58. MODIFY_EACH (Function)
  59. Function_shiftXTo (me, my xmin, 0.0);
  60. MODIFY_EACH_END
  61. }
  62. FORM (MODIFY_TimeFunction_scaleTimesBy, U"Scale times by", nullptr) {
  63. POSITIVE (factor, U"Factor", U"2.0")
  64. OK
  65. DO
  66. MODIFY_EACH (Function)
  67. Function_scaleXBy (me, factor);
  68. MODIFY_EACH_END
  69. }
  70. FORM (MODIFY_TimeFunction_scaleTimesTo, U"Scale times to", nullptr) {
  71. REAL (newStartTime, U"New start time (s)", U"0.0")
  72. REAL (newEndTime, U"New end time (s)", U"1.0")
  73. OK
  74. DO
  75. if (newStartTime >= newEndTime) Melder_throw (U"New end time should be greater than new start time.");
  76. MODIFY_EACH (Function)
  77. Function_scaleXTo (me, newStartTime, newEndTime);
  78. MODIFY_EACH_END
  79. }
  80. // MARK: - buttons
  81. void praat_TimeFunction_query_init (ClassInfo klas) {
  82. praat_addAction1 (klas, 1, U"Query time domain", nullptr, 1, nullptr);
  83. praat_addAction1 (klas, 1, U"Get start time", nullptr, 2, REAL_TimeFunction_getStartTime);
  84. praat_addAction1 (klas, 1, U"Get starting time", U"*Get start time", praat_DEPTH_2 | praat_DEPRECATED_2006, REAL_TimeFunction_getStartTime);
  85. praat_addAction1 (klas, 1, U"Get end time", nullptr, 2, REAL_TimeFunction_getEndTime);
  86. praat_addAction1 (klas, 1, U"Get finishing time", U"*Get end time", praat_DEPTH_2 | praat_DEPRECATED_2006, REAL_TimeFunction_getEndTime);
  87. praat_addAction1 (klas, 1, U"Get total duration", nullptr, 2, REAL_TimeFunction_getTotalDuration);
  88. praat_addAction1 (klas, 1, U"Get duration", U"*Get total duration", praat_DEPTH_2 | praat_DEPRECATED_2004, REAL_TimeFunction_getTotalDuration);
  89. }
  90. void praat_TimeFunction_modify_init (ClassInfo klas) {
  91. praat_addAction1 (klas, 0, U"Modify times", nullptr, 1, nullptr);
  92. praat_addAction1 (klas, 0, U"Shift times by...", nullptr, 2, MODIFY_TimeFunction_shiftTimesBy);
  93. praat_addAction1 (klas, 0, U"Shift times to...", nullptr, 2, MODIFY_TimeFunction_shiftTimesTo);
  94. praat_addAction1 (klas, 0, U"Shift to zero", U"*Shift times to...", praat_DEPTH_2 | praat_DEPRECATED_2008, MODIFY_TimeFunction_shiftToZero);
  95. praat_addAction1 (klas, 0, U"Scale times by...", nullptr, 2, MODIFY_TimeFunction_scaleTimesBy);
  96. praat_addAction1 (klas, 0, U"Scale times to...", nullptr, 2, MODIFY_TimeFunction_scaleTimesTo);
  97. praat_addAction1 (klas, 0, U"Scale times...", U"*Scale times to...", praat_DEPTH_2 | praat_DEPRECATED_2008, MODIFY_TimeFunction_scaleTimesTo);
  98. }
  99. /* End of file praat_TimeFunction.cpp */