MovieWindow.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* MovieWindow.cpp
  2. *
  3. * Copyright (C) 2011-2012,2013,2014,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 "MovieWindow.h"
  19. #include "EditorM.h"
  20. Thing_implement (MovieWindow, TimeSoundAnalysisEditor, 0);
  21. /********** MENU COMMANDS **********/
  22. void structMovieWindow :: v_createMenuItems_view (EditorMenu menu) {
  23. our MovieWindow_Parent :: v_createMenuItems_view (menu);
  24. //EditorMenu_addCommand (menu, L"-- view/realtier --", 0, 0);
  25. //EditorMenu_addCommand (menu, v_setRangeTitle (), 0, menu_cb_setRange);
  26. }
  27. void structMovieWindow :: v_createMenus () {
  28. our MovieWindow_Parent :: v_createMenus ();
  29. //EditorMenu menu = Editor_addMenu (this, L"Movie", 0);
  30. //EditorMenu_addCommand (menu, L"Add point at cursor", 'T', menu_cb_addPointAtCursor);
  31. our v_createMenus_analysis (); // insert some of the ancestor's menus *after* the Movie menus
  32. }
  33. /********** DRAWING AREA **********/
  34. /**
  35. * @returns a value between 0.0 and 1.0; depends on whether the Sound and/or analyses are visible
  36. */
  37. static double _MovieWindow_getSoundBottomPosition (MovieWindow me) {
  38. Movie movie = (Movie) my data;
  39. bool showAnalysis = (my p_spectrogram_show || my p_pitch_show || my p_intensity_show || my p_formant_show) && movie -> d_sound;
  40. return movie -> d_sound ? (showAnalysis ? 0.7 : 0.3) : 1.0;
  41. }
  42. void structMovieWindow :: v_draw () {
  43. Movie movie = (Movie) our data;
  44. bool showAnalysis = (our p_spectrogram_show || our p_pitch_show || our p_intensity_show || our p_formant_show) && movie -> d_sound;
  45. double soundY = _MovieWindow_getSoundBottomPosition (this);
  46. if (movie -> d_sound) {
  47. Graphics_Viewport viewport = Graphics_insetViewport (our graphics.get(), 0.0, 1.0, soundY, 1.0);
  48. Graphics_setColour (our graphics.get(), Graphics_WHITE);
  49. Graphics_setWindow (our graphics.get(), 0.0, 1.0, 0.0, 1.0);
  50. Graphics_fillRectangle (our graphics.get(), 0.0, 1.0, 0.0, 1.0);
  51. TimeSoundEditor_drawSound (this, -1.0, 1.0);
  52. Graphics_flushWs (our graphics.get());
  53. Graphics_resetViewport (our graphics.get(), viewport);
  54. }
  55. if (true) {
  56. Graphics_Viewport viewport = Graphics_insetViewport (our graphics.get(), 0.0, 1.0, 0.0, 0.3);
  57. Graphics_setColour (our graphics.get(), Graphics_WHITE);
  58. Graphics_setWindow (our graphics.get(), 0.0, 1.0, 0.0, 1.0);
  59. Graphics_fillRectangle (our graphics.get(), 0.0, 1.0, 0.0, 1.0);
  60. Graphics_setColour (our graphics.get(), Graphics_BLACK);
  61. Graphics_setWindow (our graphics.get(), our startWindow, our endWindow, 0.0, 1.0);
  62. integer firstFrame = Sampled_xToNearestIndex (movie, our startWindow);
  63. integer lastFrame = Sampled_xToNearestIndex (movie, our endWindow);
  64. if (firstFrame < 1) firstFrame = 1;
  65. if (lastFrame > movie -> nx) lastFrame = movie -> nx;
  66. for (integer iframe = firstFrame; iframe <= lastFrame; iframe ++) {
  67. double time = Sampled_indexToX (movie, iframe);
  68. double timeLeft = time - 0.5 * movie -> dx, timeRight = time + 0.5 * movie -> dx;
  69. if (timeLeft < our startWindow) timeLeft = our startWindow;
  70. if (timeRight > our endWindow) timeRight = our endWindow;
  71. Movie_paintOneImageInside (movie, our graphics.get(), iframe, timeLeft, timeRight, 0.0, 1.0);
  72. }
  73. Graphics_flushWs (our graphics.get());
  74. Graphics_resetViewport (our graphics.get(), viewport);
  75. }
  76. if (showAnalysis) {
  77. Graphics_Viewport viewport = Graphics_insetViewport (our graphics.get(), 0.0, 1.0, 0.3, soundY);
  78. our v_draw_analysis ();
  79. Graphics_flushWs (our graphics.get());
  80. Graphics_resetViewport (our graphics.get(), viewport);
  81. /* Draw pulses. */
  82. if (our p_pulses_show) {
  83. viewport = Graphics_insetViewport (our graphics.get(), 0.0, 1.0, soundY, 1.0);
  84. our v_draw_analysis_pulses ();
  85. TimeSoundEditor_drawSound (this, -1.0, 1.0); // second time, partially across the pulses
  86. Graphics_flushWs (our graphics.get());
  87. Graphics_resetViewport (our graphics.get(), viewport);
  88. }
  89. }
  90. our v_updateMenuItems_file ();
  91. }
  92. void structMovieWindow :: v_highlightSelection (double left, double right, double bottom, double top) {
  93. if (our p_spectrogram_show)
  94. Graphics_highlight (our graphics.get(), left, right, 0.3 * bottom + 0.7 * top, top);
  95. else
  96. Graphics_highlight (our graphics.get(), left, right, 0.7 * bottom + 0.3 * top, top);
  97. }
  98. void structMovieWindow :: v_unhighlightSelection (double left, double right, double bottom, double top) {
  99. if (our p_spectrogram_show)
  100. Graphics_highlight (our graphics.get(), left, right, 0.3 * bottom + 0.7 * top, top);
  101. else
  102. Graphics_highlight (our graphics.get(), left, right, 0.7 * bottom + 0.3 * top, top);
  103. }
  104. bool structMovieWindow :: v_click (double xWC, double yWC, bool shiftKeyPressed) {
  105. return our MovieWindow_Parent :: v_click (xWC, yWC, shiftKeyPressed);
  106. }
  107. void structMovieWindow :: v_play (double tmin, double tmax) {
  108. Movie movie = (Movie) data;
  109. Movie_play (movie, our graphics.get(), tmin, tmax, theFunctionEditor_playCallback, this);
  110. }
  111. void MovieWindow_init (MovieWindow me, conststring32 title, Movie movie) {
  112. Melder_assert (movie);
  113. TimeSoundAnalysisEditor_init (me, title, movie, movie -> d_sound.get(), false);
  114. }
  115. autoMovieWindow MovieWindow_create (conststring32 title, Movie movie) {
  116. try {
  117. autoMovieWindow me = Thing_new (MovieWindow);
  118. MovieWindow_init (me.get(), title, movie);
  119. return me;
  120. } catch (MelderError) {
  121. Melder_throw (U"Movie window not created.");
  122. }
  123. }
  124. /* End of file MovieWindow.cpp */