KlattGridEditors.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /* KlattGridEditors.c
  2. *
  3. * Copyright (C) 2009-2017 david Weenink
  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. * djmw 20090123
  20. * djmw 20090128 Remove source menu from formant grid editor.
  21. * djmw 20090420 dbEditor
  22. * djmw 20090527 Protect FormantGridEditor against empty FormantGrids.
  23. * djmw 20110304 Thing_new
  24. */
  25. #include "Preferences.h"
  26. #include "KlattGridEditors.h"
  27. #include "EditorM.h"
  28. static void KlattGrid_Editor_defaultPlay (KlattGrid me, double tmin, double tmax) {
  29. my options -> xmin = tmin; my options-> xmax = tmax;
  30. KlattGrid_playSpecial (me);
  31. }
  32. /************************** KlattGrid_RealTierEditor *********************************/
  33. Thing_implement (KlattGrid_RealTierEditor, RealTierEditor, 0);
  34. static void menu_cb_KlattGridHelp (KlattGrid_RealTierEditor, EDITOR_ARGS_DIRECT) {
  35. Melder_help (U"KlattGrid");
  36. }
  37. void structKlattGrid_RealTierEditor :: v_createHelpMenuItems (EditorMenu menu) {
  38. KlattGrid_RealTierEditor_Parent :: v_createHelpMenuItems (menu);
  39. EditorMenu_addCommand (menu, U"KlattGrid help", 0, menu_cb_KlattGridHelp);
  40. }
  41. void structKlattGrid_RealTierEditor :: v_play (double ltmin, double ltmax) {
  42. KlattGrid_Editor_defaultPlay (klattgrid, ltmin, ltmax);
  43. }
  44. void KlattGrid_RealTierEditor_init (KlattGrid_RealTierEditor me, conststring32 title, KlattGrid klattgrid, RealTier data) {
  45. my klattgrid = klattgrid;
  46. RealTierEditor_init (me, title, data, nullptr, false);
  47. }
  48. /************************** KlattGrid_PitchTierEditor *********************************/
  49. Thing_implement (KlattGrid_PitchTierEditor, KlattGrid_RealTierEditor, 0);
  50. static void menu_cb_KlattGrid_PitchTierEditorHelp (KlattGrid_PitchTierEditor, EDITOR_ARGS_DIRECT) {
  51. Melder_help (U"PitchTierEditor");
  52. }
  53. static void menu_cb_PitchTierHelp (KlattGrid_PitchTierEditor, EDITOR_ARGS_DIRECT) {
  54. Melder_help (U"PitchTier");
  55. }
  56. void structKlattGrid_PitchTierEditor :: v_createHelpMenuItems (EditorMenu menu) {
  57. EditorMenu_addCommand (menu, U"PitchTierEditor help", 0, menu_cb_KlattGrid_PitchTierEditorHelp);
  58. EditorMenu_addCommand (menu, U"PitchTier help", 0, menu_cb_PitchTierHelp);
  59. }
  60. autoKlattGrid_PitchTierEditor KlattGrid_PitchTierEditor_create (conststring32 title, KlattGrid klattgrid) {
  61. try {
  62. autoKlattGrid_PitchTierEditor me = Thing_new (KlattGrid_PitchTierEditor);
  63. RealTier tier = klattgrid -> phonation -> pitch.get();
  64. KlattGrid_RealTierEditor_init (me.get(), title, klattgrid, tier);
  65. return me;
  66. } catch (MelderError) {
  67. Melder_throw (U"KlattGrid pitch window not created.");
  68. }
  69. }
  70. /************************** KlattGrid_IntensityTierEditor *********************************/
  71. Thing_implement (KlattGrid_IntensityTierEditor, KlattGrid_RealTierEditor, 0);
  72. static void menu_cb_IntensityTierHelp (KlattGrid_IntensityTierEditor, EDITOR_ARGS_DIRECT) {
  73. Melder_help (U"IntensityTier");
  74. }
  75. void structKlattGrid_IntensityTierEditor :: v_createHelpMenuItems (EditorMenu menu) {
  76. KlattGrid_IntensityTierEditor_Parent :: v_createHelpMenuItems (menu);
  77. EditorMenu_addCommand (menu, U"IntensityTier help", 0, menu_cb_IntensityTierHelp);
  78. }
  79. void KlattGrid_IntensityTierEditor_init (KlattGrid_IntensityTierEditor me, conststring32 title, KlattGrid klattgrid, RealTier tier) {
  80. KlattGrid_RealTierEditor_init (me, title, klattgrid, tier);
  81. }
  82. /************************** KlattGrid_DecibelTierEditor *********************************/
  83. Thing_implement (KlattGrid_DecibelTierEditor, KlattGrid_IntensityTierEditor, 0);
  84. autoKlattGrid_DecibelTierEditor KlattGrid_DecibelTierEditor_create (conststring32 title, KlattGrid klattgrid, RealTier tier) {
  85. try {
  86. autoKlattGrid_DecibelTierEditor me = Thing_new (KlattGrid_DecibelTierEditor);
  87. KlattGrid_IntensityTierEditor_init (me.get(), title, klattgrid, tier);
  88. return me;
  89. } catch (MelderError) {
  90. Melder_throw (U"KlattGrid decibel window not created.");
  91. }
  92. }
  93. /************************** KlattGrid_VoicingAmplitudeTierEditor *********************************/
  94. Thing_implement (KlattGrid_VoicingAmplitudeTierEditor, KlattGrid_IntensityTierEditor, 0);
  95. autoKlattGrid_VoicingAmplitudeTierEditor KlattGrid_VoicingAmplitudeTierEditor_create (conststring32 title, KlattGrid klattgrid) {
  96. try {
  97. autoKlattGrid_VoicingAmplitudeTierEditor me = Thing_new (KlattGrid_VoicingAmplitudeTierEditor);
  98. RealTier tier = klattgrid -> phonation -> voicingAmplitude.get();
  99. KlattGrid_IntensityTierEditor_init (me.get(), title, klattgrid, tier);
  100. return me;
  101. } catch (MelderError) {
  102. Melder_throw (U"KlattGrid voicing amplitude window not created.");
  103. }
  104. }
  105. /************************** KlattGrid_AspirationAmplitudeTierEditor *********************************/
  106. Thing_implement (KlattGrid_AspirationAmplitudeTierEditor, KlattGrid_IntensityTierEditor, 0);
  107. autoKlattGrid_AspirationAmplitudeTierEditor KlattGrid_AspirationAmplitudeTierEditor_create (conststring32 title, KlattGrid klattgrid) {
  108. try {
  109. autoKlattGrid_AspirationAmplitudeTierEditor me = Thing_new (KlattGrid_AspirationAmplitudeTierEditor);
  110. RealTier tier = klattgrid -> phonation -> aspirationAmplitude.get();
  111. KlattGrid_IntensityTierEditor_init (me.get(), title, klattgrid, tier);
  112. return me;
  113. } catch (MelderError) {
  114. Melder_throw (U"KlattGrid aspiration amplitude window not created.");
  115. }
  116. }
  117. /************************** KlattGrid_BreathinessAmplitudeTierEditor *********************************/
  118. Thing_implement (KlattGrid_BreathinessAmplitudeTierEditor, KlattGrid_IntensityTierEditor, 0);
  119. autoKlattGrid_BreathinessAmplitudeTierEditor KlattGrid_BreathinessAmplitudeTierEditor_create (conststring32 title, KlattGrid klattgrid) {
  120. try {
  121. autoKlattGrid_BreathinessAmplitudeTierEditor me = Thing_new (KlattGrid_BreathinessAmplitudeTierEditor);
  122. RealTier tier = klattgrid -> phonation -> breathinessAmplitude.get();
  123. KlattGrid_IntensityTierEditor_init (me.get(), title, klattgrid, tier);
  124. return me;
  125. } catch (MelderError) {
  126. Melder_throw (U"KlattGrid breathiness amplitude window not created.");
  127. }
  128. }
  129. /************************** KlattGrid_SpectralTiltTierEditor *********************************/
  130. Thing_implement (KlattGrid_SpectralTiltTierEditor, KlattGrid_IntensityTierEditor, 0);
  131. autoKlattGrid_SpectralTiltTierEditor KlattGrid_SpectralTiltTierEditor_create (conststring32 title, KlattGrid klattgrid) {
  132. try {
  133. autoKlattGrid_SpectralTiltTierEditor me = Thing_new (KlattGrid_SpectralTiltTierEditor);
  134. RealTier tier = klattgrid -> phonation -> spectralTilt.get();
  135. KlattGrid_IntensityTierEditor_init (me.get(), title, klattgrid, tier);
  136. return me;
  137. } catch (MelderError) {
  138. Melder_throw (U"KlattGrid spectral tilt window not created.");
  139. }
  140. }
  141. /************************** KlattGrid_FricationBypassTierEditor *********************************/
  142. Thing_implement (KlattGrid_FricationBypassTierEditor, KlattGrid_IntensityTierEditor, 0);
  143. autoKlattGrid_FricationBypassTierEditor KlattGrid_FricationBypassTierEditor_create (conststring32 title, KlattGrid klattgrid) {
  144. try {
  145. autoKlattGrid_FricationBypassTierEditor me = Thing_new (KlattGrid_FricationBypassTierEditor);
  146. RealTier tier = klattgrid -> frication -> bypass.get();
  147. KlattGrid_IntensityTierEditor_init (me.get(), title, klattgrid, tier);
  148. return me;
  149. } catch (MelderError) {
  150. Melder_throw (U"KlattGrid frication bypass window not created.");
  151. }
  152. }
  153. /************************** KlattGrid_FricationAmplitudeTierEditor *********************************/
  154. Thing_implement (KlattGrid_FricationAmplitudeTierEditor, KlattGrid_IntensityTierEditor, 0);
  155. autoKlattGrid_FricationAmplitudeTierEditor KlattGrid_FricationAmplitudeTierEditor_create (conststring32 title, KlattGrid klattgrid) {
  156. try {
  157. autoKlattGrid_FricationAmplitudeTierEditor me = Thing_new (KlattGrid_FricationAmplitudeTierEditor);
  158. RealTier tier = klattgrid -> frication -> fricationAmplitude.get();
  159. KlattGrid_IntensityTierEditor_init (me.get(), title, klattgrid, tier);
  160. return me;
  161. } catch (MelderError) {
  162. Melder_throw (U"KlattGrid frication amplitude window not created.");
  163. }
  164. }
  165. /************************** KlattGrid_OpenPhaseTierEditor *********************************/
  166. Thing_implement (KlattGrid_OpenPhaseTierEditor, KlattGrid_RealTierEditor, 0);
  167. autoKlattGrid_OpenPhaseTierEditor KlattGrid_OpenPhaseTierEditor_create (conststring32 title, KlattGrid klattgrid) {
  168. try {
  169. autoKlattGrid_OpenPhaseTierEditor me = Thing_new (KlattGrid_OpenPhaseTierEditor);
  170. RealTier tier = klattgrid -> phonation -> openPhase.get();
  171. KlattGrid_RealTierEditor_init (me.get(), title, klattgrid, tier);
  172. return me;
  173. } catch (MelderError) {
  174. Melder_throw (U"KlattGrid open phase window not created.");
  175. }
  176. }
  177. /************************** KlattGrid_CollisionPhaseTierEditor *********************************/
  178. Thing_implement (KlattGrid_CollisionPhaseTierEditor, KlattGrid_RealTierEditor, 0);
  179. autoKlattGrid_CollisionPhaseTierEditor KlattGrid_CollisionPhaseTierEditor_create (conststring32 title, KlattGrid klattgrid) {
  180. try {
  181. autoKlattGrid_CollisionPhaseTierEditor me = Thing_new (KlattGrid_CollisionPhaseTierEditor);
  182. RealTier tier = klattgrid -> phonation -> collisionPhase.get();
  183. KlattGrid_RealTierEditor_init (me.get(), title, klattgrid, tier);
  184. return me;
  185. } catch (MelderError) {
  186. Melder_throw (U"KlattGrid collision phase window not created.");
  187. }
  188. }
  189. /************************** KlattGrid_Power1TierEditor *********************************/
  190. Thing_implement (KlattGrid_Power1TierEditor, KlattGrid_RealTierEditor, 0);
  191. autoKlattGrid_Power1TierEditor KlattGrid_Power1TierEditor_create (conststring32 title, KlattGrid klattgrid) {
  192. try {
  193. autoKlattGrid_Power1TierEditor me = Thing_new (KlattGrid_Power1TierEditor);
  194. RealTier tier = klattgrid -> phonation -> power1.get();
  195. KlattGrid_RealTierEditor_init (me.get(), title, klattgrid, tier);
  196. return me;
  197. } catch (MelderError) {
  198. Melder_throw (U"KlattGrid power1 window not created.");
  199. }
  200. }
  201. /************************** KlattGrid_Power2TierEditor *********************************/
  202. Thing_implement (KlattGrid_Power2TierEditor, KlattGrid_RealTierEditor, 0);
  203. autoKlattGrid_Power2TierEditor KlattGrid_Power2TierEditor_create (conststring32 title, KlattGrid klattgrid) {
  204. try {
  205. autoKlattGrid_Power2TierEditor me = Thing_new (KlattGrid_Power2TierEditor);
  206. RealTier tier = klattgrid -> phonation -> power2.get();
  207. KlattGrid_RealTierEditor_init (me.get(), title, klattgrid, tier);
  208. return me;
  209. } catch (MelderError) {
  210. Melder_throw (U"KlattGrid power2 window not created.");
  211. }
  212. }
  213. /************************** KlattGrid_FlutterTierEditor *********************************/
  214. Thing_implement (KlattGrid_FlutterTierEditor, KlattGrid_RealTierEditor, 0);
  215. autoKlattGrid_FlutterTierEditor KlattGrid_FlutterTierEditor_create (conststring32 title, KlattGrid klattgrid) {
  216. try {
  217. autoKlattGrid_FlutterTierEditor me = Thing_new (KlattGrid_FlutterTierEditor);
  218. RealTier tier = klattgrid -> phonation -> flutter.get();
  219. KlattGrid_RealTierEditor_init (me.get(), title, klattgrid, tier);
  220. return me;
  221. } catch (MelderError) {
  222. Melder_throw (U"KlattGrid flutter window not created.");
  223. }
  224. }
  225. /************************** KlattGrid_DoublePulsingTierEditor *********************************/
  226. Thing_implement (KlattGrid_DoublePulsingTierEditor, KlattGrid_RealTierEditor, 0);
  227. autoKlattGrid_DoublePulsingTierEditor KlattGrid_DoublePulsingTierEditor_create (conststring32 title, KlattGrid klattgrid) {
  228. try {
  229. autoKlattGrid_DoublePulsingTierEditor me = Thing_new (KlattGrid_DoublePulsingTierEditor);
  230. RealTier tier = klattgrid -> phonation -> doublePulsing.get();
  231. KlattGrid_RealTierEditor_init (me.get(), title, klattgrid, tier);
  232. return me;
  233. } catch (MelderError) {
  234. Melder_throw (U"KlattGrid double pulsing window not created.");
  235. }
  236. }
  237. /************************** KlattGrid_FormantGridEditor *********************************/
  238. Thing_implement (KlattGrid_FormantGridEditor, FormantGridEditor, 0);
  239. static bool FormantGrid_isEmpty (FormantGrid me) {
  240. return my formants.size == 0 || my bandwidths.size == 0;
  241. }
  242. void structKlattGrid_FormantGridEditor :: v_play (double ltmin, double ltmax) {
  243. KlattGrid_Editor_defaultPlay (klattgrid, ltmin, ltmax);
  244. }
  245. autoKlattGrid_FormantGridEditor KlattGrid_FormantGridEditor_create (conststring32 title, KlattGrid data, int formantType) {
  246. try {
  247. Melder_assert (data);
  248. autoFormantGrid* fg = KlattGrid_getAddressOfFormantGrid (data, formantType);
  249. Melder_require (fg, U"Formant type unknown.");
  250. Melder_require (! FormantGrid_isEmpty (fg -> get()), U"Cannot edit an empty formant grid.");
  251. autoKlattGrid_FormantGridEditor me = Thing_new (KlattGrid_FormantGridEditor);
  252. my klattgrid = data;
  253. FormantGridEditor_init (me.get(), title, fg->get());
  254. return me;
  255. } catch (MelderError) {
  256. Melder_throw (U"KlattGrid formant window not created.");
  257. }
  258. }
  259. /* End of file KlattGridEditors.cpp */