FormantGrid_extensions.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* FormantGrid_extensions.cpp
  2. *
  3. * Copyright (C) 2009-2017 David Weenink, 2015 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. See the GNU
  13. * 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 "FormantGrid_extensions.h"
  19. #include "NUM2.h"
  20. void FormantGrid_draw (FormantGrid me, Graphics g, double xmin, double xmax, double ymin, double ymax,
  21. bool bandwidths, bool garnish, conststring32 method)
  22. {
  23. OrderedOf<structRealTier>* tiers = bandwidths ? & my bandwidths : & my formants;
  24. if (xmax <= xmin) {
  25. xmin = my xmin;
  26. xmax = my xmax;
  27. }
  28. if (ymax <= ymin) {
  29. ymin = 0.0;
  30. ymax = bandwidths ? 1000.0 : 8000.0;
  31. }
  32. for (integer iformant = 1; iformant <= tiers->size; iformant ++) {
  33. conststring32 quantity = nullptr;
  34. bool garnish2 = false;
  35. RealTier tier = tiers->at [iformant];
  36. if (iformant == my formants.size) {
  37. quantity = U"Frequency (Hz)";
  38. if (garnish)
  39. garnish2 = true;
  40. }
  41. RealTier_draw (tier, g, xmin, xmax, ymin, ymax, garnish2, method, quantity);
  42. }
  43. }
  44. static void FormantGrid_removeFormantTier (FormantGrid me, integer position) {
  45. if (position < 1 || position > my formants.size)
  46. return;
  47. my formants. removeItem (position);
  48. }
  49. static void FormantGrid_removeBandwidthTier (FormantGrid me, integer position) {
  50. if (position < 1 || position > my bandwidths.size)
  51. return;
  52. my bandwidths. removeItem (position);
  53. }
  54. void FormantGrid_removeFormantAndBandwidthTiers (FormantGrid me, integer position) {
  55. FormantGrid_removeFormantTier (me, position);
  56. FormantGrid_removeBandwidthTier (me, position);
  57. }
  58. static void FormantGrid_addFormantTier (FormantGrid me, integer position) {
  59. if (position > my formants.size || position < 1)
  60. position = my formants.size + 1;
  61. autoRealTier rt = RealTier_create (my xmin, my xmax);
  62. my formants. addItemAtPosition_move (rt.move(), position);
  63. }
  64. static void FormantGrid_addBandwidthTier (FormantGrid me, integer position) {
  65. if (position > my bandwidths.size || position < 1)
  66. position = my bandwidths.size + 1;
  67. autoRealTier rt = RealTier_create (my xmin, my xmax);
  68. my bandwidths. addItemAtPosition_move (rt.move(), position);
  69. }
  70. void FormantGrid_addFormantAndBandwidthTiers (FormantGrid me, integer position) {
  71. try {
  72. Melder_require (my formants.size == my bandwidths.size, U"Number of formants and bandwidths should be equal.");
  73. if (position > my formants.size || position < 1)
  74. position = my formants.size + 1;
  75. FormantGrid_addFormantTier (me, position);
  76. try {
  77. FormantGrid_addBandwidthTier (me, position);
  78. } catch (MelderError) {
  79. FormantGrid_removeFormantTier (me, position);
  80. throw;
  81. }
  82. } catch (MelderError) {
  83. Melder_throw (me, U": no ties added.");
  84. }
  85. }
  86. /* End of file FormantGrid_extensions.cpp */