praat_TimeTier.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #include "praat_TimeTier.h"
  19. // MARK: TIMETIER
  20. // MARK: Query
  21. DIRECT (INTEGER_TimeTier_getNumberOfPoints) {
  22. NUMBER_ONE (AnyTier)
  23. integer result = my points.size;
  24. NUMBER_ONE_END (U" points")
  25. }
  26. FORM (INTEGER_TimeTier_getLowIndexFromTime, U"Get low index", U"AnyTier: Get low index from time...") {
  27. REAL (time, U"Time (s)", U"0.5")
  28. OK
  29. DO
  30. FIND_ONE (AnyTier)
  31. Melder_information (my points.size == 0 ? U"--undefined--" : Melder_integer (AnyTier_timeToLowIndex (me, time)));
  32. END
  33. }
  34. FORM (INTEGER_TimeTier_getHighIndexFromTime, U"Get high index", U"AnyTier: Get high index from time...") {
  35. REAL (time, U"Time (s)", U"0.5")
  36. OK
  37. DO
  38. FIND_ONE (AnyTier)
  39. Melder_information (my points.size == 0 ? U"--undefined--" : Melder_integer (AnyTier_timeToHighIndex (me, time)));
  40. END
  41. }
  42. FORM (INTEGER_TimeTier_getNearestIndexFromTime, U"Get nearest index", U"AnyTier: Get nearest index from time...") {
  43. REAL (time, U"Time (s)", U"0.5")
  44. OK
  45. DO
  46. FIND_ONE (AnyTier)
  47. Melder_information (my points.size == 0 ? U"--undefined--" : Melder_integer (AnyTier_timeToNearestIndex (me, time)));
  48. END
  49. }
  50. FORM (REAL_TimeTier_getTimeFromIndex, U"Get time", nullptr /*"AnyTier: Get time from index..."*/) {
  51. NATURAL (pointNumber, U"Point number", U"10")
  52. OK
  53. DO
  54. FIND_ONE (AnyTier)
  55. if (pointNumber > my points.size) Melder_information (U"--undefined--");
  56. else Melder_informationReal (my points.at [pointNumber] -> number, U"seconds");
  57. END
  58. }
  59. // MARK: Modify
  60. FORM (MODIFY_TimeTier_removePoint, U"Remove one point", U"AnyTier: Remove point...") {
  61. NATURAL (pointNumber, U"Point number", U"1")
  62. OK
  63. DO
  64. MODIFY_EACH (AnyTier)
  65. AnyTier_removePoint (me, pointNumber);
  66. MODIFY_EACH_END
  67. }
  68. FORM (MODIFY_TimeTier_removePointNear, U"Remove one point", U"AnyTier: Remove point near...") {
  69. REAL (time, U"Time (s)", U"0.5")
  70. OK
  71. DO
  72. MODIFY_EACH (AnyTier)
  73. AnyTier_removePointNear (me, time);
  74. MODIFY_EACH_END
  75. }
  76. FORM (MODIFY_TimeTier_removePointsBetween, U"Remove points", U"AnyTier: Remove points between...") {
  77. REAL (fromTime, U"left Time range (s)", U"0.0")
  78. REAL (toTime, U"right Time range (s)", U"1.0")
  79. OK
  80. DO
  81. MODIFY_EACH (AnyTier)
  82. AnyTier_removePointsBetween (me, fromTime, toTime);
  83. MODIFY_EACH_END
  84. }
  85. // MARK: - buttons
  86. void praat_TimeTier_query_init (ClassInfo klas) {
  87. praat_TimeFunction_query_init (klas);
  88. praat_addAction1 (klas, 1, U"Get number of points", nullptr, 1, INTEGER_TimeTier_getNumberOfPoints);
  89. praat_addAction1 (klas, 1, U"Get low index from time...", nullptr, 1, INTEGER_TimeTier_getLowIndexFromTime);
  90. praat_addAction1 (klas, 1, U"Get high index from time...", nullptr, 1, INTEGER_TimeTier_getHighIndexFromTime);
  91. praat_addAction1 (klas, 1, U"Get nearest index from time...", nullptr, 1, INTEGER_TimeTier_getNearestIndexFromTime);
  92. praat_addAction1 (klas, 1, U"Get time from index...", nullptr, 1, REAL_TimeTier_getTimeFromIndex);
  93. }
  94. void praat_TimeTier_modify_init (ClassInfo klas) {
  95. praat_TimeFunction_modify_init (klas);
  96. praat_addAction1 (klas, 0, U"Remove point...", nullptr, 1, MODIFY_TimeTier_removePoint);
  97. praat_addAction1 (klas, 0, U"Remove point near...", nullptr, 1, MODIFY_TimeTier_removePointNear);
  98. praat_addAction1 (klas, 0, U"Remove points between...", nullptr, 1, MODIFY_TimeTier_removePointsBetween);
  99. }
  100. /* End of file praat_TimeTier.cpp */