SpectrogramEditor.cpp 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* SpectrogramEditor.cpp
  2. *
  3. * Copyright (C) 1992-2011,2012,2014,2015,2016,2017 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 "SpectrogramEditor.h"
  19. Thing_implement (SpectrogramEditor, FunctionEditor, 0);
  20. void structSpectrogramEditor :: v_draw () {
  21. Spectrogram spectrogram = (Spectrogram) our data;
  22. Graphics_setWindow (our graphics.get(), 0.0, 1.0, 0.0, 1.0);
  23. Graphics_setColour (our graphics.get(), Graphics_WHITE);
  24. Graphics_fillRectangle (our graphics.get(), 0.0, 1.0, 0.0, 1.0);
  25. Graphics_setColour (our graphics.get(), Graphics_BLACK);
  26. Graphics_rectangle (our graphics.get(), 0.0, 1.0, 0.0, 1.0);
  27. integer itmin, itmax;
  28. Sampled_getWindowSamples (spectrogram, our startWindow, our endWindow, & itmin, & itmax);
  29. /*
  30. * Autoscale frequency axis.
  31. */
  32. our maximum = spectrogram -> ymax;
  33. Graphics_setWindow (our graphics.get(), our startWindow, our endWindow, 0.0, our maximum);
  34. Spectrogram_paintInside (spectrogram, our graphics.get(), our startWindow, our endWindow, 0, 0, 0.0, true,
  35. 60, 6.0, 0);
  36. /*
  37. * Horizontal scaling lines.
  38. */
  39. Graphics_setWindow (our graphics.get(), 0.0, 1.0, 0.0, our maximum);
  40. Graphics_setTextAlignment (our graphics.get(), Graphics_RIGHT, Graphics_HALF);
  41. Graphics_setColour (our graphics.get(), Graphics_RED);
  42. integer df = 1000;
  43. for (integer f = df; f <= our maximum; f += df) {
  44. Graphics_line (our graphics.get(), 0.0, f, 1.0, f);
  45. Graphics_text (our graphics.get(), -0.01, f, f, U" Hz");
  46. }
  47. /*
  48. * Vertical cursor lines.
  49. */
  50. Graphics_setWindow (our graphics.get(), our startWindow, our endWindow, 0.0, our maximum);
  51. if (our startSelection > our startWindow && our startSelection < our endWindow)
  52. Graphics_line (our graphics.get(), our startSelection, 0, our startSelection, our maximum);
  53. if (our endSelection > our startWindow && our endSelection < our endWindow)
  54. Graphics_line (our graphics.get(), our endSelection, 0, our endSelection, our maximum);
  55. Graphics_setColour (our graphics.get(), Graphics_BLACK);
  56. }
  57. bool structSpectrogramEditor :: v_click (double xWC, double yWC, bool shiftKeyPressed) {
  58. Spectrogram spectrogram = (Spectrogram) our data;
  59. /*double frequency = yWC * our maximum;*/
  60. integer bestFrame;
  61. bestFrame = Sampled_xToNearestIndex (spectrogram, xWC);
  62. if (bestFrame < 1)
  63. bestFrame = 1;
  64. else if (bestFrame > spectrogram -> nx)
  65. bestFrame = spectrogram -> nx;
  66. return our SpectrogramEditor_Parent :: v_click (xWC, yWC, shiftKeyPressed);
  67. }
  68. autoSpectrogramEditor SpectrogramEditor_create (conststring32 title, Spectrogram data) {
  69. try {
  70. autoSpectrogramEditor me = Thing_new (SpectrogramEditor);
  71. FunctionEditor_init (me.get(), title, data);
  72. my maximum = 10000.0;
  73. return me;
  74. } catch (MelderError) {
  75. Melder_throw (U"Spectrogram window not created.");
  76. }
  77. }
  78. /* End of file SpectrogramEditor.cpp */